From patchwork Thu Jan 25 16:56:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 765959 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:1007:b0:337:62d3:c6d5 with SMTP id a7csp56117wrx; Thu, 25 Jan 2024 08:58:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCroV58qT3G7fBzIagqUhhxs5z2e550m98X2IO6vo5BGivUbQYInAPSEc0gpWFNMMmzbEd X-Received: by 2002:a05:620a:1d8a:b0:783:3314:e79b with SMTP id pj10-20020a05620a1d8a00b007833314e79bmr1465966qkn.119.1706201925065; Thu, 25 Jan 2024 08:58:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706201925; cv=none; d=google.com; s=arc-20160816; b=CLBTrb3m6cV/h0M3q7Q15swByrD4dkOZGb9fjBxASIMFT/dN2zuzLUg3U87NPyn6oR kbyfSRGp2N7F3X4La7X3Nxajquu7DRvKueGMV3gPy740UMW0rMUNXuMtOe8PV+fObyuU eQoLhdk+A9WLinZFPaeC7sua/1yAgu3lH8Cu0pEmpnjXF+agysTdKVeRJOCbHTmLSP6J Uaq7bBqSleOdNXePxEB7irw+1vNc0RtdDp2RC2eJKTqvBeyzQsC4K2cqrl3aPyngFl8R VPSwbPjpdJytVgObMx3jizRzxBDwywi3oA3eT9opxwuoaP492OswFIaE6PLXm5gnrhKr UrZg== 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=tu0Wmz1gyaDFvvITpysE/w6FwQ0wlgaZK51MD3LFw0E=; fh=LrpQCMqEWkkfcCkbk4oEAKfm9hfQMuham9yWwcV3vYQ=; b=a6mS4vpy4dyJK8n/M2yJHfjjjk0c5p6gUJy0HKBfrdtg1h2cghwcLoxruYV0xP8NkB Mj2cDglmhekJn7CxyY0VGE6qdzo12KIbKSz6Q0JE0/g4YUwYIvk4eD7EqtmjZ9PXT+IV +ooKp/Syv94DpttVmkf8t1QukdoyJ9sxFVSA/1Jt4DQHN+7ysnpz4LEyMjkty+E3BD/G uQu7rFRivDfKdsk6rHvA5r8me/OQRodmz7iqhXIZW0t/uMrMnDvW7Q5RM0RjjjteZOqR PzyOWb87zu4hDavJyiZVQv5RAQF9fT47VQQMBpg6jUuBuTe8NmwD3FUCNSACoW+FDnw0 73YA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="b1sRax/G"; 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 j16-20020a05620a0a5000b00783a280dd83si8103262qka.592.2024.01.25.08.58.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Jan 2024 08:58:45 -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="b1sRax/G"; 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] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rT32E-0007Vq-Gp; Thu, 25 Jan 2024 11:57:02 -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 1rT32C-0007Up-MW for qemu-devel@nongnu.org; Thu, 25 Jan 2024 11:57:00 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rT329-00017n-TU for qemu-devel@nongnu.org; Thu, 25 Jan 2024 11:57:00 -0500 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40e72a567eeso82927425e9.0 for ; Thu, 25 Jan 2024 08:56:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706201816; x=1706806616; 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=tu0Wmz1gyaDFvvITpysE/w6FwQ0wlgaZK51MD3LFw0E=; b=b1sRax/GvB438lPXezIU42qinJF4oEXHnkbT25JikElIKa4NfBd91r7JSgB0NBNTgh FTgC7h02zgRWJQwEr3e7JrXfZ4uxOtP8mb3uzvjee/vAIuKbQMiUapQEtvYL7jW8y6zf +H1JSfWq9VwzCwesdnlofcqJXTRt/yHUUfnGEird/X0L7NQRfau+W/kUzQh8dRcsbZjZ cmOXSrDe4eUYycSFdGUaReFYTMzpNWWccNatneLKDJKsOye58l2DWjcpvotgmdTPdaTn NlKa9Ppi801MEZFhbavJ7wZgJTSi58J4kZQGcFZr8gIVm6dAmjByeuWRR1s9O0Pa51lQ RMVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706201816; x=1706806616; 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=tu0Wmz1gyaDFvvITpysE/w6FwQ0wlgaZK51MD3LFw0E=; b=sfOolfffZhGR5V8AGOUVjm0cQvKEHVR/pnfYPM/jF6TL85LqT9XZHiqlyZ1Vjlt/1z aafUrxgaopnpTGMNjVDVIx/lbz9/CIVbDgP0VA2kAJhHs3H0PR0FfjvAXWJaowN2KGc1 TWZLwrQd5G15vTVzQv9thXXbgMQXKWLfMih4fIOfslUuiBXD0WkzS13QPJ5ZN47AnbiX I+Sd8BUbW+T9EeYPKcuSou8kT7as01oTkz0p3Zt2V9V0k7wQibzErZU57RaYUZI7t4aQ 7m8toZFb2gJbJHbr3MHk2I1IM3PR/vmTq1o/ABHwXesBJVHYGDRKNrjnKYXWkCQsUp0Q FLuw== X-Gm-Message-State: AOJu0YwPyIUAEZYZv93YdG4tDvu97fuFRwWjNTejxjbcBn9SNvvzE9Dy 8UfglOxuLFVYdplBzaFBVslVkfJ1PYcn68N8hoUv9zhMYBZPdZNiGd7J31JubYlWuJWdYREYlk1 Z X-Received: by 2002:a05:600c:b52:b0:40e:cca8:dd32 with SMTP id k18-20020a05600c0b5200b0040ecca8dd32mr7264wmr.364.1706201816314; Thu, 25 Jan 2024 08:56:56 -0800 (PST) Received: from m1x-phil.lan (lec62-h02-176-184-19-125.dsl.sta.abo.bbox.fr. [176.184.19.125]) by smtp.gmail.com with ESMTPSA id j11-20020a05600c190b00b0040e53f24ceasm3223034wmq.16.2024.01.25.08.56.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 25 Jan 2024 08:56:56 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Peter Maydell , Paolo Bonzini , Eduardo Habkost , Vladimir Sementsov-Ogievskiy , Richard Henderson , qemu-s390x@nongnu.org, qemu-ppc@nongnu.org, qemu-riscv@nongnu.org, qemu-arm@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 1/2] scripts/coccinelle: Add cpu_env.cocci_template script Date: Thu, 25 Jan 2024 17:56:45 +0100 Message-ID: <20240125165648.49898-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240125165648.49898-1-philmd@linaro.org> References: <20240125165648.49898-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=philmd@linaro.org; helo=mail-wm1-x333.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=unavailable 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 Add a Coccinelle script to convert the following slow path (due to the QOM cast macro): &ARCH_CPU(..)->env to the following fast path: cpu_env(..) Signed-off-by: Philippe Mathieu-Daudé --- MAINTAINERS | 1 + scripts/coccinelle/cpu_env.cocci_template | 60 +++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 scripts/coccinelle/cpu_env.cocci_template diff --git a/MAINTAINERS b/MAINTAINERS index dfaca8323e..1d57130ff8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -157,6 +157,7 @@ F: accel/tcg/ F: accel/stubs/tcg-stub.c F: util/cacheinfo.c F: util/cacheflush.c +F: scripts/coccinelle/cpu_env.cocci_template F: scripts/decodetree.py F: docs/devel/decodetree.rst F: docs/devel/tcg* diff --git a/scripts/coccinelle/cpu_env.cocci_template b/scripts/coccinelle/cpu_env.cocci_template new file mode 100644 index 0000000000..53aa3a1fea --- /dev/null +++ b/scripts/coccinelle/cpu_env.cocci_template @@ -0,0 +1,60 @@ +/* + + Convert &ARCH_CPU(..)->env to use cpu_env(..). + + Rationale: ARCH_CPU() might be slow, being a QOM cast macro. + cpu_env() is its fast equivalent. + + SPDX-License-Identifier: GPL-2.0-or-later + SPDX-FileCopyrightText: Linaro Ltd 2024 + SPDX-FileContributor: Philippe Mathieu-Daudé + + Usage as of v8.2.0: + + $ for targetdir in target/*; do test -d $targetdir || continue; \ + export target=${targetdir:7}; \ + sed \ + -e "s/__CPUArchState__/$( \ + git grep -h --no-line-number '@env: #CPU.*State' \ + target/$target/cpu.h \ + | sed -n -e 's/.*\(CPU.*State\).\?/\1/p')/g" \ + -e "s/__ARCHCPU__/$( \ + git grep -h --no-line-number OBJECT_DECLARE_CPU_TYPE.*CPU \ + target/$target/cpu-qom.h \ + | sed -n -e 's/.*(\(.*\), .*, .*)/\1/p')/g" \ + -e "s/__ARCH_CPU__/$( \ + git grep -h --no-line-number OBJECT_DECLARE_CPU_TYPE.*CPU \ + target/$target/cpu-qom.h \ + | sed -n -e 's/.*(.*, .*, \(.*\))/\1/p')/g" \ + < scripts/coccinelle/cpu_env.cocci_template \ + > $TMPDIR/cpu_env_$target.cocci; \ + for dir in hw target/$target; do \ + spatch --macro-file scripts/cocci-macro-file.h \ + --sp-file $TMPDIR/cpu_env_$target.cocci \ + --keep-comments \ + --dir $dir \ + --in-place; \ + done; \ + done + +*/ + +@ CPUState_arg_used @ +CPUState *cs; +identifier cpu; +identifier env; +@@ +- __ARCHCPU__ *cpu = __ARCH_CPU__(cs); +- __CPUArchState__ *env = &cpu->env; ++ __CPUArchState__ *env = cpu_env(cs); + ... when != cpu + +@ depends on never CPUState_arg_used @ +identifier obj; +identifier cpu; +identifier env; +@@ +- __ARCHCPU__ *cpu = __ARCH_CPU__(obj); +- __CPUArchState__ *env = &cpu->env; ++ __CPUArchState__ *env = cpu_env(CPU(obj)); + ... when != cpu