mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@kernel.org, laijs@cn.fujitsu.com, dipankar@in.ibm.com,
	akpm@linux-foundation.org, mathieu.desnoyers@efficios.com,
	josh@joshtriplett.org, tglx@linutronix.de, peterz@infradead.org,
	rostedt@goodmis.org, dhowells@redhat.com, edumazet@google.com,
	dvhart@linux.intel.com, fweisbec@gmail.com, oleg@redhat.com,
	bobby.prani@gmail.com,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCH tip/core/rcu 2/9] compiler: Allow 1- and 2-byte smp_load_acquire() and smp_store_release()
Date: Tue, 28 Oct 2014 15:09:55 -0700	[thread overview]
Message-ID: <1414534202-27312-2-git-send-email-paulmck@linux.vnet.ibm.com> (raw)
In-Reply-To: <1414534202-27312-1-git-send-email-paulmck@linux.vnet.ibm.com>

From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>

CPUs without single-byte and double-byte loads and stores place some
"interesting" requirements on concurrent code.  For example (adapted
from Peter Hurley's test code), suppose we have the following structure:

	struct foo {
		spinlock_t lock1;
		spinlock_t lock2;
		char a; /* Protected by lock1. */
		char b; /* Protected by lock2. */
	};
	struct foo *foop;

Of course, it is common (and good) practice to place data protected
by different locks in separate cache lines.  However, if the locks are
rarely acquired (for example, only in rare error cases), and there are
a great many instances of the data structure, then memory footprint can
trump false-sharing concerns, so that it can be better to place them in
the same cache cache line as above.

But if the CPU does not support single-byte loads and stores, a store
to foop->a will do a non-atomic read-modify-write operation on foop->b,
which will come as a nasty surprise to someone holding foop->lock2.  So we
now require CPUs to support single-byte and double-byte loads and stores.
Therefore, this commit adjusts the definition of __native_word() to allow
these sizes to be used by smp_load_acquire() and smp_store_release().

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
---
 include/linux/compiler.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index d5ad7b1118fc..934a834ab9f9 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -311,7 +311,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
 
 /* Is this type a native word size -- useful for atomic operations */
 #ifndef __native_word
-# define __native_word(t) (sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
+# define __native_word(t) (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
 #endif
 
 /* Compile time object size, -1 for unknown */
-- 
1.8.1.5


  reply	other threads:[~2014-10-28 22:16 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-28 22:09 [PATCH tip/core/rcu 0/9] Miscellaneous fixes for 3.19 Paul E. McKenney
2014-10-28 22:09 ` [PATCH tip/core/rcu 1/9] rcu: Remove CONFIG_RCU_CPU_STALL_VERBOSE Paul E. McKenney
2014-10-28 22:09   ` Paul E. McKenney [this message]
2014-10-28 22:09   ` [PATCH tip/core/rcu 3/9] drivers/md: Use rcu_dereference() for accessing rcu pointer Paul E. McKenney
2014-11-21 13:31     ` Kirill A. Shutemov
2014-11-21 14:30       ` Pranith Kumar
2014-11-21 14:58         ` Kirill A. Shutemov
2014-11-23 12:21           ` Pranith Kumar
2014-11-23 16:39             ` Eric Dumazet
2014-11-23 16:40             ` [PATCH ] drivers/md: use proper rcu accessor Eric Dumazet
2014-11-23 16:53               ` Mike Snitzer
2014-11-23 17:31                 ` Eric Dumazet
2014-11-23 19:12                   ` Mike Snitzer
2014-11-23 17:34               ` [PATCH v2] " Eric Dumazet
2014-11-24  4:09                 ` Mike Snitzer
2014-10-28 22:09   ` [PATCH tip/core/rcu 4/9] dm: sparse: Annotate field with __rcu for checking Paul E. McKenney
2014-10-28 22:09   ` [PATCH tip/core/rcu 5/9] rcu: Add sparse check for RCU_INIT_POINTER() Paul E. McKenney
2014-10-28 22:09   ` [PATCH tip/core/rcu 6/9] rcu: Optimize cond_resched_rcu_qs() Paul E. McKenney
2014-10-28 22:10   ` [PATCH tip/core/rcu 7/9] rcu: More info about potential deadlocks with rcu_read_unlock() Paul E. McKenney
2014-10-28 22:10   ` [PATCH tip/core/rcu 8/9] rcu: Fix FIXME in rcu_tasks_kthread() Paul E. McKenney
2014-10-28 22:10   ` [PATCH tip/core/rcu 9/9] rcu: Provide counterpart to rcu_dereference() for non-RCU situations Paul E. McKenney
2014-10-29 10:57     ` Peter Zijlstra
2014-10-29 12:42       ` Paul E. McKenney
2014-10-29 19:15         ` Oleg Nesterov
2014-10-29 18:43           ` Paul E. McKenney

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=1414534202-27312-2-git-send-email-paulmck@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=bobby.prani@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=dvhart@linux.intel.com \
    --cc=edumazet@google.com \
    --cc=fweisbec@gmail.com \
    --cc=josh@joshtriplett.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®