[2/3] linux-generic: sysinfo: make cpu_hz stand for max CPU frequency

Message ID 1435223104-15434-3-git-send-email-hongbo.zhang@freescale.com
State New
Headers show

Commit Message

hongbo.zhang@freescale.com June 25, 2015, 9:05 a.m.
From: Hongbo Zhang <hongbo.zhang@linaro.org>

In the previous x86 platform code, the variable is acquired from segment
"cpu MHz" of /proc/cpuinfo, this is the current CPU frequency when
acquired, and it may be scaled from time to time. But most of the use
cases when odp_sys_cpu_hz() is called, users just want to show the max
capacity of CPU, so this patch makes it clear that the cpu_hz stand for
max CPU frequecy.

While there may still be some use case of aquiring the current CPU
frequecy, another new API for this is introduced for this in the next
patch.

As to platforms other than x86, if their cpu_hz's don't stand for max CPU
frequency, they should be changed following up this patch, and then max or
current frequency of CPU should be clear.

Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
---
 platform/linux-generic/odp_system_info.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

Comments

Mike Holmes June 29, 2015, 8:24 p.m. | #1
Current API definition does not state this was instantaneous frequency, jut
that it is in HZ, it needs to now say this is the max frequency


http://docs.opendataplane.org/master/linux-generic-doxygen-html/group__odp__ver__abt__log__dbg.html#ga135b9f3168549a9d043fe0a1b8f8ae08


On 25 June 2015 at 05:05, <hongbo.zhang@freescale.com> wrote:

> From: Hongbo Zhang <hongbo.zhang@linaro.org>
>
> In the previous x86 platform code, the variable is acquired from segment
> "cpu MHz" of /proc/cpuinfo, this is the current CPU frequency when
> acquired, and it may be scaled from time to time. But most of the use
> cases when odp_sys_cpu_hz() is called, users just want to show the max
> capacity of CPU, so this patch makes it clear that the cpu_hz stand for
> max CPU frequecy
>

frequency


>
> While there may still be some use case of aquiring


acquiring


> the current CPU
> frequecy,


frequency


> another new API for this is introduced for this in the next
> patch.
>
> As to platforms other than x86, if their cpu_hz's don't stand for max CPU
> frequency, they should be changed following up this patch, and then max or
> current frequency of CPU should be clear.
>
> Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
> ---
>  platform/linux-generic/odp_system_info.c | 20 ++++++--------------
>  1 file changed, 6 insertions(+), 14 deletions(-)
>
> diff --git a/platform/linux-generic/odp_system_info.c
> b/platform/linux-generic/odp_system_info.c
> index c9f6be1..3ca8b27 100644
> --- a/platform/linux-generic/odp_system_info.c
> +++ b/platform/linux-generic/odp_system_info.c
> @@ -120,35 +120,27 @@ static int cpuinfo_x86(FILE *file, odp_system_info_t
> *sysinfo)
>  {
>         char str[1024];
>         char *pos;
> -       double mhz = 0.0;
> +       double ghz = 0.0;
>         int model = 0;
> -       int count = 2;
> +       int count = 1;
>
>         while (fgets(str, sizeof(str), file) != NULL && count > 0) {
> -               if (!mhz) {
> -                       pos = strstr(str, "cpu MHz");
> -                       if (pos) {
> -                               sscanf(pos, "cpu MHz : %lf", &mhz);
> -                               count--;
> -                       }
> -               }
> -
>                 if (!model) {
>                         pos = strstr(str, "model name");
>                         if (pos) {
> -                               int len;
>                                 pos = strchr(str, ':');
>                                 strncpy(sysinfo->model_str[0], pos + 2,
>                                         sizeof(sysinfo->model_str[0]));
> -                               len = strlen(sysinfo->model_str[0]);
> -                               sysinfo->model_str[0][len - 1] = 0;
> +                               pos = strchr(sysinfo->model_str[0], '@');
> +                               *(pos - 1) = '\0';
> +                               sscanf(pos, "@ %lfGHz", &ghz);
>                                 model = 1;
>                                 count--;
>                         }
>                 }
>         }
>
> -       sysinfo->cpu_hz[0] = (uint64_t)(mhz * 1000000.0);
> +       sysinfo->cpu_hz[0] = (uint64_t)(ghz * 1000000000.0);
>
>         return 0;
>  }
> --
> 1.9.1
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
>
Hongbo Zhang July 1, 2015, 10:15 a.m. | #2
On 30 June 2015 at 04:24, Mike Holmes <mike.holmes@linaro.org> wrote:
> Current API definition does not state this was instantaneous frequency, jut
> that it is in HZ, it needs to now say this is the max frequency
>
>
> http://docs.opendataplane.org/master/linux-generic-doxygen-html/group__odp__ver__abt__log__dbg.html#ga135b9f3168549a9d043fe0a1b8f8ae08
>

Then after this patch set being merged, this should be updated.

Will correct all typos, thanks.

>
> On 25 June 2015 at 05:05, <hongbo.zhang@freescale.com> wrote:
>>
>> From: Hongbo Zhang <hongbo.zhang@linaro.org>
>>
>> In the previous x86 platform code, the variable is acquired from segment
>> "cpu MHz" of /proc/cpuinfo, this is the current CPU frequency when
>> acquired, and it may be scaled from time to time. But most of the use
>> cases when odp_sys_cpu_hz() is called, users just want to show the max
>> capacity of CPU, so this patch makes it clear that the cpu_hz stand for
>> max CPU frequecy
>
>
> frequency
>
>>
>>
>> While there may still be some use case of aquiring
>
>
> acquiring
>
>>
>> the current CPU
>> frequecy,
>
>
> frequency
>
>>
>> another new API for this is introduced for this in the next
>> patch.
>>
>> As to platforms other than x86, if their cpu_hz's don't stand for max CPU
>> frequency, they should be changed following up this patch, and then max or
>> current frequency of CPU should be clear.
>>
>> Signed-off-by: Hongbo Zhang <hongbo.zhang@linaro.org>
>> ---
>>  platform/linux-generic/odp_system_info.c | 20 ++++++--------------
>>  1 file changed, 6 insertions(+), 14 deletions(-)
>>
>> diff --git a/platform/linux-generic/odp_system_info.c
>> b/platform/linux-generic/odp_system_info.c
>> index c9f6be1..3ca8b27 100644
>> --- a/platform/linux-generic/odp_system_info.c
>> +++ b/platform/linux-generic/odp_system_info.c
>> @@ -120,35 +120,27 @@ static int cpuinfo_x86(FILE *file, odp_system_info_t
>> *sysinfo)
>>  {
>>         char str[1024];
>>         char *pos;
>> -       double mhz = 0.0;
>> +       double ghz = 0.0;
>>         int model = 0;
>> -       int count = 2;
>> +       int count = 1;
>>
>>         while (fgets(str, sizeof(str), file) != NULL && count > 0) {
>> -               if (!mhz) {
>> -                       pos = strstr(str, "cpu MHz");
>> -                       if (pos) {
>> -                               sscanf(pos, "cpu MHz : %lf", &mhz);
>> -                               count--;
>> -                       }
>> -               }
>> -
>>                 if (!model) {
>>                         pos = strstr(str, "model name");
>>                         if (pos) {
>> -                               int len;
>>                                 pos = strchr(str, ':');
>>                                 strncpy(sysinfo->model_str[0], pos + 2,
>>                                         sizeof(sysinfo->model_str[0]));
>> -                               len = strlen(sysinfo->model_str[0]);
>> -                               sysinfo->model_str[0][len - 1] = 0;
>> +                               pos = strchr(sysinfo->model_str[0], '@');
>> +                               *(pos - 1) = '\0';
>> +                               sscanf(pos, "@ %lfGHz", &ghz);
>>                                 model = 1;
>>                                 count--;
>>                         }
>>                 }
>>         }
>>
>> -       sysinfo->cpu_hz[0] = (uint64_t)(mhz * 1000000.0);
>> +       sysinfo->cpu_hz[0] = (uint64_t)(ghz * 1000000000.0);
>>
>>         return 0;
>>  }
>> --
>> 1.9.1
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
>
>
> --
> Mike Holmes
> Technical Manager - Linaro Networking Group
> Linaro.org │ Open source software for ARM SoCs
>
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
>

Patch

diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c
index c9f6be1..3ca8b27 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -120,35 +120,27 @@  static int cpuinfo_x86(FILE *file, odp_system_info_t *sysinfo)
 {
 	char str[1024];
 	char *pos;
-	double mhz = 0.0;
+	double ghz = 0.0;
 	int model = 0;
-	int count = 2;
+	int count = 1;
 
 	while (fgets(str, sizeof(str), file) != NULL && count > 0) {
-		if (!mhz) {
-			pos = strstr(str, "cpu MHz");
-			if (pos) {
-				sscanf(pos, "cpu MHz : %lf", &mhz);
-				count--;
-			}
-		}
-
 		if (!model) {
 			pos = strstr(str, "model name");
 			if (pos) {
-				int len;
 				pos = strchr(str, ':');
 				strncpy(sysinfo->model_str[0], pos + 2,
 					sizeof(sysinfo->model_str[0]));
-				len = strlen(sysinfo->model_str[0]);
-				sysinfo->model_str[0][len - 1] = 0;
+				pos = strchr(sysinfo->model_str[0], '@');
+				*(pos - 1) = '\0';
+				sscanf(pos, "@ %lfGHz", &ghz);
 				model = 1;
 				count--;
 			}
 		}
 	}
 
-	sysinfo->cpu_hz[0] = (uint64_t)(mhz * 1000000.0);
+	sysinfo->cpu_hz[0] = (uint64_t)(ghz * 1000000000.0);
 
 	return 0;
 }