Hi, Hongbo
On 11.08.15 10:33, hongbo.zh...@freescale.com wrote:
From: Hongbo Zhang <hongbo.zh...@linaro.org>
Currently the API to get CPU frequency is vague, it needs to be clarified
whether max or current frequency is returned, and now most use cases want
to get max capacity of CPU in fact, so this patch makes it clear that the
cpu_hz stand for max CPU frequency. (there is no need to store current
instant frequency)
Also patch name linux-generic, but it's changing api/examples/tests and
linux-generic in one patch
What about to split it? I don't know how others, but I tend to miss
linux-generic specific patches
when I have no time enough and look only on common patches. In this case it's
hidden.
Accordingly the API odp_cpu_hz() is renamed to odp_cpu_hz_max().
While there may still be some use case of acquiring the current CPU
frequency, so the previous odp_cpu_hz() will be re-implemented for this
purpose 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.zh...@linaro.org>
---
example/classifier/odp_classifier.c | 2 +-
example/generator/odp_generator.c | 2 +-
example/ipsec/odp_ipsec.c | 2 +-
example/packet/odp_pktio.c | 2 +-
example/timer/odp_timer_test.c | 4 ++--
include/odp/api/cpu.h | 2 +-
platform/linux-generic/arch/linux/odp_time.c | 2 +-
platform/linux-generic/odp_system_info.c | 22 +++++++---------------
platform/linux-generic/odp_time.c | 4 ++--
test/api_test/odp_common.c | 2 +-
test/performance/odp_atomic.c | 2 +-
test/performance/odp_l2fwd.c | 2 +-
test/performance/odp_scheduling.c | 2 +-
test/validation/system/system.c | 6 +++---
test/validation/system/system.h | 2 +-
15 files changed, 25 insertions(+), 33 deletions(-)
diff --git a/example/classifier/odp_classifier.c
b/example/classifier/odp_classifier.c
index 8b68ce0..16e567d 100644
--- a/example/classifier/odp_classifier.c
+++ b/example/classifier/odp_classifier.c
@@ -733,7 +733,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"
diff --git a/example/generator/odp_generator.c
b/example/generator/odp_generator.c
index 2ed4ea2..7982801 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -988,7 +988,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"
diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index 32a91e4..b2bc501 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -1516,7 +1516,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"
diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c
index 75de6b8..f0bc528 100644
--- a/example/packet/odp_pktio.c
+++ b/example/packet/odp_pktio.c
@@ -628,7 +628,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"
diff --git a/example/timer/odp_timer_test.c b/example/timer/odp_timer_test.c
index b7d3dcd..68345b7 100644
--- a/example/timer/odp_timer_test.c
+++ b/example/timer/odp_timer_test.c
@@ -350,7 +350,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());
@@ -445,7 +445,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);
diff --git a/include/odp/api/cpu.h b/include/odp/api/cpu.h
index 7b548ce..9d0aaf5 100644
--- a/include/odp/api/cpu.h
+++ b/include/odp/api/cpu.h
@@ -48,7 +48,7 @@ int odp_cpu_count(void);
*
* @return CPU frequency in Hz
*/
-uint64_t odp_cpu_hz(void);
+uint64_t odp_cpu_hz_max(void);
/**
* CPU model name
diff --git a/platform/linux-generic/arch/linux/odp_time.c
b/platform/linux-generic/arch/linux/odp_time.c
index 3309da0..ed6e560 100644
--- a/platform/linux-generic/arch/linux/odp_time.c
+++ b/platform/linux-generic/arch/linux/odp_time.c
@@ -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;
diff --git a/platform/linux-generic/odp_system_info.c
b/platform/linux-generic/odp_system_info.c
index 8e903b0..d78fd3e 100644
--- a/platform/linux-generic/odp_system_info.c
+++ b/platform/linux-generic/odp_system_info.c
@@ -121,35 +121,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;
We can use float here, :-|?
But it's linux-generic, probably yes.
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;
}
@@ -374,7 +366,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];
}
diff --git a/platform/linux-generic/odp_time.c
b/platform/linux-generic/odp_time.c
index a137a36..f864ade 100644
--- a/platform/linux-generic/odp_time.c
+++ b/platform/linux-generic/odp_time.c
@@ -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;
diff --git a/test/api_test/odp_common.c b/test/api_test/odp_common.c
index 8d05efe..bb89f63 100644
--- a/test/api_test/odp_common.c
+++ b/test/api_test/odp_common.c
@@ -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);
diff --git a/test/performance/odp_atomic.c b/test/performance/odp_atomic.c
index 74d4f3a..dea6210 100644
--- a/test/performance/odp_atomic.c
+++ b/test/performance/odp_atomic.c
@@ -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);
diff --git a/test/performance/odp_l2fwd.c b/test/performance/odp_l2fwd.c
index 6951837..37c62ca 100644
--- a/test/performance/odp_l2fwd.c
+++ b/test/performance/odp_l2fwd.c
@@ -641,7 +641,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"
diff --git a/test/performance/odp_scheduling.c
b/test/performance/odp_scheduling.c
index a73f013..53f84a7 100644
--- a/test/performance/odp_scheduling.c
+++ b/test/performance/odp_scheduling.c
@@ -881,7 +881,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());
diff --git a/test/validation/system/system.c b/test/validation/system/system.c
index 54cb7c5..9134161 100644
--- a/test/validation/system/system.c
+++ b/test/validation/system/system.c
@@ -75,11 +75,11 @@ void system_test_odp_sys_huge_page_size(void)
CU_ASSERT(0 < page);
}
-void system_test_odp_cpu_hz(void)
+void system_test_odp_cpu_hz_max(void)
{
uint64_t hz;
- hz = odp_cpu_hz();
+ hz = odp_cpu_hz_max();
CU_ASSERT(0 < hz);
}
@@ -90,7 +90,7 @@ CU_TestInfo system_suite[] = {
{"odp_cpu_model_str", system_test_odp_cpu_model_str},
{"odp_sys_page_size", system_test_odp_sys_page_size},
{"odp_sys_huge_page_size", system_test_odp_sys_huge_page_size},
- {"odp_cpu_hz", system_test_odp_cpu_hz},
+ {"odp_cpu_hz_max", system_test_odp_cpu_hz_max},
CU_TEST_INFO_NULL,
};
diff --git a/test/validation/system/system.h b/test/validation/system/system.h
index d05f104..67ddb7a 100644
--- a/test/validation/system/system.h
+++ b/test/validation/system/system.h
@@ -16,7 +16,7 @@ void system_test_odp_sys_cache_line_size(void);
void system_test_odp_cpu_model_str(void);
void system_test_odp_sys_page_size(void);
void system_test_odp_sys_huge_page_size(void);
-void system_test_odp_cpu_hz(void);
+void system_test_odp_cpu_hz_max(void);
/* test arrays: */
extern CU_TestInfo system_suite[];
--
Regards,
Ivan Khoronzhuk
_______________________________________________
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp