public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Fyodorov <halcy@yandex.ru>
To: Waiman Long <waiman.long@hp.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	"Chandramouleeswaran, Aswin" <aswin@hp.com>,
	"Norton, Scott J" <scott.norton@hp.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH RFC v2 1/2] qspinlock: Introducing a 4-byte queue spinlock implementation
Date: Thu, 22 Aug 2013 17:28:41 +0400	[thread overview]
Message-ID: <169431377178121@web21f.yandex.ru> (raw)
In-Reply-To: <5215638E.5020702@hp.com>

22.08.2013, 05:04, "Waiman Long" <waiman.long@hp.com>:
> On 08/21/2013 11:51 AM, Alexander Fyodorov wrote:
> In this case, we should have smp_wmb() before freeing the lock. The
> question is whether we need to do a full mb() instead. The x86 ticket
> spinlock unlock code is just a regular add instruction except for some
> exotic processors. So it is a compiler barrier but not really a memory
> fence. However, we may need to do a full memory fence for some other
> processors.

The thing is that x86 ticket spinlock code does have full memory barriers both in lock() and unlock() code: "add" instruction there has "lock" prefix which implies a full memory barrier. So it is better to use smp_mb() and let each architecture define it.

> At this point, I am inclined to have either a smp_wmb() or smp_mb() at
> the beginning of the unlock function and a barrier() at the end.
>
> As the lock/unlock functions can be inlined, it is possible that a
> memory variable can be accessed earlier in the calling function and the
> stale copy may be used in the inlined lock/unlock function instead of
> fetching a new copy. That is why I prefer a more liberal use of
> ACCESS_ONCE() for safety purpose.

That is impossible: both lock() and unlock() must have either full memory barrier or an atomic operation which returns value. Both of them prohibit optimizations and compiler cannot reuse any global variable. So this usage of ACCESS_ONCE() is unneeded.

You can read more on this in Documentation/volatile-considered-harmful.txt

And although I already suggested that, have you read Documentation/memory-barriers.txt? There is a lot of valuable information there.

  reply	other threads:[~2013-08-22 13:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <15321377012704@web8h.yandex.ru>
2013-08-21  3:01 ` [PATCH RFC v2 1/2] qspinlock: Introducing a 4-byte queue spinlock implementation Waiman Long
2013-08-21 15:51   ` Alexander Fyodorov
2013-08-22  1:04     ` Waiman Long
2013-08-22 13:28       ` Alexander Fyodorov [this message]
2013-08-26 20:14         ` Waiman Long
2013-08-27 12:09           ` Alexander Fyodorov
     [not found]             ` <20130827091436.3d5971a0@gandalf.local.home>
2013-08-27 13:53               ` Peter Zijlstra
2013-08-28  1:21                 ` Paul E. McKenney
2013-08-28  8:19                   ` Peter Zijlstra
2013-08-28 12:59                     ` Steven Rostedt
2013-08-28 13:05                       ` Peter Zijlstra
2013-08-28 13:15                         ` Steven Rostedt
2013-08-28 13:37                           ` Peter Zijlstra
2013-08-29 15:24             ` Waiman Long
2013-08-29 17:03               ` Alexander Fyodorov
2013-08-30  3:16                 ` Waiman Long
2013-08-30  8:15                   ` Alexander Fyodorov
2013-08-13 18:41 [PATCH RFC v2 0/2] qspinlock: Introducing a 4-byte queue spinlock Waiman Long
2013-08-13 18:41 ` [PATCH RFC v2 1/2] qspinlock: Introducing a 4-byte queue spinlock implementation Waiman Long

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=169431377178121@web21f.yandex.ru \
    --to=halcy@yandex.ru \
    --cc=aswin@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=scott.norton@hp.com \
    --cc=tglx@linutronix.de \
    --cc=waiman.long@hp.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