From: "Nikunj A. Dadhania" <nikunj@linux.vnet.ibm.com>
To: peterz@infradead.org, mingo@elte.hu
Cc: jeremy@goop.org, mtosatti@redhat.com, kvm@vger.kernel.org,
x86@kernel.org, vatsa@linux.vnet.ibm.com,
linux-kernel@vger.kernel.org, avi@redhat.com, hpa@zytor.com
Subject: [RFC PATCH v1 1/5] KVM Guest: Add VCPU running/pre-empted state for guest
Date: Fri, 27 Apr 2012 21:53:33 +0530 [thread overview]
Message-ID: <20120427162314.27082.13703.stgit@abhimanyu> (raw)
In-Reply-To: <20120427161727.27082.43096.stgit@abhimanyu>
The patch adds guest code for msr between guest and hypervisor. The
msr will export the vcpu running/pre-empted information to the guest
from host. This will enable guest to intelligently send ipi to running
vcpus and set flag for pre-empted vcpus. This will prevent waiting for
vcpus that are not running.
Suggested-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: Nikunj A. Dadhania <nikunj@linux.vnet.ibm.com>
---
arch/x86/include/asm/kvm_para.h | 10 ++++++++++
arch/x86/kernel/kvm.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h
index 77266d3..f57b5cc 100644
--- a/arch/x86/include/asm/kvm_para.h
+++ b/arch/x86/include/asm/kvm_para.h
@@ -24,6 +24,7 @@
#define KVM_FEATURE_ASYNC_PF 4
#define KVM_FEATURE_STEAL_TIME 5
#define KVM_FEATURE_PV_UNHALT 6
+#define KVM_FEATURE_VCPU_STATE 7
/* The last 8 bits are used to indicate how to interpret the flags field
* in pvclock structure. If no bits are set, all flags are ignored.
@@ -39,6 +40,7 @@
#define MSR_KVM_SYSTEM_TIME_NEW 0x4b564d01
#define MSR_KVM_ASYNC_PF_EN 0x4b564d02
#define MSR_KVM_STEAL_TIME 0x4b564d03
+#define MSR_KVM_VCPU_STATE 0x4b564d04
struct kvm_steal_time {
__u64 steal;
@@ -51,6 +53,14 @@ struct kvm_steal_time {
#define KVM_STEAL_VALID_BITS ((-1ULL << (KVM_STEAL_ALIGNMENT_BITS + 1)))
#define KVM_STEAL_RESERVED_MASK (((1 << KVM_STEAL_ALIGNMENT_BITS) - 1 ) << 1)
+struct kvm_vcpu_state {
+ __u32 state;
+ __u32 pad[15];
+};
+
+#define KVM_VCPU_STATE_ALIGN_BITS 5
+#define KVM_VCPU_STATE_VALID_BITS ((-1ULL << (KVM_VCPU_STATE_ALIGN_BITS + 1)))
+
#define KVM_MAX_MMU_OP_BATCH 32
#define KVM_ASYNC_PF_ENABLED (1 << 0)
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 98f0378..bb686a6 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -64,6 +64,9 @@ static DEFINE_PER_CPU(struct kvm_vcpu_pv_apf_data, apf_reason) __aligned(64);
static DEFINE_PER_CPU(struct kvm_steal_time, steal_time) __aligned(64);
static int has_steal_clock = 0;
+DEFINE_PER_CPU(struct kvm_vcpu_state, vcpu_state) __aligned(64);
+static int has_vcpu_state;
+
/*
* No need for any "IO delay" on KVM
*/
@@ -291,6 +294,22 @@ static void kvm_register_steal_time(void)
cpu, __pa(st));
}
+static void kvm_register_vcpu_state(void)
+{
+ int cpu = smp_processor_id();
+ struct kvm_vcpu_state *v_state;
+
+ if (!has_vcpu_state)
+ return;
+
+ v_state = &per_cpu(vcpu_state, cpu);
+ memset(v_state, 0, sizeof(*v_state));
+
+ wrmsrl(MSR_KVM_VCPU_STATE, (__pa(v_state) | KVM_MSR_ENABLED));
+ printk(KERN_INFO "kvm-vcpustate: cpu %d, msr %lu\n",
+ cpu, __pa(v_state));
+}
+
void __cpuinit kvm_guest_cpu_init(void)
{
if (!kvm_para_available())
@@ -310,6 +329,9 @@ void __cpuinit kvm_guest_cpu_init(void)
if (has_steal_clock)
kvm_register_steal_time();
+
+ if (has_vcpu_state)
+ kvm_register_vcpu_state();
}
static void kvm_pv_disable_apf(void *unused)
@@ -361,6 +383,14 @@ void kvm_disable_steal_time(void)
wrmsr(MSR_KVM_STEAL_TIME, 0, 0);
}
+void kvm_disable_vcpu_state(void)
+{
+ if (!has_vcpu_state)
+ return;
+
+ wrmsr(MSR_KVM_VCPU_STATE, 0, 0);
+}
+
#ifdef CONFIG_SMP
static void __init kvm_smp_prepare_boot_cpu(void)
{
@@ -379,6 +409,7 @@ static void __cpuinit kvm_guest_cpu_online(void *dummy)
static void kvm_guest_cpu_offline(void *dummy)
{
+ kvm_disable_vcpu_state();
kvm_disable_steal_time();
kvm_pv_disable_apf(NULL);
apf_task_wake_all();
@@ -433,6 +464,8 @@ void __init kvm_guest_init(void)
pv_time_ops.steal_clock = kvm_steal_clock;
}
+ has_vcpu_state = 1;
+
#ifdef CONFIG_SMP
smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
register_cpu_notifier(&kvm_cpu_notifier);
next prev parent reply other threads:[~2012-04-27 16:24 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-27 16:23 [RFC PATCH v1 0/5] KVM paravirt remote flush tlb Nikunj A. Dadhania
2012-04-27 16:23 ` Nikunj A. Dadhania [this message]
2012-05-01 1:03 ` [RFC PATCH v1 1/5] KVM Guest: Add VCPU running/pre-empted state for guest Raghavendra K T
2012-05-01 3:25 ` Nikunj A Dadhania
2012-04-27 16:23 ` [RFC PATCH v1 2/5] KVM-HV: " Nikunj A. Dadhania
2012-04-27 16:24 ` [RFC PATCH v1 3/5] KVM: Add paravirt kvm_flush_tlb_others Nikunj A. Dadhania
2012-04-29 12:23 ` Avi Kivity
2012-05-01 3:34 ` Nikunj A Dadhania
2012-05-01 9:39 ` Peter Zijlstra
2012-05-01 10:47 ` Avi Kivity
2012-05-01 10:57 ` Peter Zijlstra
2012-05-01 10:59 ` Peter Zijlstra
2012-05-01 22:49 ` Jeremy Fitzhardinge
2012-05-03 14:09 ` Stefano Stabellini
2012-05-01 12:12 ` Avi Kivity
2012-05-01 14:59 ` Peter Zijlstra
2012-05-01 15:31 ` Avi Kivity
2012-05-01 15:36 ` Peter Zijlstra
2012-05-01 15:39 ` Avi Kivity
2012-05-01 15:42 ` Peter Zijlstra
2012-05-01 15:11 ` Peter Zijlstra
2012-05-01 15:33 ` Avi Kivity
2012-05-01 15:14 ` Peter Zijlstra
2012-05-01 15:36 ` Avi Kivity
2012-05-01 16:16 ` Peter Zijlstra
2012-05-01 16:43 ` Paul E. McKenney
2012-05-01 16:18 ` Peter Zijlstra
2012-05-01 16:20 ` Peter Zijlstra
2012-05-02 8:51 ` Nikunj A Dadhania
2012-05-02 10:20 ` Peter Zijlstra
2012-05-02 13:53 ` Nikunj A Dadhania
2012-05-04 4:32 ` Nikunj A Dadhania
2012-05-04 11:44 ` Srivatsa Vaddagiri
2012-05-07 3:10 ` Nikunj A Dadhania
2012-04-27 16:26 ` [RFC PATCH v1 4/5] KVM: get kvm_kick_vcpu out for pv_flush Nikunj A. Dadhania
2012-04-27 16:27 ` [RFC PATCH v1 5/5] KVM: Introduce PV kick in flush tlb Nikunj A. Dadhania
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=20120427162314.27082.13703.stgit@abhimanyu \
--to=nikunj@linux.vnet.ibm.com \
--cc=avi@redhat.com \
--cc=hpa@zytor.com \
--cc=jeremy@goop.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mtosatti@redhat.com \
--cc=peterz@infradead.org \
--cc=vatsa@linux.vnet.ibm.com \
--cc=x86@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;
as well as URLs for NNTP newsgroup(s).