From patchwork Wed Mar 1 02:55:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 657757 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp3269579wrb; Tue, 28 Feb 2023 18:59:12 -0800 (PST) X-Google-Smtp-Source: AK7set+SIfVLjBx1x2OAaLMS/RasyZx07wRXzzCLtc+9/UiYu5xJ3vSYzZmmCWO7M9fAKLg6YWnp X-Received: by 2002:ad4:5ae9:0:b0:56e:a7d1:4d65 with SMTP id c9-20020ad45ae9000000b0056ea7d14d65mr9859745qvh.52.1677639551915; Tue, 28 Feb 2023 18:59:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677639551; cv=none; d=google.com; s=arc-20160816; b=ECFcn7BuQcaLmRlsFyqCNbvbxbK6noRVB6xJeuAt5Jp3FrZ1dnw92IwfOG44pE2WVH MS8vszKPVK4kmLAVCnksCKD+yOAEHy4aHNAMZi4bdG0xptd5o0vfNfxFXH8CNSkJWVMg gUEM813F4JoL+SkkCHsf7DBHB7zzzyGz46jg7XGXJM8fRQ77+IOjpRky0c3Ut0R9c8SJ DqcfYEKl+mFQ83QzuTQOLCdUOX5X47RuEsmDjj9qfLMJAEJKNse/MutQQAEO4RBKD4cL KJd5DyEVDPMQHtyDu43ArzAQr1PEjzWrHEM0+0flS0pXNeFGl+sNHjCjQh80aV9IfgFa W2RA== 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=QSj4VJsjFHaRvQs4eWwMwZJtQE/UiuIsIRLvGg9jXBw=; b=VxSQMqWAuNIV+rgySYuna8+LIiKLw22NTF/Raylqjfn/5O8VlpQDZ7pw40dUofnmsv Q9h3X6snhN1133+lCrZFcRBwH/hdfLUn56YFMMLQdJd2IEnItO1GSi52oDOGa1gCTB8Y CfaHgIQVHbcRL7wI5j8zuSTbmLuvv+M2FcKSrV7b9N6Uex+t3J8Ydg9IJhoL79OdFyOD eGZ/qY13RuS/Lnp7EJokApO/g+Lg1TG6lArS8IOvzIJknCxKO9ZE7sdAd1KuUnc5i6GA hOcN/88CaP6w3YElO4FMXjjPigQiL0ScmebO84R3MIVdzcfrVwvoBj9wHQ4n4LnGbD1y gkiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sgLNgVyF; 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 t8-20020a374608000000b0073ba88f6df5si8994958qka.341.2023.02.28.18.59.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Feb 2023 18:59:11 -0800 (PST) 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=sgLNgVyF; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pXCel-0000jr-Em; Tue, 28 Feb 2023 21:57:27 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pXCed-0008VW-0F for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:57:19 -0500 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pXCeZ-00038m-VY for qemu-devel@nongnu.org; Tue, 28 Feb 2023 21:57:18 -0500 Received: by mail-pj1-x1030.google.com with SMTP id 6-20020a17090a190600b00237c5b6ecd7so11263918pjg.4 for ; Tue, 28 Feb 2023 18:57:13 -0800 (PST) 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:subject:date :message-id:reply-to; bh=QSj4VJsjFHaRvQs4eWwMwZJtQE/UiuIsIRLvGg9jXBw=; b=sgLNgVyFesr+/dj8Suw1oH59GtsURNGvcOkDk5pCAtGvtfPCzB+5c4+q+QONuv+4ip iar4Ha8ZJudKR0bZkQt4cPTEt9f3US8sc5TrUR5se2V5hlT5y93mpBHAC8BsBkW5nPeu QhL5Vk2KmMQXUnkAPAcXr0DArLNjih9UxSNvZYeq98Vm2CFSqM7Rum5kbuaJFt7dfVI7 wjEy6AL3/PwKgFcYpbq/x2zApsM9Np+T6n5a9Dt38XazB+pQyF3kmnKqNLdz/BGa4Jx2 ErBuxBZMQup2TV+1CwSe3HslpuB89+eRLah0pk+1/ASJjfz6PK2e+dJWRT+k3rJqw61z 4Q7g== 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 :subject:date:message-id:reply-to; bh=QSj4VJsjFHaRvQs4eWwMwZJtQE/UiuIsIRLvGg9jXBw=; b=uR7zQKid8lyq1u/Xdqe1k/zNpp1HN2mnLlmdw54Y0SI35yIFGgFVxisV10XCYTbzuO 8G/7J1NfWtOsSVvJCCZz19sbAoX+BmDEEC6F8HCH5Q7AKufdL3yEWLUjSU83IlX497eC 9nNJbZfc8xuQugSt+huQeC2bcdqBaQePsuNmFKrysgRmak1fWSJZhIf4NIMHOqTFz89Q 9At6KEA1IfuVdnQt5mTlznGt4Re8xZ4aSuNcZlExkrzJDB5AZp72p4XxtioVb0ZgtcSh w3Zlc5M+g+adjt8nHG4KtOApCKbAbV49JVq7pPxRMU0FLXlOkM61GP7j6K+n5an73kn4 Mzmw== X-Gm-Message-State: AO0yUKV2jNJ12yjuKRxvlLQOfbv+p+Z8YWrpzbbLdPyZiddiV8PuvsyN E/LiLvvlRh3MrTJiVvWqBpxdSw9QHV9h/omnfP0= X-Received: by 2002:a17:902:d4c3:b0:19c:f84b:58be with SMTP id o3-20020a170902d4c300b0019cf84b58bemr6582532plg.3.1677639431985; Tue, 28 Feb 2023 18:57:11 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id jg15-20020a17090326cf00b0019adbef6a63sm7210120plb.235.2023.02.28.18.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Feb 2023 18:57:11 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Anton Johansson , =?utf-8?q?Phili?= =?utf-8?q?ppe_Mathieu-Daud=C3=A9?= Subject: [PULL 15/62] accel/tcg: Move jmp-cache `CF_PCREL` checks to caller Date: Tue, 28 Feb 2023 16:55:56 -1000 Message-Id: <20230301025643.1227244-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230301025643.1227244-1-richard.henderson@linaro.org> References: <20230301025643.1227244-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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 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-bounces+patch=linaro.org@nongnu.org From: Anton Johansson via tb-jmp-cache.h contains a few small functions that only exist to hide a CF_PCREL check, however the caller often already performs such a check. This patch moves CF_PCREL checks from the callee to the caller, and also removes these functions which now only hide an access of the jmp-cache. Signed-off-by: Anton Johansson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20230227135202.9710-12-anjo@rev.ng> Signed-off-by: Richard Henderson --- accel/tcg/tb-jmp-cache.h | 36 --------------------------- accel/tcg/cpu-exec.c | 54 +++++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 50 deletions(-) diff --git a/accel/tcg/tb-jmp-cache.h b/accel/tcg/tb-jmp-cache.h index 083939b302..bee87eb840 100644 --- a/accel/tcg/tb-jmp-cache.h +++ b/accel/tcg/tb-jmp-cache.h @@ -25,40 +25,4 @@ struct CPUJumpCache { } array[TB_JMP_CACHE_SIZE]; }; -static inline TranslationBlock * -tb_jmp_cache_get_tb(CPUJumpCache *jc, uint32_t cflags, uint32_t hash) -{ - if (cflags & CF_PCREL) { - /* Use acquire to ensure current load of pc from jc. */ - return qatomic_load_acquire(&jc->array[hash].tb); - } else { - /* Use rcu_read to ensure current load of pc from *tb. */ - return qatomic_rcu_read(&jc->array[hash].tb); - } -} - -static inline target_ulong -tb_jmp_cache_get_pc(CPUJumpCache *jc, uint32_t hash, TranslationBlock *tb) -{ - if (tb_cflags(tb) & CF_PCREL) { - return jc->array[hash].pc; - } else { - return tb_pc(tb); - } -} - -static inline void -tb_jmp_cache_set(CPUJumpCache *jc, uint32_t hash, - TranslationBlock *tb, target_ulong pc) -{ - if (tb_cflags(tb) & CF_PCREL) { - jc->array[hash].pc = pc; - /* Use store_release on tb to ensure pc is written first. */ - qatomic_store_release(&jc->array[hash].tb, tb); - } else{ - /* Use the pc value already stored in tb->pc. */ - qatomic_set(&jc->array[hash].tb, tb); - } -} - #endif /* ACCEL_TCG_TB_JMP_CACHE_H */ diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 013856f103..aa14e97958 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -254,21 +254,46 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, hash = tb_jmp_cache_hash_func(pc); jc = cpu->tb_jmp_cache; - tb = tb_jmp_cache_get_tb(jc, cflags, hash); - if (likely(tb && - tb_jmp_cache_get_pc(jc, hash, tb) == pc && - tb->cs_base == cs_base && - tb->flags == flags && - tb->trace_vcpu_dstate == *cpu->trace_dstate && - tb_cflags(tb) == cflags)) { - return tb; + if (cflags & CF_PCREL) { + /* Use acquire to ensure current load of pc from jc. */ + tb = qatomic_load_acquire(&jc->array[hash].tb); + + if (likely(tb && + jc->array[hash].pc == pc && + tb->cs_base == cs_base && + tb->flags == flags && + tb->trace_vcpu_dstate == *cpu->trace_dstate && + tb_cflags(tb) == cflags)) { + return tb; + } + tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags); + if (tb == NULL) { + return NULL; + } + jc->array[hash].pc = pc; + /* Use store_release on tb to ensure pc is written first. */ + qatomic_store_release(&jc->array[hash].tb, tb); + } else { + /* Use rcu_read to ensure current load of pc from *tb. */ + tb = qatomic_rcu_read(&jc->array[hash].tb); + + if (likely(tb && + tb_pc(tb) == pc && + tb->cs_base == cs_base && + tb->flags == flags && + tb->trace_vcpu_dstate == *cpu->trace_dstate && + tb_cflags(tb) == cflags)) { + return tb; + } + tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags); + if (tb == NULL) { + return NULL; + } + /* Use the pc value already stored in tb->pc. */ + qatomic_set(&jc->array[hash].tb, tb); } - tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags); - if (tb == NULL) { - return NULL; - } - tb_jmp_cache_set(jc, hash, tb, pc); + return tb; } @@ -957,7 +982,8 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc) * for the fast lookup */ h = tb_jmp_cache_hash_func(pc); - tb_jmp_cache_set(cpu->tb_jmp_cache, h, tb, pc); + /* Use the pc value already stored in tb->pc. */ + qatomic_set(&cpu->tb_jmp_cache->array[h].tb, tb); } #ifndef CONFIG_USER_ONLY