On 16 September 2015 at 17:21, Savolainen, Petri (Nokia - FI/Espoo)
<petri.savolai...@nokia.com> wrote:
> This patch does not change the API. It changes implementation and should be 
> named
>
>
> linux-generic: sysinfo: revise odp_cpu_hz() to return current frequency
>
OK

>
> -Petri
>
>
>> -----Original Message-----
>> From: EXT hongbo.zh...@freescale.com
>> [mailto:hongbo.zh...@freescale.com]
>> Sent: Tuesday, September 15, 2015 4:56 PM
>> To: lng-odp@lists.linaro.org
>> Cc: mike.hol...@linaro.org; stuart.has...@arm.com; Savolainen, Petri
>> (Nokia - FI/Espoo); petri.savolai...@linaro.org;
>> ivan.khoronz...@linaro.org; Hongbo Zhang
>> Subject: [API NEXT PATCH v5 08/17] api: sysinfo: revise odp_cpu_hz() to
>> return current frequency
>>
>> From: Hongbo Zhang <hongbo.zh...@linaro.org>
>>
>> The odp_cpu_hz_max() is added to returm maximum frequency of CPU,
>> while the odp_cpu_hz(), as shown by its name, should return current
>> frequency of CPU, this patch revise odp_cpu_hz() for this purpose.
>>
>> Signed-off-by: Hongbo Zhang <hongbo.zh...@linaro.org>
>> ---
>>  platform/linux-generic/odp_system_info.c | 56
>> +++++++++++++++++++++++++++++++-
>>  1 file changed, 55 insertions(+), 1 deletion(-)
>>
>> diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-
>> generic/odp_system_info.c
>> index 8532fa0..ed61d36 100644
>> --- a/platform/linux-generic/odp_system_info.c
>> +++ b/platform/linux-generic/odp_system_info.c
>> @@ -146,6 +146,42 @@ static int cpuinfo_x86(FILE *file,
>> odp_system_info_t *sysinfo)
>>       return 0;
>>  }
>>
>> +static uint64_t arch_cpu_hz_current(int id)
>> +{
>> +     char str[1024];
>> +     FILE *file;
>> +     int cpu;
>> +     char *pos;
>> +     double mhz = 0.0;
>> +
>> +     file = fopen("/proc/cpuinfo", "rt");
>> +
>> +     /* find the correct processor instance */
>> +     while (fgets(str, sizeof(str), file) != NULL) {
>> +             pos = strstr(str, "processor");
>> +             if (pos) {
>> +                     sscanf(pos, "processor : %d", &cpu);
>> +                     if (cpu == id)
>> +                             break;
>> +             }
>> +     }
>> +
>> +     /* extract the cpu current speed */
>> +     while (fgets(str, sizeof(str), file) != NULL) {
>> +             pos = strstr(str, "cpu MHz");
>> +             if (pos) {
>> +                     sscanf(pos, "cpu MHz : %lf", &mhz);
>> +                     break;
>> +             }
>> +     }
>> +
>> +     fclose(file);
>> +     if (mhz)
>> +             return (uint64_t)(mhz * 1000000.0);
>> +
>> +     return -1;
>> +}
>> +
>>  #elif defined __arm__ || defined __aarch64__
>>
>>  static int cpuinfo_arm(FILE *file ODP_UNUSED,
>> @@ -154,6 +190,11 @@ odp_system_info_t *sysinfo ODP_UNUSED)
>>       return 0;
>>  }
>>
>> +static uint64_t arch_cpu_hz_current(int id)
>> +{
>> +     return -1;
>> +}
>> +
>>  #elif defined __OCTEON__
>>
>>  static int cpuinfo_octeon(FILE *file, odp_system_info_t *sysinfo)
>> @@ -195,6 +236,12 @@ static int cpuinfo_octeon(FILE *file,
>> odp_system_info_t *sysinfo)
>>
>>       return 0;
>>  }
>> +
>> +static uint64_t arch_cpu_hz_current(int id)
>> +{
>> +     return -1;
>> +}
>> +
>>  #elif defined __powerpc__
>>  static int cpuinfo_powerpc(FILE *file, odp_system_info_t *sysinfo)
>>  {
>> @@ -236,6 +283,11 @@ static int cpuinfo_powerpc(FILE *file,
>> odp_system_info_t *sysinfo)
>>       return 0;
>>  }
>>
>> +static uint64_t arch_cpu_hz_current(int id)
>> +{
>> +     return -1;
>> +}
>> +
>>  #else
>>       #error GCC target not found
>>  #endif
>> @@ -368,7 +420,9 @@ int odp_system_info_init(void)
>>   */
>>  uint64_t odp_cpu_hz(void)
>>  {
>> -     return odp_global_data.system_info.cpu_hz[0];
>> +     int id = sched_getcpu();
>> +
>> +     return arch_cpu_hz_current(id);
>>  }
>>
>>  uint64_t odp_cpu_hz_max(void)
>> --
>> 1.9.1
>
_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp

Reply via email to