linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* cmpxchg and x86 flags output
@ 2016-06-14 23:53 H. Peter Anvin
  2016-06-15  8:50 ` Peter Zijlstra
  0 siblings, 1 reply; 14+ messages in thread
From: H. Peter Anvin @ 2016-06-14 23:53 UTC (permalink / raw)
  To: Linux Kernel Mailing List, linux-arch, Linus Torvalds,
	Ingo Molnar, Thomas Gleixner

The x86 gcc now has the ability to return the value of flags output.  In
most use cases, this has been trivial to use in the kernel.

However, cmpxchg() presents a problem.  The current definition of
cmpxchg() and its variants is:

	out = cmpxchg(ptr, old, new);

... which is then frequently followed by:

	if (likely(old == out))

... or something along those lines.

This test is unnecessary and can now be elided, but this means changing
the signature on the cmpxchg() function (macro, generally).

It seems to me that the sanest way to handle this is to add a new
interface with a fourth parameter, so:

	changed = cmpxchgx(ptr, old, new, out);

A generic implementation of cmpxchgx() would be provided, looking like:

#define cmpxchgx(ptr, old, new, out) ({			\
	__typeof__((*(ptr))) __old = (old);		\
	__typeof__((*(ptr))) __new = (new);		\
	__typeof__((*(ptr))) __old = (old);		\
	__typeof__((*(ptr))) __out; 			\
	(out) = __out = cmpxchg(ptr, __old, __new);	\
	(__old != __out);				\
})

... and so on for all the many other variants.

However, I'm wondering how well this will fit in with other
architectures.  Keep in mind gcc will probably gain this ability for
other architectures with flags at some point, although that doesn't
inherently mean that cmpxchg will be able to make use of it.

This means a lot of changes even to common code, so I want to make sure
the interface is right before embarking on an implementation.

Thoughts?

	-hpa

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-08-22 15:13 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-14 23:53 cmpxchg and x86 flags output H. Peter Anvin
2016-06-15  8:50 ` Peter Zijlstra
2016-06-16 22:21   ` H. Peter Anvin
2016-06-21  9:06   ` David Howells
2016-06-21 17:00     ` H. Peter Anvin
2016-06-21 17:24     ` H. Peter Anvin
2016-06-22  0:09       ` H. Peter Anvin
2016-06-22 16:14       ` David Howells
2016-08-19 17:22         ` H. Peter Anvin
2016-08-22 15:13         ` David Howells
2016-06-22 16:11     ` David Howells
2016-06-22 16:36       ` H. Peter Anvin
2016-06-22 17:11         ` Linus Torvalds
2016-06-22 17:49           ` H. Peter Anvin

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).