From: ehrhardt@linux.vnet.ibm.com
To: kvm@vger.kernel.org
Cc: hollisb@us.ibm.com, avi@qumranet.com, kvm-ppc@vger.kernel.org,
ehrhardt@linux.vnet.ibm.com
Subject: [PATCH 2/5] kvmtrace: make cycle calculation architecture aware
Date: Mon, 07 Jul 2008 13:56:50 +0000 [thread overview]
Message-ID: <1215439013-11480-3-git-send-email-ehrhardt@linux.vnet.ibm.com> (raw)
In-Reply-To: <1215439013-11480-1-git-send-email-ehrhardt@linux.vnet.ibm.com>
From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
The current implementation of kvmtrace uses always a 64 bit cycle variable,
but get_cycles() which is used to fill it is "unsigned long" which might be 32
bit.
This reduces the accuracy e.g. on embedded powerpc since we would have a 64bit
value but get_cycle() only returns the low 32 bit.
To solve that this patch introduces kvm_arch_trace_cycles() which allows us
to make this calculation architecture aware. That way every architecture can
insert whatever fits best for their "kvmtrace cycle counter".
Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
---
[diffstat]
arch/powerpc/kvm/powerpc.c | 25 +++++++++++++++++++++++++
arch/x86/kvm/x86.c | 5 +++++
include/linux/kvm_host.h | 2 ++
virt/kvm/kvm_trace.c | 2 +-
4 files changed, 33 insertions(+), 1 deletion(-)
[diff]
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -521,6 +521,31 @@
return r;
}
+/*
+ * We need a 64 bit value here and the default get_cycles has only 32bit (tbl)
+ * on 32bit ppc. Since we have a 64bit counter for that we provide it here in
+ * full resolution for the trace records.
+*/
+__u64 kvm_arch_trace_cycles()
+{
+ unsigned long ruval;
+ unsigned long ruval2;
+ unsigned long rlval;
+
+ /* get a consistant pair of upper/lower timebase (no wrap occured) */
+ asm volatile(
+ "loop:\n"
+ "mftbu %0\n"
+ "mftbl %1\n"
+ "mftbu %2\n"
+ "cmpw %0, %2\n"
+ "bne loop"
+ : "=r" (ruval), "=r" (rlval), "=r" (ruval2)
+ );
+
+ return (((__u64)ruval) << 32) | rlval;
+}
+
int kvm_arch_init(void *opaque)
{
return 0;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2458,6 +2458,11 @@
}
EXPORT_SYMBOL_GPL(kvm_emulate_pio_string);
+__u64 kvm_arch_trace_cycles()
+{
+ return get_cycles();
+}
+
int kvm_arch_init(void *opaque)
{
int r;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -278,6 +278,8 @@
int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
+__u64 kvm_arch_trace_cycles(void);
+
static inline void kvm_guest_enter(void)
{
account_system_vtime(current);
diff --git a/virt/kvm/kvm_trace.c b/virt/kvm/kvm_trace.c
--- a/virt/kvm/kvm_trace.c
+++ b/virt/kvm/kvm_trace.c
@@ -74,7 +74,7 @@
| TRACE_REC_NUM_DATA_ARGS(extra);
if (p->cycle_in) {
- rec.u.cycle.cycle_u64 = get_cycles();
+ rec.u.cycle.cycle_u64 = kvm_arch_trace_cycles();
for (i = 0; i < extra; i++)
rec.u.cycle.extra_u32[i] = va_arg(*args, u32);
WARNING: multiple messages have this Message-ID (diff)
From: ehrhardt@linux.vnet.ibm.com
To: kvm@vger.kernel.org
Cc: hollisb@us.ibm.com, avi@qumranet.com, kvm-ppc@vger.kernel.org,
ehrhardt@linux.vnet.ibm.com
Subject: [PATCH 2/5] kvmtrace: make cycle calculation architecture aware
Date: Mon, 7 Jul 2008 15:56:50 +0200 [thread overview]
Message-ID: <1215439013-11480-3-git-send-email-ehrhardt@linux.vnet.ibm.com> (raw)
In-Reply-To: <1215439013-11480-1-git-send-email-ehrhardt@linux.vnet.ibm.com>
From: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
The current implementation of kvmtrace uses always a 64 bit cycle variable,
but get_cycles() which is used to fill it is "unsigned long" which might be 32
bit.
This reduces the accuracy e.g. on embedded powerpc since we would have a 64bit
value but get_cycle() only returns the low 32 bit.
To solve that this patch introduces kvm_arch_trace_cycles() which allows us
to make this calculation architecture aware. That way every architecture can
insert whatever fits best for their "kvmtrace cycle counter".
Signed-off-by: Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
---
[diffstat]
arch/powerpc/kvm/powerpc.c | 25 +++++++++++++++++++++++++
arch/x86/kvm/x86.c | 5 +++++
include/linux/kvm_host.h | 2 ++
virt/kvm/kvm_trace.c | 2 +-
4 files changed, 33 insertions(+), 1 deletion(-)
[diff]
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -521,6 +521,31 @@
return r;
}
+/*
+ * We need a 64 bit value here and the default get_cycles has only 32bit (tbl)
+ * on 32bit ppc. Since we have a 64bit counter for that we provide it here in
+ * full resolution for the trace records.
+*/
+__u64 kvm_arch_trace_cycles()
+{
+ unsigned long ruval;
+ unsigned long ruval2;
+ unsigned long rlval;
+
+ /* get a consistant pair of upper/lower timebase (no wrap occured) */
+ asm volatile(
+ "loop:\n"
+ "mftbu %0\n"
+ "mftbl %1\n"
+ "mftbu %2\n"
+ "cmpw %0, %2\n"
+ "bne loop"
+ : "=r" (ruval), "=r" (rlval), "=r" (ruval2)
+ );
+
+ return (((__u64)ruval) << 32) | rlval;
+}
+
int kvm_arch_init(void *opaque)
{
return 0;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2458,6 +2458,11 @@
}
EXPORT_SYMBOL_GPL(kvm_emulate_pio_string);
+__u64 kvm_arch_trace_cycles()
+{
+ return get_cycles();
+}
+
int kvm_arch_init(void *opaque)
{
int r;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -278,6 +278,8 @@
int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
+__u64 kvm_arch_trace_cycles(void);
+
static inline void kvm_guest_enter(void)
{
account_system_vtime(current);
diff --git a/virt/kvm/kvm_trace.c b/virt/kvm/kvm_trace.c
--- a/virt/kvm/kvm_trace.c
+++ b/virt/kvm/kvm_trace.c
@@ -74,7 +74,7 @@
| TRACE_REC_NUM_DATA_ARGS(extra);
if (p->cycle_in) {
- rec.u.cycle.cycle_u64 = get_cycles();
+ rec.u.cycle.cycle_u64 = kvm_arch_trace_cycles();
for (i = 0; i < extra; i++)
rec.u.cycle.extra_u32[i] = va_arg(*args, u32);
next prev parent reply other threads:[~2008-07-07 13:56 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-07 13:56 [PATCH 0/5] kvmtrace: add powerpc support for KVM_TRACE ehrhardt
2008-07-07 13:56 ` ehrhardt
2008-07-07 13:56 ` [PATCH 1/5] kvmtrace: Remove use of bit fields in kvm trace structure v3 ehrhardt
2008-07-07 13:56 ` ehrhardt
2008-07-07 13:56 ` ehrhardt [this message]
2008-07-07 13:56 ` [PATCH 2/5] kvmtrace: make cycle calculation architecture aware ehrhardt
2008-07-07 15:45 ` Hollis Blanchard
2008-07-07 15:45 ` Hollis Blanchard
2008-07-09 8:25 ` Christian Ehrhardt
2008-07-09 8:25 ` Christian Ehrhardt
2008-07-07 16:37 ` Hollis Blanchard
2008-07-07 16:37 ` Hollis Blanchard
2008-07-09 9:17 ` Christian Ehrhardt
2008-07-09 9:17 ` Christian Ehrhardt
2008-07-09 15:03 ` Hollis Blanchard
2008-07-09 15:03 ` Hollis Blanchard
2008-07-10 10:22 ` Yang, Sheng
2008-07-10 10:22 ` Yang, Sheng
2008-07-10 10:24 ` Yang, Sheng
2008-07-10 10:24 ` Yang, Sheng
2008-07-10 13:32 ` Avi Kivity
2008-07-10 13:32 ` Avi Kivity
2008-07-11 1:06 ` Yang, Sheng
2008-07-11 1:06 ` Yang, Sheng
2008-07-11 7:34 ` Carsten Otte
2008-07-11 7:34 ` Carsten Otte
2008-07-11 15:19 ` Hollis Blanchard
2008-07-11 15:19 ` Hollis Blanchard
2008-07-13 15:41 ` Avi Kivity
2008-07-13 15:41 ` Avi Kivity
2008-07-14 7:44 ` Christian Borntraeger
2008-07-14 7:44 ` Christian Borntraeger
2008-07-07 13:56 ` [PATCH 3/5] kvmppc: kvmtrace: enable KVM_TRACE building for powerpc ehrhardt
2008-07-07 13:56 ` ehrhardt
2008-07-07 13:56 ` [PATCH 4/5] kvmppc: kvmtrace: adds trace points for ppc tlb activity v2 ehrhardt
2008-07-07 13:56 ` ehrhardt
2008-07-07 13:56 ` [PATCH 5/5] kvmppc: kvmtrace: trace powerpc instruction emulation ehrhardt
2008-07-07 13:56 ` ehrhardt
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=1215439013-11480-3-git-send-email-ehrhardt@linux.vnet.ibm.com \
--to=ehrhardt@linux.vnet.ibm.com \
--cc=avi@qumranet.com \
--cc=hollisb@us.ibm.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@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 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.