LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Rik van Riel <riel@redhat.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Avi Kiviti <avi@redhat.com>,
Srivatsa Vaddagiri <vatsa@linux.vnet.ibm.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Mike Galbraith <efault@gmx.de>,
Chris Wright <chrisw@sous-sol.org>,
ttracy@redhat.com, "Nakajima, Jun" <jun.nakajima@intel.com>
Subject: [RFC -v7 PATCH 6/7] kvm: keep track of which task is running a KVM vcpu
Date: Wed, 26 Jan 2011 17:24:08 -0500 [thread overview]
Message-ID: <20110126172408.38dc385e@annuminas.surriel.com> (raw)
In-Reply-To: <20110126165657.2ddd2ac9@annuminas.surriel.com>
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>
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index a055742..9d56ed5 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -81,6 +81,7 @@ struct kvm_vcpu {
#endif
int vcpu_id;
struct mutex mutex;
+ struct pid *pid;
int cpu;
atomic_t guest_mode;
struct kvm_run *run;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 5225052..0fa9a48 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -117,6 +117,14 @@ void vcpu_load(struct kvm_vcpu *vcpu)
int cpu;
mutex_lock(&vcpu->mutex);
+ if (unlikely(vcpu->pid != current->pids[PIDTYPE_PID].pid)) {
+ /* The thread running this VCPU changed. */
+ struct pid *oldpid = vcpu->pid;
+ struct pid *newpid = get_task_pid(current, PIDTYPE_PID);
+ rcu_assign_pointer(vcpu->pid, newpid);
+ synchronize_rcu();
+ put_pid(oldpid);
+ }
cpu = get_cpu();
preempt_notifier_register(&vcpu->preempt_notifier);
kvm_arch_vcpu_load(vcpu, cpu);
@@ -185,6 +193,7 @@ int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id)
vcpu->cpu = -1;
vcpu->kvm = kvm;
vcpu->vcpu_id = id;
+ vcpu->pid = NULL;
init_waitqueue_head(&vcpu->wq);
page = alloc_page(GFP_KERNEL | __GFP_ZERO);
@@ -208,6 +217,7 @@ EXPORT_SYMBOL_GPL(kvm_vcpu_init);
void kvm_vcpu_uninit(struct kvm_vcpu *vcpu)
{
+ put_pid(vcpu->pid);
kvm_arch_vcpu_uninit(vcpu);
free_page((unsigned long)vcpu->run);
}
next prev parent reply other threads:[~2011-01-26 22:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-26 21:56 [RFC -v7 PATCH 0/7] directed yield for Pause Loop Exiting Rik van Riel
2011-01-26 22:19 ` [RFC -v7 PATCH 2/7] sched: limit the scope of clear_buddies Rik van Riel
2011-01-26 22:19 ` [RFC -v7 PATCH 1/7] sched: check the right ->nr_running in yield_task_fair Rik van Riel
2011-01-26 22:21 ` [RFC -v7 PATCH 3/7] sched: use a buddy to implement yield_task_fair Rik van Riel
2011-01-31 11:47 ` Peter Zijlstra
2011-01-31 15:02 ` Rik van Riel
2011-01-26 22:21 ` [RFC -v7 PATCH 4/7] Add yield_to(task, preempt) functionality Rik van Riel
2011-01-31 11:49 ` Peter Zijlstra
2011-01-31 18:11 ` Rik van Riel
2011-01-26 22:23 ` [RFC -v7 PATCH 5/7] export pid symbols needed for kvm_vcpu_on_spin Rik van Riel
2011-01-31 11:51 ` Peter Zijlstra
2011-01-31 13:26 ` Avi Kivity
2011-01-31 13:43 ` Peter Zijlstra
2011-01-31 13:45 ` Avi Kivity
2011-01-26 22:24 ` Rik van Riel [this message]
2011-01-26 22:25 ` [RFC -v7 PATCH 7/7] kvm: use yield_to instead of sleep in kvm_vcpu_on_spin Rik van Riel
2011-01-27 13:20 ` [RFC -v7 PATCH 0/7] directed yield for Pause Loop Exiting Avi Kivity
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=20110126172408.38dc385e@annuminas.surriel.com \
--to=riel@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=avi@redhat.com \
--cc=chrisw@sous-sol.org \
--cc=efault@gmx.de \
--cc=jun.nakajima@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ttracy@redhat.com \
--cc=vatsa@linux.vnet.ibm.com \
--subject='Re: [RFC -v7 PATCH 6/7] kvm: keep track of which task is running a KVM vcpu' \
/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
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).