From patchwork Thu Nov 28 21:38:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 845961 Delivered-To: patch@linaro.org Received: by 2002:adf:f2c4:0:b0:382:43a8:7b94 with SMTP id d4csp477993wrp; Thu, 28 Nov 2024 13:39:02 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUVGqYNlMAdsZ0qQAvLMDZ1581nFMhXgRqHBgnhPN+bxGEk2s6yyR6s/UU/zyrp8bYukbEc1w==@linaro.org X-Google-Smtp-Source: AGHT+IHRy4NFbO8zn6KEiIWg1Stua1ZF/FBF3kgCj2HgqkCSfZY4dznY7eQRcMA862VmMcGdG4iM X-Received: by 2002:ac8:5d05:0:b0:458:243c:e3e5 with SMTP id d75a77b69052e-466b3558a17mr143436221cf.23.1732829942288; Thu, 28 Nov 2024 13:39:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1732829942; cv=none; d=google.com; s=arc-20240605; b=Kdd+xN/d+7gUOdr1TYnYdRZ0XOy95mgt3UB1659JtB6OcLkSDIyNz65xdVilp256PC OSQxdV+sEntvkbe/9HAhfv1RsvGchjZ3hD/DxTKPbKfzC/3YN3iwXtH3bQf5JqRu4uv8 /TzKwqa+mEAsykRxkpP7CpF0cwU0H0BvIhjPKEIR3iWij1HZlyXcH99HLlaQAKxo64UY 6U8C3U7WSc7873661iuMs7LaH46XKddp1fyhxxIAqL9CwGyLu1QqP8MU3Ai1+AngNZ6h ngliQn9Mnx0q9ns+8zm/yvK0OcJ8iC7ckbilkDK/2udzzceUvBgQbZB7TxpPsH8OjSd3 BuOw== 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:message-id:date:subject:cc:to:from:dkim-signature; bh=xXXQwrbvgY9SrfkpFjpcfAWTIlYv5Ij04FfSfNgrax8=; fh=rVhxkalvytTWzhzi/2gtB0QygEnQD6EkiiDvguXBIv0=; b=RjaFaI5I3zCSce0kY+H/sKUjUEZ4osqb+KzyJFJnYooyfOe3dO2HyoTQb0vCsPrJOp ymeLwgICoyORbYKf34fY6PKFo4i68wLo8PoK3RLoOLTXM+lVYhLJhz2mj2OHD5HavkvT iIolHDNa+9HBS4zepIHPdCyQ76ZBKHWWTiByJLGDXl7iYda90ZCj6e1RASPn8AsKflMO 0uX7y+mGWQ9+GBDTAfM80wcNdB6Qrg7XcuPJHKZqA0QNKesGF5pjPobVqBsB949UeYhz NYErrMWMFiI5iuADUGqgphEcz4I6S6lDkb4bHX/XoTLGKWc+KANtcJdMgj5LHS1+AK/Q k9ig==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pc5nNqfr; 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 d75a77b69052e-466c4055557si29308531cf.87.2024.11.28.13.39.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Nov 2024 13:39:02 -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=pc5nNqfr; 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 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) 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-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) 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) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Richard Henderson , =?utf-8?q?Alex_Benn?= =?utf-8?q?=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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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) 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));