[tip:locking/core] locking/atomics: Clean up the atomic.h maze of #defines

2018-05-06 Thread tip-bot for Ingo Molnar
Commit-ID:  a2d636a4bfd5e9b31215e5d1913e7fe0d0c0970a
Gitweb: https://git.kernel.org/tip/a2d636a4bfd5e9b31215e5d1913e7fe0d0c0970a
Author: Ingo Molnar 
AuthorDate: Sat, 5 May 2018 10:11:00 +0200
Committer:  Ingo Molnar 
CommitDate: Sat, 5 May 2018 15:22:44 +0200

locking/atomics: Clean up the atomic.h maze of #defines

Use structured defines to make it all much more readable.

Before:

 #ifndef atomic_fetch_dec_relaxed

 #ifndef atomic_fetch_dec
 #define atomic_fetch_dec(v)atomic_fetch_sub(1, (v))
 #define atomic_fetch_dec_relaxed(v)atomic_fetch_sub_relaxed(1, (v))
 #define atomic_fetch_dec_acquire(v)atomic_fetch_sub_acquire(1, (v))
 #define atomic_fetch_dec_release(v)atomic_fetch_sub_release(1, (v))
 #else /* atomic_fetch_dec */
 #define atomic_fetch_dec_relaxed   atomic_fetch_dec
 #define atomic_fetch_dec_acquire   atomic_fetch_dec
 #define atomic_fetch_dec_release   atomic_fetch_dec
 #endif /* atomic_fetch_dec */

 #else /* atomic_fetch_dec_relaxed */

 #ifndef atomic_fetch_dec_acquire
 #define atomic_fetch_dec_acquire(...)  \
__atomic_op_acquire(atomic_fetch_dec, __VA_ARGS__)
 #endif

 #ifndef atomic_fetch_dec_release
 #define atomic_fetch_dec_release(...)  \
__atomic_op_release(atomic_fetch_dec, __VA_ARGS__)
 #endif

 #ifndef atomic_fetch_dec
 #define atomic_fetch_dec(...)  \
__atomic_op_fence(atomic_fetch_dec, __VA_ARGS__)
 #endif
 #endif /* atomic_fetch_dec_relaxed */

After:

 #ifndef atomic_fetch_dec_relaxed
 # ifndef atomic_fetch_dec
 #  define atomic_fetch_dec(v)  atomic_fetch_sub(1, (v))
 #  define atomic_fetch_dec_relaxed(v)  atomic_fetch_sub_relaxed(1, (v))
 #  define atomic_fetch_dec_acquire(v)  atomic_fetch_sub_acquire(1, (v))
 #  define atomic_fetch_dec_release(v)  atomic_fetch_sub_release(1, (v))
 # else
 #  define atomic_fetch_dec_relaxed atomic_fetch_dec
 #  define atomic_fetch_dec_acquire atomic_fetch_dec
 #  define atomic_fetch_dec_release atomic_fetch_dec
 # endif
 #else
 # ifndef atomic_fetch_dec_acquire
 #  define atomic_fetch_dec_acquire(...)
__atomic_op_acquire(atomic_fetch_dec, __VA_ARGS__)
 # endif
 # ifndef atomic_fetch_dec_release
 #  define atomic_fetch_dec_release(...)
__atomic_op_release(atomic_fetch_dec, __VA_ARGS__)
 # endif
 # ifndef atomic_fetch_dec
 #  define atomic_fetch_dec(...)
__atomic_op_fence(atomic_fetch_dec, __VA_ARGS__)
 # endif
 #endif

Beyond the linecount reduction this also makes it easier to follow
the various conditions.

Also clean up a few other minor details and make the code more
consistent throughout.

No change in functionality.

Cc: Andrew Morton 
Cc: Linus Torvalds 
Cc: Mark Rutland 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: aryabi...@virtuozzo.com
Cc: boqun.f...@gmail.com
Cc: catalin.mari...@arm.com
Cc: dvyu...@google.com
Cc: linux-arm-ker...@lists.infradead.org
Link: http://lkml.kernel.org/r/20180505081100.nsyrqrpzq2vd2...@gmail.com
Signed-off-by: Ingo Molnar 
---
 include/linux/atomic.h | 1275 +---
 1 file changed, 543 insertions(+), 732 deletions(-)

diff --git a/include/linux/atomic.h b/include/linux/atomic.h
index 01ce3997cb42..12f4ad559ab1 100644
--- a/include/linux/atomic.h
+++ b/include/linux/atomic.h
@@ -24,11 +24,11 @@
  */
 
 #ifndef atomic_read_acquire
-#define  atomic_read_acquire(v)smp_load_acquire(&(v)->counter)
+# define atomic_read_acquire(v)
smp_load_acquire(&(v)->counter)
 #endif
 
 #ifndef atomic_set_release
-#define  atomic_set_release(v, i)  smp_store_release(&(v)->counter, (i))
+# define atomic_set_release(v, i)  
smp_store_release(&(v)->counter, (i))
 #endif
 
 /*
@@ -71,454 +71,351 @@
 })
 #endif
 
-/* atomic_add_return_relaxed */
-#ifndef atomic_add_return_relaxed
-#define  atomic_add_return_relaxed atomic_add_return
-#define  atomic_add_return_acquire atomic_add_return
-#define  atomic_add_return_release atomic_add_return
-
-#else /* atomic_add_return_relaxed */
-
-#ifndef atomic_add_return_acquire
-#define  atomic_add_return_acquire(...)
\
-   __atomic_op_acquire(atomic_add_return, __VA_ARGS__)
-#endif
+/* atomic_add_return_relaxed() et al: */
 
-#ifndef atomic_add_return_release
-#define  atomic_add_return_release(...)
\
-   __atomic_op_release(atomic_add_return, __VA_ARGS__)
-#endif
-
-#ifndef atomic_add_return
-#define  atomic_add_return(...)  

[tip:locking/core] locking/atomics: Clean up the atomic.h maze of #defines

2018-05-06 Thread tip-bot for Ingo Molnar
Commit-ID:  a2d636a4bfd5e9b31215e5d1913e7fe0d0c0970a
Gitweb: https://git.kernel.org/tip/a2d636a4bfd5e9b31215e5d1913e7fe0d0c0970a
Author: Ingo Molnar 
AuthorDate: Sat, 5 May 2018 10:11:00 +0200
Committer:  Ingo Molnar 
CommitDate: Sat, 5 May 2018 15:22:44 +0200

locking/atomics: Clean up the atomic.h maze of #defines

Use structured defines to make it all much more readable.

Before:

 #ifndef atomic_fetch_dec_relaxed

 #ifndef atomic_fetch_dec
 #define atomic_fetch_dec(v)atomic_fetch_sub(1, (v))
 #define atomic_fetch_dec_relaxed(v)atomic_fetch_sub_relaxed(1, (v))
 #define atomic_fetch_dec_acquire(v)atomic_fetch_sub_acquire(1, (v))
 #define atomic_fetch_dec_release(v)atomic_fetch_sub_release(1, (v))
 #else /* atomic_fetch_dec */
 #define atomic_fetch_dec_relaxed   atomic_fetch_dec
 #define atomic_fetch_dec_acquire   atomic_fetch_dec
 #define atomic_fetch_dec_release   atomic_fetch_dec
 #endif /* atomic_fetch_dec */

 #else /* atomic_fetch_dec_relaxed */

 #ifndef atomic_fetch_dec_acquire
 #define atomic_fetch_dec_acquire(...)  \
__atomic_op_acquire(atomic_fetch_dec, __VA_ARGS__)
 #endif

 #ifndef atomic_fetch_dec_release
 #define atomic_fetch_dec_release(...)  \
__atomic_op_release(atomic_fetch_dec, __VA_ARGS__)
 #endif

 #ifndef atomic_fetch_dec
 #define atomic_fetch_dec(...)  \
__atomic_op_fence(atomic_fetch_dec, __VA_ARGS__)
 #endif
 #endif /* atomic_fetch_dec_relaxed */

After:

 #ifndef atomic_fetch_dec_relaxed
 # ifndef atomic_fetch_dec
 #  define atomic_fetch_dec(v)  atomic_fetch_sub(1, (v))
 #  define atomic_fetch_dec_relaxed(v)  atomic_fetch_sub_relaxed(1, (v))
 #  define atomic_fetch_dec_acquire(v)  atomic_fetch_sub_acquire(1, (v))
 #  define atomic_fetch_dec_release(v)  atomic_fetch_sub_release(1, (v))
 # else
 #  define atomic_fetch_dec_relaxed atomic_fetch_dec
 #  define atomic_fetch_dec_acquire atomic_fetch_dec
 #  define atomic_fetch_dec_release atomic_fetch_dec
 # endif
 #else
 # ifndef atomic_fetch_dec_acquire
 #  define atomic_fetch_dec_acquire(...)
__atomic_op_acquire(atomic_fetch_dec, __VA_ARGS__)
 # endif
 # ifndef atomic_fetch_dec_release
 #  define atomic_fetch_dec_release(...)
__atomic_op_release(atomic_fetch_dec, __VA_ARGS__)
 # endif
 # ifndef atomic_fetch_dec
 #  define atomic_fetch_dec(...)
__atomic_op_fence(atomic_fetch_dec, __VA_ARGS__)
 # endif
 #endif

Beyond the linecount reduction this also makes it easier to follow
the various conditions.

Also clean up a few other minor details and make the code more
consistent throughout.

No change in functionality.

Cc: Andrew Morton 
Cc: Linus Torvalds 
Cc: Mark Rutland 
Cc: Paul E. McKenney 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: aryabi...@virtuozzo.com
Cc: boqun.f...@gmail.com
Cc: catalin.mari...@arm.com
Cc: dvyu...@google.com
Cc: linux-arm-ker...@lists.infradead.org
Link: http://lkml.kernel.org/r/20180505081100.nsyrqrpzq2vd2...@gmail.com
Signed-off-by: Ingo Molnar 
---
 include/linux/atomic.h | 1275 +---
 1 file changed, 543 insertions(+), 732 deletions(-)

diff --git a/include/linux/atomic.h b/include/linux/atomic.h
index 01ce3997cb42..12f4ad559ab1 100644
--- a/include/linux/atomic.h
+++ b/include/linux/atomic.h
@@ -24,11 +24,11 @@
  */
 
 #ifndef atomic_read_acquire
-#define  atomic_read_acquire(v)smp_load_acquire(&(v)->counter)
+# define atomic_read_acquire(v)
smp_load_acquire(&(v)->counter)
 #endif
 
 #ifndef atomic_set_release
-#define  atomic_set_release(v, i)  smp_store_release(&(v)->counter, (i))
+# define atomic_set_release(v, i)  
smp_store_release(&(v)->counter, (i))
 #endif
 
 /*
@@ -71,454 +71,351 @@
 })
 #endif
 
-/* atomic_add_return_relaxed */
-#ifndef atomic_add_return_relaxed
-#define  atomic_add_return_relaxed atomic_add_return
-#define  atomic_add_return_acquire atomic_add_return
-#define  atomic_add_return_release atomic_add_return
-
-#else /* atomic_add_return_relaxed */
-
-#ifndef atomic_add_return_acquire
-#define  atomic_add_return_acquire(...)
\
-   __atomic_op_acquire(atomic_add_return, __VA_ARGS__)
-#endif
+/* atomic_add_return_relaxed() et al: */
 
-#ifndef atomic_add_return_release
-#define  atomic_add_return_release(...)
\
-   __atomic_op_release(atomic_add_return, __VA_ARGS__)
-#endif
-
-#ifndef atomic_add_return
-#define  atomic_add_return(...)
\
-   __atomic_op_fence(atomic_add_return, __VA_ARGS__)
-#endif
-#endif /* atomic_add_return_relaxed */
+#ifndef atomic_add_return_relaxed
+# define atomic_add_return_relaxed atomic_add_return
+#