From patchwork Fri Aug 12 18:07:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 596820 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b345:0:0:0:0 with SMTP id w5csp1783725maz; Fri, 12 Aug 2022 11:19:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR46aJ0kN+e6zQXHTHU2T42qO5orScdIqrbPf/kATsTFSz1uJaZ+NcIILcyMESmCnv6+2B77 X-Received: by 2002:a05:6214:d4b:b0:476:5d58:9b63 with SMTP id 11-20020a0562140d4b00b004765d589b63mr4691361qvr.33.1660328375384; Fri, 12 Aug 2022 11:19:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660328375; cv=none; d=google.com; s=arc-20160816; b=yaxi3S5RUPvs3ddnK5XoQBCmkQvWHHebEmvnpae5ik9kz1g25v4kndp6EPYcRD4A2n DDaw+U13aIOP2Y8KLrvoZM3hhLzx/VzchD5c5FzFS4UtAA3C9g2H6p35inyOAuxUzhcK 3hViZ42hMY33Tj8PEUFeUNSLqNFL74EAdEe1qQADFvjuTecdkJKnv5MHbAXSh7XW/7h0 Nl0NtvXk/zDBwhtZ5xwCZmeVkyL8opDnBo8T5s7z52kcIDUHlkfZ2zxHE6L3rGcGlubw 1BzpTETlmKxG2QINIHUR9XWm2wZmbdpfeelURzr11qQIQszFanReX+kCYqBrZJp6WQbc +3AQ== 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=zLRxaasl4+x84svDvG8c3cbdQrK278he5Svo5wRC8nA=; b=o471AYplbN46Z8pQ/EMjyUOPsc1WWbzjBxkhczG0QKjGmc95ftBDMFKFZswePdUD0I Fx2//dgNjYQs14DYR9XuZISZvZ8s02X5HW1eAuZFKU/B9SA7Bvj6GkB9ZfSvcVmKko/z zI3RjmP9cBaosvwEDxJXvA0IpRymv+0UAUQCzkSJhNQXVsvyS4wSwwakAwFt0rVe3m9F toTQCJ963/pPBOtaIxsCjuEDL/JcgzI46kRstUbbsB6XkZaBx42s5AW4CvUNN1+K51ZI flfgQ5Fu2onx6kc2DzUtl2sNiXgpCrMicza8BT63s2n+07ausrQGOj2jrh930w8VLFgr HPQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cETksFk4; 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 u27-20020a05622a199b00b003403b69a4f9si1901307qtc.317.2022.08.12.11.19.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Aug 2022 11:19:35 -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=cETksFk4; 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]:60656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMZFu-00069I-Vo for patch@linaro.org; Fri, 12 Aug 2022 14:19:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMZ54-0003Vm-7B for qemu-devel@nongnu.org; Fri, 12 Aug 2022 14:08:23 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:53088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oMZ52-0006XK-Ds for qemu-devel@nongnu.org; Fri, 12 Aug 2022 14:08:21 -0400 Received: by mail-pj1-x102c.google.com with SMTP id ha11so1684879pjb.2 for ; Fri, 12 Aug 2022 11:08:19 -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=zLRxaasl4+x84svDvG8c3cbdQrK278he5Svo5wRC8nA=; b=cETksFk4/WjbelGXaMiLpboEpx2SJGWBTHydRs4r335eU5m7yUTQALR1lolY7OFlz2 cLObBLzAPB7kFHnKp4dTjTa5x8JRvmO0bi87pOzV62xLjrsPwYqtFQDHFZn0h88cAOUl m3+vi6E+jMd6sMK+j7Pz9+9F2fhVS5r5kY4Ek5pGvTeI2AzEbekLwBlzWRlmU9ctQ3m/ w0MKJOXnj3MyvznA+OGfCuEdiw63NeoaHphhw4jC/6yL7RA0Sv1WWhHpcM+lghZK96Fy YKPd46jjKJ+6sEfj5t9V3n7iESEQ+//gIaJUkOjr6wX+iJ0VPR8Qoi9KIu76rQs5dKRE zqNA== 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=zLRxaasl4+x84svDvG8c3cbdQrK278he5Svo5wRC8nA=; b=VLE5svwY2lf2WIECKerwFklqiGUzX5/LH85SEQ1pl63rX3JCytj1WcM+R3PgJ0RpEM TdPa1lWlNDDNvM1i2HQ/dd4c0hEnBFhVax55r3cjUE48Lc9taFMxM6ytEk16/GTw0dss J0nzpfn9rQl2n/07q136DB5g7Ppx01511nX6q4StOa1hDR5BLCroFP1B5WJXJGWwU3Po cfXbUz/YetUNa2MiruATegCX2ON3DDD+0mjwTkaKg7v2zmiz2mvTSQCAweCysVM+lL3T GPTcFunr1s9l6eLflZH4UW82UR4ppTi2PKMp57KlB3ebshxKNY4E3vJ7Ig16lK/Ay19i k5Bg== X-Gm-Message-State: ACgBeo2fP7njduATDYEVA6JaVoMEpJbEbAUsDApsF/9PK5kCQyJTibUu WewrHxZCy5d0p+seYO3KaQMTEQTzyg4tZQ== X-Received: by 2002:a17:902:ce05:b0:16c:2a1:c335 with SMTP id k5-20020a170902ce0500b0016c02a1c335mr5230396plg.5.1660327699041; Fri, 12 Aug 2022 11:08:19 -0700 (PDT) Received: from stoup.. ([2602:ae:154e:e201:a7aa:1d1d:c857:5500]) by smtp.gmail.com with ESMTPSA id h9-20020a056a00000900b0052dee21fecdsm1914761pfk.77.2022.08.12.11.08.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Aug 2022 11:08:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: laurent@vivier.eu, iii@linux.ibm.com, alex.bennee@linaro.org Subject: [PATCH for-7.2 08/21] accel/tcg: Merge tb_htable_lookup into caller Date: Fri, 12 Aug 2022 11:07:53 -0700 Message-Id: <20220812180806.2128593-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220812180806.2128593-1-richard.henderson@linaro.org> References: <20220812180806.2128593-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.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" This function is used only once, so merge it into its only caller, tb_lookup. This requires moving the support routine, tb_lookup_cmp, and its private data structure, tb_desc, up in the file. Signed-off-by: Richard Henderson --- include/exec/exec-all.h | 3 - accel/tcg/cpu-exec.c | 134 +++++++++++++++++++--------------------- 2 files changed, 64 insertions(+), 73 deletions(-) diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h index 311e5fb422..e7e30d55b8 100644 --- a/include/exec/exec-all.h +++ b/include/exec/exec-all.h @@ -552,9 +552,6 @@ void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs); #endif void tb_flush(CPUState *cpu); void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr); -TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, - target_ulong cs_base, uint32_t flags, - uint32_t cflags); void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr); /* GETPC is the true target of the return instruction that we'll execute. */ diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index a565a3f8ec..f6c0c0aff6 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -170,19 +170,60 @@ uint32_t curr_cflags(CPUState *cpu) return cflags; } -/* Might cause an exception, so have a longjmp destination ready */ -static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, - target_ulong cs_base, - uint32_t flags, uint32_t cflags) +struct tb_desc { + target_ulong pc; + target_ulong cs_base; + CPUArchState *env; + tb_page_addr_t phys_page1; + uint32_t flags; + uint32_t cflags; + uint32_t trace_vcpu_dstate; +}; + +static bool tb_lookup_cmp(const void *p, const void *d) { + const TranslationBlock *tb = p; + const struct tb_desc *desc = d; + + if (tb->pc == desc->pc && + tb->page_addr[0] == desc->phys_page1 && + tb->cs_base == desc->cs_base && + tb->flags == desc->flags && + tb->trace_vcpu_dstate == desc->trace_vcpu_dstate && + tb_cflags(tb) == desc->cflags) { + /* check next page if needed */ + if (tb->page_addr[1] == -1) { + return true; + } else { + tb_page_addr_t phys_page2; + target_ulong virt_page2; + + virt_page2 = (desc->pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; + phys_page2 = get_page_addr_code(desc->env, virt_page2); + if (tb->page_addr[1] == phys_page2) { + return true; + } + } + } + return false; +} + +/* Might cause an exception, so have a longjmp destination ready */ +static TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, + target_ulong cs_base, + uint32_t flags, uint32_t cflags) +{ + CPUArchState *env = cpu->env_ptr; TranslationBlock *tb; - uint32_t hash; + tb_page_addr_t phys_pc; + struct tb_desc desc; + uint32_t jmp_hash, tb_hash; /* we should never be trying to look up an INVALID tb */ tcg_debug_assert(!(cflags & CF_INVALID)); - hash = tb_jmp_cache_hash_func(pc); - tb = qatomic_rcu_read(&cpu->tb_jmp_cache[hash]); + jmp_hash = tb_jmp_cache_hash_func(pc); + tb = qatomic_rcu_read(&cpu->tb_jmp_cache[jmp_hash]); if (likely(tb && tb->pc == pc && @@ -192,11 +233,25 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, tb_cflags(tb) == cflags)) { return tb; } - tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags); + + desc.env = env; + desc.cs_base = cs_base; + desc.flags = flags; + desc.cflags = cflags; + desc.trace_vcpu_dstate = *cpu->trace_dstate; + desc.pc = pc; + phys_pc = get_page_addr_code(desc.env, pc); + if (phys_pc == -1) { + return NULL; + } + desc.phys_page1 = phys_pc & TARGET_PAGE_MASK; + tb_hash = tb_hash_func(phys_pc, pc, flags, cflags, *cpu->trace_dstate); + tb = qht_lookup_custom(&tb_ctx.htable, &desc, tb_hash, tb_lookup_cmp); if (tb == NULL) { return NULL; } - qatomic_set(&cpu->tb_jmp_cache[hash], tb); + + qatomic_set(&cpu->tb_jmp_cache[jmp_hash], tb); return tb; } @@ -487,67 +542,6 @@ void cpu_exec_step_atomic(CPUState *cpu) end_exclusive(); } -struct tb_desc { - target_ulong pc; - target_ulong cs_base; - CPUArchState *env; - tb_page_addr_t phys_page1; - uint32_t flags; - uint32_t cflags; - uint32_t trace_vcpu_dstate; -}; - -static bool tb_lookup_cmp(const void *p, const void *d) -{ - const TranslationBlock *tb = p; - const struct tb_desc *desc = d; - - if (tb->pc == desc->pc && - tb->page_addr[0] == desc->phys_page1 && - tb->cs_base == desc->cs_base && - tb->flags == desc->flags && - tb->trace_vcpu_dstate == desc->trace_vcpu_dstate && - tb_cflags(tb) == desc->cflags) { - /* check next page if needed */ - if (tb->page_addr[1] == -1) { - return true; - } else { - tb_page_addr_t phys_page2; - target_ulong virt_page2; - - virt_page2 = (desc->pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; - phys_page2 = get_page_addr_code(desc->env, virt_page2); - if (tb->page_addr[1] == phys_page2) { - return true; - } - } - } - return false; -} - -TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, - target_ulong cs_base, uint32_t flags, - uint32_t cflags) -{ - tb_page_addr_t phys_pc; - struct tb_desc desc; - uint32_t h; - - desc.env = cpu->env_ptr; - desc.cs_base = cs_base; - desc.flags = flags; - desc.cflags = cflags; - desc.trace_vcpu_dstate = *cpu->trace_dstate; - desc.pc = pc; - phys_pc = get_page_addr_code(desc.env, pc); - if (phys_pc == -1) { - return NULL; - } - desc.phys_page1 = phys_pc & TARGET_PAGE_MASK; - h = tb_hash_func(phys_pc, pc, flags, cflags, *cpu->trace_dstate); - return qht_lookup_custom(&tb_ctx.htable, &desc, h, tb_lookup_cmp); -} - void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr) { if (TCG_TARGET_HAS_direct_jump) {