From patchwork Tue Apr 19 13:39:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alvise rigo X-Patchwork-Id: 8880191 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 854769F39A for ; Tue, 19 Apr 2016 13:42:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AA59220270 for ; Tue, 19 Apr 2016 13:42:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ACFE020263 for ; Tue, 19 Apr 2016 13:42:24 +0000 (UTC) Received: from localhost ([::1]:58147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asVv6-0008D6-2O for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Apr 2016 09:42:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asVsZ-0003Es-BH for qemu-devel@nongnu.org; Tue, 19 Apr 2016 09:39:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asVsT-0000ef-6x for qemu-devel@nongnu.org; Tue, 19 Apr 2016 09:39:47 -0400 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:38873) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asVsS-0000eY-Tm for qemu-devel@nongnu.org; Tue, 19 Apr 2016 09:39:41 -0400 Received: by mail-wm0-x22f.google.com with SMTP id u206so30241569wme.1 for ; Tue, 19 Apr 2016 06:39:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtualopensystems-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1t8980rgidYP1Y/V4c38N9VJVliK9RoAZd7X+LDrbDo=; b=O1zVZ6Njj5JwkpcUeVOZqaqDlemYRYVxUA+5kfJtnmP+rhVfQj1UorO21KN8IdqtGj ZVY4XesitMYtZCDFFha+cK5RaVu9aioOJDpI2i4G2aEEKxSPvkXPhP/VKZJM+rqlJbm4 PID5mq0GXAepzHnKWhOAGoz7KZhEzfHzssOFGEIuRT5+47mLOvGbV9kjAFQgCJAlUF6M X3clZQ8c6h2YWlcuCMY+4IocKPjHK6kkpXoBjAmSdlubvWjXp5AbzS1iPQ9iX6b1TsQW bz1nzmNu4GleXxSOiN85+m2nELzhwHOBt32UuU3hS+Edn1Z/W+pMUJZTsE5Qgg6nLIEJ cN1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1t8980rgidYP1Y/V4c38N9VJVliK9RoAZd7X+LDrbDo=; b=AnaRlneASmI4JMTZNO++lQIdvt8xwfI+kNDd3XXjchysyPPI3bTuyni+hswWm/XN4n yqImFtg9XkX7VDEyzSJh/SvaLv+OA+sFaN+Us6WWtUxIJjxLPshkS6isDQFXKtxRqpPy RCJKc0tPAtdKrOMrmZYnwbrxgl79sE/ixFPtDbY25NMNitRMTEzOoQkJRWrkLqfneu0q kcXeWKuYNXJQBN0Qn6HMuH/HilxCgLiXvCnWIhUOchhEatUjqWwTX7fuYi2fSYDfA3pz +yrCyTIMNE3714FXkKBO+K3HdkY3A09ZVEPut4lYrhTFuW7AQvOxvp4vz4nBzXGGGUPi LN5w== X-Gm-Message-State: AOPr4FUsZ/ixKh48UsOLC9BcqIYMFzDB4BqwcS9VUp+OoJ0iF7HfnTkSU/tJWxC3Yg8XmA== X-Received: by 10.194.117.70 with SMTP id kc6mr3612855wjb.94.1461073180247; Tue, 19 Apr 2016 06:39:40 -0700 (PDT) Received: from localhost.localdomain (LPuteaux-656-1-278-113.w80-15.abo.wanadoo.fr. [80.15.154.113]) by smtp.googlemail.com with ESMTPSA id c85sm2789756wmd.0.2016.04.19.06.39.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Apr 2016 06:39:39 -0700 (PDT) From: Alvise Rigo To: qemu-devel@nongnu.org, mttcg@listserver.greensocs.com Date: Tue, 19 Apr 2016 15:39:18 +0200 Message-Id: <1461073171-22953-2-git-send-email-a.rigo@virtualopensystems.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1461073171-22953-1-git-send-email-a.rigo@virtualopensystems.com> References: <1461073171-22953-1-git-send-email-a.rigo@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::22f Subject: [Qemu-devel] [RFC v8 01/14] exec.c: Add new exclusive bitmap to ram_list 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: Peter Crosthwaite , claudio.fontana@huawei.com, Alvise Rigo , serge.fdrv@gmail.com, pbonzini@redhat.com, jani.kokkonen@huawei.com, tech@virtualopensystems.com, alex.bennee@linaro.org, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The purpose of this new bitmap is to flag the memory pages that are in the middle of LL/SC operations (after a LL, before a SC). For all these pages, the corresponding TLB entries will be generated in such a way to force the slow-path for all the VCPUs (see the following patches). When the system starts, the whole memory is set to dirty. Suggested-by: Jani Kokkonen Suggested-by: Claudio Fontana Signed-off-by: Alvise Rigo --- exec.c | 2 +- include/exec/memory.h | 3 ++- include/exec/ram_addr.h | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index 7115403..cefee1b 100644 --- a/exec.c +++ b/exec.c @@ -1579,7 +1579,7 @@ static ram_addr_t ram_block_add(RAMBlock *new_block, Error **errp) ram_list.dirty_memory[i] = bitmap_zero_extend(ram_list.dirty_memory[i], old_ram_size, new_ram_size); - } + } } cpu_physical_memory_set_dirty_range(new_block->offset, new_block->used_length, diff --git a/include/exec/memory.h b/include/exec/memory.h index c92734a..71e0480 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -19,7 +19,8 @@ #define DIRTY_MEMORY_VGA 0 #define DIRTY_MEMORY_CODE 1 #define DIRTY_MEMORY_MIGRATION 2 -#define DIRTY_MEMORY_NUM 3 /* num of dirty bits */ +#define DIRTY_MEMORY_EXCLUSIVE 3 +#define DIRTY_MEMORY_NUM 4 /* num of dirty bits */ #include #include diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index ef1489d..19789fc 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -21,6 +21,7 @@ #ifndef CONFIG_USER_ONLY #include "hw/xen/xen.h" +#include "sysemu/sysemu.h" struct RAMBlock { struct rcu_head rcu; @@ -172,6 +173,9 @@ static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start, if (unlikely(mask & (1 << DIRTY_MEMORY_CODE))) { bitmap_set_atomic(d[DIRTY_MEMORY_CODE], page, end - page); } + if (unlikely(mask & (1 << DIRTY_MEMORY_EXCLUSIVE))) { + bitmap_set_atomic(d[DIRTY_MEMORY_EXCLUSIVE], page, end - page); + } xen_modified_memory(start, length); } @@ -287,5 +291,32 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(unsigned long *dest, } void migration_bitmap_extend(ram_addr_t old, ram_addr_t new); + +/* Exclusive bitmap support. */ +#define EXCL_BITMAP_GET_OFFSET(addr) (addr >> TARGET_PAGE_BITS) + +/* Make the page of @addr not exclusive. */ +static inline void cpu_physical_memory_unset_excl(ram_addr_t addr) +{ + set_bit_atomic(EXCL_BITMAP_GET_OFFSET(addr), + ram_list.dirty_memory[DIRTY_MEMORY_EXCLUSIVE]); +} + +/* Return true if the page of @addr is exclusive, i.e. the EXCL bit is set. */ +static inline int cpu_physical_memory_is_excl(ram_addr_t addr) +{ + return !test_bit(EXCL_BITMAP_GET_OFFSET(addr), + ram_list.dirty_memory[DIRTY_MEMORY_EXCLUSIVE]); +} + +/* Set the page of @addr as exclusive clearing its EXCL bit and return the + * previous bit's state. */ +static inline int cpu_physical_memory_set_excl(ram_addr_t addr) +{ + return bitmap_test_and_clear_atomic( + ram_list.dirty_memory[DIRTY_MEMORY_EXCLUSIVE], + EXCL_BITMAP_GET_OFFSET(addr), 1); +} + #endif #endif