From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQHHj-0003we-JL for qemu-devel@nongnu.org; Fri, 14 Aug 2015 11:52:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZQHHg-0003Vy-Bq for qemu-devel@nongnu.org; Fri, 14 Aug 2015 11:52:47 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:37523) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZQHHg-0003Vn-6T for qemu-devel@nongnu.org; Fri, 14 Aug 2015 11:52:44 -0400 Received: by wibhh20 with SMTP id hh20so25426979wib.0 for ; Fri, 14 Aug 2015 08:52:43 -0700 (PDT) From: Alvise Rigo Date: Fri, 14 Aug 2015 17:55:29 +0200 Message-Id: <1439567732-14118-4-git-send-email-a.rigo@virtualopensystems.com> In-Reply-To: <1439567732-14118-1-git-send-email-a.rigo@virtualopensystems.com> References: <1439567732-14118-1-git-send-email-a.rigo@virtualopensystems.com> Subject: [Qemu-devel] [mttcg RFC v4 3/6] exec: ram_addr: Fix exclusive bitmap accessor List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, mttcg@listserver.greensocs.com Cc: claudio.fontana@huawei.com, pbonzini@redhat.com, jani.kokkonen@huawei.com, tech@virtualopensystems.com, alex.bennee@linaro.org, aurelien@aurel32.net Signed-off-by: Alvise Rigo --- include/exec/ram_addr.h | 61 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 6b678d6..34bb486 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -269,11 +269,28 @@ static inline int cpu_physical_memory_excl_atleast_one_clean(ram_addr_t addr) unsigned long next, end; if (likely(smp_cpus <= BITS_PER_LONG)) { - unsigned long mask = (1 << smp_cpus) - 1; - - return - (mask & (bitmap[BIT_WORD(EXCL_BITMAP_GET_OFFSET(addr))] >> - (EXCL_BITMAP_GET_OFFSET(addr) & (BITS_PER_LONG-1)))) != mask; + unsigned long mask1; + uint32_t shift, first_off; + /* Number of vCPUs bits in the next long. */ + int bits_left; + + first_off = BIT_WORD(EXCL_BITMAP_GET_OFFSET(addr)); + shift = (EXCL_BITMAP_GET_OFFSET(addr) & (BITS_PER_LONG-1)); + bits_left = (shift + smp_cpus) - BITS_PER_LONG; + + if (bits_left <= 0) { + mask1 = (1 << smp_cpus) - 1; + return (mask1 & (bitmap[first_off] >> shift)) != mask1; + } else { + /* The bits we need to access span two different longs. */ + unsigned long mask2; + + mask2 = (1 << bits_left) - 1; + mask1 = (1 << (smp_cpus - bits_left)) - 1; + + return !(((mask2 & bitmap[first_off + 1]) == mask2) && + ((mask1 & (bitmap[first_off] >> shift)) == mask1)); + } } end = BIT_WORD(EXCL_BITMAP_GET_OFFSET(addr)) + smp_cpus; @@ -288,15 +305,41 @@ static inline int cpu_physical_memory_excl_is_dirty(ram_addr_t addr, { unsigned long *bitmap = ram_list.dirty_memory[DIRTY_MEMORY_EXCLUSIVE]; unsigned long end, next; - uint32_t add; + uint32_t add, first_off; assert(cpu <= smp_cpus); if (likely(smp_cpus <= BITS_PER_LONG)) { - cpu = (cpu == smp_cpus) ? (1 << cpu) - 1 : (1 << cpu); + uint32_t shift = 0; + + if (cpu == smp_cpus) { + unsigned long mask1, mask2; + int bits_left; + + first_off = BIT_WORD(EXCL_BITMAP_GET_OFFSET(addr)); + shift = (EXCL_BITMAP_GET_OFFSET(addr) & (BITS_PER_LONG-1)); + bits_left = (shift + cpu) - BITS_PER_LONG; + + if (bits_left <= 0) { + mask1 = (1 << cpu) - 1; + + return mask1 & (bitmap[first_off] >> shift); + } + + mask2 = (1 << bits_left) - 1; + mask1 = (1 << (cpu - bits_left)) - 1; + + return (mask1 & (bitmap[first_off] >> shift)) | + (mask2 & (bitmap[first_off + 1])); + } else { + first_off = BIT_WORD(EXCL_BITMAP_GET_OFFSET(addr) + cpu); + shift = ((EXCL_BITMAP_GET_OFFSET(addr) + cpu) & (BITS_PER_LONG-1)); + + return 1 & (bitmap[first_off] >> shift); + } return cpu & (bitmap[BIT_WORD(EXCL_BITMAP_GET_OFFSET(addr))] >> - (EXCL_BITMAP_GET_OFFSET(addr) & (BITS_PER_LONG-1))); + (shift)); } add = (cpu == smp_cpus) ? 0 : 1; @@ -315,7 +358,5 @@ static inline bool cpu_physical_memory_clear_excl_dirty(ram_addr_t addr, EXCL_BITMAP_GET_OFFSET(addr) + cpu_index, 1); } - - #endif #endif -- 2.5.0