summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Monjalon <thomas.monjalon@6wind.com>2012-05-31 19:00:31 +0200
committerThomas Monjalon <thomas.monjalon@6wind.com>2013-09-17 14:16:11 +0200
commitb9bbf657d30b5b59b4b9c2918b221e1ed05331a4 (patch)
tree78a63b91be90bb522edaad5f2e9dfcda7232404a
parent947b971aea95c9f508607883bd6849860316002e (diff)
downloaddpdk-b9bbf657d30b5b59b4b9c2918b221e1ed05331a4.zip
dpdk-b9bbf657d30b5b59b4b9c2918b221e1ed05331a4.tar.gz
dpdk-b9bbf657d30b5b59b4b9c2918b221e1ed05331a4.tar.xz
timer: get TSC frequency from /proc/cpuinfo
TSC frequency was guessed by reading CLOCK_MONOTONIC_RAW or sleeping 1 sec. Now, read frequency from cpuinfo first. Keep other methods as fallbacks. Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com> Acked-by: Ivan Boule <ivan.boule@6wind.com>
-rw-r--r--lib/librte_eal/linuxapp/eal/eal_timer.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/lib/librte_eal/linuxapp/eal/eal_timer.c b/lib/librte_eal/linuxapp/eal/eal_timer.c
index 67e45d6..a4107bb 100644
--- a/lib/librte_eal/linuxapp/eal/eal_timer.c
+++ b/lib/librte_eal/linuxapp/eal/eal_timer.c
@@ -280,6 +280,35 @@ check_tsc_flags(void)
}
static int
+set_tsc_freq_from_cpuinfo(void)
+{
+ char line[256];
+ FILE *stream;
+ double dmhz;
+
+ stream = fopen("/proc/cpuinfo", "r");
+ if (!stream) {
+ RTE_LOG(WARNING, EAL, "WARNING: Unable to open /proc/cpuinfo\n");
+ return -1;
+ }
+
+ while (fgets(line, sizeof line, stream)) {
+ if (sscanf(line, "cpu MHz\t: %lf", &dmhz) == 1) {
+ eal_tsc_resolution_hz = (uint64_t)(dmhz * 1000000UL);
+ break;
+ }
+ }
+
+ fclose(stream);
+
+ if (!eal_tsc_resolution_hz) {
+ RTE_LOG(WARNING, EAL, "WARNING: Cannot read CPU clock from cpuinfo\n");
+ return -1;
+ }
+ return 0;
+}
+
+static int
set_tsc_freq_from_clock(void)
{
#ifdef CLOCK_MONOTONIC_RAW
@@ -327,8 +356,9 @@ set_tsc_freq_fallback(void)
static void
set_tsc_freq(void)
{
- if (set_tsc_freq_from_clock() < 0)
- set_tsc_freq_fallback();
+ if (set_tsc_freq_from_cpuinfo() < 0 &&
+ set_tsc_freq_from_clock() < 0)
+ set_tsc_freq_fallback();
RTE_LOG(INFO, EAL, "TSC frequency is ~%"PRIu64" KHz\n",
eal_tsc_resolution_hz/1000);