From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Keir Fraser <keir@xen.org>, Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH v2 2/3] xen/atomic: Implement atomic_{inc, dec}_bounded()
Date: Wed, 2 Jul 2014 15:17:12 +0100 [thread overview]
Message-ID: <53B41468.9060300@citrix.com> (raw)
In-Reply-To: <53B42DD3020000780001F977@mail.emea.novell.com>
On 02/07/14 15:05, Jan Beulich wrote:
>>>> On 02.07.14 at 15:47, <andrew.cooper3@citrix.com> 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 <dslutz@verizon.com>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> CC: Keir Fraser <keir@xen.org>
>> CC: Jan Beulich <JBeulich@suse.com>
> 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 <xen/atomic.h>
>> +
>> +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
next prev parent reply other threads:[~2014-07-02 14:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-02 13:47 [PATCH v2 0/3] Improvements to allow refcoutning of DOMCTL_{, un}pausedomain Andrew Cooper
2014-07-02 13:47 ` [PATCH v2 1/3] xen/atomic: Introduce common atomic header and update includes Andrew Cooper
2014-07-02 14:01 ` Jan Beulich
2014-07-02 14:07 ` Andrew Cooper
2014-07-02 13:47 ` [PATCH v2 2/3] xen/atomic: Implement atomic_{inc, dec}_bounded() Andrew Cooper
2014-07-02 14:05 ` Jan Beulich
2014-07-02 14:17 ` Andrew Cooper [this message]
2014-07-02 13:47 ` [PATCH v2 3/3] xen/common: Properly reference count DOMCTL_{, un}pausedomain hypercalls Andrew Cooper
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53B41468.9060300@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=keir@xen.org \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.