From patchwork Wed Jul 21 19:59:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 483343 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp6531610jao; Wed, 21 Jul 2021 13:24:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5qZZ+rZ8R48T+DgMOMK2y98QalY3suV6DwzXstBuugltnosvBQXFpuV1aaRg3h4gIp0Fh X-Received: by 2002:a5e:d707:: with SMTP id v7mr13225546iom.46.1626899051394; Wed, 21 Jul 2021 13:24:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626899051; cv=none; d=google.com; s=arc-20160816; b=WkpMMZ6fASbD23B4Z8ClUSIPy+amShNqCL7oi7tNfQZVzuFPaS0ojcol5BPZx0Kkc2 XHJfIFdbtzWqEQWUJ0s8/lwUL07p899CWiPR5/P2pcRzgyx4ueMZlwrvh5uBj3K5W0Sy V8VIZc4RwHbG2VBPujVT1Mu+GYLNGEpWvJ5oXyDwAvQ92BvNpvrvLirgAD2/SnVcGmTW L26+BmYo3xPJmyogf5FnLnGNPEVMR0O51wnBSgMRmqP3TYF/kKS4bVFLx93AmmBdXPC4 0AEQifjKgno6PldnFtXtzO29LNRC427hj7hncCJ/KjKjQOaJli6NDxtFQALiYtW7J6Or S4vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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=DXOXSEfLZBNIVX60+JbD+azd+XSC/P1pd7+HVk2RYSk=; b=ieGmX7LzntIbAsagrYXcDhtkzqZTreZmMumgiyvT0ZMUjLprbVwAgVqpyBwxKO1ZhY NHqSCKeD7jGCZwvvOS4/ICijK8l4/bfZk4sWuuZ9/yqqIfJMMJ1E10xrhH9OMiKJYy6o WQf+YkU7QZZAPzTZAW2A73CCm1qnq9ACkKKX3EatlyKSfO+MqnYQ06MlDqb8wwTfisoG gbclvwJHIq3LK86UezBcdtippuxwg9t7Yea2/2eW8KgLM75CuoN+x7Dy7C69UDYKF/KB SXUFvLz02+N476KmSTHZ7qB6Vbk8TKS73KX/40OpFxlsvyk1VbUcaPLDNfS3XGHto99C UAaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=JZlvrbtv; 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=fail (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 h4si11200377ilj.137.2021.07.21.13.24.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Jul 2021 13:24:11 -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=fail header.i=@linaro.org header.s=google header.b=JZlvrbtv; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m6IlG-0006Os-LI for patch@linaro.org; Wed, 21 Jul 2021 16:24:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m6IOP-00031c-V2 for qemu-devel@nongnu.org; Wed, 21 Jul 2021 16:00:38 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:44771) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m6IOL-0005wr-J7 for qemu-devel@nongnu.org; Wed, 21 Jul 2021 16:00:33 -0400 Received: by mail-pj1-x102a.google.com with SMTP id p4-20020a17090a9304b029016f3020d867so1947481pjo.3 for ; Wed, 21 Jul 2021 13:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DXOXSEfLZBNIVX60+JbD+azd+XSC/P1pd7+HVk2RYSk=; b=JZlvrbtv17tMQNoo6DyuqjZlN5d6ilPvNVtxWVrsFoJkauAbBY+b8CCSvAYBlZ7DqR yWBojgR+fbX/953xDHhxXNF1NK17teA1B3CpT4IOWdIH0iYkbCfYVazso+78JxT9niJd jio/QHe3mCOODYXGXvmw8hy5eDoNbtGi4MTseCP/FpcTbZ35uPQywiBnf20HhxP9bHY6 geHfqxY0TDVDVLSoI2Gyw2rbmdAsfmzfXUlesbfEmeMrLpTrgpqwnbjOPLG8SpJlh84A Qo/OUdNKd+UVuArNzeqqO6QBDjNJokmq0/1hk84bCjT8U02Kqewg4Zqbk6JjzCLKxAwf Rfhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DXOXSEfLZBNIVX60+JbD+azd+XSC/P1pd7+HVk2RYSk=; b=TZJRTcC2dSSF0VHRMqJlSaR+PJMahr4SwdXKlz80Ltz2du0NIFxSB1sVkJa9V4bnql NrqvEH3HeplEWR1u/OewGrD/biwQH930Cd0biY+w1vdVXQnHGBqe5J/8Ti0Yi8kSCZWj QcXcYy8WDEq1Fb4OPwS0ZPBJSzrysJzVtms6VcC6WIKgbzg8U1RHgV0lXgEYTpBFXuI5 RrSxbpl4Iib8TiDDyUYtKB+075oI+69ULAgmZzvB0bJDPZrTLqlo44asEySRa7ABotU/ Eh7f2XbYEyfNkzBKPhQfN666Xarzar1SS53bJedS3clbhlQ2tDbBh558SxZPwvg5oAp7 Ea7A== X-Gm-Message-State: AOAM530A5Tlh6M3JzUt7NJAC7/lbNqF87OC5IyK+/fsSecnlrusIPk7m wR1DRDmk/cP9C/PQHZ46M5n3t9C/ckLihA== X-Received: by 2002:a17:903:4101:b029:12b:8d5a:f883 with SMTP id r1-20020a1709034101b029012b8d5af883mr12847936pld.39.1626897628280; Wed, 21 Jul 2021 13:00:28 -0700 (PDT) Received: from localhost.localdomain (204-210-126-223.res.spectrum.com. [204.210.126.223]) by smtp.gmail.com with ESMTPSA id w3sm706028pjq.12.2021.07.21.13.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jul 2021 13:00:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 23/27] accel/tcg: Merge tb_find into its only caller Date: Wed, 21 Jul 2021 09:59:50 -1000 Message-Id: <20210721195954.879535-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210721195954.879535-1-richard.henderson@linaro.org> References: <20210721195954.879535-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , peter.maydell@linaro.org, Mark Cave-Ayland Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" We are going to want two things: (1) check for breakpoints will want to break out of the loop here, (2) cflags can only be calculated with pc in hand. Tested-by: Mark Cave-Ayland Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- accel/tcg/cpu-exec.c | 83 ++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 42 deletions(-) -- 2.25.1 diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c index 5bb099174f..cde7069eb7 100644 --- a/accel/tcg/cpu-exec.c +++ b/accel/tcg/cpu-exec.c @@ -500,41 +500,6 @@ static inline void tb_add_jump(TranslationBlock *tb, int n, return; } -static inline TranslationBlock *tb_find(CPUState *cpu, - TranslationBlock *last_tb, - int tb_exit, uint32_t cflags) -{ - CPUArchState *env = (CPUArchState *)cpu->env_ptr; - TranslationBlock *tb; - target_ulong cs_base, pc; - uint32_t flags; - - cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); - - tb = tb_lookup(cpu, pc, cs_base, flags, cflags); - if (tb == NULL) { - mmap_lock(); - tb = tb_gen_code(cpu, pc, cs_base, flags, cflags); - mmap_unlock(); - /* 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); - } -#ifndef CONFIG_USER_ONLY - /* We don't take care of direct jumps when address mapping changes in - * system emulation. So it's not safe to make a direct jump to a TB - * spanning two pages because the mapping for the second page can change. - */ - if (tb->page_addr[1] != -1) { - last_tb = NULL; - } -#endif - /* See if we can patch the calling TB. */ - if (last_tb) { - tb_add_jump(last_tb, tb_exit, tb); - } - return tb; -} - static inline bool cpu_handle_halt(CPUState *cpu) { if (cpu->halted) { @@ -868,22 +833,56 @@ int cpu_exec(CPUState *cpu) int tb_exit = 0; while (!cpu_handle_interrupt(cpu, &last_tb)) { - uint32_t cflags = cpu->cflags_next_tb; TranslationBlock *tb; + target_ulong cs_base, pc; + uint32_t flags, cflags; - /* When requested, use an exact setting for cflags for the next - execution. This is used for icount, precise smc, and stop- - after-access watchpoints. Since this request should never - have CF_INVALID set, -1 is a convenient invalid value that - does not require tcg headers for cpu_common_reset. */ + /* + * When requested, use an exact setting for cflags for the next + * execution. This is used for icount, precise smc, and stop- + * after-access watchpoints. Since this request should never + * have CF_INVALID set, -1 is a convenient invalid value that + * does not require tcg headers for cpu_common_reset. + */ + cflags = cpu->cflags_next_tb; if (cflags == -1) { cflags = curr_cflags(cpu); } else { cpu->cflags_next_tb = -1; } - tb = tb_find(cpu, last_tb, tb_exit, cflags); + cpu_get_tb_cpu_state(cpu->env_ptr, &pc, &cs_base, &flags); + + tb = tb_lookup(cpu, pc, cs_base, flags, cflags); + if (tb == NULL) { + mmap_lock(); + tb = tb_gen_code(cpu, pc, cs_base, flags, cflags); + mmap_unlock(); + /* + * 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); + } + +#ifndef CONFIG_USER_ONLY + /* + * We don't take care of direct jumps when address mapping + * changes in system emulation. So it's not safe to make a + * direct jump to a TB spanning two pages because the mapping + * for the second page can change. + */ + if (tb->page_addr[1] != -1) { + last_tb = NULL; + } +#endif + /* See if we can patch the calling TB. */ + if (last_tb) { + tb_add_jump(last_tb, tb_exit, tb); + } + cpu_loop_exec_tb(cpu, tb, &last_tb, &tb_exit); + /* Try to align the host and virtual clocks if the guest is in advance */ align_clocks(&sc, cpu);