[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y7blVTSogV2miG8+@phenom.ffwll.local>
Date: Thu, 5 Jan 2023 15:57:25 +0100
From: Daniel Vetter <daniel@...ll.ch>
To: David Laight <David.Laight@...lab.com>
Cc: 'Daniel Vetter' <daniel@...ll.ch>,
'Jani Nikula' <jani.nikula@...ux.intel.com>,
Arnd Bergmann <arnd@...db.de>,
"intel-gfx@...ts.freedesktop.org" <intel-gfx@...ts.freedesktop.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"dri-devel@...ts.freedesktop.org" <dri-devel@...ts.freedesktop.org>,
'Andrzej Hajda' <andrzej.hajda@...el.com>,
Rodrigo Vivi <rodrigo.vivi@...el.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Subject: Re: [Intel-gfx] [PATCH 1/5] linux/minmax.h: add non-atomic version
of xchg
On Thu, Jan 05, 2023 at 02:41:43PM +0000, David Laight wrote:
> From: Daniel Vetter
> > Sent: 05 January 2023 14:13
> ...
> > > > So here we are, with Andrzej looking to add the common helper. And the
> > > > same concerns crop up. What should it be called to make it clear that
> > > > it's not atomic? Is that possible?
> > >
> > > old_value = read_write(variable, new_value);
> > >
> > > But two statements are much clearer.
> >
> > Yeah this is my point for fetch_and_zero or any of the other proposals.
> > We're essentially replacing these two lines:
> >
> > var = some->pointer->chase;
> > some->pointer->chase = NULL;
> >
> > with a macro. C is verbose, and sometimes painfully so,
>
> Try ADA or VHDL :-)
>
> > if the pointer
> > chase is really to onerous then I think that should be refactored with a
> > meaningfully locally name variable, not fancy macros wrapped around to
> > golf a few characters away.
>
> Provided 'var' is a local the compiler is pretty likely to only do the
> 'pointer chase' once.
> You can also do:
> var = NULL;
> swap(some->pointer->chase, var);
> and get pretty much the same object code.
>
> > But what about swap() you ask? That one needs a temp variable, and it does
> > make sense to hide that in a ({}) block in a macro.
>
> Sometimes, but not enough for the 'missed opportunity for swap()'
> message.
>
> > But for the above two
> > lines I really don't see a point outside of obfuscated C contexts.
>
> Indeed.
>
> Isn't the suggested __xchg() in one of the 'reserved for implementation'
> namespaces - so shouldn't be a function that might be expected to be
> actually used.
It's more fun, for the atomic functions which don't have the atomic_
prefix in their names, the __ prefixed versions provide the non-atomic
implementation. This pattern was started with the long * bitops stuff for
managing really big bitmasks.
And I really don't think it's a great function name scheme that we should
proliferate.
The "reserved for implementation" only applies to the standard C library
in userspace, which the kernel doesn't use, so can fairly freely use that
namespace.
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
Powered by blists - more mailing lists