From patchwork Tue Oct 10 00:55:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 115307 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3165395qgn; Mon, 9 Oct 2017 17:56:30 -0700 (PDT) X-Received: by 10.237.60.101 with SMTP id u34mr16118230qte.153.1507596990537; Mon, 09 Oct 2017 17:56:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507596990; cv=none; d=google.com; s=arc-20160816; b=riH2lJWMAhvC6LYYchCk7fNsvlBBRbUSF1QvlZEtXklS4zgGvXAkJOnBC5Huq6hCGD dEYt1LKRT/wKjU51Fy8uoC0Bsh0g0qDt2zOka3TgMMQL8JGmO4FVW3/NYCIaegDk0ttE TfLmu/G0NQfwDUSlsGZtfG8DVpXMrs/YFQ/ORL7BE9A2CXf+CIB/NGGaIoSK1aEamRvz R6xsoMnq3v8ZOJNvHUGYjvVf4sux5rKzAe5b5pQACFaLUd925tp8JreBOGqUXYrqPrzq Gp9SSYlQdzi61hZw0zLjXf4RXpewMdONRxLrXq8ocOFUzBOgZCQqIkgPiqHRlOxtmzLM SY3w== 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=YNe0k1IYwzpEoWYXWYPj4YqwSLbe27HvtyVkrgeE/iCuLRby3G6xGW+bRpWGF5Qal+ mHxnkG8LgsP2d0vlr7CfPPEjtsmCsRt4Tzv0v5CMAF6iJ9IDkmNJT4Y6eRhhbfs3xjoL oyoz264lyxFO9CESDKZ0s5Lor4CdSm0cMdTO6P6QSZZsYQ5Z24n81zhdKJA8UYwlgjtH 272316EhfqacEDnJvEmzc8XItGPjqDvj3LH+ee1/6UsLi76Af8fOhrGnh0eXWal1kUdv tg4v+5TyucHlflUd8mOTyPWHboDfdWoK+2qTiC0ggOxNKLj8A9flNyW0qmIP8w1Ov5pB THfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=XOuH9YQv; 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 40si2338921qts.209.2017.10.09.17.56.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 09 Oct 2017 17:56:30 -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=XOuH9YQv; 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]:60484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1iqS-0002AC-Bu for patch@linaro.org; Mon, 09 Oct 2017 20:56:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e1iq7-00029v-VF for qemu-devel@nongnu.org; Mon, 09 Oct 2017 20:56:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e1iq6-0004GD-3s for qemu-devel@nongnu.org; Mon, 09 Oct 2017 20:56:08 -0400 Received: from mail-pf0-x231.google.com ([2607:f8b0:400e:c00::231]:52377) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e1iq5-0004FP-Ui for qemu-devel@nongnu.org; Mon, 09 Oct 2017 20:56:06 -0400 Received: by mail-pf0-x231.google.com with SMTP id a1so12238343pfj.9 for ; Mon, 09 Oct 2017 17:56:05 -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=XOuH9YQvwHKWKirerHu2GryaBKPrJrf9W6qjDHbw3YZ2ogiTFcD4J1qPnYiRExCkZI Vr/FcpcNIpnCjHQelblbIFNgYl1cOrGa8/L7rs1DTTzn0PbqdjnEBIh9oS6D1Dlwtgby s79tLic3fJrXIXQy/OstLmb5QNhu9IR6WxnnQ= 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=Htk1TelQA33aooue+m7Qtoqd58NdVftANgdIIAes0ACes+jBqRa06sBf26rHwm3DFZ hll/ngpNCTcuJAra9iVYoDo+jQaWzzLbmFEU2acLOl7xtTZPmW4Ryfpod5dsOuHoYK0U aiGSplZiwh03fn6IRf4DRl75zfISOqhyHQBv6FeHbiodRPbAskxKWLpX8L77KpM6fZW7 wXppGlSms9x4cld/2HjqWnVFA4Y2K5y8a6874GEYqFYnv/wLpa3jMlW8h+VAm5/NtoFd t2gYd7UtvDs+uZo0qlTsCbzBi/qoeQz5GWiBevH8nJH2kqc43V2isEu4RMs5z+pw/Xof 2TYw== X-Gm-Message-State: AMCzsaWbEUXYN4EG/uODQqITmulkmt4++qh2b9G9E1SOuO52M9UTuIRV t072FN4WrdLh8zAwlXttEONbvb8PfWg= X-Google-Smtp-Source: AOwi7QA1RjyBky7hWDWGBCNpHXuWe7zQqLxiOWe68WHp2IGz/LOHhnyyTKnZw4zWR7+azqrnabvQ0g== X-Received: by 10.98.50.66 with SMTP id y63mr11740327pfy.155.1507596964564; Mon, 09 Oct 2017 17:56:04 -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 n19sm17121368pfj.52.2017.10.09.17.56.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 09 Oct 2017 17:56:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 9 Oct 2017 17:55:38 -0700 Message-Id: <20171010005600.28735-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171010005600.28735-1-richard.henderson@linaro.org> References: <20171010005600.28735-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 01/23] 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();