All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glauber de Oliveira Costa <gcosta@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, glommer@gmail.com, tglx@linutronix.de,
	mingo@elte.hu, ehabkost@redhat.com, jeremy@goop.org,
	avi@qumranet.com, anthony@codemonkey.ws,
	virtualization@lists.linux-foundation.org, rusty@rustcorp.com.au,
	ak@suse.de, chrisw@sous-sol.org, rostedt@goodmis.org,
	hpa@zytor.com, Glauber de Oliveira Costa <gcosta@redhat.com>
Subject: [PATCH 4/10] split get_cycles_sync
Date: Tue,  4 Dec 2007 09:09:58 -0200	[thread overview]
Message-ID: <11967666263502-git-send-email-gcosta@redhat.com> (raw)
In-Reply-To: <11967666212496-git-send-email-gcosta@redhat.com>

This patch splits get_cycles_sync() into  __get_cycles_sync(),
and the rdtscll part. Paravirt guests cannot issue rdtscl directly,
as it involves a function call in vdso area.

So, using the __get_cycles_sync() base, we introduce vget_cycles_sync,
which then calls the native version of rdtscll. Ideally, however, a guest
should define its own clocksource, together with a vread function

Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com>
---
 arch/x86/kernel/tsc_64.c |    2 +-
 include/asm-x86/tsc.h    |   37 +++++++++++++++++++++++++++++++++----
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/tsc_64.c b/arch/x86/kernel/tsc_64.c
index 5158476..4502539 100644
--- a/arch/x86/kernel/tsc_64.c
+++ b/arch/x86/kernel/tsc_64.c
@@ -269,7 +269,7 @@ static cycle_t read_tsc(void)
 
 static cycle_t __vsyscall_fn vread_tsc(void)
 {
-	cycle_t ret = (cycle_t)get_cycles_sync();
+	cycle_t ret = (cycle_t)vget_cycles_sync();
 	return ret;
 }
 
diff --git a/include/asm-x86/tsc.h b/include/asm-x86/tsc.h
index 6baab30..d6cb056 100644
--- a/include/asm-x86/tsc.h
+++ b/include/asm-x86/tsc.h
@@ -33,14 +33,14 @@ 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)
+static __always_inline cycles_t __get_cycles_sync(void)
 {
 	unsigned long long ret;
 	unsigned eax, edx;
 
 	/*
-  	 * Use RDTSCP if possible; it is guaranteed to be synchronous
- 	 * and doesn't cause a VMEXIT on Hypervisors
+	 * Use RDTSCP if possible; it is guaranteed to be synchronous
+	 * and doesn't cause a VMEXIT on Hypervisors
 	 */
 	alternative_io(ASM_NOP3, ".byte 0x0f,0x01,0xf9", X86_FEATURE_RDTSCP,
 		       ASM_OUTPUT2("=a" (eax), "=d" (edx)),
@@ -55,11 +55,40 @@ static __always_inline cycles_t get_cycles_sync(void)
 	 */
 	alternative_io("cpuid", ASM_NOP2, X86_FEATURE_SYNC_RDTSC,
 			  "=a" (eax), "0" (1) : "ebx","ecx","edx","memory");
-	rdtscll(ret);
 
+	return 0;
+}
+
+static __always_inline cycles_t get_cycles_sync(void)
+{
+	unsigned long long ret;
+	ret = __get_cycles_sync();
+	if (!ret)
+		rdtscll(ret);
 	return ret;
 }
 
+#ifdef CONFIG_PARAVIRT
+/*
+ * For paravirt guests, some functionalities are executed through function
+ * pointers in the various pvops structures.
+ * These function pointers exist inside the kernel and can not
+ * be accessed by user space. To avoid this, we make a copy of the
+ * get_cycles_sync (called in kernel) but force the use of native_read_tsc.
+ * Ideally, the guest should set up it's own clock and vread
+ */
+static __always_inline long long vget_cycles_sync(void)
+{
+	unsigned long long ret;
+	ret = __get_cycles_sync();
+	if (!ret)
+		ret = native_read_tsc();
+	return ret;
+}
+#else
+# define vget_cycles_sync() get_cycles_sync()
+#endif
+
 extern void tsc_init(void);
 extern void mark_tsc_unstable(char *reason);
 extern int unsynchronized_tsc(void);
-- 
1.4.4.2


  reply	other threads:[~2007-12-04 13:55 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-04 11:09 [PATCH 0/10] Integrate msr.h Glauber de Oliveira Costa
2007-12-04 11:09 ` [PATCH 1/10] Wipe out traditional opt from x86_64 Makefile Glauber de Oliveira Costa
2007-12-04 11:09   ` Glauber de Oliveira Costa
2007-12-04 11:09   ` [PATCH 2/10] unify msr smp funcs Glauber de Oliveira Costa
2007-12-04 11:09   ` Glauber de Oliveira Costa
2007-12-04 11:09     ` [PATCH 3/10] allow sched clock to be overridden by paravirt Glauber de Oliveira Costa
2007-12-04 11:09     ` Glauber de Oliveira Costa
2007-12-04 11:09       ` Glauber de Oliveira Costa [this message]
2007-12-04 11:09         ` [PATCH 5/10] unify cpuid functions Glauber de Oliveira Costa
2007-12-04 11:09           ` Glauber de Oliveira Costa
2007-12-04 11:10           ` [PATCH 6/10] introduce native_read_tscp Glauber de Oliveira Costa
2007-12-04 11:10             ` Glauber de Oliveira Costa
2007-12-04 11:10             ` [PATCH 7/10] change rdpmc interface Glauber de Oliveira Costa
2007-12-04 11:10               ` Glauber de Oliveira Costa
2007-12-04 11:10               ` [PATCH 8/10] change write msr functions interface Glauber de Oliveira Costa
2007-12-04 11:10                 ` Glauber de Oliveira Costa
2007-12-04 11:10                 ` [PATCH 9/10] make fixups wordsize agnostic Glauber de Oliveira Costa
2007-12-04 11:10                   ` Glauber de Oliveira Costa
2007-12-04 11:10                   ` [PATCH 10/10] integrate i386 and x86_64 code in msr.h Glauber de Oliveira Costa
2007-12-04 11:10                     ` Glauber de Oliveira Costa
2007-12-04 11:09       ` [PATCH 4/10] split get_cycles_sync Glauber de Oliveira Costa
2007-12-04 13:56       ` [PATCH 3/10] allow sched clock to be overridden by paravirt Andi Kleen
2007-12-04 13:56       ` Andi Kleen
2007-12-04 14:09 ` [PATCH 0/10] Integrate msr.h Ingo Molnar
2007-12-04 15:47   ` Glauber de Oliveira Costa
2007-12-04 15:47   ` Glauber de Oliveira Costa
2007-12-04 14:09 ` Ingo Molnar
2007-12-04 16:03 [PATCH 0/10 - V2] msr.h integration - fixups Glauber de Oliveira Costa
2007-12-04 16:03 ` [PATCH 1/10] Wipe out traditional opt from x86_64 Makefile Glauber de Oliveira Costa
2007-12-04 16:03   ` [PATCH 2/10] unify msr smp funcs Glauber de Oliveira Costa
2007-12-04 16:03     ` [PATCH 3/10] allow sched clock to be overridden by paravirt Glauber de Oliveira Costa
2007-12-04 16:03       ` [PATCH 4/10] split get_cycles_sync Glauber de Oliveira Costa
2007-12-04 16:03         ` Glauber de Oliveira Costa

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=11967666263502-git-send-email-gcosta@redhat.com \
    --to=gcosta@redhat.com \
    --cc=ak@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=anthony@codemonkey.ws \
    --cc=avi@qumranet.com \
    --cc=chrisw@sous-sol.org \
    --cc=ehabkost@redhat.com \
    --cc=glommer@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=rusty@rustcorp.com.au \
    --cc=tglx@linutronix.de \
    --cc=virtualization@lists.linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.