From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:54457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLJj9-0005XH-22 for qemu-devel@nongnu.org; Mon, 29 Apr 2019 23:46:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLJj7-000352-6N for qemu-devel@nongnu.org; Mon, 29 Apr 2019 23:46:43 -0400 Received: from mga12.intel.com ([192.55.52.136]:44784) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hLJj5-00032B-AZ for qemu-devel@nongnu.org; Mon, 29 Apr 2019 23:46:39 -0400 From: Wei Yang Date: Tue, 30 Apr 2019 11:44:12 +0800 Message-Id: <20190430034412.12935-4-richardw.yang@linux.intel.com> In-Reply-To: <20190430034412.12935-1-richardw.yang@linux.intel.com> References: <20190430034412.12935-1-richardw.yang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 3/3] ram: RAMBlock->offset is always aligned to a word List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, quintela@redhat.com, dgilbert@redhat.com, Wei Yang RAMBlock->offset is calculated by find_ram_offset, which makes sure the offset is aligned to a word. This patch removes the alignment check on offset and unnecessary variable *word*. Signed-off-by: Wei Yang --- include/exec/ram_addr.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 3dfb2d52fb..a7c81bdb32 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -413,18 +413,21 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, uint64_t *real_dirty_pages) { ram_addr_t addr; - unsigned long word = BIT_WORD(rb->offset >> TARGET_PAGE_BITS); uint64_t num_dirty = 0; unsigned long *dest = rb->bmap; - /* offset and length is aligned at the start of a word? */ - if (((word * BITS_PER_LONG) << TARGET_PAGE_BITS) == (rb->offset) && - !(length & ((BITS_PER_LONG << TARGET_PAGE_BITS) - 1))) { + /* + * Since RAMBlock->offset is guaranteed to be aligned to a word by + * find_ram_offset(), if length is aligned at the start of a word, go the + * fast path. + */ + if (!(length & ((BITS_PER_LONG << TARGET_PAGE_BITS) - 1))) { int k; int nr = BITS_TO_LONGS(length >> TARGET_PAGE_BITS); unsigned long * const *src; - unsigned long idx = (word * BITS_PER_LONG) / DIRTY_MEMORY_BLOCK_SIZE; - unsigned long offset = BIT_WORD((word * BITS_PER_LONG) % + unsigned long idx = (rb->offset >> TARGET_PAGE_BITS) / + DIRTY_MEMORY_BLOCK_SIZE; + unsigned long offset = BIT_WORD((rb->offset >> TARGET_PAGE_BITS) % DIRTY_MEMORY_BLOCK_SIZE); rcu_read_lock(); -- 2.19.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.9 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7151AC43219 for ; Tue, 30 Apr 2019 03:50:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 429042080C for ; Tue, 30 Apr 2019 03:50:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 429042080C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([127.0.0.1]:38634 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLJmt-0007eG-HA for qemu-devel@archiver.kernel.org; Mon, 29 Apr 2019 23:50:35 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hLJj9-0005XH-22 for qemu-devel@nongnu.org; Mon, 29 Apr 2019 23:46:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hLJj7-000352-6N for qemu-devel@nongnu.org; Mon, 29 Apr 2019 23:46:43 -0400 Received: from mga12.intel.com ([192.55.52.136]:44784) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hLJj5-00032B-AZ for qemu-devel@nongnu.org; Mon, 29 Apr 2019 23:46:39 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Apr 2019 20:46:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,412,1549958400"; d="scan'208";a="153455310" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by FMSMGA003.fm.intel.com with ESMTP; 29 Apr 2019 20:46:33 -0700 From: Wei Yang To: qemu-devel@nongnu.org Date: Tue, 30 Apr 2019 11:44:12 +0800 Message-Id: <20190430034412.12935-4-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190430034412.12935-1-richardw.yang@linux.intel.com> References: <20190430034412.12935-1-richardw.yang@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.136 Subject: [Qemu-devel] [PATCH 3/3] ram: RAMBlock->offset is always aligned to a word X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, Wei Yang , dgilbert@redhat.com, quintela@redhat.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="UTF-8" Message-ID: <20190430034412.sI2P0Ov4Tupq6kV30zytGPP8uTek6mfaGhfbS-02KA4@z> RAMBlock->offset is calculated by find_ram_offset, which makes sure the offset is aligned to a word. This patch removes the alignment check on offset and unnecessary variable *word*. Signed-off-by: Wei Yang --- include/exec/ram_addr.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 3dfb2d52fb..a7c81bdb32 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -413,18 +413,21 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb, uint64_t *real_dirty_pages) { ram_addr_t addr; - unsigned long word = BIT_WORD(rb->offset >> TARGET_PAGE_BITS); uint64_t num_dirty = 0; unsigned long *dest = rb->bmap; - /* offset and length is aligned at the start of a word? */ - if (((word * BITS_PER_LONG) << TARGET_PAGE_BITS) == (rb->offset) && - !(length & ((BITS_PER_LONG << TARGET_PAGE_BITS) - 1))) { + /* + * Since RAMBlock->offset is guaranteed to be aligned to a word by + * find_ram_offset(), if length is aligned at the start of a word, go the + * fast path. + */ + if (!(length & ((BITS_PER_LONG << TARGET_PAGE_BITS) - 1))) { int k; int nr = BITS_TO_LONGS(length >> TARGET_PAGE_BITS); unsigned long * const *src; - unsigned long idx = (word * BITS_PER_LONG) / DIRTY_MEMORY_BLOCK_SIZE; - unsigned long offset = BIT_WORD((word * BITS_PER_LONG) % + unsigned long idx = (rb->offset >> TARGET_PAGE_BITS) / + DIRTY_MEMORY_BLOCK_SIZE; + unsigned long offset = BIT_WORD((rb->offset >> TARGET_PAGE_BITS) % DIRTY_MEMORY_BLOCK_SIZE); rcu_read_lock(); -- 2.19.1