[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wiDXWy8ekFDxVzCbudZv_3CqiWa9w+xO8mxJkk8SNmJCg@mail.gmail.com>
Date: Fri, 10 Dec 2021 08:53:29 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Will Deacon <will@...nel.org>, Boqun Feng <boqun.feng@...il.com>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
"the arch/x86 maintainers" <x86@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Marco Elver <elver@...gle.com>,
Kees Cook <keescook@...omium.org>,
Christoph Hellwig <hch@...radead.org>,
Jens Axboe <axboe@...nel.dk>
Subject: Re: [PATCH v2 8/9] atomic,x86: Alternative atomic_*_overflow() scheme
On Fri, Dec 10, 2021 at 8:27 AM Peter Zijlstra <peterz@...radead.org> wrote:
>
> Shift the overflow range from [0,INT_MIN] to [-1,INT_MIN], this allows
> optimizing atomic_inc_overflow() to use "jle" to detect increment
> from free-or-negative (with -1 being the new free and it's increment
> being 0 which sets ZF).
Thanks.
However, I think you can simplify this further:
> This then gives the following primitives:
>
> [-1, INT_MIN] [0, INT_MIN]
>
> inc() inc()
> lock inc %[var] mov $-1, %[reg]
> jle error-free-or-negative lock xadd %[reg], %[var]
> test %[reg], %[reg]
> jle error-zero-or-negative
>
> dec() dec()
> lock sub $1, %[var] lock dec %[var]
> jc error-to-free jle error-zero-or-negative
> jl error-from-negative
>
> dec_and_test() dec_and_test()
> lock sub $1, %[var] lock dec %[var]
> jc do-free jl error-from-negative
> jl error-from-negative je do-free
That "dec()" case could be just
lock dec %[var]
js error
because an underflow is an underflow - it doesn't matter if it's a "it
went to free" or "it became some other negative number".
That said - it may not matter - I'm not sure a plain "dec" is even a
valid operation on a ref in the first place. How could you ever
validly decrement a ref without checking for it being the last entry?
So I'm not sure "atomic_dec_overflow()" is even worth having as a
primitive, because I can't see any valid use for it. Is it for some
legacy case?
Linus
Powered by blists - more mailing lists