From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XvRPv-0004Ps-Co for qemu-devel@nongnu.org; Mon, 01 Dec 2014 08:53:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XvRPp-0002em-3m for qemu-devel@nongnu.org; Mon, 01 Dec 2014 08:53:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41059) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XvRPo-0002eQ-QG for qemu-devel@nongnu.org; Mon, 01 Dec 2014 08:53:25 -0500 Date: Mon, 1 Dec 2014 13:53:18 +0000 From: Stefan Hajnoczi Message-ID: <20141201135318.GB6744@stefanha-thinkpad.redhat.com> References: <1417091366-4469-1-git-send-email-stefanha@redhat.com> <1417091366-4469-3-git-send-email-stefanha@redhat.com> <547754CC.5070704@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="PmA2V3Z32TCmWXqI" Content-Disposition: inline In-Reply-To: <547754CC.5070704@redhat.com> Subject: Re: [Qemu-devel] [RFC 2/6] bitmap: add atomic test and clear List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Peter Maydell , Juan Quintela , qemu-devel@nongnu.org, rth@redhat.com --PmA2V3Z32TCmWXqI Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Nov 27, 2014 at 05:43:56PM +0100, Paolo Bonzini wrote: >=20 >=20 > 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 =3D map + BIT_WORD(start); > > + const long size =3D start + nr; > > + int bits_to_clear =3D BITS_PER_LONG - (start % BITS_PER_LONG); > > + unsigned long mask_to_clear =3D BITMAP_FIRST_WORD_MASK(start); > > + unsigned long dirty =3D 0; > > + unsigned long old_bits; > > + > > + while (nr - bits_to_clear >=3D 0) { > > + old_bits =3D atomic_fetch_and(p, ~mask_to_clear); > > + dirty |=3D old_bits & mask_to_clear; > > + nr -=3D bits_to_clear; > > + bits_to_clear =3D BITS_PER_LONG; > > + mask_to_clear =3D ~0UL; > > + p++; > > + } > > + if (nr) { > > + mask_to_clear &=3D BITMAP_LAST_WORD_MASK(size); > > + old_bits =3D atomic_fetch_and(p, ~mask_to_clear); > > + dirty |=3D old_bits & mask_to_clear; > > + } > > + > > + return dirty; > > +} >=20 > Same here; you can use atomic_xchg, which is faster because on x86 > atomic_fetch_and must do a compare-and-swap loop. Will fix in v2. --PmA2V3Z32TCmWXqI Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJUfHLOAAoJEJykq7OBq3PIU4sH/AmCJLx/Ag76UJTu1BWrFkFk hPtMsXob3Ku3iu++hO6YrR4BTadWXmDHFbmwV07cH4uTW7cnJfaQOCMTBXr7ckCb 4gu9QgSEHufkJGB8AlV9CYJmA/XhKZLjOp9OpdZwD0of06gvXKoLhda30XR8H5kd 0hzxHe78mfFikCKKKrvUjt6QDAq5QocJ/Ef0oCDv9OMkxUtMadHc/ubjXpj0g0Eb fuPn/nTHHn7e4QbEP90g4dxfKqRg790oKWRIhb85BFU+E/hjtwLHBdlA8D3xO6fB xqXpbY/l6yWKGPfDYWdBFnZdHFfx3GTHYlVpMW2i4wV/+isX472785yZ/DtFkms= =+Pk/ -----END PGP SIGNATURE----- --PmA2V3Z32TCmWXqI--