From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932103AbbKXVT6 (ORCPT ); Tue, 24 Nov 2015 16:19:58 -0500 Received: from mail-wm0-f47.google.com ([74.125.82.47]:33726 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752459AbbKXVTz (ORCPT ); Tue, 24 Nov 2015 16:19:55 -0500 Date: Tue, 24 Nov 2015 22:19:52 +0100 From: Frederic Weisbecker To: Chris Metcalf Cc: LKML , Peter Zijlstra , Thomas Gleixner , Luiz Capitulino , Christoph Lameter , Ingo Molnar , Viresh Kumar , Rik van Riel Subject: Re: [PATCH 1/7] atomic: Export fetch_or() Message-ID: <20151124211951.GA16609@lerouge> References: <1447424529-13671-1-git-send-email-fweisbec@gmail.com> <1447424529-13671-2-git-send-email-fweisbec@gmail.com> <56548908.50509@ezchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56548908.50509@ezchip.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 24, 2015 at 10:58:00AM -0500, Chris Metcalf wrote: > 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 > >Cc: Chris Metcalf > >Cc: Ingo Molnar > >Cc: Luiz Capitulino > >Cc: Peter Zijlstra > >Cc: Rik van Riel > >Cc: Thomas Gleixner > >Cc: Viresh Kumar > >Signed-off-by: Frederic Weisbecker > >--- > > 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 > > #ifdef CONFIG_GENERIC_ATOMIC64 > > #include > > 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. Right. > > 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". I think Peterz needs it to be type-generic, like cmpxchg, such that he can use it on tsk->thread_info->flags which type can vary. But if we happen to need an atomic_t version, we can also provide an atomic_fetch_or() version. Also note that or_return() means that you first do OR and then return the new value. I remember debating a bit the name with Peterz and the current one now makes quite some sense to me too :-) Thanks!