[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <56548908.50509@ezchip.com>
Date: Tue, 24 Nov 2015 10:58:00 -0500
From: Chris Metcalf <cmetcalf@...hip.com>
To: Frederic Weisbecker <fweisbec@...il.com>,
LKML <linux-kernel@...r.kernel.org>
CC: Peter Zijlstra <peterz@...radead.org>,
Thomas Gleixner <tglx@...utronix.de>,
Luiz Capitulino <lcapitulino@...hat.com>,
Christoph Lameter <cl@...ux.com>,
Ingo Molnar <mingo@...nel.org>,
Viresh Kumar <viresh.kumar@...aro.org>,
Rik van Riel <riel@...hat.com>
Subject: Re: [PATCH 1/7] atomic: Export fetch_or()
On 11/13/2015 09:22 AM, Frederic Weisbecker wrote:
> Export fetch_or() that's implemented and used internally by the
> scheduler. We are going to use it for NO_HZ so make it generally
> available.
>
> Cc: Christoph Lameter<cl@...ux.com>
> Cc: Chris Metcalf<cmetcalf@...hip.com>
> Cc: Ingo Molnar<mingo@...nel.org>
> Cc: Luiz Capitulino<lcapitulino@...hat.com>
> Cc: Peter Zijlstra<peterz@...radead.org>
> Cc: Rik van Riel<riel@...hat.com>
> Cc: Thomas Gleixner<tglx@...utronix.de>
> Cc: Viresh Kumar<viresh.kumar@...aro.org>
> Signed-off-by: Frederic Weisbecker<fweisbec@...il.com>
> ---
> include/linux/atomic.h | 18 ++++++++++++++++++
> kernel/sched/core.c | 14 --------------
> 2 files changed, 18 insertions(+), 14 deletions(-)
>
> diff --git a/include/linux/atomic.h b/include/linux/atomic.h
> index 00a5763..c3b99f8 100644
> --- a/include/linux/atomic.h
> +++ b/include/linux/atomic.h
> @@ -451,6 +451,24 @@ static inline int atomic_dec_if_positive(atomic_t *v)
> }
> #endif
>
> +/**
> + * fetch_or - perform *ptr |= mask and return old value of *ptr
> + * @ptr: pointer to value
> + * @mask: mask to OR on the value
> + *
> + * cmpxchg based fetch_or, macro so it works for different integer types
> + */
> +#define fetch_or(ptr, mask) \
> +({ typeof(*(ptr)) __old, __val = *(ptr); \
> + for (;;) { \
> + __old = cmpxchg((ptr), __val, __val | (mask)); \
> + if (__old == __val) \
> + break; \
> + __val = __old; \
> + } \
> + __old; \
> +})
> +
> #include <asm-generic/atomic-long.h>
> #ifdef CONFIG_GENERIC_ATOMIC64
> #include <asm-generic/atomic64.h>
I think this should be guarded by an "#ifndef" like other things in
this file, so architectures can provide their own implementations,
or can use the C11 atomic_fetch_or() for newer compilers.
Also, I wonder about the nomenclature here: other than cmpxchg
and xchg, all the atomic ops are named "atomic_xxx". For something
that returns the old value, I'd expect it to be atomic_or_return()
and be otherwise like the existing atomic_or() routine, and thus you'd
specify "atomic_t tick_dependency".
Avoiding all of these issues is probably why fetch_or() is not exported :-)
I made some similar comments last time around:
https://lkml.kernel.org/r/55B2794A.8040707@ezchip.com
--
Chris Metcalf, EZChip Semiconductor
http://www.ezchip.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists