diff options
author | Didier Pallard <didier.pallard@6wind.com> | 2014-02-19 17:46:08 +0100 |
---|---|---|
committer | Thomas Monjalon <thomas.monjalon@6wind.com> | 2014-02-26 10:37:02 +0100 |
commit | 941b3d621e0d09553ead1429d4430e4208e832ce (patch) | |
tree | e39ccc8ae3b0febc69e50d800a11fe8f52d3de7d /lib | |
parent | 65b0663b7f32e4157b71dc14a016215e1bc63157 (diff) | |
download | dpdk-941b3d621e0d09553ead1429d4430e4208e832ce.zip dpdk-941b3d621e0d09553ead1429d4430e4208e832ce.tar.gz dpdk-941b3d621e0d09553ead1429d4430e4208e832ce.tar.xz |
timer: add precise TSC function
According to Intel Developer's Manual:
"The RDTSC instruction is not a serializing instruction. It does not necessarily wait
until all previous instructions have been executed before reading the counter. Simi-
larly, subsequent instructions may begin execution before the read operation is
performed. If software requires RDTSC to be executed only after all previous instruc-
tions have completed locally, it can either use RDTSCP (if the processor supports that
instruction) or execute the sequence LFENCE;RDTSC."
So add a rte_rdtsc_precise function that do a memory barrier before rdtsc to
synchronize operations and ensure that the TSC read is done at the expected place.
Use r/w memory barrier instead of lfence to serialize both loads and stores.
Signed-off-by: Didier Pallard <didier.pallard@6wind.com>
Reviewed-by: François-Frédéric Ozog <ff@ozog.com>
Reviewed-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/librte_eal/common/include/rte_cycles.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/librte_eal/common/include/rte_cycles.h b/lib/librte_eal/common/include/rte_cycles.h index cc6fe71..0c19ca9 100644 --- a/lib/librte_eal/common/include/rte_cycles.h +++ b/lib/librte_eal/common/include/rte_cycles.h @@ -76,6 +76,7 @@ extern "C" { #include <stdint.h> #include <rte_debug.h> +#include <rte_atomic.h> #ifdef RTE_LIBRTE_EAL_VMWARE_TSC_MAP_SUPPORT /** Global switch to use VMWARE mapping of TSC instead of RDTSC */ @@ -128,6 +129,19 @@ rte_rdtsc(void) } /** + * Read the TSC register precisely where function is called. + * + * @return + * The TSC for this lcore. + */ +static inline uint64_t +rte_rdtsc_precise(void) +{ + rte_mb(); + return rte_rdtsc(); +} + +/** * Get the measured frequency of the RDTSC counter * * @return |