@@ -64,6 +64,26 @@ uint64_t odp_cpu_hz_max(void);
uint64_t odp_cpu_id_hz_max(int id);
/**
+ * Current CPU frequency in Hz
+ *
+ * Returns current frequency of this CPU
+ *
+ * @return CPU frequency in Hz
+ */
+uint64_t odp_cpu_hz(void);
+
+/**
+ * Current CPU frequency of a CPU (in Hz)
+ *
+ * Returns current frequency of the specified CPU
+ *
+ * @param id CPU ID
+ *
+ * @return CPU frequency in Hz
+ */
+uint64_t odp_cpu_id_hz(int id);
+
+/**
* CPU model name
*
* @return Pointer to CPU model name string
@@ -145,6 +145,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,
@@ -153,6 +189,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,11 @@ 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 +282,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
@@ -379,6 +430,18 @@ uint64_t odp_cpu_id_hz_max(int id)
return -1;
}
+uint64_t odp_cpu_hz(void)
+{
+ int id = sched_getcpu();
+
+ return arch_cpu_hz_current(id);
+}
+
+uint64_t odp_cpu_id_hz(int id)
+{
+ return arch_cpu_hz_current(id);
+}
+
uint64_t odp_sys_huge_page_size(void)
{
return odp_global_data.system_info.huge_page_size;