From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Cooper Subject: Re: [PATCH v2 2/3] xen/atomic: Implement atomic_{inc, dec}_bounded() Date: Wed, 2 Jul 2014 15:17:12 +0100 Message-ID: <53B41468.9060300@citrix.com> References: <1404308871-23368-1-git-send-email-andrew.cooper3@citrix.com> <1404308871-23368-3-git-send-email-andrew.cooper3@citrix.com> <53B42DD3020000780001F977@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <53B42DD3020000780001F977@mail.emea.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich Cc: Keir Fraser , Xen-devel List-Id: xen-devel@lists.xenproject.org On 02/07/14 15:05, Jan Beulich wrote: >>>> On 02.07.14 at 15:47, wrote: >> These will increment/decremented an atomic_t, while ensuring that the >> atomic_t >> doesn't hit a specific bound. >> >> This involves introducing atomic_cmpxchg() for x86, which previously only >> existed on ARM. >> >> Suggested-by: Don Slutz >> Signed-off-by: Andrew Cooper >> CC: Keir Fraser >> CC: Jan Beulich > You should be getting used to Cc all "REST" maintainers on respective > changes. Oops yes - I will see about updating my auto-cc list hooks. > >> --- /dev/null >> +++ b/xen/common/atomic.c >> @@ -0,0 +1,35 @@ >> +#include >> + >> +bool_t atomic_inc_bounded(atomic_t *v, int bound) >> +{ >> + int old, new, prev = atomic_read(v); >> + >> + do >> + { >> + old = prev; >> + new = old + 1; >> + if ( new >= bound ) >> + return 0; >> + >> + prev = atomic_cmpxchg(v, old, new); >> + } while ( prev != old ); >> + >> + return 1; >> +} >> + >> +bool_t atomic_dec_bounded(atomic_t *v, int bound) >> +{ >> + int old, new, prev = atomic_read(v); >> + >> + do >> + { >> + old = prev; >> + new = old - 1; >> + if ( new <= bound ) >> + return 0; >> + >> + prev = atomic_cmpxchg(v, old, new); >> + } while ( prev != old ); >> + >> + return 1; >> +} > Same question here: Do we really need these? There are various uses > of cmpxchg() in common code already, and in patch 3 you don't really > need the cmpxchg to happen on an atomic_t, so plain cmpxchg() with > the little bit of extra logic open coded would seem fine to me. > > Jan > These as in atomic_{inc,dec}_bounded() ? They logically fit alongside atomic_{inc,dec}_and_test(), and I came to the conclusion that they would likely be useful elsewhere. I realise that these are not fantastic reasons alone... ~Andrew