linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Davidlohr Bueso <dave@stgolabs.net>
To: Jason Low <jason.low2@hpe.com>
Cc: Peter Hurley <peter@hurleysoftware.com>,
	jason.low2@hp.com, Waiman Long <waiman.long@hpe.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel@vger.kernel.org, Dave Chinner <david@fromorbit.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Scott J Norton <scott.norton@hpe.com>,
	Douglas Hatch <doug.hatch@hpe.com>
Subject: Re: [PATCH v4 2/5] locking/rwsem: Protect all writes to owner by WRITE_ONCE
Date: Mon, 23 May 2016 12:44:16 -0700	[thread overview]
Message-ID: <20160523194416.up365sfbm7f55kbq@linux-uzut.site> (raw)
In-Reply-To: <1464029181.2479.21.camel@j-VirtualBox>

On Mon, 23 May 2016, Jason Low wrote:

>On Sat, 2016-05-21 at 09:04 -0700, Peter Hurley wrote:
>> On 05/18/2016 12:58 PM, Jason Low wrote:
>> > It should be fine to use the standard READ_ONCE here, even if it's just
>> > for documentation, as it's probably not going to cost anything in
>> > practice. It would be better to avoid adding any special macros for this
>> > which may just add more complexity.
>>
>> See, I don't understand this line of reasoning at all.
>>
>> I read this as "it's ok to be non-optimal here where were spinning CPU
>> time but not ok to be non-optimal generally elsewhere where it's
>> way less important like at init time".
>
>So I think there is a difference between using it during init time and
>using it here where we're spinning. During init time, initializing the
>owner field locklessly is normal. No other thread should be concurrently
>be writing to the field, since the structure is just getting
>initialized, so there are no surprises there.
>
>Our access of the owner field in this function is special in that we're
>using a bit of "lockless magic" to read and write to a field that gets
>concurrently accessed without any serialization. Since we're not taking
>the wait_lock in a scenario where we'd normally would take a lock, it
>would be good to have this documented.
>
>> And by the way, it's not just "here" but _everywhere_.
>> What about reading ->on_cpu locklessly?
>
>Sure, we could also use READ_ONCE when reading ->on_cpu  :)

Locking wise we should be covered with ->on_cpu as we're always under rcu_read_lock
(barrier, preempt_disable). But I'm not sure if this rule applies throughout the
scheduler, however, like it does in, say thread_group_cputime(). cpu_clock_sample()
(from posix timers) seems to mix and match being done under rcu. So ultimately I
think you're right.

Thanks,
Davidlohr

  reply	other threads:[~2016-05-23 19:44 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-18  1:26 [PATCH v4 0/5] [PATCH v3 0/4] locking/rwsem: Add reader-owned state to the owner field Waiman Long
2016-05-18  1:26 ` [PATCH v4 1/5] " Waiman Long
2016-06-06 17:18   ` Davidlohr Bueso
2016-06-06 20:03     ` Waiman Long
2016-06-06 21:02     ` Peter Zijlstra
2016-06-06 21:49       ` Waiman Long
2016-06-08 14:25   ` [tip:locking/core] " tip-bot for Waiman Long
2016-05-18  1:26 ` [PATCH v4 2/5] locking/rwsem: Protect all writes to owner by WRITE_ONCE() Waiman Long
2016-05-18 14:04   ` Davidlohr Bueso
2016-05-18 17:21     ` [PATCH v4 2/5] locking/rwsem: Protect all writes to owner by WRITE_ONCE Jason Low
2016-05-18 18:29       ` Waiman Long
2016-05-18 19:58         ` Jason Low
2016-05-19 22:21           ` Jason Low
2016-05-20 20:26             ` Waiman Long
2016-05-21 16:04           ` Peter Hurley
2016-05-22 10:42             ` Peter Zijlstra
2016-05-23 18:46             ` Jason Low
2016-05-23 19:44               ` Davidlohr Bueso [this message]
2016-05-23 20:15                 ` Paul E. McKenney
2016-05-23 21:04                   ` Davidlohr Bueso
2016-05-25  1:25               ` Waiman Long
2016-05-18 17:23     ` [PATCH v4 2/5] locking/rwsem: Protect all writes to owner by WRITE_ONCE() Jason Low
2016-06-08 14:25   ` [tip:locking/core] " tip-bot for Waiman Long
2016-05-18  1:26 ` [PATCH v4 3/5] locking/rwsem: Don't wake up one's own task Waiman Long
2016-05-18 10:30   ` Peter Zijlstra
2016-05-18 16:04     ` Waiman Long
2016-05-18  1:26 ` [PATCH v4 4/5] locking/rwsem: Improve reader wakeup code Waiman Long
2016-06-08 14:25   ` [tip:locking/core] " tip-bot for Waiman Long
2016-05-18  1:26 ` [PATCH v4 5/5] locking/rwsem: Streamline the rwsem_optimistic_spin() code Waiman Long
2016-06-08 14:26   ` [tip:locking/core] " tip-bot for Waiman Long
2016-05-18 10:52 ` [PATCH v4 0/5] [PATCH v3 0/4] locking/rwsem: Add reader-owned state to the owner field Peter Zijlstra

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=20160523194416.up365sfbm7f55kbq@linux-uzut.site \
    --to=dave@stgolabs.net \
    --cc=david@fromorbit.com \
    --cc=doug.hatch@hpe.com \
    --cc=jason.low2@hp.com \
    --cc=jason.low2@hpe.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peter@hurleysoftware.com \
    --cc=peterz@infradead.org \
    --cc=scott.norton@hpe.com \
    --cc=waiman.long@hpe.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 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).