[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 16/64] PPC: KVM: Add generic function to read host c
From: |
Alexander Graf |
Subject: |
[Qemu-devel] [PATCH 16/64] PPC: KVM: Add generic function to read host clockfreq |
Date: |
Thu, 6 Oct 2011 10:05:18 +0200 |
We need to find out the host's clock-frequency when running on KVM, so
let's export a respective function.
Signed-off-by: Alexander Graf <address@hidden>
---
v1 -> v2:
- enable 64bit values
---
target-ppc/kvm.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++
target-ppc/kvm_ppc.h | 1 +
2 files changed, 68 insertions(+), 0 deletions(-)
diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
index 21f35af..77b98c4 100644
--- a/target-ppc/kvm.c
+++ b/target-ppc/kvm.c
@@ -14,6 +14,7 @@
*
*/
+#include <dirent.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
@@ -38,6 +39,8 @@
do { } while (0)
#endif
+#define PROC_DEVTREE_CPU "/proc/device-tree/cpus/"
+
const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
KVM_CAP_LAST_INFO
};
@@ -509,6 +512,70 @@ uint32_t kvmppc_get_tbfreq(void)
return retval;
}
+/* Try to find a device tree node for a CPU with clock-frequency property */
+static int kvmppc_find_cpu_dt(char *buf, int buf_len)
+{
+ struct dirent *dirp;
+ DIR *dp;
+
+ if ((dp = opendir(PROC_DEVTREE_CPU)) == NULL) {
+ printf("Can't open directory " PROC_DEVTREE_CPU "\n");
+ return -1;
+ }
+
+ buf[0] = '\0';
+ while ((dirp = readdir(dp)) != NULL) {
+ FILE *f;
+ snprintf(buf, buf_len, "%s%s/clock-frequency", PROC_DEVTREE_CPU,
+ dirp->d_name);
+ f = fopen(buf, "r");
+ if (f) {
+ snprintf(buf, buf_len, "%s%s", PROC_DEVTREE_CPU, dirp->d_name);
+ fclose(f);
+ break;
+ }
+ buf[0] = '\0';
+ }
+ closedir(dp);
+ if (buf[0] == '\0') {
+ printf("Unknown host!\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+uint64_t kvmppc_get_clockfreq(void)
+{
+ char buf[512];
+ uint32_t tb[2];
+ FILE *f;
+ int len;
+
+ if (kvmppc_find_cpu_dt(buf, sizeof(buf))) {
+ return 0;
+ }
+
+ strncat(buf, "/clock-frequency", sizeof(buf) - strlen(buf));
+
+ f = fopen(buf, "rb");
+ if (!f) {
+ return -1;
+ }
+
+ len = fread(tb, sizeof(tb[0]), 2, f);
+ fclose(f);
+ switch (len) {
+ case 1:
+ /* freq is only a single cell */
+ return tb[0];
+ case 2:
+ return *(uint64_t*)tb;
+ }
+
+ return 0;
+}
+
int kvmppc_get_hypercall(CPUState *env, uint8_t *buf, int buf_len)
{
uint32_t *hc = (uint32_t*)buf;
diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h
index 2f32249..7c08c0f 100644
--- a/target-ppc/kvm_ppc.h
+++ b/target-ppc/kvm_ppc.h
@@ -23,6 +23,7 @@ int kvmppc_read_host_property(const char *node_path, const
char *prop,
#endif
uint32_t kvmppc_get_tbfreq(void);
+uint64_t kvmppc_get_clockfreq(void);
int kvmppc_get_hypercall(CPUState *env, uint8_t *buf, int buf_len);
int kvmppc_set_interrupt(CPUState *env, int irq, int level);
--
1.6.0.2
- [Qemu-devel] [PATCH 04/64] PPC: Move openpic to target specific code compilation, (continued)
- [Qemu-devel] [PATCH 04/64] PPC: Move openpic to target specific code compilation, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 18/64] PPC: E500: Remove mpc8544_copy_soc_cell, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 08/64] PPC: Set MPIC IDE for IPI to 0, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 06/64] PPC: Extend MPIC MMIO range, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 15/64] PPC: bamboo: Move host fdt copy to target, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 05/64] PPC: Add CPU local MMIO regions to MPIC, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 22/64] PPC: E500: Update freqs for all CPUs, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 20/64] PPC: KVM: Remove kvmppc_read_host_property, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 28/64] device tree: give dt more size, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 32/64] PPC: Add new target config for pseries, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 16/64] PPC: KVM: Add generic function to read host clockfreq,
Alexander Graf <=
- [Qemu-devel] [PATCH 07/64] PPC: Fix IPI support in MPIC, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 30/64] MPC8544DS: Generate CPU nodes on init, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 01/64] spapr: proper qdevification, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 17/64] PPC: E500: Use generic kvm function for freq, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 25/64] PPC: E500: Update cpu-release-addr property in cpu nodes, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 35/64] PPC: SPAPR: Use KVM function for time info, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 29/64] MPC8544DS: Remove CPU nodes, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 21/64] PPC: KVM: Add stubs for kvm helper functions, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 38/64] pseries: interrupt controller should not have a 'reg' property, Alexander Graf, 2011/10/06
- [Qemu-devel] [PATCH 09/64] PPC: MPIC: Remove read functionality for WO registers, Alexander Graf, 2011/10/06