public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Joerg Roedel" <joerg.roedel@amd.com>
To: discuss@x86-64.org
Cc: "Andi Kleen" <ak@suse.de>, linux-kernel@vger.kernel.org
Subject: [PATCH 4/4 TRY#3] optimize and simplify get_cycles_sync()
Date: Fri, 9 Mar 2007 16:15:11 +0100	[thread overview]
Message-ID: <20070309151511.GE13481@amd.com> (raw)
In-Reply-To: <20070309150825.GA13481@amd.com>

[-- Attachment #1: Type: text/plain, Size: 518 bytes --]

From: Joerg Roedel <joerg.roedel@amd.com>

This patch simplifies the get_cycles_sync() function by removing
the #ifdefs from it. Further it introduces an optimization for AMD
processors. There the RDTSCP instruction is used instead of CPUID;RDTSC
which is helpfull if the kernel runs as a KVM guest. Running as a guest
makes CPUID very expensive because it causes an intercept of the guest.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>

-- 
Joerg Roedel
Operating System Research Center
AMD Saxony LLC & Co. KG

[-- Attachment #2: optimized-get_cycles_sync.patch --]
[-- Type: text/plain, Size: 1807 bytes --]

diff --git a/include/asm-i386/cpufeature.h b/include/asm-i386/cpufeature.h
index 3f92b94..a9f1f01 100644
--- a/include/asm-i386/cpufeature.h
+++ b/include/asm-i386/cpufeature.h
@@ -49,6 +49,7 @@
 #define X86_FEATURE_MP		(1*32+19) /* MP Capable. */
 #define X86_FEATURE_NX		(1*32+20) /* Execute Disable */
 #define X86_FEATURE_MMXEXT	(1*32+22) /* AMD MMX extensions */
+#define X86_FEATURE_RDTSCP      (1*32+27) /* RDTSCP */
 #define X86_FEATURE_LM		(1*32+29) /* Long Mode (x86-64) */
 #define X86_FEATURE_3DNOWEXT	(1*32+30) /* AMD 3DNow! extensions */
 #define X86_FEATURE_3DNOW	(1*32+31) /* 3DNow! */
diff --git a/include/asm-i386/tsc.h b/include/asm-i386/tsc.h
index 84016ff..0b769ad 100644
--- a/include/asm-i386/tsc.h
+++ b/include/asm-i386/tsc.h
@@ -7,6 +7,7 @@
 #define _ASM_i386_TSC_H
 
 #include <asm/processor.h>
+#include <asm/alternative.h>
 
 /*
  * Standard way to access the cycle counter.
@@ -34,22 +35,16 @@ static inline cycles_t get_cycles(void)
 /* Like get_cycles, but make sure the CPU is synchronized. */
 static __always_inline cycles_t get_cycles_sync(void)
 {
-	unsigned long long ret;
-#ifdef X86_FEATURE_SYNC_RDTSC
-	unsigned eax;
+	unsigned int a, d;
 
-	/*
-	 * Don't do an additional sync on CPUs where we know
-	 * RDTSC is already synchronous:
-	 */
-	alternative_io("cpuid", ASM_NOP2, X86_FEATURE_SYNC_RDTSC,
-			  "=a" (eax), "0" (1) : "ebx","ecx","edx","memory");
-#else
-	sync_core();
-#endif
-	rdtscll(ret);
+#define RDTSCP ".byte 0x0f, 0x01, 0xf9"
+	alternative_io_two("cpuid\nrdtsc",
+			   "rdtsc", X86_FEATURE_SYNC_RDTSC,
+			   ".byte 0x0f, 0x01, 0xf9", X86_FEATURE_RDTSCP,
+			   ASM_OUTPUT2("=a" (a), "=d" (d)),
+			   "0" (1) : "ecx", "memory");
 
-	return ret;
+	return ((unsigned long long)a) | (((unsigned long long)d)<<32);
 }
 
 extern void tsc_init(void);

  parent reply	other threads:[~2007-03-09 15:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-09 15:08 [PATCH 0/4 TRY#3] improve alternative instruction code and optimize get_cycles_sync Joerg Roedel
2007-03-09 15:11 ` [PATCH 1/4 TRY#3] i386: extend alternative instructions framework Joerg Roedel
2007-03-09 15:12 ` [PATCH 2/4 TRY#3] x86_64: changes to x86_64 architecture for alternative instruction improvements Joerg Roedel
2007-03-09 15:13 ` [PATCH 3/4 TRY#3] i386: add the X86_FEATURE_SYNC_RDTSC flag Joerg Roedel
2007-03-09 15:15 ` Joerg Roedel [this message]
2007-03-09 18:10   ` [PATCH 4/4 TRY#3] optimize and simplify get_cycles_sync() Avi Kivity
2007-03-12 13:02     ` Joerg Roedel
2007-03-12 13:09       ` [discuss] " Andi Kleen
2007-03-12 13:21         ` Joerg Roedel
2007-03-12 13:29       ` Michael Matz
2007-03-12 13:45         ` Joerg Roedel
2007-03-12 16:08       ` Avi Kivity
2007-03-12 16:24         ` Joerg Roedel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070309151511.GE13481@amd.com \
    --to=joerg.roedel@amd.com \
    --cc=ak@suse.de \
    --cc=discuss@x86-64.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox