From: Paolo Bonzini <pbonzini@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
rth@redhat.com, Juan Quintela <quintela@redhat.com>
Subject: Re: [Qemu-devel] [RFC 2/6] bitmap: add atomic test and clear
Date: Thu, 27 Nov 2014 17:43:56 +0100 [thread overview]
Message-ID: <547754CC.5070704@redhat.com> (raw)
In-Reply-To: <1417091366-4469-3-git-send-email-stefanha@redhat.com>
On 27/11/2014 13:29, Stefan Hajnoczi wrote:
> +bool bitmap_test_and_clear_atomic(unsigned long *map, long start, long nr)
> +{
> + unsigned long *p = map + BIT_WORD(start);
> + const long size = start + nr;
> + int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);
> + unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);
> + unsigned long dirty = 0;
> + unsigned long old_bits;
> +
> + while (nr - bits_to_clear >= 0) {
> + old_bits = atomic_fetch_and(p, ~mask_to_clear);
> + dirty |= old_bits & mask_to_clear;
> + nr -= bits_to_clear;
> + bits_to_clear = BITS_PER_LONG;
> + mask_to_clear = ~0UL;
> + p++;
> + }
> + if (nr) {
> + mask_to_clear &= BITMAP_LAST_WORD_MASK(size);
> + old_bits = atomic_fetch_and(p, ~mask_to_clear);
> + dirty |= old_bits & mask_to_clear;
> + }
> +
> + return dirty;
> +}
Same here; you can use atomic_xchg, which is faster because on x86
atomic_fetch_and must do a compare-and-swap loop.
Paolo
next prev parent reply other threads:[~2014-11-27 16:44 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-27 12:29 [Qemu-devel] [RFC 0/6] memory: make dirty_memory[] accesses atomic Stefan Hajnoczi
2014-11-27 12:29 ` [Qemu-devel] [RFC 1/6] bitmap: add atomic set functions Stefan Hajnoczi
2014-11-27 16:42 ` Paolo Bonzini
2014-12-01 13:52 ` Stefan Hajnoczi
2014-11-27 12:29 ` [Qemu-devel] [RFC 2/6] bitmap: add atomic test and clear Stefan Hajnoczi
2014-11-27 16:43 ` Paolo Bonzini [this message]
2014-12-01 13:53 ` Stefan Hajnoczi
2014-11-27 12:29 ` [Qemu-devel] [RFC 3/6] memory: use atomic ops for setting dirty memory bits Stefan Hajnoczi
2014-11-27 12:29 ` [Qemu-devel] [RFC 4/6] migration: move dirty bitmap sync to ram_addr.h Stefan Hajnoczi
2014-11-27 16:29 ` Dr. David Alan Gilbert
2014-12-01 14:01 ` Stefan Hajnoczi
2014-12-01 14:49 ` Dr. David Alan Gilbert
2014-11-27 12:29 ` [Qemu-devel] [RFC 5/6] memory: replace cpu_physical_memory_reset_dirty() with test-and-clear Stefan Hajnoczi
2014-11-27 12:29 ` [Qemu-devel] [RFC 6/6] memory: make cpu_physical_memory_sync_dirty_bitmap() fully atomic Stefan Hajnoczi
2014-11-27 13:21 ` [Qemu-devel] [RFC 0/6] memory: make dirty_memory[] accesses atomic Peter Maydell
2014-11-28 12:44 ` Stefan Hajnoczi
2015-03-23 11:09 ` Paolo Bonzini
2015-03-24 16:48 ` Stefan Hajnoczi
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=547754CC.5070704@redhat.com \
--to=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=rth@redhat.com \
--cc=stefanha@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).