Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1384881 > unrolled thread

[RFC][PATCH 01/31] locking: Flip arguments to atomic_fetch_or

Started byPeter Zijlstra <peterz@infradead.org>
First post2016-04-22 12:00 +0200
Last post2016-04-22 16:30 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [RFC][PATCH 01/31] locking: Flip arguments to atomic_fetch_or Peter Zijlstra <peterz@infradead.org> - 2016-04-22 12:00 +0200
    Re: [RFC][PATCH 01/31] locking: Flip arguments to atomic_fetch_or Will Deacon <will.deacon@arm.com> - 2016-04-22 13:00 +0200
    Re: [RFC][PATCH 01/31] locking: Flip arguments to atomic_fetch_or Geert Uytterhoeven <geert@linux-m68k.org> - 2016-04-22 13:10 +0200
      Re: [RFC][PATCH 01/31] locking: Flip arguments to atomic_fetch_or Peter Zijlstra <peterz@infradead.org> - 2016-04-22 16:30 +0200

#1384881 — [RFC][PATCH 01/31] locking: Flip arguments to atomic_fetch_or

FromPeter Zijlstra <peterz@infradead.org>
Date2016-04-22 12:00 +0200
Subject[RFC][PATCH 01/31] locking: Flip arguments to atomic_fetch_or
Message-ID<rqG2x-8lR-61@gated-at.bofh.it>
All the atomic operations have their arguments the wrong way around;
make atomic_fetch_or() consistent and flip them.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 include/linux/atomic.h   |    4 ++--
 kernel/time/tick-sched.c |    4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

--- a/include/linux/atomic.h
+++ b/include/linux/atomic.h
@@ -560,11 +560,11 @@ static inline int atomic_dec_if_positive
 
 /**
  * atomic_fetch_or - perform *p |= mask and return old value of *p
- * @p: pointer to atomic_t
  * @mask: mask to OR on the atomic_t
+ * @p: pointer to atomic_t
  */
 #ifndef atomic_fetch_or
-static inline int atomic_fetch_or(atomic_t *p, int mask)
+static inline int atomic_fetch_or(int mask, atomic_t *p)
 {
 	int old, val = atomic_read(p);
 
--- a/kernel/time/tick-sched.c
+++ b/kernel/time/tick-sched.c
@@ -262,7 +262,7 @@ static void tick_nohz_dep_set_all(atomic
 {
 	int prev;
 
-	prev = atomic_fetch_or(dep, BIT(bit));
+	prev = atomic_fetch_or(BIT(bit), dep);
 	if (!prev)
 		tick_nohz_full_kick_all();
 }
@@ -292,7 +292,7 @@ void tick_nohz_dep_set_cpu(int cpu, enum
 
 	ts = per_cpu_ptr(&tick_cpu_sched, cpu);
 
-	prev = atomic_fetch_or(&ts->tick_dep_mask, BIT(bit));
+	prev = atomic_fetch_or(BIT(bit), &ts->tick_dep_mask);
 	if (!prev) {
 		preempt_disable();
 		/* Perf needs local kick that is NMI safe */

[toc] | [next] | [standalone]


#1384975

FromWill Deacon <will.deacon@arm.com>
Date2016-04-22 13:00 +0200
Message-ID<rqGYy-EU-27@gated-at.bofh.it>
In reply to#1384881
On Fri, Apr 22, 2016 at 11:04:14AM +0200, Peter Zijlstra wrote:
> All the atomic operations have their arguments the wrong way around;
> make atomic_fetch_or() consistent and flip them.
> 
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> ---
>  include/linux/atomic.h   |    4 ++--
>  kernel/time/tick-sched.c |    4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)

Makes sense:

Acked-by: Will Deacon <will.deacon@arm.com>

Will

> --- a/include/linux/atomic.h
> +++ b/include/linux/atomic.h
> @@ -560,11 +560,11 @@ static inline int atomic_dec_if_positive
>  
>  /**
>   * atomic_fetch_or - perform *p |= mask and return old value of *p
> - * @p: pointer to atomic_t
>   * @mask: mask to OR on the atomic_t
> + * @p: pointer to atomic_t
>   */
>  #ifndef atomic_fetch_or
> -static inline int atomic_fetch_or(atomic_t *p, int mask)
> +static inline int atomic_fetch_or(int mask, atomic_t *p)
>  {
>  	int old, val = atomic_read(p);
>  
> --- a/kernel/time/tick-sched.c
> +++ b/kernel/time/tick-sched.c
> @@ -262,7 +262,7 @@ static void tick_nohz_dep_set_all(atomic
>  {
>  	int prev;
>  
> -	prev = atomic_fetch_or(dep, BIT(bit));
> +	prev = atomic_fetch_or(BIT(bit), dep);
>  	if (!prev)
>  		tick_nohz_full_kick_all();
>  }
> @@ -292,7 +292,7 @@ void tick_nohz_dep_set_cpu(int cpu, enum
>  
>  	ts = per_cpu_ptr(&tick_cpu_sched, cpu);
>  
> -	prev = atomic_fetch_or(&ts->tick_dep_mask, BIT(bit));
> +	prev = atomic_fetch_or(BIT(bit), &ts->tick_dep_mask);
>  	if (!prev) {
>  		preempt_disable();
>  		/* Perf needs local kick that is NMI safe */
> 
> 

[toc] | [prev] | [next] | [standalone]


#1384990

FromGeert Uytterhoeven <geert@linux-m68k.org>
Date2016-04-22 13:10 +0200
Message-ID<rqH8g-ZP-67@gated-at.bofh.it>
In reply to#1384881
On Fri, Apr 22, 2016 at 11:04 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> All the atomic operations have their arguments the wrong way around;

s/wrong/other/?

> make atomic_fetch_or() consistent and flip them.

BTW, there are a few other inconsistencies:

atomic_add_unless()
atomic_cmpxchg()
atomic_inc_not_zero_hint()
atomic_set()
atomic_xchg

git grep "\<atomic_.*atomic_t\>.*\<int\>"

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

[toc] | [prev] | [next] | [standalone]


#1385228

FromPeter Zijlstra <peterz@infradead.org>
Date2016-04-22 16:30 +0200
Message-ID<rqKfM-3ke-13@gated-at.bofh.it>
In reply to#1384990
On Fri, Apr 22, 2016 at 01:09:38PM +0200, Geert Uytterhoeven wrote:
> On Fri, Apr 22, 2016 at 11:04 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> > All the atomic operations have their arguments the wrong way around;
> 
> s/wrong/other/?

Nah, I find they really are the wrong way around. I forever write:
atomic_add(&v, val); and then have the compiler yell at me.

> > make atomic_fetch_or() consistent and flip them.
> 
> BTW, there are a few other inconsistencies:
> 
> atomic_add_unless()
> atomic_cmpxchg()
> atomic_inc_not_zero_hint()
> atomic_set()
> atomic_xchg
> 
> git grep "\<atomic_.*atomic_t\>.*\<int\>"

Yes, but fixing those will be much more pain :/ atomic_fetch_or() was
freshly introduced and only has a few callers, furthermore, the
following patches would require it to be in line with the other
atomic_$op() due to them all being generated from the same 'template'.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web