diff options
author | Rik van Riel <riel@redhat.com> | 2011-02-01 09:52:41 -0500 |
---|---|---|
committer | Marcelo Tosatti <mtosatti@redhat.com> | 2011-03-17 12:08:29 -0400 |
commit | 34bb10b79de7df118de832f6832efb630e646577 (patch) | |
tree | 2284a88be869a13a55b0435eafa572cde9ae53aa /virt/kvm/kvm_main.c | |
parent | 77c100c83e84316ced2507c5799f79c2c80bc6b9 (diff) |
KVM: keep track of which task is running a KVM vcpu
Keep track of which task is running a KVM vcpu. This helps us
figure out later what task to wake up if we want to boost a
vcpu that got preempted.
Unfortunately there are no guarantees that the same task
always keeps the same vcpu, so we can only track the task
across a single "run" of the vcpu.
Signed-off-by: Rik van Riel <riel@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'virt/kvm/kvm_main.c')
-rw-r--r-- | virt/kvm/kvm_main.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 002fe0b12c9f..bc8bfd15ab71 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -137,6 +137,14 @@ void vcpu_load(struct kvm_vcpu *vcpu) | |||
137 | int cpu; | 137 | int cpu; |
138 | 138 | ||
139 | mutex_lock(&vcpu->mutex); | 139 | mutex_lock(&vcpu->mutex); |
140 | if (unlikely(vcpu->pid != current->pids[PIDTYPE_PID].pid)) { | ||
141 | /* The thread running this VCPU changed. */ | ||
142 | struct pid *oldpid = vcpu->pid; | ||
143 | struct pid *newpid = get_task_pid(current, PIDTYPE_PID); | ||
144 | rcu_assign_pointer(vcpu->pid, newpid); | ||
145 | synchronize_rcu(); | ||
146 | put_pid(oldpid); | ||
147 | } | ||
140 | cpu = get_cpu(); | 148 | cpu = get_cpu(); |
141 | preempt_notifier_register(&vcpu->preempt_notifier); | 149 | preempt_notifier_register(&vcpu->preempt_notifier); |
142 | kvm_arch_vcpu_load(vcpu, cpu); | 150 | kvm_arch_vcpu_load(vcpu, cpu); |
@@ -212,6 +220,7 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id) | |||
212 | vcpu->cpu = -1; | 220 | vcpu->cpu = -1; |
213 | vcpu->kvm = kvm; | 221 | vcpu->kvm = kvm; |
214 | vcpu->vcpu_id = id; | 222 | vcpu->vcpu_id = id; |
223 | vcpu->pid = NULL; | ||
215 | init_waitqueue_head(&vcpu->wq); | 224 | init_waitqueue_head(&vcpu->wq); |
216 | kvm_async_pf_vcpu_init(vcpu); | 225 | kvm_async_pf_vcpu_init(vcpu); |
217 | 226 | ||
@@ -236,6 +245,7 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_init); | |||
236 | 245 | ||
237 | void kvm_vcpu_uninit(struct kvm_vcpu *vcpu) | 246 | void kvm_vcpu_uninit(struct kvm_vcpu *vcpu) |
238 | { | 247 | { |
248 | put_pid(vcpu->pid); | ||
239 | kvm_arch_vcpu_uninit(vcpu); | 249 | kvm_arch_vcpu_uninit(vcpu); |
240 | free_page((unsigned long)vcpu->run); | 250 | free_page((unsigned long)vcpu->run); |
241 | } | 251 | } |