qemu-devel
[Top][All Lists]
Advanced

[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: Alexander Graf
Subject: Re: [Qemu-devel] [PATCH 14/23] PPC: KVM: Add generic function to read host clockfreq
Date: Thu, 21 Jul 2011 20:59:40 +0200




Am 21.07.2011 um 19:51 schrieb Scott Wood <address@hidden>:

> 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.  

Hm. This is kvm specific code for ppc, so only ever runs on host==big :)

> Also, the frequency can be 64-bit.

Would the parameter just be 2 cells then? Got an example how this works?

Alex

> 
> -Scott
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]