From patchwork Tue Sep 6 09:11:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 602972 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:4388:0:0:0:0 with SMTP id w8csp4370496mae; Tue, 6 Sep 2022 02:51:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR6q8HRGmnFm6K32EfW2Ll2yDiVbtBpSFEJwL3sx/FTU7jPXpVP53Gp+swdqJR1b+ZJ9KqCx X-Received: by 2002:a05:622a:104:b0:343:7f18:5142 with SMTP id u4-20020a05622a010400b003437f185142mr42388033qtw.210.1662457863711; Tue, 06 Sep 2022 02:51:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662457863; cv=none; d=google.com; s=arc-20160816; b=ujT5KYL0TlGGzm7k8Wc2gEoRO9f9ncMvabghDUUKRPWNhzChpZOSKWBcbunFvDNGgZ +7/1FW7NVtl0tutm7R1RIaLxG+FzhF0U5fDMVfcoTQZMYEPCFKO0b6dUmrhcS8A0p2U7 DiVuvO/RBL8xoYbu0db/0TBX4L6uc6OiEX9k4mB6XME+MSuEadkqJ3wGtx5dKh4t0u35 bYQiZV5XnFxMBCOyQS+jTxvTm5UsTrTpZ5qIRLyK5gIhD3r3646b8C8I8ppl3phH4jAt RmABS8jVrcof2u3v6n3OXViMuN9eZW7FWyhZbI3+Gz2KQWEqwhan2kvCdVsL+nOUzrIK inzA== 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:to:from :dkim-signature; bh=oQjXVWydC6/Y9j167mUwZz3YYHjGsA013pbtkQ/vYzs=; b=yzuhjjLnxgjWGO+j24dhh57l158FwBcrLMOi6l+iFTRqKaGFwbmmXH+dfwMaou69uC eL+l6uuIf7ditiZxAIao/8JLxVHGwXWUBjqND24OUy1DfvzQiul9xHcSR5URjkQYXbAD XW1UjEm2a55rCzib6Q26oDUHI3Zsw7I+wvq1/r3iUb7jihfsy//0ASKBrxx/Vms5iSK2 Y0eXH9i4kmfGuuTF3CDu1AEl79uybcmp+zdIxS1byqWhC+wVGr5Q57vE1z7ZvzITr4VC SVnFTHpMAw4Nu/NkvQWT8kXdeVjHTvEaBcz66fruAlJUhKCXQyijkkrd+KOzNvVdDqcE j2rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rgI+HDN+; 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 do26-20020a05620a2b1a00b006c0935b50c0si7391455qkb.81.2022.09.06.02.51.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2022 02:51:03 -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=rgI+HDN+; 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]:34696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVVEV-0000y8-6s for patch@linaro.org; Tue, 06 Sep 2022 05:51:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVUcQ-0007W8-2S for qemu-devel@nongnu.org; Tue, 06 Sep 2022 05:11:44 -0400 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]:45029) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVUcJ-0002ec-2K for qemu-devel@nongnu.org; Tue, 06 Sep 2022 05:11:41 -0400 Received: by mail-wr1-x42f.google.com with SMTP id c11so10202006wrp.11 for ; Tue, 06 Sep 2022 02:11:33 -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:to:from:from:to:cc:subject:date; bh=oQjXVWydC6/Y9j167mUwZz3YYHjGsA013pbtkQ/vYzs=; b=rgI+HDN+UPFSdqeRohjQdV4Ndmh+g+mf9y5WQgktfF+pQzoPgBeulNiCmKnh8UlFgi GdNefCxb4rNtNNlHWCCeLikQkKVx4YrtOrjXFhDhVZ1wuMKR+nuPWaGRXvj3qYSrhhon 89p6ElVLJd3WJDsaTfKzhALUiCKSjVty9ShHo3jya7uAAJksKcP39mPdELpVfjh5q82K wkorVGK21iHPTcrnp1hmppo6ECCFU+9ohv938mp4PY4DEs+JDMnd2FucdMYjeM89IriG ABvC3tc9Z1qbTkxG8KVZgJYrVZHJoEOB/aFi4Da5/MF+Bm1gr/wOUTfm9ChzOPkO/R3T bkuw== 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:to:from:x-gm-message-state:from:to:cc :subject:date; bh=oQjXVWydC6/Y9j167mUwZz3YYHjGsA013pbtkQ/vYzs=; b=IC3oPL3CbtqGnCfECKUn809OcYzCkBD5gM2+jrag/DoaeGFl/7cpYtxNBeS8BdNJTD 82urLr1ZznVNNB3cKUbZje9oVuz23jthStkqJnzwCkggFF0vchyORQ78gh6wtm/AZWYo c5FT1/bAECvtzBFVjB4TC3/gSv2EbBNvCxc5v2kvvGN4d6tr8tDGxZVul0OLzFqNs5z+ oXqEwy7XwU3GpFJav2gmDQ9c6I23GIwrcf+8OysoxtIIFD6E8wzg9RC5Z3nqWc2mPUWb ppXEAYi2xdLVSPhHwLD6fVg3TlU5DUjbOlRPX+1w5WQIPB8hMcpcWVx6yMJ4fTTsIyoT lBvA== X-Gm-Message-State: ACgBeo1h72BR0CMYptKz8r/Pypy9UqaBIBoy7ixCCk+RhAaaZxGasel3 7qj7UuL7Q7yuNbw0w6y9AAvExR8DnCsGh1kU X-Received: by 2002:a05:6000:1849:b0:228:c848:2593 with SMTP id c9-20020a056000184900b00228c8482593mr3269033wri.557.1662455492345; Tue, 06 Sep 2022 02:11:32 -0700 (PDT) Received: from localhost.localdomain ([2a02:8084:a5c0:5a80:ba98:3a71:8524:e0b1]) by smtp.gmail.com with ESMTPSA id m64-20020a1c2643000000b003a5ee64cc98sm20094193wmm.33.2022.09.06.02.11.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 02:11:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 2/7] accel/tcg: Use DisasContextBase in plugin_gen_tb_start Date: Tue, 6 Sep 2022 10:11:21 +0100 Message-Id: <20220906091126.298041-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220906091126.298041-1-richard.henderson@linaro.org> References: <20220906091126.298041-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-wr1-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" Use the pc coming from db->pc_first rather than the TB. Use the cached host_addr rather than re-computing for the first page. We still need a separate lookup for the second page because it won't be computed for DisasContextBase until the translator actually performs a read from the page. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- include/exec/plugin-gen.h | 7 ++++--- accel/tcg/plugin-gen.c | 22 +++++++++++----------- accel/tcg/translator.c | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/include/exec/plugin-gen.h b/include/exec/plugin-gen.h index f92f169739..5004728c61 100644 --- a/include/exec/plugin-gen.h +++ b/include/exec/plugin-gen.h @@ -19,7 +19,8 @@ struct DisasContextBase; #ifdef CONFIG_PLUGIN -bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb, bool supress); +bool plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db, + bool supress); void plugin_gen_tb_end(CPUState *cpu); void plugin_gen_insn_start(CPUState *cpu, const struct DisasContextBase *db); void plugin_gen_insn_end(void); @@ -48,8 +49,8 @@ static inline void plugin_insn_append(abi_ptr pc, const void *from, size_t size) #else /* !CONFIG_PLUGIN */ -static inline -bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb, bool supress) +static inline bool +plugin_gen_tb_start(CPUState *cpu, const struct DisasContextBase *db, bool sup) { return false; } diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 3d0b101e34..80dff68934 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -852,7 +852,8 @@ static void plugin_gen_inject(const struct qemu_plugin_tb *plugin_tb) pr_ops(); } -bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb, bool mem_only) +bool plugin_gen_tb_start(CPUState *cpu, const DisasContextBase *db, + bool mem_only) { bool ret = false; @@ -870,9 +871,9 @@ bool plugin_gen_tb_start(CPUState *cpu, const TranslationBlock *tb, bool mem_onl ret = true; - ptb->vaddr = tb->pc; + ptb->vaddr = db->pc_first; ptb->vaddr2 = -1; - get_page_addr_code_hostp(cpu->env_ptr, tb->pc, &ptb->haddr1); + ptb->haddr1 = db->host_addr[0]; ptb->haddr2 = NULL; ptb->mem_only = mem_only; @@ -898,16 +899,15 @@ void plugin_gen_insn_start(CPUState *cpu, const DisasContextBase *db) * Note that we skip this when haddr1 == NULL, e.g. when we're * fetching instructions from a region not backed by RAM. */ - if (likely(ptb->haddr1 != NULL && ptb->vaddr2 == -1) && - unlikely((db->pc_next & TARGET_PAGE_MASK) != - (db->pc_first & TARGET_PAGE_MASK))) { - get_page_addr_code_hostp(cpu->env_ptr, db->pc_next, - &ptb->haddr2); - ptb->vaddr2 = db->pc_next; - } - if (likely(ptb->vaddr2 == -1)) { + if (ptb->haddr1 == NULL) { + pinsn->haddr = NULL; + } else if (is_same_page(db, db->pc_next)) { pinsn->haddr = ptb->haddr1 + pinsn->vaddr - ptb->vaddr; } else { + if (ptb->vaddr2 == -1) { + ptb->vaddr2 = TARGET_PAGE_ALIGN(db->pc_first); + get_page_addr_code_hostp(cpu->env_ptr, ptb->vaddr2, &ptb->haddr2); + } pinsn->haddr = ptb->haddr2 + pinsn->vaddr - ptb->vaddr2; } } diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index ca8a5f2d83..8e78fd7a9c 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -75,7 +75,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, ops->tb_start(db, cpu); tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ - plugin_enabled = plugin_gen_tb_start(cpu, tb, cflags & CF_MEMI_ONLY); + plugin_enabled = plugin_gen_tb_start(cpu, db, cflags & CF_MEMI_ONLY); while (true) { db->num_insns++;