From: Valentin Schneider <valentin.schneider@arm.com>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, rcu@vger.kernel.org,
linux-rt-users@vger.kernel.org,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@linutronix.de>,
Steven Rostedt <rostedt@goodmis.org>,
Daniel Bristot de Oliveira <bristot@redhat.com>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
"Paul E. McKenney" <paulmck@kernel.org>,
Frederic Weisbecker <frederic@kernel.org>,
Josh Triplett <josh@joshtriplett.org>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Lai Jiangshan <jiangshanlai@gmail.com>,
Joel Fernandes <joel@joelfernandes.org>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Steven Price <steven.price@arm.com>,
Ard Biesheuvel <ardb@kernel.org>
Subject: Re: [PATCH v2 2/4] sched: Introduce is_pcpu_safe()
Date: Tue, 10 Aug 2021 14:04:16 +0100 [thread overview]
Message-ID: <87wnot8n8v.mognet@arm.com> (raw)
In-Reply-To: <YRJ1yvfRjDJpXZWf@boqun-archlinux>
On 10/08/21 20:49, Boqun Feng wrote:
> On Sun, Aug 08, 2021 at 05:15:20PM +0100, Valentin Schneider wrote:
>> On 07/08/21 03:42, Mike Galbraith wrote:
>> > On Sat, 2021-08-07 at 01:58 +0100, Valentin Schneider wrote:
>> >>
>> >> +static inline bool is_pcpu_safe(void)
>> >
>> > Nit: seems odd to avoid spelling it out to save two characters, percpu
>> > is word like, rolls off the ole tongue better than p-c-p-u.
>> >
>> > -Mike
>>
>> True. A quick grep says both versions are used, though "percpu" wins by
>> about a factor of 2. I'll tweak that for a v3.
>
> I wonder why is_percpu_safe() is the correct name. The safety of
> accesses to percpu variables means two things to me:
>
> a) The thread cannot migrate to other CPU in the middle of
> accessing a percpu variable, in other words, the following
> cannot happen:
>
> { percpu variable X is 0 on CPU 0 and 2 on CPU 1
> CPU 0 CPU 1
> ======== =========
> <in thread A>
> __this_cpu_inc(X);
> tmp = X; // tmp is 0
> <preempted>
> <migrate to CPU 1>
> // continue __this_cpu_inc(X);
> X = tmp + 1; // CPU 0 miss this
> // increment (this
> // may be OK), and
> // CPU 1's X got
> // corrupted.
>
> b) The accesses to a percpu variable are exclusive, i.e. no
> interrupt or preemption can happen in the middle of accessing,
> in other words, the following cannot happen:
>
> { percpu variable X is 0 on CPU 0 }
> CPU 0
> ========
> <in thread A>
> __this_cpu_inc(X);
> tmp = X; // tmp is 0
> <preempted>
> <in other thread>
> this_cpu_inc(X); // X is 1 afterwards.
> <back to thread A>
> X = tmp + 1; // X is 1, and we have a race condition.
>
> And the is_p{er}cpu_safe() only detects the first, and it doesn't mean
> totally safe for percpu accesses.
>
Right. I do briefly point this out in the changelog (the bit about
"acquiring a sleepable lock if relevant"), but that doesn't do much to
clarify the helper name itself.
> Maybe we can implement a migratable()? Although not sure it's a English
> word.
>
Funnily enough that is exactly how I named the thing in my initial draft,
but then I somehow convinced myself that tailoring the name to per-CPU
accesses would make its intent clearer.
I think you're right that "migratable()" is less confusing at the end of
the day. Oh well, so much for overthinking the naming problem :-)
> Regards,
> Boqun
next prev parent reply other threads:[~2021-08-10 13:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-07 0:58 [PATCH v2 0/4] rcu, arm64: PREEMPT_RT fixlets Valentin Schneider
2021-08-07 0:58 ` [PATCH v2 1/4] rcutorture: Don't disable softirqs with preemption disabled when PREEMPT_RT Valentin Schneider
2021-08-07 0:58 ` [PATCH v2 2/4] sched: Introduce is_pcpu_safe() Valentin Schneider
2021-08-07 1:42 ` Mike Galbraith
2021-08-08 16:15 ` Valentin Schneider
2021-08-10 12:49 ` Boqun Feng
2021-08-10 13:04 ` Valentin Schneider [this message]
2021-08-10 2:42 ` Boqun Feng
2021-08-10 9:26 ` Valentin Schneider
2021-08-07 0:58 ` [PATCH v2 3/4] rcu/nocb: Protect NOCB state via local_lock() under PREEMPT_RT Valentin Schneider
2021-08-07 0:58 ` [PATCH v2 4/4] arm64: mm: Make arch_faults_on_old_pte() check for migratability Valentin Schneider
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=87wnot8n8v.mognet@arm.com \
--to=valentin.schneider@arm.com \
--cc=anshuman.khandual@arm.com \
--cc=ardb@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=boqun.feng@gmail.com \
--cc=bristot@redhat.com \
--cc=catalin.marinas@arm.com \
--cc=dave@stgolabs.net \
--cc=efault@gmx.de \
--cc=frederic@kernel.org \
--cc=jiangshanlai@gmail.com \
--cc=joel@joelfernandes.org \
--cc=josh@joshtriplett.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=steven.price@arm.com \
--cc=tglx@linutronix.de \
--cc=vincenzo.frascino@arm.com \
--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 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).