public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "Ingo Molnar" <mingo@kernel.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	"Frédéric Weisbecker" <fweisbec@gmail.com>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Andrew Morton" <akpm@linux-foundation.org>
Subject: Re: [GIT PULL] NOHZ updates for v4.6
Date: Tue, 15 Mar 2016 09:42:20 +0100	[thread overview]
Message-ID: <20160315084220.GR6344@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <CA+55aFyqG0xriTOus7wu527rdYHeLX3Qidt9ZzggL+MsR=_iQQ@mail.gmail.com>

On Mon, Mar 14, 2016 at 07:44:14PM -0700, Linus Torvalds wrote:
> On Mon, Mar 14, 2016 at 5:32 AM, Ingo Molnar <mingo@kernel.org> wrote:
> > +/**
> > + * fetch_or - perform *ptr |= mask and return old value of *ptr
> > + * @ptr: pointer to value
> > + * @mask: mask to OR on the value
> > + *
> > + * cmpxchg based fetch_or, macro so it works for different integer types
> > + */
> > +#ifndef fetch_or
> > +#define fetch_or(ptr, mask)                                            \
> > +({     typeof(*(ptr)) __old, __val = *(ptr);                           \
> > +       for (;;) {                                                      \
> > +               __old = cmpxchg((ptr), __val, __val | (mask));          \
> > +               if (__old == __val)                                     \
> > +                       break;                                          \
> > +               __val = __old;                                          \
> > +       }                                                               \
> > +       __old;                                                          \
> > +})
> > +#endif
> 
> This is garbage.
> 
> This macro re-uses the "mask" argument potentially many many times, so
> semantically it's very dubious.

So the below cures that; but do we want to maybe pull this back into
sched.c and expose a version that operates on a fixed type instead?

Although with xchg() and cmpxchg() we've already set a precedence for
multi-width operators.

The whole thread_info::flags thing is rather 'special' and I'm not sure
we even want to go clean that up, I can see why 64bit arch would very
much want a 64bit flags word etc. And TIF_flags are very arch specific.

---
 include/linux/atomic.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/atomic.h b/include/linux/atomic.h
index 6c502cb13c95..114caf672b11 100644
--- a/include/linux/atomic.h
+++ b/include/linux/atomic.h
@@ -558,8 +558,9 @@ static inline int atomic_dec_if_positive(atomic_t *v)
 #ifndef fetch_or
 #define fetch_or(ptr, mask)						\
 ({	typeof(*(ptr)) __old, __val = *(ptr);				\
+ 	typeof(mask) __mask = (mask);					\
 	for (;;) {							\
-		__old = cmpxchg((ptr), __val, __val | (mask));		\
+		__old = cmpxchg((ptr), __val, __val | __mask);		\
 		if (__old == __val)					\
 			break;						\
 		__val = __old;						\

  reply	other threads:[~2016-03-15  8:43 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-14 12:32 [GIT PULL] NOHZ updates for v4.6 Ingo Molnar
2016-03-15  2:44 ` Linus Torvalds
2016-03-15  8:42   ` Peter Zijlstra [this message]
2016-03-15  9:49     ` Ingo Molnar
2016-03-15  9:32   ` [PATCH] atomic: Fix bugs in 'fetch_or()' and rename it to 'xchg_or()' Ingo Molnar
2016-03-15 10:50     ` Peter Zijlstra
2016-03-15 12:08       ` Ingo Molnar
2016-03-15 12:42         ` Peter Zijlstra
2016-03-15 11:06     ` Peter Zijlstra
2016-03-15 11:59     ` Peter Zijlstra
2016-03-15 12:01     ` Ingo Molnar
2016-03-15 12:32       ` Ingo Molnar
2016-03-15 12:37         ` Ingo Molnar
2016-03-15 13:17         ` Peter Zijlstra
2016-03-15 12:21     ` [PATCH v2] " Ingo Molnar
2016-03-15 13:26       ` Peter Zijlstra
2016-03-16  8:04         ` Ingo Molnar
2016-03-16  8:29           ` Peter Zijlstra
2016-03-15 17:08       ` Frederic Weisbecker
2016-03-16  8:14         ` Ingo Molnar
2016-03-17  0:54           ` Frederic Weisbecker
2016-03-15 16:18     ` [PATCH] " Linus Torvalds
2016-03-15  9:53   ` [PATCH] nohz: Change tick_dep_mask from 'unsigned long' to 'unsigned int' Ingo Molnar
2016-03-15 12:15     ` Ingo Molnar
2016-03-15 16:30       ` Linus Torvalds
2016-03-15 17:28         ` Frederic Weisbecker
2016-03-15 17:36           ` Linus Torvalds

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=20160315084220.GR6344@twins.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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