From patchwork Sat Mar 23 19:08:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160994 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp2201378jan; Sat, 23 Mar 2019 12:52:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1zLer8Ghv65Mt7agSOAbHP4hRpbwfIeUul9o2wiJ4DevZrJO1nHhRk0Oy6u6HaNto7AsL X-Received: by 2002:a25:9941:: with SMTP id n1mr13605590ybo.85.1553370750929; Sat, 23 Mar 2019 12:52:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553370750; cv=none; d=google.com; s=arc-20160816; b=iMAi26pQfDtuAnvtTJfHvvJZ/npLyENVE1UtnI6IZ1vt7EOW31I/IIuiJ4mllIeiHY EdfQfcKi6V17sqRKFQ48gis0MFh6a1zFg21U9jERRwU78wfjLqimfM9GOhIEjAH/Pmac 41CjUyqBWBh30OhfKR7EZXR0EtgECe8KiDX0+K4mUoa/eHPf7zM5d1b9gvy7hgHXdjj8 /rVrII+rw0IMi4gXr8WevxohgCpstmNa3WA2eeIUCqrS8nTcJ+xJDwnhEg0oToQ2yiv6 Haskrx5sIHqpjgRcQMhbv86kbYOq9UIXXHU6V85eS+T9CP6z/nL0A1c6KBf/SqywOJgw pY0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=WieJSx5BImKOVOCxOodAUYBI2M76j22iORgFgoIM8L0=; b=KugrkiwOBrGN5rfxNSHzbDWHQholwXy4Z8fNSmxV32sArU24HmhMbX9hlcgd8PZN84 I2a214yh/P5WxmEPpd5WUhebd+Zm7C1xcvy4mBmCZwW/rI1Q9jYc0zx9xjL+C5Wl7xgF MSWmsS+NHmLNovLUcq3lAXZqsZIEKtXlxT3ojIa3Ry0bAP21bz4+irIMy977OuBhElhS pOClL8xDg+DIN44ERW3MRWn+u+UNewdTR/H1GhWeTvE/1gHH3enLUExdeVrVZaSJ7Nku ifwOsLd90SheCtRpyXooYc8Zc6VWbLUpVaSnR/SX1i3OvV+P0VdlTvVhL8cz0+JQxhVt fi0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=AEnEpx3D; 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 c131si6603348ybb.37.2019.03.23.12.52.30 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 23 Mar 2019 12:52:30 -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=AEnEpx3D; 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 ([127.0.0.1]:47346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7mgw-0007LV-CJ for patch@linaro.org; Sat, 23 Mar 2019 15:52:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7mGI-0007kB-9s for qemu-devel@nongnu.org; Sat, 23 Mar 2019 15:24:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h7m1L-0006lC-FD for qemu-devel@nongnu.org; Sat, 23 Mar 2019 15:09:32 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:38924) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h7m1L-0006kg-70 for qemu-devel@nongnu.org; Sat, 23 Mar 2019 15:09:31 -0400 Received: by mail-pg1-x541.google.com with SMTP id k3so1567pga.6 for ; Sat, 23 Mar 2019 12:09:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=WieJSx5BImKOVOCxOodAUYBI2M76j22iORgFgoIM8L0=; b=AEnEpx3DT80jDgyDBRgP4xCoKJVaibz10nFpxbwQn/RbWDoP1ipI+/caOvXNdAU6VP YYGYlDNucxolbmyYuA6aTZlhQafq458XFByN0a2KReiOXcg5UJv6auLiMcqbRK7mYfsz JFbR/TTg1ST8tRnufA+jWzKqUL5DclaOXN/8hBQyYiUG59Rgw/P3EacMVyJfQQiYicTj 7Mz5SIVcfGCCy5Nl1RPVlogs8f01LL5IIzs+oIT7v+VQGLYITVh6JqI+ip2DPOPnUh7D mqYm0RL8/LNdI8PLaKFlbF58HRBDpQlz5Uf6uyzC5vL/MjMx2ZO/ZWTvvBZ72YjoaZ+S F6uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=WieJSx5BImKOVOCxOodAUYBI2M76j22iORgFgoIM8L0=; b=P0/zOd3fY7S67RXM8WdfprbAUe1fz/+uo1heCgEqGkkFkbZv2x9DfAM6UC6sagj7aX 5OVpAFwg6QNyHqS5MVLSj5IYK+1f9D6iNlf7yAeILxX/+NR6fBaYnObPTHNyKi9O7xP6 7Q/NYbvTcnzshZolRMAADHleFmi7h4D1K2TPChePQ4QfBx1nuPRrAtKsYgtNlW2OWghC RF+G/XpKU/rKWnJAOFx9JsaVmlzJAO4/UWwzSsAGAqmbqKwMiWNHEyJ0wNX5OOXo2U2R rE7TZPVE+zuEip7P4pIBIk5otBMAZK+X6nsDQBi2P8TfqvDbEKh+gMNde01fqgzlOwAs bUbQ== X-Gm-Message-State: APjAAAWaYKBAj5Ug6mo0Zou8GKCvTJBawzTzHUashFakcF/gDEXLcciA VYfh3V+3jnxNgw/tzVEC6x4t5G4myYM= X-Received: by 2002:a63:1d20:: with SMTP id d32mr15424553pgd.49.1553368169740; Sat, 23 Mar 2019 12:09:29 -0700 (PDT) Received: from localhost.localdomain (174-21-5-201.tukw.qwest.net. [174.21.5.201]) by smtp.gmail.com with ESMTPSA id h184sm25990703pfc.78.2019.03.23.12.09.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 23 Mar 2019 12:09:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sat, 23 Mar 2019 12:08:51 -0700 Message-Id: <20190323190925.21324-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190323190925.21324-1-richard.henderson@linaro.org> References: <20190323190925.21324-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::541 Subject: [Qemu-devel] [PATCH 01/35] tcg: Fold CPUTLBWindow into CPUTLBDesc 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 88cc8389e9..23586f9974 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);