kvm: Simplify kvm_get_running_vcpu()
PATCH 1/1 kvm: Simplify kvm_get_running_vcpu()
From: Lai Jiangshan <[email protected]>
this_cpu_read() is exactly the same behavior as "preempt_disable() + __this_cpu_read() + preempt_enable()", and it uses less instructions in X86.
Just use this_cpu_read() to simplify kvm_get_running_vcpu().
Cc Marc Zyngier <[email protected]>
Cc Zenghui Yu <[email protected]>
Signed-off-by Lai Jiangshan <[email protected]>
--- virt/kvm/kvm_main.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
virt/kvm/kvm_main.c +2 -9
@@ -6306,21 +6306,14 @@ static void kvm_sched_out(struct preempt_notifier *pn,/** * kvm_get_running_vcpu - get the vcpu running on the current CPU. * -* We can disable preemption locally around accessing the per-CPU variable, -* and use the resolved vcpu pointer after enabling preemption again, +* The result is either NULL or the vcpu running on the current thread * because even if the current thread is migrated to another CPU, reading * the per-CPU value later will give us the same value as we update the * per-CPU variable in the preempt notifier handlers. */ struct kvm_vcpu *kvm_get_running_vcpu (void ) { -struct kvm_vcpu *vcpu; - -preempt_disable (); - vcpu =__this_cpu_read (kvm_running_vcpu); -preempt_enable (); - -return vcpu; +return this_cpu_read (kvm_running_vcpu); }EXPORT_SYMBOL_GPL (kvm_get_running_vcpu);
Signature · 1 line
2.19.1.6.gb485710b
Queued, thanks.
Paolo