From: Gleb Natapov <gleb@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: avi@redhat.com, kvm@vger.kernel.org, joerg.roedel@amd.com,
mingo@elte.hu, a.p.zijlstra@chello.nl
Subject: [PATCH 8/9] KVM, VMX: Add support for guest/host-only profiling
Date: Mon, 3 Oct 2011 15:49:54 +0200 [thread overview]
Message-ID: <1317649795-18259-9-git-send-email-gleb@redhat.com> (raw)
In-Reply-To: <1317649795-18259-1-git-send-email-gleb@redhat.com>
Support guest/host-only profiling by switch perf msrs on
a guest entry if needed.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
arch/x86/kvm/vmx.c | 35 +++++++++++++++++++++++++++++++++++
1 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index e4cc3c2..fef7bd9 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -39,6 +39,7 @@
#include <asm/mce.h>
#include <asm/i387.h>
#include <asm/xcr.h>
+#include <asm/perf_event.h>
#include "trace.h"
@@ -417,6 +418,9 @@ struct vcpu_vmx {
/* Support for a guest hypervisor (nested VMX) */
struct nested_vmx nested;
+
+ int perf_msrs_cnt;
+ struct perf_guest_switch_msr *perf_msrs;
};
enum segment_cache_field {
@@ -6052,6 +6056,26 @@ static void vmx_cancel_injection(struct kvm_vcpu *vcpu)
vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 0);
}
+static void atomic_switch_perf_msrs(struct vcpu_vmx *vmx)
+{
+#ifdef CONFIG_PERF_EVENTS
+ int i;
+
+ if (!cpu_has_arch_perfmon || vmx->perf_msrs_cnt <= 0)
+ return;
+
+ perf_guest_get_msrs(vmx->perf_msrs_cnt, vmx->perf_msrs);
+ for (i = 0; i < vmx->perf_msrs_cnt; i++) {
+ struct perf_guest_switch_msr *msr = &vmx->perf_msrs[i];
+ if (msr->host == msr->guest)
+ clear_atomic_switch_msr(vmx, msr->msr);
+ else
+ add_atomic_switch_msr(vmx, msr->msr, msr->guest,
+ msr->host);
+ }
+#endif
+}
+
#ifdef CONFIG_X86_64
#define R "r"
#define Q "q"
@@ -6101,6 +6125,8 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
vmx_set_interrupt_shadow(vcpu, 0);
+ atomic_switch_perf_msrs(vmx);
+
vmx->__launched = vmx->loaded_vmcs->launched;
asm(
/* Store host registers */
@@ -6306,6 +6332,15 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
vmx->nested.current_vmptr = -1ull;
vmx->nested.current_vmcs12 = NULL;
+ vmx->perf_msrs_cnt = perf_guest_get_msrs_count();
+ if (vmx->perf_msrs_cnt > 0) {
+ vmx->perf_msrs = kmalloc(vmx->perf_msrs_cnt *
+ sizeof(struct perf_guest_switch_msr),
+ GFP_KERNEL);
+ if (!vmx->perf_msrs)
+ goto free_vmcs;
+ }
+
return &vmx->vcpu;
free_vmcs:
--
1.7.5.3
next prev parent reply other threads:[~2011-10-03 13:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-03 13:49 [PATCH 0/9] perf support for x86 guest/host-only bits Gleb Natapov
2011-10-03 13:49 ` [PATCH 1/9] perf, core: Introduce attrs to count in either host or guest mode Gleb Natapov
2011-10-03 13:49 ` [PATCH 2/9] perf, amd: Use GO/HO bits in perf-ctr Gleb Natapov
2011-10-03 13:49 ` [PATCH 3/9] perf, tools: Add support for guest/host-only profiling Gleb Natapov
2011-10-03 13:49 ` [PATCH 4/9] perf, tools: Fix copy&paste error in perf-kvm option description Gleb Natapov
2011-10-03 13:49 ` [PATCH 5/9] perf, tools: Do guest-only counting in perf-kvm by default Gleb Natapov
2011-10-03 13:49 ` [PATCH 6/9] perf, intel: Use GO/HO bits in perf-ctr Gleb Natapov
2011-10-03 15:06 ` Avi Kivity
2011-10-03 15:41 ` Gleb Natapov
2011-10-04 9:21 ` Avi Kivity
2011-10-03 13:49 ` [PATCH 7/9] KVM, VMX: add support for switching of PERF_GLOBAL_CTRL Gleb Natapov
2011-10-04 9:32 ` Avi Kivity
2011-10-04 9:57 ` Gleb Natapov
2011-10-03 13:49 ` Gleb Natapov [this message]
2011-10-03 15:00 ` [PATCH 8/9] KVM, VMX: Add support for guest/host-only profiling Avi Kivity
2011-10-03 15:36 ` Gleb Natapov
2011-10-04 9:28 ` Avi Kivity
2011-10-04 9:56 ` Gleb Natapov
2011-10-04 11:10 ` Avi Kivity
2011-10-04 11:17 ` Gleb Natapov
2011-10-04 11:24 ` Avi Kivity
2011-10-04 12:12 ` Gleb Natapov
2011-10-03 13:49 ` [PATCH 9/9] KVM, VMX: Check for automatic switch msr table overflow Gleb Natapov
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=1317649795-18259-9-git-send-email-gleb@redhat.com \
--to=gleb@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=avi@redhat.com \
--cc=joerg.roedel@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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
Powered by JetHome