Skip to content

Commit 91ab933

Browse files
lrq-maxbonzini
authored andcommitted
KVM: VMX: clean up pi_wakeup_handler
Passing per_cpu() to list_for_each_entry() causes the macro to be evaluated N+1 times for N sleeping vCPUs. This is a very small inefficiency, and the code is cleaner if the address of the per-CPU variable is loaded earlier. Do this for both the list and the spinlock. Signed-off-by: Li RongQing <lirongqing@baidu.com> Message-Id: <1649244302-6777-1-git-send-email-lirongqing@baidu.com> Reviewed-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 33fbe6b commit 91ab933

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

arch/x86/kvm/vmx/posted_intr.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,17 @@ void vmx_vcpu_pi_put(struct kvm_vcpu *vcpu)
202202
void pi_wakeup_handler(void)
203203
{
204204
int cpu = smp_processor_id();
205+
struct list_head *wakeup_list = &per_cpu(wakeup_vcpus_on_cpu, cpu);
206+
raw_spinlock_t *spinlock = &per_cpu(wakeup_vcpus_on_cpu_lock, cpu);
205207
struct vcpu_vmx *vmx;
206208

207-
raw_spin_lock(&per_cpu(wakeup_vcpus_on_cpu_lock, cpu));
208-
list_for_each_entry(vmx, &per_cpu(wakeup_vcpus_on_cpu, cpu),
209-
pi_wakeup_list) {
209+
raw_spin_lock(spinlock);
210+
list_for_each_entry(vmx, wakeup_list, pi_wakeup_list) {
210211

211212
if (pi_test_on(&vmx->pi_desc))
212213
kvm_vcpu_wake_up(&vmx->vcpu);
213214
}
214-
raw_spin_unlock(&per_cpu(wakeup_vcpus_on_cpu_lock, cpu));
215+
raw_spin_unlock(spinlock);
215216
}
216217

217218
void __init pi_init_cpu(int cpu)

0 commit comments

Comments
 (0)