This touches include/odp/api so the subject must include API-NEXT

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

> From: Hongbo Zhang <hongbo.zh...@linaro.org>
>
> This patch add API to return the current frequency of the CPU on which
> the thread is running.
>
> Only x86 platform is implemented, others are to be done.
>

If accepted this patch would break the ARM regression for this function
because it is x86 only, need to add stubs for all platforms. (assuming the
needed tests are added to the validation suite)


>
> Signed-off-by: Hongbo Zhang <hongbo.zh...@linaro.org>
> ---
>  include/odp/api/system_info.h            |  7 ++++++
>  platform/linux-generic/odp_system_info.c | 40
> ++++++++++++++++++++++++++++++++
>  2 files changed, 47 insertions(+)
>
> diff --git a/include/odp/api/system_info.h b/include/odp/api/system_info.h
> index 55a4180..02fabd3 100644
> --- a/include/odp/api/system_info.h
> +++ b/include/odp/api/system_info.h
> @@ -33,6 +33,13 @@ uint64_t odp_sys_cpu_hz(void);
>  uint64_t odp_sys_cpu_hz_amp(int cpu);
>
>  /**
> + * CPU current frequency in Hz
> + *
> + * @return CPU current frequency in Hz
>

Need to specify that -1 is returned on error


> + */
> +uint64_t odp_sys_cpu_hz_current(void);
> +
> +/**
>   * Huge page size in bytes
>   *
>   * @return Huge page size in bytes
> diff --git a/platform/linux-generic/odp_system_info.c
> b/platform/linux-generic/odp_system_info.c
> index 3ca8b27..624d75d 100644
> --- a/platform/linux-generic/odp_system_info.c
> +++ b/platform/linux-generic/odp_system_info.c
> @@ -145,6 +145,41 @@ static int cpuinfo_x86(FILE *file, odp_system_info_t
> *sysinfo)
>         return 0;
>  }
>
> +static uint64_t arch_cpu_hz_current(void)
> +{
> +       char str[1024];
> +       FILE *file;
> +       int cpu_curr, cpu;
> +       char *pos;
> +       double mhz = 0.0;
> +
> +       file = fopen("/proc/cpuinfo", "rt");
> +       cpu_curr = sched_getcpu();
> +
>

/* 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 == cpu_curr)
> +                               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,
> @@ -378,6 +413,11 @@ uint64_t odp_sys_cpu_hz_amp(int cpu)
>                 return -1;
>  }
>
> +uint64_t odp_sys_cpu_hz_current(void)
> +{
> +       return arch_cpu_hz_current();
> +}
> +
>  uint64_t odp_sys_huge_page_size(void)
>  {
>         return odp_global_data.system_info.huge_page_size;
> --
> 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 <http://www.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

Reply via email to