diff options
author | Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com> | 2013-03-04 13:02:07 -0500 |
---|---|---|
committer | Gleb Natapov <gleb@redhat.com> | 2013-03-11 05:37:08 -0400 |
commit | 3a08a8f9f0936e182d387afd85fdc5d303381521 (patch) | |
tree | 092f3ba314b1822b84fa24af6f211c9388bc566d /virt/kvm | |
parent | 5da596078f915a62e39a20e582308eab91b88c9a (diff) |
kvm: Record the preemption status of vcpus using preempt notifiers
Note that we mark as preempted only when vcpu's task state was
Running during preemption.
Thanks Jiannan, Avi for preemption notifier ideas. Thanks Gleb, PeterZ
for their precious suggestions. Thanks Srikar for an idea on avoiding
rcu lock while checking task state that improved overcommit numbers.
Reviewed-by: Chegu Vinod <chegu_vinod@hp.com>
Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>
Signed-off-by: Gleb Natapov <gleb@redhat.com>
Diffstat (limited to 'virt/kvm')
-rw-r--r-- | virt/kvm/kvm_main.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index faf05bddd131..470f2bc8205a 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -244,6 +244,7 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id) | |||
244 | 244 | ||
245 | kvm_vcpu_set_in_spin_loop(vcpu, false); | 245 | kvm_vcpu_set_in_spin_loop(vcpu, false); |
246 | kvm_vcpu_set_dy_eligible(vcpu, false); | 246 | kvm_vcpu_set_dy_eligible(vcpu, false); |
247 | vcpu->preempted = false; | ||
247 | 248 | ||
248 | r = kvm_arch_vcpu_init(vcpu); | 249 | r = kvm_arch_vcpu_init(vcpu); |
249 | if (r < 0) | 250 | if (r < 0) |
@@ -2880,6 +2881,8 @@ struct kvm_vcpu *preempt_notifier_to_vcpu(struct preempt_notifier *pn) | |||
2880 | static void kvm_sched_in(struct preempt_notifier *pn, int cpu) | 2881 | static void kvm_sched_in(struct preempt_notifier *pn, int cpu) |
2881 | { | 2882 | { |
2882 | struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn); | 2883 | struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn); |
2884 | if (vcpu->preempted) | ||
2885 | vcpu->preempted = false; | ||
2883 | 2886 | ||
2884 | kvm_arch_vcpu_load(vcpu, cpu); | 2887 | kvm_arch_vcpu_load(vcpu, cpu); |
2885 | } | 2888 | } |
@@ -2889,6 +2892,8 @@ static void kvm_sched_out(struct preempt_notifier *pn, | |||
2889 | { | 2892 | { |
2890 | struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn); | 2893 | struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn); |
2891 | 2894 | ||
2895 | if (current->state == TASK_RUNNING) | ||
2896 | vcpu->preempted = true; | ||
2892 | kvm_arch_vcpu_put(vcpu); | 2897 | kvm_arch_vcpu_put(vcpu); |
2893 | } | 2898 | } |
2894 | 2899 | ||