diff mbox

[v3,10/12] x86: odp_cpu_cycles for x86_64

Message ID 20160726025625.7343-11-brian.brooks@linaro.org
State New
Headers show

Commit Message

Brian Brooks July 26, 2016, 2:56 a.m. UTC
Signed-off-by: Brian Brooks <brian.brooks@linaro.org>

---
 platform/linux-generic/arch/x86/odp_cpu_arch.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

-- 
2.9.0

Comments

Maxim Uvarov July 26, 2016, 7:46 a.m. UTC | #1
On 07/26/16 05:56, Brian Brooks wrote:
> Signed-off-by: Brian Brooks <brian.brooks@linaro.org>

> ---

>   platform/linux-generic/arch/x86/odp_cpu_arch.c | 19 ++++++-------------

>   1 file changed, 6 insertions(+), 13 deletions(-)

>

> diff --git a/platform/linux-generic/arch/x86/odp_cpu_arch.c b/platform/linux-generic/arch/x86/odp_cpu_arch.c

> index c3be356..a9e819d 100644

> --- a/platform/linux-generic/arch/x86/odp_cpu_arch.c

> +++ b/platform/linux-generic/arch/x86/odp_cpu_arch.c

> @@ -7,17 +7,10 @@

>   

>   uint64_t odp_cpu_cycles(void)

>   {

> -	union {

> -		uint64_t tsc_64;

> -		struct {

> -			uint32_t lo_32;

> -			uint32_t hi_32;

> -		};

> -	} tsc;

> -

> -	__asm__ __volatile__ ("rdtsc" :

> -		     "=a" (tsc.lo_32),

> -		     "=d" (tsc.hi_32) : : "memory");

> -

> -	return tsc.tsc_64;

> +#if defined(__x86_64__) || defined(__amd64__)

> +	uint64_t hi, lo;

> +	__asm__ volatile("mfence" : : : "memory");

> +	__asm__ volatile("rdtsc" : "=a" (lo), "=d" (hi));

> +	return (hi << 32) | lo;

> +#endif


return for non #ifdef case is missing.

Maxim.
>   }
Brian Brooks July 26, 2016, 4:57 p.m. UTC | #2
On 07/26 10:46:08, Maxim Uvarov wrote:
> On 07/26/16 05:56, Brian Brooks wrote:

> > Signed-off-by: Brian Brooks <brian.brooks@linaro.org>

> > ---

> >   platform/linux-generic/arch/x86/odp_cpu_arch.c | 19 ++++++-------------

> >   1 file changed, 6 insertions(+), 13 deletions(-)

> > 

> > diff --git a/platform/linux-generic/arch/x86/odp_cpu_arch.c b/platform/linux-generic/arch/x86/odp_cpu_arch.c

> > index c3be356..a9e819d 100644

> > --- a/platform/linux-generic/arch/x86/odp_cpu_arch.c

> > +++ b/platform/linux-generic/arch/x86/odp_cpu_arch.c

> > @@ -7,17 +7,10 @@

> >   uint64_t odp_cpu_cycles(void)

> >   {

> > -	union {

> > -		uint64_t tsc_64;

> > -		struct {

> > -			uint32_t lo_32;

> > -			uint32_t hi_32;

> > -		};

> > -	} tsc;

> > -

> > -	__asm__ __volatile__ ("rdtsc" :

> > -		     "=a" (tsc.lo_32),

> > -		     "=d" (tsc.hi_32) : : "memory");

> > -

> > -	return tsc.tsc_64;

> > +#if defined(__x86_64__) || defined(__amd64__)

> > +	uint64_t hi, lo;

> > +	__asm__ volatile("mfence" : : : "memory");

> > +	__asm__ volatile("rdtsc" : "=a" (lo), "=d" (hi));

> > +	return (hi << 32) | lo;

> > +#endif

> 

> return for non #ifdef case is missing.

> 

> Maxim.


changed in v5
diff mbox

Patch

diff --git a/platform/linux-generic/arch/x86/odp_cpu_arch.c b/platform/linux-generic/arch/x86/odp_cpu_arch.c
index c3be356..a9e819d 100644
--- a/platform/linux-generic/arch/x86/odp_cpu_arch.c
+++ b/platform/linux-generic/arch/x86/odp_cpu_arch.c
@@ -7,17 +7,10 @@ 
 
 uint64_t odp_cpu_cycles(void)
 {
-	union {
-		uint64_t tsc_64;
-		struct {
-			uint32_t lo_32;
-			uint32_t hi_32;
-		};
-	} tsc;
-
-	__asm__ __volatile__ ("rdtsc" :
-		     "=a" (tsc.lo_32),
-		     "=d" (tsc.hi_32) : : "memory");
-
-	return tsc.tsc_64;
+#if defined(__x86_64__) || defined(__amd64__)
+	uint64_t hi, lo;
+	__asm__ volatile("mfence" : : : "memory");
+	__asm__ volatile("rdtsc" : "=a" (lo), "=d" (hi));
+	return (hi << 32) | lo;
+#endif
 }