From patchwork Tue Aug 16 20:33:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 597525 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp2712177maz; Tue, 16 Aug 2022 14:07:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR6ZVIoJfiSRfUbzPiTR2KyGNcauiJJlgeXv5P7hHV5FcaDYepjlD6lqMLN9dNr6MURhfZCb X-Received: by 2002:a05:620a:f0d:b0:6a9:b3e9:dc3f with SMTP id v13-20020a05620a0f0d00b006a9b3e9dc3fmr16675849qkl.437.1660684070946; Tue, 16 Aug 2022 14:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660684070; cv=none; d=google.com; s=arc-20160816; b=Yiy+d+s5WwpjPN8CtLPIN+DnaEiAIEZMn6qg/FrsGMO1cPVRSca+f7e8AVmXcfQDEn rBYqto4V3M50iWi4SFerFWJmzRugpTgFSD3bIbLvw/sihIjPDr8RsmhHEuw9n8cCvD2+ 6I1YOcnhY02TgdAxNvqG6X1G2a1NPzliaDu0muSjf/tG4709yBFrA8de7p/PjKorXn+Y cjfl7bmG2m0yTsaucEvbgE/v4qMjlrStqQ5ZwWYSqUNHtHjQ4UfQZsBi2qWo0nD8Gsof A05OfQYytiiLZowSYRmhsdhkuM+1dODiB9Ii8Jt6iZFTVMx72IqUkPNCajvNCl3jgEjV RYsg== 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=ECDz/oO8bv8CfHdHpWcznE5xX39jdlybIsdmEI27v0u2n4nqkMh7UKUGRt5/cZDPz/ JCFtr54/iyrNi0UX+LtWoScizaN19MjaILypLs9A0OedGYxaodru41uaivhilIP4wIBY LBNpZUtpL2zsYgWv1BG55pJdwS/gDQCj1V8Wv2LPXFmSRYrklNZFa/RUvnfVWkG8Kp2O btLg4Zyfd7XoRj0iRu+9H8K3HF4tNu4ymYerIJNeSJ2wwPvmfGqWh9blMaaXoTSw/nd0 7MkyiqXucSuntosfjIvOTE9ekU7YDu/e+y79je70ANzxO6jMuai3p/ENQHQv/C/4gZj9 nE4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UnMscL2t; 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 y12-20020a05620a44cc00b006b90f8b0b66si9189526qkp.551.2022.08.16.14.07.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 16 Aug 2022 14:07:50 -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=UnMscL2t; 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]:37736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oO3mw-00041N-Gh for patch@linaro.org; Tue, 16 Aug 2022 17:07:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oO3H7-00057c-7M for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:34:58 -0400 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]:36416) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oO3H1-0004WL-UP for qemu-devel@nongnu.org; Tue, 16 Aug 2022 16:34:56 -0400 Received: by mail-oi1-x233.google.com with SMTP id s199so13320253oie.3 for ; Tue, 16 Aug 2022 13:34:51 -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=UnMscL2tGHKxQ8TdC8xytlcZW/r7PhcnXy3TItnrZ47TsrTywSvBINJs52001Zqgq8 iXEVGm3hy1Wpt9zLgfyEY9E9yCU4wQlALd9D98sB6lyK9lxw8PMuKE+zfYUbQFyilMxi IOrXGV6MQCo1jUm39K+9nv9gQvXz14aa40zy3SwAQX4m5qzeMh8UmoRdp4rWQ7fIT+le vMdpjMw0sdcz1xz40XVtLDShRKru6Vv1wNSbKwGjwg3Cz0sHQacu+U3rPA151E9hmUr5 6BM32PQU2xnP6rC29ml7MAntrAjfjl2npY/PMXunwp+d9E8f9cdItfLw0XIC6rHSynxA ISMA== 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=LqfWxNa3zaG7/ZhgNj96/LUMpmtw4NwHD77ez/O7tfDTvdj56Wa4jq4O6lPwajXCoV 9IPN9+Bzd7LXVbSGaFzIe/1TKEU7eiK7NsqYmnk3zhexAyh2bhmNvKA0wOJhImadNjjt bnsK1/BSIQROsCPEc273dsKRJfPSJOI2AzMABFfGhVXvCVW8FrFmsmsHPhV8v9olEWuP sA3BBrAoNr+4soBpnFriqbT1YI8jx5QT51bWrfa1M1CRx27b+0CFKT/Vj2iKWkh5MEgA Wh7kTgrpUrjil2ifosT/7YFp/n/CiNUzoQORWnedyj00BaJ4zurX4xTGoco3bEJT0ioW ahHg== X-Gm-Message-State: ACgBeo29mE4ylK6LrXkHmEWKupw6y+2CCGq4w9Ewn5A06r3P3I/PFs1S 9J0suGLQ1bq9VEwAq0pgYFTxresYuyUUcw== X-Received: by 2002:a05:6808:23ca:b0:344:be60:144d with SMTP id bq10-20020a05680823ca00b00344be60144dmr154235oib.38.1660682091126; Tue, 16 Aug 2022 13:34:51 -0700 (PDT) Received: from stoup.. ([2605:ef80:80f6:61fa:9bc2:5095:d612:5e22]) by smtp.gmail.com with ESMTPSA id y23-20020a056870b01700b0010ef8ccde67sm2285220oae.13.2022.08.16.13.34.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 13:34:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, alex.bennee@linaro.org, iii@linux.ibm.com Subject: [PATCH v2 21/33] include/hw/core: Create struct CPUJumpCache Date: Tue, 16 Aug 2022 15:33:48 -0500 Message-Id: <20220816203400.161187-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220816203400.161187-1-richard.henderson@linaro.org> References: <20220816203400.161187-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::233; envelope-from=richard.henderson@linaro.org; helo=mail-oi1-x233.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); } }