All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: "Li,Rongqing" <lirongqing@baidu.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"vkuznets@redhat.com" <vkuznets@redhat.com>
Subject: Re: 答复: [PATCH] KVM: VMX: optimize pi_wakeup_handler
Date: Mon, 4 Apr 2022 15:15:13 +0000	[thread overview]
Message-ID: <YksLgfrKuX78e0ja@google.com> (raw)
In-Reply-To: <d63acc4d9ac24a48b49415a45238e907@baidu.com>

On Sat, Apr 02, 2022, Li,Rongqing wrote:
> > 发件人: Paolo Bonzini <paolo.bonzini@gmail.com> 代表 Paolo Bonzini
> > On 4/2/22 06:01, Li RongQing wrote:
> > > pi_wakeup_handler is used to wakeup the sleep vCPUs by posted irq
> > > list_for_each_entry is used in it, and whose input is other function
> > > per_cpu(), That cause that per_cpu() be invoked at least twice when
> > > there is one sleep vCPU
> > >
> > > so optimize pi_wakeup_handler it by reading once which is safe in
> > > spinlock protection

There's no need to protect reading the per-cpu variable with the spinlock, only
walking the list needs to be protected.  E.g. the code can be compacted to:

	int cpu = smp_processor_id();
	raw_spinlock_t *spinlock = &per_cpu(wakeup_vcpus_on_cpu_lock, cpu);
	struct list_head *wakeup_list = &per_cpu(wakeup_vcpus_on_cpu, cpu);
	struct vcpu_vmx *vmx;

	raw_spin_lock(spinlock);
	list_for_each_entry(vmx, wakeup_list, pi_wakeup_list) {
		if (pi_test_on(&vmx->pi_desc))
			kvm_vcpu_wake_up(&vmx->vcpu);
	}
	raw_spin_unlock(spinlock);

> > >
> > > and same to per CPU spinlock
> > 
> > What's the difference in the generated code?
> > 
> 
> This reduces one fifth asm codes

...

> these is a similar patch 031e3bd8986fffe31e1ddbf5264cccfe30c9abd7

Is there a measurable performance improvement though?  I don't dislike the patch,
but it probably falls into the "technically an optimization but no one will ever
notice" category.

  reply	other threads:[~2022-04-04 15:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-02  4:01 [PATCH] KVM: VMX: optimize pi_wakeup_handler Li RongQing
2022-04-02  8:14 ` Paolo Bonzini
2022-04-02  8:32   ` 答复: " Li,Rongqing
2022-04-04 15:15     ` Sean Christopherson [this message]
2022-04-05  8:26       ` 答复: " Li,Rongqing

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=YksLgfrKuX78e0ja@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=lirongqing@baidu.com \
    --cc=pbonzini@redhat.com \
    --cc=vkuznets@redhat.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.