lkml.org 
[lkml]   [2016]   [Jun]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH -tip 00/12] locking/atomics: Add and use inc,dec calls for FETCH-OP flavors
From
Date
On Fri, 2016-06-24 at 10:30 -0700, Davidlohr Bueso wrote:
> On Fri, 24 Jun 2016, James Bottomley wrote:
>
> > On Mon, 2016-06-20 at 13:05 -0700, Davidlohr Bueso wrote:
> > > Hi,
> > >
> > > The series is really straightforward and based on Peter's work
> > > that introduces[1] the atomic_fetch_$op machinery. Only patch 1
> > > implements the actual atomic_fetch_{inc,dec} calls based on
> > > atomic_fetch_{add,sub}.
> >
> > Could I just ask why? atomic_inc_return(x) - 1 seems a reasonable
> > thing to do to me.
>
> For one restoring the old state like that can be racy and looses the
> notion of atomicity.

I don't understand this argument: any return of an atomic value is
inherently racy because the atomic source may have changed by the time
you use the returned value. It's no more or less racy to my mind to
return the original value and increment than to return the incremented
value and subtract one.

> The new family of atomic_fetch_$ops also better express the purpose
> of the call imo.

So this is probably the core of my objection: adding APIs simply
because we can. A good reason to add things like this is because it's
a common pattern people get wrong, because we can optimize it nicely on
an architecture, or some other good reason. Absent a good reason it
doesn't seem like a good API addition because trying to keep up with
all the API variants when you want to use atomics adds to the burden of
the programmer.

> Finally, the added machinery (considering it came from fetch_op()
> NOHZ needs), was mainly suggested by Linus (although yes, we don't
> have users for all the calls):
> https://lkml.org/lkml/2016/3/15/352.

I'd really rather you told me *you* believed it was a good idea (and
why) ...

James


\
 
 \ /
  Last update: 2016-06-24 20:21    [W:0.092 / U:0.236 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site