@@ -26,3 +26,8 @@ int cpuinfo_parser(FILE *file ODP_UNUSED, system_info_t *sysinfo)
void sys_info_print_arch(void)
{
}
+
+uint64_t odp_cpu_arch_hz_current(int id ODP_UNUSED)
+{
+ return 0;
+}
@@ -63,3 +63,8 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo)
void sys_info_print_arch(void)
{
}
+
+uint64_t odp_cpu_arch_hz_current(int id ODP_UNUSED)
+{
+ return 0;
+}
@@ -62,3 +62,8 @@ int cpuinfo_parser(FILE *file, system_info_t *sysinfo)
void sys_info_print_arch(void)
{
}
+
+uint64_t odp_cpu_arch_hz_current(int id ODP_UNUSED)
+{
+ return 0;
+}
@@ -45,3 +45,39 @@ void sys_info_print_arch(void)
{
cpu_flags_print_all();
}
+
+uint64_t odp_cpu_arch_hz_current(int id ODP_UNUSED)
+{
+ 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) {
+ if (sscanf(pos, "processor : %d", &cpu) == 1)
+ if (cpu == id)
+ break;
+ }
+ }
+
+ /* extract the cpu current speed */
+ while (fgets(str, sizeof(str), file) != NULL) {
+ pos = strstr(str, "cpu MHz");
+ if (pos) {
+ if (sscanf(pos, "cpu MHz : %lf", &mhz) == 1)
+ break;
+ }
+ }
+
+ fclose(file);
+ if (mhz)
+ return (uint64_t)(mhz * 1000000.0);
+
+ return 0;
+}
@@ -133,6 +133,7 @@ int _odp_ishm_term_local(void);
int cpuinfo_parser(FILE *file, system_info_t *sysinfo);
uint64_t odp_cpufreq_id(const char *filename, int id);
uint64_t odp_cpu_hz_current(int id);
+uint64_t odp_cpu_arch_hz_current(int id);
void sys_info_print_arch(void);
#ifdef __cplusplus
@@ -385,7 +385,12 @@ int odp_system_info_term(void)
*/
uint64_t odp_cpu_hz_current(int id)
{
- return odp_cpufreq_id("cpuinfo_cur_freq", id);
+ uint64_t cur_hz = odp_cpufreq_id("cpuinfo_cur_freq", id);
+
+ if (!cur_hz)
+ cur_hz = odp_cpu_arch_hz_current(id);
+
+ return cur_hz;
}
uint64_t odp_cpu_hz(void)