Skip to content

Commit

Permalink
kvm: Record the preemption status of vcpus using preempt notifiers
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Marcelo Tosatti <[email protected]>
Signed-off-by: Raghavendra K T <[email protected]>
Signed-off-by: Gleb Natapov <[email protected]>
  • Loading branch information
ktraghavendra authored and Gleb Natapov committed Mar 11, 2013
1 parent 5da5960 commit 3a08a8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/linux/kvm_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ struct kvm_vcpu {
bool dy_eligible;
} spin_loop;
#endif
bool preempted;
struct kvm_vcpu_arch arch;
};

Expand Down
5 changes: 5 additions & 0 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id)

kvm_vcpu_set_in_spin_loop(vcpu, false);
kvm_vcpu_set_dy_eligible(vcpu, false);
vcpu->preempted = false;

r = kvm_arch_vcpu_init(vcpu);
if (r < 0)
Expand Down Expand Up @@ -2880,6 +2881,8 @@ struct kvm_vcpu *preempt_notifier_to_vcpu(struct preempt_notifier *pn)
static void kvm_sched_in(struct preempt_notifier *pn, int cpu)
{
struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn);
if (vcpu->preempted)
vcpu->preempted = false;

kvm_arch_vcpu_load(vcpu, cpu);
}
Expand All @@ -2889,6 +2892,8 @@ static void kvm_sched_out(struct preempt_notifier *pn,
{
struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn);

if (current->state == TASK_RUNNING)
vcpu->preempted = true;
kvm_arch_vcpu_put(vcpu);
}

Expand Down

0 comments on commit 3a08a8f

Please sign in to comment.