From patchwork Tue Apr 19 13:39:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alvise rigo X-Patchwork-Id: 8880211 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 71CD1BF29F for ; Tue, 19 Apr 2016 13:43:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8CE6620268 for ; Tue, 19 Apr 2016 13:42:58 +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 AE8EC201C8 for ; Tue, 19 Apr 2016 13:42:57 +0000 (UTC) Received: from localhost ([::1]:58154 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asVvd-0000uC-2t for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Apr 2016 09:42:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asVsd-0003Oy-QZ for qemu-devel@nongnu.org; Tue, 19 Apr 2016 09:39:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1asVsc-0000hl-Ie for qemu-devel@nongnu.org; Tue, 19 Apr 2016 09:39:51 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:34539) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1asVsc-0000hN-8i for qemu-devel@nongnu.org; Tue, 19 Apr 2016 09:39:50 -0400 Received: by mail-wm0-x244.google.com with SMTP id n3so5310491wmn.1 for ; Tue, 19 Apr 2016 06:39:50 -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=N7CaiWd0kQDhp94Pe66JWuMvKiDvz+iPRaJQmnnHGfc=; b=pJRa002w7noaDEXO1xWPBOXKNsqlc9y5wdR7VLSEAymaI0sBZD6dESHkFoKBACZiUT u2pnuc+O3R1qR5aXWWpT1dq6WfiN1OT0q29ykQ6fEErxkVUVCAhNpMNCjGvOTFOAcT90 42Q7dpCAWlbLhAVgRE+ZZwTHM1058vpxLTprsPy79oPMfJGL2aqaLTKmbcXRpdyUk1eC 0SS3VYAxbCdc3im+Uno88Jl/T3nBKtmlmNfy+4SoWTPWhYb3wNHFMx7Olmh8tr6JT9vi 5jc9tbHqnvc7WR4c4BsbwzfuKSsGb9sw+yGiJFfTmNPuGqp/E8mEFwrM0wpG8vZkiPWa 8Azg== 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=N7CaiWd0kQDhp94Pe66JWuMvKiDvz+iPRaJQmnnHGfc=; b=lHMUHY6bnUVHor+PZs9iIQbTdyZGwfTm5RSsxJS3mrfXE6X5ysTIuzdwytgxr/xPmL C99ojiYdZi0esqf5ic+wZbBjkVdNi0m+a9yKxMDvzcrB7o44+oOg0Xx2KFZhOwQF6CNw Dz9g7VP3dr7NYCwqVVGzKqpSUc80pHd3N9YStN8B3kR5vCpRl8+/G8rux1vhiUBzonzV 1ttfklJ1+mnRaARFQfbvsvdayCysR3GBvmEa2j5IUBNPI6dT/JFWW6ZaFP05iZ1QdfTf yDcwRl+nNheY4Jk8WoEPwkI1NOfWR7ofD4q13HzLq6H1q+/tUt+VwitjP6ZQEtrLKIj4 lAjg== X-Gm-Message-State: AOPr4FV7o0Kz2FUW/a56t4rL6CYBZUAvwFykAOQlAgXM/e1y57btNf4l+qKZ157nX/2+JQ== X-Received: by 10.194.61.231 with SMTP id t7mr3713144wjr.32.1461073189657; Tue, 19 Apr 2016 06:39:49 -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.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Apr 2016 06:39:48 -0700 (PDT) From: Alvise Rigo To: qemu-devel@nongnu.org, mttcg@listserver.greensocs.com Date: Tue, 19 Apr 2016 15:39:25 +0200 Message-Id: <1461073171-22953-9-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::244 Subject: [Qemu-devel] [RFC v8 08/14] softmmu: Add history of excl accesses 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, =?UTF-8?q?Andreas=20F=C3=A4rber?= , 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 Add a circular buffer to store the hw addresses used in the last EXCLUSIVE_HISTORY_LEN exclusive accesses. When an address is pop'ed from the buffer, its page will be set as not exclusive. In this way we avoid frequent set/unset of a page (causing frequent flushes as well). Suggested-by: Jani Kokkonen Suggested-by: Claudio Fontana Signed-off-by: Alvise Rigo --- cputlb.c | 21 +++++++++++++++++++++ exec.c | 19 +++++++++++++++++++ include/qom/cpu.h | 8 ++++++++ softmmu_llsc_template.h | 1 + vl.c | 3 +++ 5 files changed, 52 insertions(+) diff --git a/cputlb.c b/cputlb.c index 58d6f03..02b0d14 100644 --- a/cputlb.c +++ b/cputlb.c @@ -475,6 +475,27 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulong addr) return qemu_ram_addr_from_host_nofail(p); } +/* Keep a circular array with the last excl_history.length addresses used for + * exclusive accesses. The exiting addresses are marked as non-exclusive. */ +extern CPUExclusiveHistory excl_history; +static inline void excl_history_put_addr(hwaddr addr) +{ + hwaddr last; + + /* Calculate the index of the next exclusive address */ + excl_history.last_idx = (excl_history.last_idx + 1) % excl_history.length; + + last = excl_history.c_array[excl_history.last_idx]; + + /* Unset EXCL bit of the oldest entry */ + if (last != EXCLUSIVE_RESET_ADDR) { + cpu_physical_memory_unset_excl(last); + } + + /* Add a new address, overwriting the oldest one */ + excl_history.c_array[excl_history.last_idx] = addr & TARGET_PAGE_MASK; +} + #define MMUSUFFIX _mmu /* Generates LoadLink/StoreConditional helpers in softmmu_template.h */ diff --git a/exec.c b/exec.c index cefee1b..3c54b92 100644 --- a/exec.c +++ b/exec.c @@ -177,6 +177,25 @@ struct CPUAddressSpace { MemoryListener tcg_as_listener; }; +/* Exclusive memory support */ +CPUExclusiveHistory excl_history; +void cpu_exclusive_history_init(void) +{ + /* Initialize exclusive history for atomic instruction handling. */ + if (tcg_enabled()) { + g_assert(EXCLUSIVE_HISTORY_CPU_LEN * max_cpus <= UINT16_MAX); + excl_history.length = EXCLUSIVE_HISTORY_CPU_LEN * max_cpus; + excl_history.c_array = g_malloc(excl_history.length * sizeof(hwaddr)); + memset(excl_history.c_array, -1, excl_history.length * sizeof(hwaddr)); + } +} + +void cpu_exclusive_history_free(void) +{ + if (tcg_enabled()) { + g_free(excl_history.c_array); + } +} #endif #if !defined(CONFIG_USER_ONLY) diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 014851e..de144f6 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -232,7 +232,15 @@ struct kvm_run; #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS) /* Atomic insn translation TLB support. */ +typedef struct CPUExclusiveHistory { + uint16_t last_idx; /* index of last insertion */ + uint16_t length; /* history's length, it depends on smp_cpus */ + hwaddr *c_array; /* history's circular array */ +} CPUExclusiveHistory; #define EXCLUSIVE_RESET_ADDR ULLONG_MAX +#define EXCLUSIVE_HISTORY_CPU_LEN 256 +void cpu_exclusive_history_init(void); +void cpu_exclusive_history_free(void); /** * CPUState: diff --git a/softmmu_llsc_template.h b/softmmu_llsc_template.h index ca2ac95..1e24fec 100644 --- a/softmmu_llsc_template.h +++ b/softmmu_llsc_template.h @@ -77,6 +77,7 @@ WORD_TYPE helper_ldlink_name(CPUArchState *env, target_ulong addr, CPUState *cpu; cpu_physical_memory_set_excl(hw_addr); + excl_history_put_addr(hw_addr); CPU_FOREACH(cpu) { if (this_cpu != cpu) { tlb_flush(cpu, 1); diff --git a/vl.c b/vl.c index f043009..b22d99b 100644 --- a/vl.c +++ b/vl.c @@ -547,6 +547,7 @@ static void res_free(void) { g_free(boot_splash_filedata); boot_splash_filedata = NULL; + cpu_exclusive_history_free(); } static int default_driver_check(void *opaque, QemuOpts *opts, Error **errp) @@ -4322,6 +4323,8 @@ int main(int argc, char **argv, char **envp) configure_accelerator(current_machine); + cpu_exclusive_history_init(); + if (qtest_chrdev) { qtest_init(qtest_chrdev, qtest_log, &error_fatal); }