From patchwork Mon Jun 10 02:01:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 166243 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp455615ilk; Sun, 9 Jun 2019 19:02:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsy2/9dtgNUal1lkgu4u8UA24oPyqf5P49AZ6kWLzMwRzRBrmKZwN4bWL1L9SZ5Z8yRxCv X-Received: by 2002:a0c:89f3:: with SMTP id 48mr36032646qvs.68.1560132159871; Sun, 09 Jun 2019 19:02:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560132159; cv=none; d=google.com; s=arc-20160816; b=jCBfVwz8Nsoi3hTkdyXRdc9bntU6IePn9kWMy5sYCWTrMg/Cbi01dp7mvIYyCETXXp dX5+AEQAQP3bmEmjq8TGlWIeWqzhjgERZvf99oK8m3D2HR9UeSA6BvC082M1NLo3HUtR uJGrW3iJ8pu6tOoQwSvISGUEeneI6Zq+EseufS1xEbO+bOivI5Mvm/sZO2PpH8/gftJr Cy7HXfoYKJwUtw6jqRFjXKRoHKRmSsP9B/JyU6EVDCylrsyPdM9KPveAuIpYfzUtETX8 ottjmMibCWbFRXbpEOMyhUoKs+iuZLcJuhl72O1qNfiq7EWq8ldl06Wde8IOh9pVkclF 4tzg== 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; bh=SsD841efZqo7uciuvvdZgxC3XyiWIUZWbge19pY103g=; b=dmApalruVQ+VqTeb1FHty2ZPOney2POUUr/aq5sNb8SqgPUviat65mXnRtDkW9AFzv 3iWygCm//O08J1+XjQ+Ue1B1uU816Nzldu9nUP7C3YuKXDh3VWmoZVc+IsPPlIQYEZ/B vSYfLnCk/wsWKlibIq7WAFi8M9VudNJmIYfQykzT2t2c/+8yGeNjXC6RqvXdRGEwu6wz qyBfzzYpTRjnqcrs6cdRzqWdO1eRz8eq4DLDh7wqiFp/oy/kNDCfChDJy7ud15BGqunF +lp8FP3Poc5wBi9N5bg2zRIGRABAfHkoKV7C7SIH9uDIc29k95MuEvUsxZd96o3L1dMu QsCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CBAm1099; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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. [209.51.188.17]) by mx.google.com with ESMTPS id d68si4916280qkf.180.2019.06.09.19.02.39 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 09 Jun 2019 19:02:39 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CBAm1099; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 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]:39602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1ha9dv-0005dC-Fa for patch@linaro.org; Sun, 09 Jun 2019 22:02:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52824) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1ha9di-0005Zq-Ct for qemu-devel@nongnu.org; Sun, 09 Jun 2019 22:02:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ha9dg-0001ZD-7g for qemu-devel@nongnu.org; Sun, 09 Jun 2019 22:02:26 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:35012) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ha9dg-0001Yt-1X for qemu-devel@nongnu.org; Sun, 09 Jun 2019 22:02:24 -0400 Received: by mail-pg1-x543.google.com with SMTP id s27so4160181pgl.2 for ; Sun, 09 Jun 2019 19:02:23 -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=SsD841efZqo7uciuvvdZgxC3XyiWIUZWbge19pY103g=; b=CBAm1099LtYSIKw0sl/uMXhR+PRHUjz7KHQV9pVsJXf1YGCNImXpZZahy/pLWNHMkK rdzw5H2ob1r6rOT3JBBUVwclbMxYVfWRQRVFfxUsF4EpYhHFfpMHrC0cgaZGY3TE3FaA FqtTU/A0yPJDFBwsPr9Hk2wHtYPJWrdBQ5Ea5tGYSDyGB2Eabsd9Lpqh7pfMb77y7kRO fOCPISv6Cn3b8dzZO3kUMojKDoXKEvxLE47L3Qd1pdUsSIGbExxDxQitYwebRODHFXZq s0OtoLhdtKPH3N9EI8dfbOjYEvBNr/4uW1SawJgbejOKrzIBbgAMOwZ68qc7tzrKa/in Uu0Q== 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=SsD841efZqo7uciuvvdZgxC3XyiWIUZWbge19pY103g=; b=kTJjDR2cGtj/wBB2yCbi5dOhAHAdYi3oHnIbhHmVnK39DwzZBD3IZ93BqTH86PS628 pMOKKATarUyvj/QhnPW07NDXili8gTKMEIefeH28TDKIGTSWsRaBBMp2iKaf7aGz9XCI tJLSCDWNpahawld5G72mMdPqhUvM4sHVoZn1ZD7Ah1d4hSMlExwldA1Gsm1gu7S2GJm2 sucwxzn/exZpogRqUOCDcnaU0Dq3xGVICpSHLLtCJo9TLzwWFCtszlOL+zlFBxNZhieU Ma5LFffG4FJYgRh5WSVig8s91kJ/wvHZwhujzADnOP2/B64zz3oYeEw/ZSvqoR+1j5bH 2SDw== X-Gm-Message-State: APjAAAVT9niqonjU0cJFgq0dps7s8rEuFTJHJJJCFTR0/Fro80nscA6D 5S/YGtCq39vPoMo6kJmxpecs2rLBwD8= X-Received: by 2002:a65:6495:: with SMTP id e21mr13441057pgv.383.1560132142263; Sun, 09 Jun 2019 19:02:22 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id l63sm9749013pfl.181.2019.06.09.19.02.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Jun 2019 19:02:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 9 Jun 2019 19:01:40 -0700 Message-Id: <20190610020218.9228-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190610020218.9228-1-richard.henderson@linaro.org> References: <20190610020218.9228-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:4864:20::543 Subject: [Qemu-devel] [PULL 01/39] tcg: Fold CPUTLBWindow into CPUTLBDesc X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Both structures are allocated once per mmu_idx. There is no reason for them to be separate. Reviewed-by: Alistair Francis Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- include/exec/cpu-defs.h | 17 ++++------------- accel/tcg/cputlb.c | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 25 deletions(-) -- 2.17.1 diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h index 8f2a848bf5..52d150aaf1 100644 --- a/include/exec/cpu-defs.h +++ b/include/exec/cpu-defs.h @@ -127,18 +127,6 @@ typedef struct CPUIOTLBEntry { MemTxAttrs attrs; } CPUIOTLBEntry; -/** - * struct CPUTLBWindow - * @begin_ns: host time (in ns) at the beginning of the time window - * @max_entries: maximum number of entries observed in the window - * - * See also: tlb_mmu_resize_locked() - */ -typedef struct CPUTLBWindow { - int64_t begin_ns; - size_t max_entries; -} CPUTLBWindow; - typedef struct CPUTLBDesc { /* * Describe a region covering all of the large pages allocated @@ -148,9 +136,12 @@ typedef struct CPUTLBDesc { */ target_ulong large_page_addr; target_ulong large_page_mask; + /* host time (in ns) at the beginning of the time window */ + int64_t window_begin_ns; + /* maximum number of entries observed in the window */ + size_t window_max_entries; /* The next index to use in the tlb victim table. */ size_t vindex; - CPUTLBWindow window; size_t n_used_entries; } CPUTLBDesc; diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index cdcc377102..41f2296f93 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -79,11 +79,11 @@ static inline size_t sizeof_tlb(CPUArchState *env, uintptr_t mmu_idx) return env->tlb_mask[mmu_idx] + (1 << CPU_TLB_ENTRY_BITS); } -static void tlb_window_reset(CPUTLBWindow *window, int64_t ns, +static void tlb_window_reset(CPUTLBDesc *desc, int64_t ns, size_t max_entries) { - window->begin_ns = ns; - window->max_entries = max_entries; + desc->window_begin_ns = ns; + desc->window_max_entries = max_entries; } static void tlb_dyn_init(CPUArchState *env) @@ -94,7 +94,7 @@ static void tlb_dyn_init(CPUArchState *env) CPUTLBDesc *desc = &env->tlb_d[i]; size_t n_entries = 1 << CPU_TLB_DYN_DEFAULT_BITS; - tlb_window_reset(&desc->window, get_clock_realtime(), 0); + tlb_window_reset(desc, get_clock_realtime(), 0); desc->n_used_entries = 0; env->tlb_mask[i] = (n_entries - 1) << CPU_TLB_ENTRY_BITS; env->tlb_table[i] = g_new(CPUTLBEntry, n_entries); @@ -151,18 +151,18 @@ static void tlb_mmu_resize_locked(CPUArchState *env, int mmu_idx) int64_t now = get_clock_realtime(); int64_t window_len_ms = 100; int64_t window_len_ns = window_len_ms * 1000 * 1000; - bool window_expired = now > desc->window.begin_ns + window_len_ns; + bool window_expired = now > desc->window_begin_ns + window_len_ns; - if (desc->n_used_entries > desc->window.max_entries) { - desc->window.max_entries = desc->n_used_entries; + if (desc->n_used_entries > desc->window_max_entries) { + desc->window_max_entries = desc->n_used_entries; } - rate = desc->window.max_entries * 100 / old_size; + rate = desc->window_max_entries * 100 / old_size; if (rate > 70) { new_size = MIN(old_size << 1, 1 << CPU_TLB_DYN_MAX_BITS); } else if (rate < 30 && window_expired) { - size_t ceil = pow2ceil(desc->window.max_entries); - size_t expected_rate = desc->window.max_entries * 100 / ceil; + size_t ceil = pow2ceil(desc->window_max_entries); + size_t expected_rate = desc->window_max_entries * 100 / ceil; /* * Avoid undersizing when the max number of entries seen is just below @@ -182,7 +182,7 @@ static void tlb_mmu_resize_locked(CPUArchState *env, int mmu_idx) if (new_size == old_size) { if (window_expired) { - tlb_window_reset(&desc->window, now, desc->n_used_entries); + tlb_window_reset(desc, now, desc->n_used_entries); } return; } @@ -190,7 +190,7 @@ static void tlb_mmu_resize_locked(CPUArchState *env, int mmu_idx) g_free(env->tlb_table[mmu_idx]); g_free(env->iotlb[mmu_idx]); - tlb_window_reset(&desc->window, now, 0); + tlb_window_reset(desc, now, 0); /* desc->n_used_entries is cleared by the caller */ env->tlb_mask[mmu_idx] = (new_size - 1) << CPU_TLB_ENTRY_BITS; env->tlb_table[mmu_idx] = g_try_new(CPUTLBEntry, new_size);