2015-07-09 17:56:44

by Peter Zijlstra

[permalink] [raw]
Subject: [RFC][PATCH 02/24] arc: Provide atomic_{or,xor,and}

Implement atomic logic ops -- atomic_{or,xor,and}.

These will replace the atomic_{set,clear}_mask functions that are
available on some archs.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
---
arch/arc/include/asm/atomic.h | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

--- a/arch/arc/include/asm/atomic.h
+++ b/arch/arc/include/asm/atomic.h
@@ -125,13 +125,23 @@ static inline int atomic_##op##_return(i
ATOMIC_OPS(add, +=, add)
ATOMIC_OPS(sub, -=, sub)
ATOMIC_OP(and, &=, and)
-
-#define atomic_clear_mask(mask, v) atomic_and(~(mask), (v))
+ATOMIC_OP(or, |=, or)
+ATOMIC_OP(xor, ^=, xor)

#undef ATOMIC_OPS
#undef ATOMIC_OP_RETURN
#undef ATOMIC_OP

+static inline __deprecated void atomic_clear_mask(unsigned int mask, atomic_t *v)
+{
+ atomic_and(~mask, v);
+}
+
+static inline __deprecated void atomic_set_mask(unsigned int mask, atomic_t *v)
+{
+ atomic_or(mask, v);
+}
+
/**
* __atomic_add_unless - add unless the number is a given value
* @v: pointer of type atomic_t


2015-07-10 04:31:03

by Vineet Gupta

[permalink] [raw]
Subject: Re: [RFC][PATCH 02/24] arc: Provide atomic_{or,xor,and}

On Thursday 09 July 2015 11:26 PM, Peter Zijlstra wrote:
> Implement atomic logic ops -- atomic_{or,xor,and}.
>
> These will replace the atomic_{set,clear}_mask functions that are
> available on some archs.
>
> Signed-off-by: Peter Zijlstra (Intel) <[email protected]>

Acked-by: Vineet Gupta <[email protected]>

Since we are on the topic, the cmpxchg() loop in arch/arc/kernel/smp.c still
irritates me.
Do we need a new set of primitives to operate atomically on non atomic_t data or
does that mean that the data *not* being atomic_t but requiring such semantics is
the fundamental problem and thus needs to be converted first.

-Vineet

2015-07-10 07:05:35

by Peter Zijlstra

[permalink] [raw]
Subject: Re: [RFC][PATCH 02/24] arc: Provide atomic_{or,xor,and}

On Fri, Jul 10, 2015 at 04:30:46AM +0000, Vineet Gupta wrote:
>
> Since we are on the topic, the cmpxchg() loop in arch/arc/kernel/smp.c still
> irritates me.
> Do we need a new set of primitives to operate atomically on non atomic_t data or
> does that mean that the data *not* being atomic_t but requiring such semantics is
> the fundamental problem and thus needs to be converted first.

So if you look at the last patch, there's already a few sites that do
things like:

+ atomic_or(*mask, (atomic_t *)&flushcache_cpumask);

Which is of course ugly as hell, but does work.

Esp. inside arch code.

Now the 'problem' with cmpxchg/xchg, the instructions working on !atomic
data is:

http://lkml.kernel.org/r/alpine.LRH.2.02.1406011342470.20831@file01.intranet.prod.int.rdu2.redhat.com
http://lkml.kernel.org/r/[email protected]

And note that includes some arc.

Adding more such primitives will only make it harder on those already
'broken' archs.

2015-07-13 12:44:00

by Vineet Gupta

[permalink] [raw]
Subject: Re: [RFC][PATCH 02/24] arc: Provide atomic_{or,xor,and}

On Friday 10 July 2015 12:35 PM, Peter Zijlstra wrote:
> On Fri, Jul 10, 2015 at 04:30:46AM +0000, Vineet Gupta wrote:
>> >
>> > Since we are on the topic, the cmpxchg() loop in arch/arc/kernel/smp.c still
>> > irritates me.
>> > Do we need a new set of primitives to operate atomically on non atomic_t data or
>> > does that mean that the data *not* being atomic_t but requiring such semantics is
>> > the fundamental problem and thus needs to be converted first.
> So if you look at the last patch, there's already a few sites that do
> things like:
>
> + atomic_or(*mask, (atomic_t *)&flushcache_cpumask);
>
> Which is of course ugly as hell, but does work.
>
> Esp. inside arch code.

Right - I don't have issues with using this API - but this requires atomic_t data
type. The specific cmpxchg() loop that I'm referring to is not for atomic_t - so
that needs to be converted to atomic_t first ?

>
> Now the 'problem' with cmpxchg/xchg, the instructions working on !atomic
> data is:
>
> http://lkml.kernel.org/r/alpine.LRH.2.02.1406011342470.20831@file01.intranet.prod.int.rdu2.redhat.com
> http://lkml.kernel.org/r/[email protected]
>
> And note that includes some arc.

Correct so we don't mix cmpxchg() with normal load/store.

>
> Adding more such primitives will only make it harder on those already
> 'broken' archs.

Not sure if I follow here - my point was not so much about expanding the
atomic_*() API but whether it makes sense to have "some" API for non atomic_t vs.
converting the non atomic_t to atomic_t and then use the API as that is the
fundamental problem for such cases.

-Vineet