From nobody Thu Dec 26 15:13:04 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1732829942; cv=none; d=zohomail.com; s=zohoarc; b=NjblX50dRVs6HSSRqAhLiz7CSKq1+nNh7PaUL8gz+e19T2HELInej/GAi+iHvc1DWBxOjf67hvcB09tHPnYAMAfKqf5PcxuXQUDKuh6eJ6D9juZJlM8RF5lV7OWCzV9lFMl/WdSRnWr8j7Y3J4FRgBSQuJfava3BlGboA98Q2bU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732829942; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xXXQwrbvgY9SrfkpFjpcfAWTIlYv5Ij04FfSfNgrax8=; b=MKdzCWJdoV1oQzrrIfxgCvoY/nIkQk8xkh+faiQ3VrICgxH/w0wWljf+r0c0Ts69BC9REd8xwAXhupMFBiKh25M8KNR9QWoP2V1pm3qtHj6bWPbkoriOoIGvM+eI8LvvJDIpVZjgEuzoOsrBeHd6YcBsllYfX1OKgIZFbJdNP3g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732829942390985.8425409504464; Thu, 28 Nov 2024 13:39:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGmDt-00085G-5z; Thu, 28 Nov 2024 16:38:53 -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 1tGmDr-00084q-Po for qemu-devel@nongnu.org; Thu, 28 Nov 2024 16:38:51 -0500 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tGmDq-0001Aq-8H for qemu-devel@nongnu.org; Thu, 28 Nov 2024 16:38:51 -0500 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-7242f559a9fso1155535b3a.1 for ; Thu, 28 Nov 2024 13:38:49 -0800 (PST) Received: from linaro.. (216-180-64-156.dyn.novuscom.net. [216.180.64.156]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ee0fad03c7sm3944850a91.39.2024.11.28.13.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 13:38:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732829929; x=1733434729; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xXXQwrbvgY9SrfkpFjpcfAWTIlYv5Ij04FfSfNgrax8=; b=pc5nNqfrCVmGIh0EitV7c4nWBdWLlzHPrqmLxY+1VtvBj+QlSJFXBR593TNzHm/Ozm OZx34+T9fxr7zqlxwS/KWSYRH2GYo7dSddupf3Lsq4L/QNJ7HZMEPcp8ui10pURDAqbL xUOQn9xl/fzHKBGyEmB2htJciBobxOeGEpW+sqPj06UG7ycvRWmRt95OTSlGQYuJNvEc 8qE6fauCWom3cwTd24zPxhkeTXxySj63kotts2gb5WYSZHm7xk88EePQ6Q/BotITBEF4 8Hqr5G45cQIBBmoBBd0vrORJNJjC21IJOAhRkzQ/9ph0d0eLSQ6pdjDbpM787Fo31y6f +qrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732829929; x=1733434729; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xXXQwrbvgY9SrfkpFjpcfAWTIlYv5Ij04FfSfNgrax8=; b=jX1FQJ3M7zI5og9TxF2Bvm/yZueb6Epcd0ujLGgfYFD9XNXD+ABmUHSFZV880Ukn5o s3cvzRGOX6t8qrOCg6KdkUo116rqyXX4xBN2UD2a27bScQu602s81jTX2yz14foQRisx /OguBK4je0Sa6+Toch92ww1l5Hc6zeH/EWyq+OjxO+mP2ShUwCZs5s6Zze9gp0NwkQzc 4zrDNzao/dqxXhN5i1pvcZwSGZQh2HiemnG20coChpfT5ipbhNcYJaDv5zBFBZijUce8 KNBta/Jw/GCfZbRkA9a/r86kdGzQOgSlqKwtUm+OnTmc8KSJubtkHGFznPcHxJPrtgXr LWCg== X-Gm-Message-State: AOJu0YyrWqumcTvZUbyX7SBhhsa9Wmx7Fj7X66nB6VanauZYnd/VG6LU vaHMPN0u4MzZrv4BHXVH2KhBiMVHY3pgJUUd1Sd0o1r69s7unkvnXXbB9PBmutLbIm9dVUfistc c3+0= X-Gm-Gg: ASbGncs8J3TebgUBRtXPjJKWevAZdO+s4IysQ+p3YjT+7JsekcxZ0BRSOZYdpTXrIIw e1dVR2kJ64EUhsTaVdXIskI1L4ZbiYgBlGlhSaWimVod01RypF3Wkk2pQs28XZhisBS4F+PHhZT L4OiSdTFQuJSF5w8TO8aQLfo6VHswZpAxvkbBO66Ch97RuURJCWCMysAwGYF1fLgSdUg20g5tWv dWvMSuqyoG5heXfENHlfoR09NDzRqkEFQnNrdP8wOjEm+wMQmMinUTeaTF+1IDwYarEzJ2JYLuL l5GEs1/ZrQHtsw== X-Google-Smtp-Source: AGHT+IGprSvxq01xwUMLowYfhfxjjmAYmq2sSnJQwlmk27T1Qa4DbQHVqxPcgmV0pw9f9GVglX3txw== X-Received: by 2002:a17:90b:380c:b0:2ea:5dcf:6f74 with SMTP id 98e67ed59e1d1-2ee08e9d449mr10556447a91.3.1732829928933; Thu, 28 Nov 2024 13:38:48 -0800 (PST) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Alexandre Iooss , Mahmoud Mandour , Pierrick Bouvier Subject: [PATCH v2] plugins: optimize cpu_index code generation Date: Thu, 28 Nov 2024 13:38:43 -0800 Message-Id: <20241128213843.1023080-1-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pf1-x433.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1732829944651019100 Content-Type: text/plain; charset="utf-8" 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 --- v2: - no need to do a flush, as user-mode already does it when spawning a second cpu (to honor CF_PARALLEL flags). - change condition detection to use CF_PARALLEL instead --- 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 0f47bfbb489..961d9305913 100644 --- a/accel/tcg/plugin-gen.c +++ b/accel/tcg/plugin-gen.c @@ -102,6 +102,15 @@ static void gen_disable_mem_helper(void) =20 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 =3D tcg_temp_ebb_new_i32(); tcg_gen_ld_i32(cpu_index, tcg_env, -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)= ); --=20 2.39.5