@@ -728,7 +728,7 @@ static void print_info(char *progname, appl_args_t *appl_args)
"CPU count: %i\n"
"\n",
odp_version_api_str(), odp_cpu_model_str(),
- odp_cpu_hz(), odp_sys_cache_line_size(),
+ odp_cpu_hz_max(), odp_sys_cache_line_size(),
odp_cpu_count());
printf("Running ODP appl: \"%s\"\n"
@@ -978,7 +978,7 @@ static void print_info(char *progname, appl_args_t *appl_args)
"Cache line size: %i\n"
"CPU count: %i\n"
"\n",
- odp_version_api_str(), odp_cpu_model_str(), odp_cpu_hz(),
+ odp_version_api_str(), odp_cpu_model_str(), odp_cpu_hz_max(),
odp_sys_cache_line_size(), odp_cpu_count());
printf("Running ODP appl: \"%s\"\n"
@@ -1517,7 +1517,7 @@ static void print_info(char *progname, appl_args_t *appl_args)
"Cache line size: %i\n"
"CPU count: %i\n"
"\n",
- odp_version_api_str(), odp_cpu_model_str(), odp_cpu_hz(),
+ odp_version_api_str(), odp_cpu_model_str(), odp_cpu_hz_max(),
odp_sys_cache_line_size(), odp_cpu_count());
printf("Running ODP appl: \"%s\"\n"
@@ -626,7 +626,7 @@ static void print_info(char *progname, appl_args_t *appl_args)
"Cache line size: %i\n"
"CPU count: %i\n"
"\n",
- odp_version_api_str(), odp_cpu_model_str(), odp_cpu_hz(),
+ odp_version_api_str(), odp_cpu_model_str(), odp_cpu_hz_max(),
odp_sys_cache_line_size(), odp_cpu_count());
printf("Running ODP appl: \"%s\"\n"
@@ -365,7 +365,7 @@ int main(int argc, char *argv[])
printf("---------------\n");
printf("ODP API version: %s\n", odp_version_api_str());
printf("CPU model: %s\n", odp_cpu_model_str());
- printf("CPU freq (hz): %"PRIu64"\n", odp_cpu_hz());
+ printf("CPU freq (hz): %"PRIu64"\n", odp_cpu_hz_max());
printf("Cache line size: %i\n", odp_sys_cache_line_size());
printf("Max CPU count: %i\n", odp_cpu_count());
@@ -463,7 +463,7 @@ int main(int argc, char *argv[])
return -1;
}
- printf("CPU freq %"PRIu64" Hz\n", odp_cpu_hz());
+ printf("CPU freq %"PRIu64" Hz\n", odp_cpu_hz_max());
printf("Cycles vs nanoseconds:\n");
ns = 0;
cycles = odp_time_ns_to_cycles(ns);
@@ -44,11 +44,13 @@ int odp_cpu_id(void);
int odp_cpu_count(void);
/**
- * CPU frequency in Hz
+ * Maximum CPU frequency in Hz
+ *
+ * Returns maximum frequency of this CPU
*
* @return CPU frequency in Hz
*/
-uint64_t odp_cpu_hz(void);
+uint64_t odp_cpu_hz_max(void);
/**
* CPU model name
@@ -28,7 +28,7 @@ uint64_t odp_time_cycles(void)
if (ret != 0)
ODP_ABORT("clock_gettime failed\n");
- hz = odp_cpu_hz();
+ hz = odp_cpu_hz_max();
sec = (uint64_t) time.tv_sec;
ns = (uint64_t) time.tv_nsec;
@@ -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;
}
@@ -373,7 +365,7 @@ int odp_system_info_init(void)
* Public access functions
*************************
*/
-uint64_t odp_cpu_hz(void)
+uint64_t odp_cpu_hz_max(void)
{
return odp_global_data.system_info.cpu_hz[0];
}
@@ -23,7 +23,7 @@ uint64_t odp_time_diff_cycles(uint64_t t1, uint64_t t2)
uint64_t odp_time_cycles_to_ns(uint64_t cycles)
{
- uint64_t hz = odp_cpu_hz();
+ uint64_t hz = odp_cpu_hz_max();
if (cycles > (UINT64_MAX / GIGA))
return (cycles/hz)*GIGA;
@@ -34,7 +34,7 @@ uint64_t odp_time_cycles_to_ns(uint64_t cycles)
uint64_t odp_time_ns_to_cycles(uint64_t ns)
{
- uint64_t hz = odp_cpu_hz();
+ uint64_t hz = odp_cpu_hz_max();
if (ns > (UINT64_MAX / hz))
return (ns/GIGA)*hz;
@@ -42,7 +42,7 @@ void odp_print_system_info(void)
printf("---------------\n");
printf("ODP API version: %s\n", odp_version_api_str());
printf("CPU model: %s\n", odp_cpu_model_str());
- printf("CPU freq (hz): %"PRIu64"\n", odp_cpu_hz());
+ printf("CPU freq (hz): %"PRIu64"\n", odp_cpu_hz_max());
printf("Cache line size: %i\n", odp_sys_cache_line_size());
printf("CPU count: %i\n", odp_cpu_count());
printf("CPU mask: %s\n", str);
@@ -338,7 +338,7 @@ void odp_print_system_info(void)
printf("---------------\n");
printf("ODP API version: %s\n", odp_version_api_str());
printf("CPU model: %s\n", odp_cpu_model_str());
- printf("CPU freq (hz): %"PRIu64"\n", odp_cpu_hz());
+ printf("CPU freq (hz): %"PRIu64"\n", odp_cpu_hz_max());
printf("Cache line size: %i\n", odp_sys_cache_line_size());
printf("CPU count: %i\n", odp_cpu_count());
printf("CPU mask: %s\n", str);
@@ -639,7 +639,7 @@ static void print_info(char *progname, appl_args_t *appl_args)
"Cache line size: %i\n"
"CPU count: %i\n"
"\n",
- odp_version_api_str(), odp_cpu_model_str(), odp_cpu_hz(),
+ odp_version_api_str(), odp_cpu_model_str(), odp_cpu_hz_max(),
odp_sys_cache_line_size(), odp_cpu_count());
printf("Running ODP appl: \"%s\"\n"
@@ -870,7 +870,7 @@ int main(int argc, char *argv[])
printf("---------------\n");
printf("ODP API version: %s\n", odp_version_api_str());
printf("CPU model: %s\n", odp_cpu_model_str());
- printf("CPU freq (hz): %"PRIu64"\n", odp_cpu_hz());
+ printf("CPU freq (hz): %"PRIu64"\n", odp_cpu_hz_max());
printf("Cache line size: %i\n", odp_sys_cache_line_size());
printf("Max CPU count: %i\n", odp_cpu_count());
@@ -74,18 +74,18 @@ static void test_odp_sys_huge_page_size(void)
CU_ASSERT(0 < page);
}
-static void test_odp_cpu_hz(void)
+static void test_odp_cpu_hz_max(void)
{
uint64_t hz;
- hz = odp_cpu_hz();
+ hz = odp_cpu_hz_max();
CU_ASSERT(0 < hz);
}
CU_TestInfo test_odp_system[] = {
{"odp version", test_odp_version_numbers},
{"odp_cpu_count", test_odp_cpu_count},
- {"odp_cpu_hz", test_odp_cpu_hz},
+ {"odp_cpu_hz_max", test_odp_cpu_hz_max},
{"odp_cpu_model_str", test_odp_cpu_model_str},
{"odp_sys_cache_line_size", test_odp_sys_cache_line_size},
{"odp_sys_page_size", test_odp_sys_page_size},