From patchwork Mon Aug 22 23:23:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 599218 Delivered-To: patch@linaro.org Received: by 2002:a05:6918:5e84:b0:d4:ea33:5523 with SMTP id nd4csp2089653ysb; Mon, 22 Aug 2022 16:38:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR6VtLy30HAuhX0MNa8tcpdnQWdDKsLqsIhTROyLB/HzymbRGKiU+Nluo5vCsouRRIBmT7f+ X-Received: by 2002:a37:aac6:0:b0:6bc:3e7b:1e9a with SMTP id t189-20020a37aac6000000b006bc3e7b1e9amr772978qke.59.1661211511246; Mon, 22 Aug 2022 16:38:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661211511; cv=none; d=google.com; s=arc-20160816; b=nwLXhlJYrS7TSnAkkCzHnrSiHOJ3OIdMJvBX9D4XmuZEC23bQLOuuD/17ypWDhXNUl 3MjYnhYbqJQWw9Nr9nLOnmNZDjg343sXKVXW7Idl8d5fnJ1oYflftYg+4mLnzR42d8im NHXsoQYs/bMXMJrZOMepx39sh75KKagNgF2U9Q8ZcGPCp8VP8hkp8+8DCQFbT1H8pNmC zgyVX4Yoh/7r+Kg9+vUIV+8ArwLXu+hmfP8ZS35iPOY9Av3NRi44a+6B2AbL+MXcCYJY OZwYVI57s0E+6GTeJLR/Q6KVnOhnBFwb5sfj40fyNV2djr+wjKdjMOZTqp+lm8qFZs17 hl6w== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XGYmwpgiZPY1AsTDknzkrjEzLYeuV4sGoEw7odttBvA=; b=sJEoz68cjbqqTcaESdAhV5uMKS/uXJaS17/vGHX4j8E2tplTAjAtnTPCZAqQpo0ZrV TGxy68Qqx0L8ulfR00SidE5y32SucC6BT6eTkEj5rvVkTOwTVnFQ6dpcaBB5Vv6PwlNW Ryuti4E20so0HfR7q/Xcw26cxYY9T1hyHhfOfnXdtEWQppoircBiAuKhwn5btkG1HdL6 hvmOd0rNwcwHbX4oJ5AYaVdSIUdoIdkUpZ8jd3AQ42Lfyv6hrEozUZa5jdOOHQBU6n4K MlBwKwPJ4lDXP2EdFv6KOWf9dHv5Ikv4nUvB0bn5foCIFl0GmQSnlerClLgnJ4BUplD3 Fvvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=adtutzQc; 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=pass (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 c12-20020ac87dcc000000b0034355e55efesi6444278qte.576.2022.08.22.16.38.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Aug 2022 16:38:31 -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=pass header.i=@linaro.org header.s=google header.b=adtutzQc; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oQH02-0001rh-P7 for patch@linaro.org; Mon, 22 Aug 2022 19:38:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32850) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQGlr-0005du-7O for qemu-devel@nongnu.org; Mon, 22 Aug 2022 19:23:51 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:43673) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQGlp-0005bY-0G for qemu-devel@nongnu.org; Mon, 22 Aug 2022 19:23:50 -0400 Received: by mail-pf1-x42f.google.com with SMTP id w138so9197080pfc.10 for ; Mon, 22 Aug 2022 16:23:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=XGYmwpgiZPY1AsTDknzkrjEzLYeuV4sGoEw7odttBvA=; b=adtutzQcMuVneKhA8FVpCHu1q4sKiS678TT+udXfA2GxQt/gEkLYfo/eFBmoTWvGhR 78m3hCCEBqOFVyle1P7fwfic+N+zUySTl+clA65+sRKCqx2WLKuCaxLlAHFXbQkSOaLI LnHmaE7uGtZbkJo7nPXiZEo1vqOlgJfSCyEhvXYCHHm7tzU/tX4/oGUYVJvynH8VpZMk L1AQ/NeYSzFns2J/5FZ286c/WTYZVE+ucMY+ocG56F0A0V8lzt6k4G1/uQE4t+oGBRZq kPZDJyvo1ytrTe2IAgSDPDzyVCzt89p3CV3PWAGVSNMFsfSB2mwRGZS29ECa4D2YpboP DHZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=XGYmwpgiZPY1AsTDknzkrjEzLYeuV4sGoEw7odttBvA=; b=nsf/YTiSOiwtbAe2y/37e6h5ldQEWDmLlwxmcFz1mk1t/NOV8bhkxaUDlhXo0QgKpL sgxukh49IxKtXmeVuiQt5RAzJzudhrs9iMwjMKIeAh+kgXYB1D1JPy/Qe1LqVXt3Y5So 7BnAWnJQUjU8sxaH60VS2HbMC9Z7equi1GLblwN+EErjzd4azxy/ajAUPvxeR8llttzI lq9HO4tK++TJ6W+18PBW5wbPay0E8VwKzjqtukFoikUIATUVKhTcTG4dkbKfo1BBybZy 2PGZw7EGci11rl8/mL/p4/39U/uK405r6KNC7Rw0VbJ/4yPrXdBgKyr2SyPkJaSaXFBX 8q7Q== X-Gm-Message-State: ACgBeo22R+hcBJJuZarelzA2GnlGMDg5sQU8jLBqhPZbA/HHMuRNL/1y 8TI60LZIB3+EjqZ8dPEQIcZsnnYIwqzxQw== X-Received: by 2002:a65:5504:0:b0:42a:352d:c79c with SMTP id f4-20020a655504000000b0042a352dc79cmr16561567pgr.58.1661210625251; Mon, 22 Aug 2022 16:23:45 -0700 (PDT) Received: from stoup.. ([2602:47:d49d:ec01:c3f1:b74f:5edd:63af]) by smtp.gmail.com with ESMTPSA id k17-20020aa79731000000b0052d3899f8c2sm3809112pfg.4.2022.08.22.16.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 16:23:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Subject: [PATCH v3 05/17] include/hw/core: Create struct CPUJumpCache Date: Mon, 22 Aug 2022 16:23:26 -0700 Message-Id: <20220822232338.1727934-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822232338.1727934-1-richard.henderson@linaro.org> References: <20220822232338.1727934-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Wrap the bare TranslationBlock pointer into a structure. Signed-off-by: Richard Henderson --- include/hw/core/cpu.h | 8 ++++++-- accel/tcg/cpu-exec.c | 9 ++++++--- accel/tcg/cputlb.c | 2 +- accel/tcg/translate-all.c | 4 ++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 500503da13..8edef14199 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -233,6 +233,10 @@ struct hvf_vcpu_state; #define TB_JMP_CACHE_BITS 12 #define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS) +typedef struct { + TranslationBlock *tb; +} CPUJumpCache; + /* work queue */ /* The union type allows passing of 64 bit target pointers on 32 bit @@ -362,7 +366,7 @@ struct CPUState { IcountDecr *icount_decr_ptr; /* Accessed in parallel; all accesses must be atomic */ - TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE]; + CPUJumpCache tb_jmp_cache[TB_JMP_CACHE_SIZE]; struct GDBRegisterState *gdb_regs; int gdb_num_regs; @@ -453,7 +457,7 @@ static inline void cpu_tb_jmp_cache_clear(CPUState *cpu) unsigned int i; for (i = 0; i < TB_JMP_CACHE_SIZE; i++) { - qatomic_set(&cpu->tb_jmp_cache[i], NULL); + qatomic_set(&cpu->tb_jmp_cache[i].tb, NULL); } } diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index b1fd962718..3f8e4bbbc8 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -243,7 +243,7 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, tcg_debug_assert(!(cflags & CF_INVALID)); hash = tb_jmp_cache_hash_func(pc); - tb = qatomic_rcu_read(&cpu->tb_jmp_cache[hash]); + tb = qatomic_rcu_read(&cpu->tb_jmp_cache[hash].tb); if (likely(tb && tb->pc == pc && @@ -257,7 +257,7 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, if (tb == NULL) { return NULL; } - qatomic_set(&cpu->tb_jmp_cache[hash], tb); + qatomic_set(&cpu->tb_jmp_cache[hash].tb, tb); return tb; } @@ -978,6 +978,8 @@ int cpu_exec(CPUState *cpu) tb = tb_lookup(cpu, pc, cs_base, flags, cflags); if (tb == NULL) { + uint32_t h; + mmap_lock(); tb = tb_gen_code(cpu, pc, cs_base, flags, cflags); mmap_unlock(); @@ -985,7 +987,8 @@ int cpu_exec(CPUState *cpu) * We add the TB in the virtual pc hash table * for the fast lookup */ - qatomic_set(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)], tb); + h = tb_jmp_cache_hash_func(pc); + qatomic_set(&cpu->tb_jmp_cache[h].tb, tb); } #ifndef CONFIG_USER_ONLY diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 8b81b07b79..a8afe1ab9f 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -103,7 +103,7 @@ static void tb_jmp_cache_clear_page(CPUState *cpu, target_ulong page_addr) unsigned int i, i0 = tb_jmp_cache_hash_page(page_addr); for (i = 0; i < TB_JMP_PAGE_SIZE; i++) { - qatomic_set(&cpu->tb_jmp_cache[i0 + i], NULL); + qatomic_set(&cpu->tb_jmp_cache[i0 + i].tb, NULL); } } diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 20f00f4335..c2745f14a6 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -1187,8 +1187,8 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list) /* remove the TB from the hash list */ h = tb_jmp_cache_hash_func(tb->pc); CPU_FOREACH(cpu) { - if (qatomic_read(&cpu->tb_jmp_cache[h]) == tb) { - qatomic_set(&cpu->tb_jmp_cache[h], NULL); + if (qatomic_read(&cpu->tb_jmp_cache[h].tb) == tb) { + qatomic_set(&cpu->tb_jmp_cache[h].tb, NULL); } }