From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xu29f-0005Md-C7 for qemu-devel@nongnu.org; Thu, 27 Nov 2014 11:43:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xu29Z-0003Rl-3d for qemu-devel@nongnu.org; Thu, 27 Nov 2014 11:42:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48596) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xu29Y-0003Rd-TG for qemu-devel@nongnu.org; Thu, 27 Nov 2014 11:42:49 -0500 Message-ID: <54775481.9020605@redhat.com> Date: Thu, 27 Nov 2014 17:42:41 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <1417091366-4469-1-git-send-email-stefanha@redhat.com> <1417091366-4469-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1417091366-4469-2-git-send-email-stefanha@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [RFC 1/6] bitmap: add atomic set functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi , qemu-devel@nongnu.org Cc: Peter Maydell , rth@redhat.com, Juan Quintela On 27/11/2014 13:29, Stefan Hajnoczi wrote: > +void bitmap_set_atomic(unsigned long *map, long start, long nr) > +{ > + unsigned long *p = map + BIT_WORD(start); > + const long size = start + nr; > + int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); > + unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start); > + > + while (nr - bits_to_set >= 0) { > + atomic_or(p, mask_to_set); atomic_or is unnecessary while mask_to_set is ~0UL. I think not even a smp_wmb() is necessary. Paolo > + nr -= bits_to_set; > + bits_to_set = BITS_PER_LONG; > + mask_to_set = ~0UL; > + p++; > + } > + if (nr) { > + mask_to_set &= BITMAP_LAST_WORD_MASK(size); > + atomic_or(p, mask_to_set); > + } > +} > +