[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 14/23] PPC: KVM: Add generic function to read ho
From: |
Scott Wood |
Subject: |
Re: [Qemu-devel] [PATCH 14/23] PPC: KVM: Add generic function to read host clockfreq |
Date: |
Thu, 21 Jul 2011 12:51:18 -0500 |
On Thu, 21 Jul 2011 03:27:25 +0200
Alexander Graf <address@hidden> wrote:
> +/* 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, "%scpus/%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;
> + }
"Unknown host!" is a little vague for an error message.
> +uint32_t kvmppc_get_clockfreq(void)
> +{
> + char buf[512];
> + uint32_t tb;
> + FILE *f;
> + int len;
> +
> + if (kvmppc_find_cpu_dt(buf, sizeof(buf))) {
> + return 0;
> + }
> +
> + snprintf(buf, sizeof(buf), "%s/clock-frequency", buf);
> +
> + f = fopen(buf, "rb");
> + if (!f) {
> + return -1;
> + }
> +
> + len = fread(&tb, sizeof(tb), 1, f);
> + if (len != 1) {
> + goto err;
> + }
> +
> + return tb;
> +err:
> + fclose(f);
> + return 0;
> +}
Need to convert endian from big to host. Also, the frequency can be 64-bit.
-Scott
[Qemu-devel] [PATCH 21/23] PPC: E500: Remove unneeded CPU nodes, Alexander Graf, 2011/07/20
[Qemu-devel] [PATCH 22/23] PPC: E500: Update cpu-release-addr property in cpu nodes, Alexander Graf, 2011/07/20
[Qemu-devel] [PATCH 19/23] PPC: KVM: Add stubs for kvm helper functions, Alexander Graf, 2011/07/20