linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chen Yu <yu.c.chen@intel.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org, x86@kernel.org,
	linux-kernel@vger.kernel.org,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <lenb@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>,
	Radim Krcmar <rkrcmar@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Wanpeng Li <wanpeng.li@hotmail.com>
Subject: Re: [PATCH][RFC] VM: x86: Return ealier if clocksource has not changed
Date: Tue, 27 Dec 2016 16:06:44 +0800	[thread overview]
Message-ID: <20161227080644.GA5370@yu-desktop-1.sh.intel.com> (raw)
In-Reply-To: <20161226194422.GA30796@amt.cnet>

Hi Marcelo,
On Mon, Dec 26, 2016 at 05:44:25PM -0200, Marcelo Tosatti wrote:
> On Fri, Dec 23, 2016 at 04:41:53PM +0800, Chen Yu wrote:
> > Currently the notifier of pvclock_gtod_notify() get invoked
> > frequently due to the periodic update_wall_time(). This might
> > slow down the system a little bit as there might be redundant
> > execution code path and unnecessary lock contention
> > in update_pvclock_gtod(), which was found when I was doing
> > suspend/resume speed testings. As pvclock_gtod_notify()
> > should be invoked only when clocksource has changed, according to
> > Commit 16e8d74d2da9 ("KVM: x86: notifier for clocksource changes")
> > , either we can add a new notifier for clocksource switch,
> > or we can simply bypass the following code in pvclock_gtod_notify()
> > earlier if there is no clocksource switch.
> > 
> > Cc: Paolo Bonzini <pbonzini@redhat.com>
> > Cc: "Radim Krcmar" <rkrcmar@redhat.com>
> > Cc: Marcelo Tosatti <mtosatti@redhat.com>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: "H. Peter Anvin" <hpa@zytor.com>
> > Cc: Wanpeng Li <wanpeng.li@hotmail.com>
> > Signed-off-by: Chen Yu <yu.c.chen@intel.com>
> > ---
> >  arch/x86/kvm/x86.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> > index 445c51b..54aa32d 100644
> > --- a/arch/x86/kvm/x86.c
> > +++ b/arch/x86/kvm/x86.c
> > @@ -5961,13 +5961,14 @@ static int pvclock_gtod_notify(struct notifier_block *nb, unsigned long unused,
> >  	struct pvclock_gtod_data *gtod = &pvclock_gtod_data;
> >  	struct timekeeper *tk = priv;
> >  
> > +	if (likely(gtod->clock.vclock_mode == VCLOCK_TSC))
> > +		return 0;
> 
> I think this is only safe if any of the values in "struct
> pvclock_gtod_data" are unchanged. Otherwise the local (KVM) copy is 
> kept incorrect.
I missread the code previously and I thought only under the condition
the clocksource has been switched to another one will the KVM copy
be touched. Apparently it is not the case because the copy should
be updated on-time during normal tick, right?
thanks for your reply,
Yu
> 
> >  	update_pvclock_gtod(tk);
> >  
> >  	/* disable master clock if host does not trust, or does not
> >  	 * use, TSC clocksource
> >  	 */
> > -	if (gtod->clock.vclock_mode != VCLOCK_TSC &&
> > -	    atomic_read(&kvm_guest_has_master_clock) != 0)
> > +	if (atomic_read(&kvm_guest_has_master_clock) != 0)
> >  		queue_work(system_long_wq, &pvclock_gtod_work);
> >  
> >  	return 0;
> > -- 
> > 2.7.4

  reply	other threads:[~2016-12-27  7:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-23  8:41 [PATCH][RFC] VM: x86: Return ealier if clocksource has not changed Chen Yu
2016-12-26 19:44 ` Marcelo Tosatti
2016-12-27  8:06   ` Chen Yu [this message]
2016-12-27 15:32     ` Marcelo Tosatti
2016-12-29  8:59       ` Chen Yu
2016-12-29  9:57         ` Marcelo Tosatti
2016-12-29 13:54           ` Chen Yu

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=20161227080644.GA5370@yu-desktop-1.sh.intel.com \
    --to=yu.c.chen@intel.com \
    --cc=hpa@zytor.com \
    --cc=kvm@vger.kernel.org \
    --cc=lenb@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rjw@rjwysocki.net \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=wanpeng.li@hotmail.com \
    --cc=x86@kernel.org \
    /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 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).