From patchwork Tue Dec 24 20:04:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 853246 Delivered-To: patch@linaro.org Received: by 2002:a5d:4888:0:b0:385:e875:8a9e with SMTP id g8csp4082396wrq; Tue, 24 Dec 2024 12:10:10 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWqX3RQ4un7DQOxKkT5zQZbiizEbtGnCchLpiUFcRG0HLyxCyakCjBspVl7UcJ0GdJ3MJMtYg==@linaro.org X-Google-Smtp-Source: AGHT+IH/bVdXqlMPTLA1YM8Jf1Jh4TwZq/ODo3TQy/CEVN9ERPU4xaBHbuCFjRSRouJhgKrscECu X-Received: by 2002:a05:620a:40d2:b0:7b6:eed4:695c with SMTP id af79cd13be357-7b9ba79d2cdmr2554026585a.32.1735071009904; Tue, 24 Dec 2024 12:10:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1735071009; cv=none; d=google.com; s=arc-20240605; b=jmHZiPRM0ukgYsK/A5jANrHJBVl/timat5WoBXmfqVdS61JmXtGT7Yv6X4Lo2/Djmj UvJKsw6c71rX5bAX673TPbZsUTFxVFQ0QSve/qw13XpMC1FbprKDQbknj6r0/p1zTHVp 1/KtVUrvPXv2Gzs62zfcWzdrkUvFNmTeFhUZDcP4I1+E0uo2cXsjDpV7YLRZ2RyV5tPk IoOyHcFbC+whAOk/CVjEN+x4Yg418qQ4EGjs1kxPezq09wNiGHDdYN+laW6KSkVEdzrr nw8XDkPoVbnH58CO9ULRTaMfu1CRYvgEEH/pTZ98K1XU7Rpf1YdqSekx4nTQEuraIg3k pDtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=ZG6ae1a+VQYDF+HP8pwyU2WyU4xA7uudCLK9pyvDcw4=; fh=vm85eyWrvOAHduw3sqEA+cYBqvHB7M0MHFcRJg7VWOo=; b=MHV7+TqK/kqvJp5q5W1TWjBRO3Kr/MyNMC67UQRFOgJ3YmK8LGikA+ZBvHCXFoI6HX ysYVLyHfjzKfEgIB4xWkoorGZSopayQGkUHkvxC4B0lAIjw6qr62cG44xfi/Ep3H6J4d 5pIHRTYttuM3WIyHkN+9jyj4FtCYb94l173ZrBsLgSpf1hPIyyD5lyhwRnkwDRVPGtWi CJVf3jNL+bpYF+QhV83wFvLQbpOHefgdWPwV/YuiE2j/eFo+ljOgCnFXf2XWfY93iom/ Lfme+09K/hPjBQItGLtiR9gOgi/OVloecXeL9gay3NyXg2awUjg11G2ZYIB+z9HjB8fV Mr5w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YP/8EBKQ"; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7b9ac2ad5cdsi1375901085a.34.2024.12.24.12.10.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Dec 2024 12:10:09 -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="YP/8EBKQ"; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tQB9t-0002li-Bh; Tue, 24 Dec 2024 15:05:37 -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 1tQB9j-0002jU-Ir for qemu-devel@nongnu.org; Tue, 24 Dec 2024 15:05:30 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tQB9h-0002Us-Of for qemu-devel@nongnu.org; Tue, 24 Dec 2024 15:05:27 -0500 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-21680814d42so52211635ad.2 for ; Tue, 24 Dec 2024 12:05:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1735070724; x=1735675524; darn=nongnu.org; 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=ZG6ae1a+VQYDF+HP8pwyU2WyU4xA7uudCLK9pyvDcw4=; b=YP/8EBKQCBeA+I5TNXMTHmBe8XG4ifwGnXK3FuD5QELLegUs0iC/r8911ZJVIQ/yWp rO9LNdSuKLNVpKt16KxOLeYV5ht4Wsnh3TpV4auhHwRLE9V3/7PRi+PDllGlnih59dMi 1Sy/VrhK2vUwb4jR8c2/RA+UK20N+pO6BWcVBAe7YcXhDlMdFy/TyyHSbVQDYiyP8Sah lMpQ4i3xMdJ+L6uDQjI4mNMf3fLGgGtZQZ3SxOKkvAPr8sMs3xsnkaIFG77uhh8flpK5 I41mHnqSLLeBU7+OYYKZLbe4dnU3U1a9Kx4GCwoaDJoX8xVG4h3mo1U7x7ApTvU6Mw+/ kkEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735070724; x=1735675524; 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=ZG6ae1a+VQYDF+HP8pwyU2WyU4xA7uudCLK9pyvDcw4=; b=iiNq6fyfsnpjgHPSmkAzkP3MHnKEzxTwfLx9gktE11gAj4g6IWHOZpGLCggMySyJB+ Qy32Z8jV/lAsiPwNfkvqmgmfgPydpug66+etxjj8+yehH8gnv78yuc1PDXWwyEnYzAtd 1E/Ul+smEh9ed7T/qHoRw5Zl5fQlpNk3i2DJAy3gfLqgGygSX57FEcrrr6MmrJqL4XE6 Q/R4ZIWEO+d6HDCoPrhCbsww6+qRvOTUM5mNRDyzp45DzXJUIabpilp/BNtW+q7hlr4U v3bZg7Qn9PB1b0pT0fJxaufXVQS7AzXYxCMosUKNCBqUafD0nX0ZSMRcprq3lu89ibd+ sx+g== X-Gm-Message-State: AOJu0YzSqtwRyUKPcXPqUu5dhOsoMOdxMY5P9dFkVyB0HMYwLWlg53sR Ki1e2Dbv6pFU/2W3dzolu7CYWORAGcK4FtLUeSJb9QCrVvamoJjzMPch14u8EVei78annICC5xJ 759k= X-Gm-Gg: ASbGncvUdkWr0xkH3K3W8Duetq602cKkm59hDgzPhKnjFJ/al8gsXx1b5EjoZfBfPwn U6O9cEZsjFDb8gDre6kQ3QXvAoau+U85VU22taJozRxvCpOBtRG3SmmCwZRxBwutVLYX78SW/MH KTDUslClD/v0utfEL7K0UVCtQkEAzfNV6WSjS/OyaBQIaX4tpWYprRRZdTSDYGQmthZYEGrena+ WRXIdyyc8gGRggA3VrlKS0o+rOPXJfI5bHim17/e6srle7OV5AU0LgngSaDMOLWUE7pYsLsijc7 mljd73JeW10UF+riw6dq490Vjg== X-Received: by 2002:a05:6a00:1942:b0:725:cfa3:bc6b with SMTP id d2e1a72fcca58-72abde404b0mr26512426b3a.3.1735070724395; Tue, 24 Dec 2024 12:05:24 -0800 (PST) Received: from stoup.. (syn-156-019-246-023.biz.spectrum.com. [156.19.246.23]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72aad8fb895sm10027159b3a.162.2024.12.24.12.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Dec 2024 12:05:24 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PULL 02/72] plugins: optimize cpu_index code generation Date: Tue, 24 Dec 2024 12:04:11 -0800 Message-ID: <20241224200521.310066-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241224200521.310066-1-richard.henderson@linaro.org> References: <20241224200521.310066-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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: Pierrick Bouvier When running with a single vcpu, we can return a constant instead of a load when accessing cpu_index. A side effect is that all tcg operations using it are optimized, most notably scoreboard access. When running a simple loop in user-mode, the speedup is around 20%. Signed-off-by: Pierrick Bouvier Reviewed-by: Richard Henderson Signed-off-by: Richard Henderson Message-ID: <20241128213843.1023080-1-pierrick.bouvier@linaro.org> --- accel/tcg/plugin-gen.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c index 1ef075552c..7e5f040bf7 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -102,6 +102,15 @@ static void gen_disable_mem_helper(void) static TCGv_i32 gen_cpu_index(void) { + /* + * Optimize when we run with a single vcpu. All values using cpu_index, + * including scoreboard index, will be optimized out. + * User-mode calls tb_flush when setting this flag. In system-mode, all + * vcpus are created before generating code. + */ + if (!tcg_cflags_has(current_cpu, CF_PARALLEL)) { + return tcg_constant_i32(current_cpu->cpu_index); + } TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); tcg_gen_ld_i32(cpu_index, tcg_env, -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index));