From patchwork Tue Oct 10 19:29:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 115451 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4116061qgn; Tue, 10 Oct 2017 12:32:20 -0700 (PDT) X-Received: by 10.200.2.158 with SMTP id p30mr6535542qtg.255.1507663940034; Tue, 10 Oct 2017 12:32:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507663940; cv=none; d=google.com; s=arc-20160816; b=X+zbfyOmrIpdbfYGlBtN4EU/M+zbVdu0zmgixiymvjq4e7K23+DkE1B2Gp4xi+148t n/lTdVEPbjbiLpcJcw85EVLaXLXbioqCuUm2w/LBer3PpVCKNkrzVGv79heucLBJBKcQ ahJvs1uzChNr2Y6gMEN91tTpT9SP1AvzoyOlBkxLNwGvr8kat8bgF94pWKVQ75Vk3mGE 561049Ae32r4xu0oqAynmq8jN+UvJCR/A0fcZ7VLKJ1klk4Ydgy9cYAQewnFPs8SoOKl 0kMK3A62Oz/+pkrKXjPV9SnVpFUWPtV6y39E8jbJeltVM2K23wvPpniOa9ICibkK3XYu mA6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=qsfB70w9CzKDOcAWwewK8f/2coAK2gFW2Q5mox1wx5o=; b=ek2QC2Xlkc3p6azZqRqFL2slCQ1nS3/sH+tdFsUEmDy/JppMrAXlhdfHH4rADWV9qJ DpdIq2wlD/X/j38VIANEdkvUWA7bH6Med40J9bB1RHeb/+KIFxPo6p/GEYPQVLFRCrkQ 1HaoNkbpLLFJgmw5kxcU4Ry9vBUARs7BK0mdrYc53T3fx4e/KrN6ZVhOZiagX1A1TYfP yt9mDZaaeE2G9XZeBoriZNKXZPpx2f+ENU4G5YUZljln9dPJdpQiXU517/Jit+kGSgnN /wBrNWaSxshuO9AyHnNdmmhCyX2C7+OueT6SpBqx/zMJNEoHVtVztEqqY7UShCXzYGvk 0gDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=A9Kdb1Yf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id t13si1954861qki.180.2017.10.10.12.32.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 10 Oct 2017 12:32:20 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=A9Kdb1Yf; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e20GH-0001iS-NF for patch@linaro.org; Tue, 10 Oct 2017 15:32:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58732) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e20EG-0000V2-JP for qemu-devel@nongnu.org; Tue, 10 Oct 2017 15:30:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e20EC-0004uP-Rw for qemu-devel@nongnu.org; Tue, 10 Oct 2017 15:30:12 -0400 Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]:51204) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e20EC-0004u1-Lu for qemu-devel@nongnu.org; Tue, 10 Oct 2017 15:30:08 -0400 Received: by mail-pf0-x231.google.com with SMTP id n14so16371872pfh.8 for ; Tue, 10 Oct 2017 12:30:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qsfB70w9CzKDOcAWwewK8f/2coAK2gFW2Q5mox1wx5o=; b=A9Kdb1Yf+xTa2xJ+b/cGi51WEEpMQLNOtvQSHdbEujCwm+cwQTDSTaz/ehyVAsvi3O d9j9HeSUuwT84Wkxveesaoe5K2nG4y9hiAHYB/m21c4RkTA/Sy0QAZWGtfoRWOJfNUTW 4PzCq3RHNeroxFU36TuZSY6pJri2Jg8D6UZhc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qsfB70w9CzKDOcAWwewK8f/2coAK2gFW2Q5mox1wx5o=; b=NHviW/DhpJtGufOyF2Vg/s0gTDLRk0GuYIjrXkuA/9AEu86BuAcokAgGdOJBog0QMi xtALrAnFBHYx2f8BVWLscfmOMVOWPiV6Ej1cCNoDhmOly2k9lib780FGDBhHc72FZ99S veoV+HyV3sAP4lugbgXXnphVcLlJgbean7mdKzJB/F0LmB4JiWVrz0a2KzRED6/1fNgS mlUhzCz9OSSgHomYd8oVXYyy5OHxepyehETitS5mb4m9AOLjQbV8Td78+jQJqZiRqwsL oqbDk4c6FSoL/inlFHx/TDu0+Y4LcZiHvbnmNnTHw4p2KvallwYCf8VFjmgTaCdhjnlO Uz6w== X-Gm-Message-State: AMCzsaVuiDadqjvKqr/iHDDY/88dYHAbvxNdVUPyiX3Y/za/kEgRfy0Q cPVp+WsjyZelw62m7UF4RRdy++RGm+s= X-Google-Smtp-Source: AOwi7QAbnHRyDKxhOXy/xy/VqeiCoK1I2ylNaQ7MZhCunFB7Pu7Z8YFZKaKWe4Ms7OdGpH4bk8vLWg== X-Received: by 10.98.54.194 with SMTP id d185mr14645738pfa.70.1507663807413; Tue, 10 Oct 2017 12:30:07 -0700 (PDT) Received: from bigtime.twiddle.net (97-126-104-76.tukw.qwest.net. [97.126.104.76]) by smtp.gmail.com with ESMTPSA id r22sm19859788pfl.15.2017.10.10.12.30.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Oct 2017 12:30:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 10 Oct 2017 12:29:44 -0700 Message-Id: <20171010193003.28857-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171010193003.28857-1-richard.henderson@linaro.org> References: <20171010193003.28857-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::231 Subject: [Qemu-devel] [PULL v2 01/20] cputlb: bring back tlb_flush_count under !TLB_DEBUG 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.maydell@linaro.org, "Emilio G. Cota" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: "Emilio G. Cota" Commit f0aff0f124 ("cputlb: add assert_cpu_is_self checks") buried the increment of tlb_flush_count under TLB_DEBUG. This results in "info jit" always (mis)reporting 0 TLB flushes when !TLB_DEBUG. Besides, under MTTCG tlb_flush_count is updated by several threads, so in order not to lose counts we'd either have to use atomic ops or distribute the counter, which is more scalable. This patch does the latter by embedding tlb_flush_count in CPUArchState. The global count is then easily obtained by iterating over the CPU list. Note that this change also requires updating the accessors to tlb_flush_count to use atomic_read/set whenever there may be conflicting accesses (as defined in C11) to it. Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Signed-off-by: Emilio G. Cota Signed-off-by: Richard Henderson --- include/exec/cpu-defs.h | 1 + include/exec/cputlb.h | 3 +-- accel/tcg/cputlb.c | 17 ++++++++++++++--- accel/tcg/translate-all.c | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) -- 2.13.6 diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h index bc8e7f848d..e43ff8346b 100644 --- a/include/exec/cpu-defs.h +++ b/include/exec/cpu-defs.h @@ -137,6 +137,7 @@ typedef struct CPUIOTLBEntry { CPUTLBEntry tlb_v_table[NB_MMU_MODES][CPU_VTLB_SIZE]; \ CPUIOTLBEntry iotlb[NB_MMU_MODES][CPU_TLB_SIZE]; \ CPUIOTLBEntry iotlb_v[NB_MMU_MODES][CPU_VTLB_SIZE]; \ + size_t tlb_flush_count; \ target_ulong tlb_flush_addr; \ target_ulong tlb_flush_mask; \ target_ulong vtlb_index; \ diff --git a/include/exec/cputlb.h b/include/exec/cputlb.h index 3f941783c5..c91db211bc 100644 --- a/include/exec/cputlb.h +++ b/include/exec/cputlb.h @@ -23,7 +23,6 @@ /* cputlb.c */ void tlb_protect_code(ram_addr_t ram_addr); void tlb_unprotect_code(ram_addr_t ram_addr); -extern int tlb_flush_count; - +size_t tlb_flush_count(void); #endif #endif diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index bcbcc4db6c..5b1ef1442c 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -92,8 +92,18 @@ static void flush_all_helper(CPUState *src, run_on_cpu_func fn, } } -/* statistics */ -int tlb_flush_count; +size_t tlb_flush_count(void) +{ + CPUState *cpu; + size_t count = 0; + + CPU_FOREACH(cpu) { + CPUArchState *env = cpu->env_ptr; + + count += atomic_read(&env->tlb_flush_count); + } + return count; +} /* This is OK because CPU architectures generally permit an * implementation to drop entries from the TLB at any time, so @@ -112,7 +122,8 @@ static void tlb_flush_nocheck(CPUState *cpu) } assert_cpu_is_self(cpu); - tlb_debug("(count: %d)\n", tlb_flush_count++); + atomic_set(&env->tlb_flush_count, env->tlb_flush_count + 1); + tlb_debug("(count: %zu)\n", tlb_flush_count()); tb_lock(); diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 2d1ed06065..6b5d4bece2 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1936,7 +1936,7 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf) atomic_read(&tcg_ctx.tb_ctx.tb_flush_count)); cpu_fprintf(f, "TB invalidate count %d\n", tcg_ctx.tb_ctx.tb_phys_invalidate_count); - cpu_fprintf(f, "TLB flush count %d\n", tlb_flush_count); + cpu_fprintf(f, "TLB flush count %zu\n", tlb_flush_count()); tcg_dump_info(f, cpu_fprintf); tb_unlock();