[dpdk-dev,v2,2/5] eal/ppc64: define architecture specific rdtsc hz

Message ID 60996b50e628207157f1b7b6dab704b8224f3cae.1506058385.git.gowrishankar.m@linux.vnet.ibm.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Gowrishankar Sept. 22, 2017, 8:25 a.m. UTC
  From: Jerin Jacob <jerin.jacob@caviumnetworks.com>

In ppc_64, rte_rdtsc() returns timebase register value which increments
at independent timebase frequency and hence not related to lcore cpu
frequency to derive TSC hz. Hence, we stick with master lcore frequency.

CC: Chao Zhu <chaozhu@linux.vnet.ibm.com>
Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
Signed-off-by: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
---

v2:
 * add ppc_64 specific implementation

 .../common/include/arch/ppc_64/rte_cycles.h        | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
  

Comments

Thomas Monjalon Oct. 12, 2017, 10:20 p.m. UTC | #1
22/09/2017 10:25, Gowrishankar:
> From: Jerin Jacob <jerin.jacob@caviumnetworks.com>
> 
> In ppc_64, rte_rdtsc() returns timebase register value which increments
> at independent timebase frequency and hence not related to lcore cpu
> frequency to derive TSC hz. Hence, we stick with master lcore frequency.
> 
> CC: Chao Zhu <chaozhu@linux.vnet.ibm.com>
> Signed-off-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>
> Signed-off-by: Gowrishankar Muthukrishnan <gowrishankar.m@linux.vnet.ibm.com>
[...]
> --- a/lib/librte_eal/common/include/arch/ppc_64/rte_cycles.h
> +++ b/lib/librte_eal/common/include/arch/ppc_64/rte_cycles.h
> @@ -38,9 +38,13 @@
>  #endif
>  
>  #include "generic/rte_cycles.h"
> +#include "../../lib/librte_eal/common/eal_filesystem.h"

rte_cycles.h is an installed header.
eal_filesystem.h is not exported.
It cannot work.
  

Patch

diff --git a/lib/librte_eal/common/include/arch/ppc_64/rte_cycles.h b/lib/librte_eal/common/include/arch/ppc_64/rte_cycles.h
index 8fa6fc6..1b36587 100644
--- a/lib/librte_eal/common/include/arch/ppc_64/rte_cycles.h
+++ b/lib/librte_eal/common/include/arch/ppc_64/rte_cycles.h
@@ -38,9 +38,13 @@ 
 #endif
 
 #include "generic/rte_cycles.h"
+#include "../../lib/librte_eal/common/eal_filesystem.h"
 
 #include <rte_byteorder.h>
 #include <rte_common.h>
+#include <rte_lcore.h>
+
+static const char sys_cpu_dir[] = "/sys/devices/system/cpu";
 
 /**
  * Read the time base register.
@@ -79,6 +83,26 @@ 
 	return tsc.tsc_64;
 }
 
+/**
+ * Get the number of rdtsc cycles in one second.
+ *
+ * @return
+ *   The number of rdtsc cycles in one second.
+ */
+static inline uint64_t
+rte_rdtsc_arch_hz(void)
+{
+	unsigned long cpu_hz;
+	char path[PATH_MAX];
+
+	snprintf(path, sizeof(path), "%s/cpu%d/cpufreq/cpuinfo_cur_freq",
+			sys_cpu_dir, rte_get_master_lcore());
+	if (eal_parse_sysfs_value(path, &cpu_hz) < 0)
+		RTE_LOG(WARNING, EAL, "Unable to parse %s\n", path);
+
+	return cpu_hz*1000;
+}
+
 static inline uint64_t
 rte_rdtsc_precise(void)
 {