LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Andy Lutomirski <luto@kernel.org>
To: Thomas Gleixner <tglx@linutronix.de>,
	Stephen Boyd <sboyd@kernel.org>,
	John Stultz <john.stultz@linaro.org>
Cc: michael-git@rodin.online, X86 ML <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Lutomirski <luto@kernel.org>
Subject: Re: [PATCH] arch/x86/entry/vsyscall/vsyscall_gtod.c: remove __read_mostly from vclocks_used
Date: Fri, 22 Jun 2018 16:25:34 -0700	[thread overview]
Message-ID: <CALCETrVDuqie6WS--gyb9ohEKXmreA+iN5P-raJbnfS7Tp8nkQ@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.21.1806222333070.1589@nanos.tec.linutronix.de>

On Fri, Jun 22, 2018 at 3:47 PM Thomas Gleixner <tglx@linutronix.de> wrote:
>
> Michael,
>
> On Mon, 4 Jun 2018, Michael Rodin wrote:
>
> > The variable "vclocks_used" doesn't appear to be "read mostly".
> > Measurements of the access frequency with perf stat [1] and
> > perf report show, that approximately half of the accesses to
> > this variable are write accesses and happen in update_vsyscall()
> > in the file arch/x86/entry/vsyscall/vsyscall_gtod.c.
> > The measurements were done with the kernel 4.13.0-43-generic used by
> > ubuntu as well as with the stable kernel 4.16.7 with a custom config.
> > I've used "perf bench sched" and iperf3 as workloads.
> >
> > This was discovered during my master thesis in the CADOS project [2].
>
> Nice find, but ...
>
> The point is that the content of that variable changes once in a blue moon,
> so the intent of marking it read_mostly is almost correct.

I would propose a rather different fix.  Add a an
arch_change_clocksource() function.  Do:

static inline void arch_change_clocksource(struct clocksource
*new_clocksource) { ... }
#define arch_change_clocksource arch_change_clocksource

and

#ifndef arch_change_clocksource
static inline void arch_change_clocksource(struct clocksource
*new_clocksource) {}
#endif

in the generic header.  In change_clocksource(), add a call to
arch_change_clocksource() right after tk_setup_internals().  In x86's
arch_change_clocksource, update vclocks_used.

Now it's genuinely read_mostly, and we don't need to touch that
cacheline at all in the normal clock tick code.  Everyone wins.
(vclocks_used is actually rather rarely read.  It's only used to
prevent user code from accessing a never-used clocksource through the
vvar area, which is a hardening measure.  It's only referenced from
the vvar fault handler code.)

--Andy

  reply	other threads:[~2018-06-22 23:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-04 17:27 Michael Rodin
2018-06-22 22:47 ` Thomas Gleixner
2018-06-22 23:25   ` Andy Lutomirski [this message]
2018-06-23  9:04     ` Thomas Gleixner

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=CALCETrVDuqie6WS--gyb9ohEKXmreA+iN5P-raJbnfS7Tp8nkQ@mail.gmail.com \
    --to=luto@kernel.org \
    --cc=hpa@zytor.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael-git@rodin.online \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --subject='Re: [PATCH] arch/x86/entry/vsyscall/vsyscall_gtod.c: remove __read_mostly from vclocks_used' \
    /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).