From: Peter Zijlstra <peterz@infradead.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
Frederic Weisbecker <frederic@kernel.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
Will Deacon <will@kernel.org>
Subject: Re: tick/sched: Make jiffies update quick check more robust
Date: Tue, 8 Dec 2020 12:16:44 +0100 [thread overview]
Message-ID: <20201208111644.GV2414@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <877dpt7k5w.fsf@nanos.tec.linutronix.de>
On Mon, Dec 07, 2020 at 03:41:47PM +0100, Thomas Gleixner wrote:
> On Mon, Dec 07 2020 at 10:59, Peter Zijlstra wrote:
> >> + if (IS_ENABLED(CONFIG_64BIT)) {
> >> + if (ktime_before(now, smp_load_acquire(&tick_next_period)))
> >> + return;
> >
> > Explicit ACQUIRE
> >
> >> + } else {
> >> + unsigned int seq;
> >> +
> >> + /*
> >> + * Avoid contention on jiffies_lock and protect the quick
> >> + * check with the sequence count.
> >> + */
> >> + do {
> >> + seq = read_seqcount_begin(&jiffies_seq);
> >> + nextp = tick_next_period;
> >> + } while (read_seqcount_retry(&jiffies_seq, seq));
> >> +
> >> + if (ktime_before(now, nextp))
> >> + return;
> >
> > Actually has an implicit ACQUIRE:
> >
> > read_seqcount_retry() implies smp_rmb(), which ensures
> > LOAD->LOAD order, IOW any later load must happen after our
> > @tick_next_period load.
> >
> > Then it has a control dependency on ktime_before(,nextp), which
> > ensures LOAD->STORE order.
> >
> > Combined we have a LOAD->{LOAD,STORE} order on the
> > @tick_next_period load, IOW ACQUIRE.
It's actually the whole of:
+ } while (read_seqcount_retry(&jiffies_seq, seq));
That implies the ACQUIRE, don't need the rest.
> >> + }
> >>
> >> + /* Quick check failed, i.e. update is required. */
> >> raw_spin_lock(&jiffies_lock);
> >
> > Another ACQUIRE, which means the above ACQUIRE only ensures we load the
> > lock value after?
> >
> > Or are we trying to guarantee the caller is sure to observe the new
> > jiffies value if we return?
>
> The guarantee we need on 64bit for the check w/o seqcount is:
>
> CPU0 CPU1
>
> if (ktime_before(now, tick_next_period))
> return;
>
> raw_spin_lock(&jiffies_lock);
> ....
> jiffies_64 += ticks;
>
> tick_next_period = next; if (ktime_before(now, tick_next_period))
> return;
>
> When CPU1 returns because it observes the new value in tick_next_period
> then it has to be guaranteed that jiffies_64 is observable as well.
Right, it does that. Good.
next prev parent reply other threads:[~2020-12-08 11:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-04 10:55 tick/sched: Make jiffies update quick check more robust Thomas Gleixner
2020-12-07 9:59 ` Peter Zijlstra
2020-12-07 14:41 ` Thomas Gleixner
2020-12-08 11:16 ` Peter Zijlstra [this message]
2020-12-11 21:28 ` Frederic Weisbecker
2020-12-11 22:22 ` [tip: timers/core] " tip-bot2 for 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=20201208111644.GV2414@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=tglx@linutronix.de \
--cc=will@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 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.