From patchwork Fri Jan 26 22:03:44 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: 766383 Delivered-To: patch@linaro.org Received: by 2002:adf:a314:0:b0:337:62d3:c6d5 with SMTP id c20csp452440wrb; Fri, 26 Jan 2024 14:05:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEsVeVsGgwKVXvnO+z9n/X0BnkhiGI+K4XUH/uBNys944N9g+Ar5wish9/ldYt512TUFdlo X-Received: by 2002:a05:622a:13ce:b0:42a:8634:6cb with SMTP id p14-20020a05622a13ce00b0042a863406cbmr800712qtk.53.1706306713007; Fri, 26 Jan 2024 14:05:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706306712; cv=none; d=google.com; s=arc-20160816; b=gBdQWmnAnEd+bic7gBQ59stUWOzr4fvZ5O4SIMEt5EEc+ZVqB8iLq90G2qgRMTNZMJ DmsoqM0Na6d32xSwCJW8ZqHH1Fd94x7rSy12uEgy799sYfPu6gj5H6gE1l1u11qDmSIW P9+YqgxHzgB150bxHI+Apf+YOu2FbZeq+E+eBM5Lq/k977vuTncDOh9fwxP6NBub2vXg G7Md1OemqUA0F9d2L0/IWnoiYTndGootuXtCuflYBl1qlCxL/0yGl9ulLSR7bb8+wMW7 TT6uqsiima1stlt4/Kldi9K0jnqVWkB5cpU6dvGN+2qHSmb7gNRjuJRBkPiphb6yTDgH FZqw== 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=44vj1U77cG8ByngsPLkvtVP46j6F/SEPuSA1albtNLM=; fh=vjIQCdGIiQvlMQV4M7vu+NKSTn5p9Q4HADr8u1W/+iI=; b=QpfharxGnys9JNR4Cg/yOEHxoPG/WjTGbDBllP+JHWUmIpOp3Rb5ENScJUGqX1NbT2 JyD6GLkngiLcJa0nlY+F9IRLsLIoD5FdDepn+rfCdAoIFXk0tyobvP68LjXbH946kMtL sNFSMA6WNJpzOaEmnKeYGl6DRM435tWQhfu4WdJPJJ+HIEXtYeYpEF2FwGRqDKXakDsK moGLneCT4bd6rG5RXiGWNAhV2oaj7fSrQdU/dt37c0nzVKCwqBH6XRTT3k1Dsnt8ea/d cWWy2EcPxJncA5CzL+DDfjqu5c2uDXe4XZ36rlcF8IiSbS8fJqMd28qNLFGKGUJK85jA xlng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qdg5POse; 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 w21-20020ac87e95000000b0042a741864d9si2191843qtj.110.2024.01.26.14.05.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 26 Jan 2024 14:05:12 -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=Qdg5POse; 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 1rTUJJ-0006yU-7a; Fri, 26 Jan 2024 17:04:29 -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 1rTUJH-0006xO-QK for qemu-devel@nongnu.org; Fri, 26 Jan 2024 17:04:27 -0500 Received: from mail-lj1-x232.google.com ([2a00:1450:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rTUJE-0003Nu-Ij for qemu-devel@nongnu.org; Fri, 26 Jan 2024 17:04:27 -0500 Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2cf4696b90fso8375371fa.1 for ; Fri, 26 Jan 2024 14:04:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706306662; x=1706911462; 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=44vj1U77cG8ByngsPLkvtVP46j6F/SEPuSA1albtNLM=; b=Qdg5POseFn96pizitSylgPijIrzKPtAg0qpl8eWI0nT7Z/FgAQsngbiFY//li5o8L+ klriDw5oNLLb890mf1Xp4lD5lOxg+IZDaxaVS9gv4OkIQc5mdkqMiGsXUqu3EwT7c40A fP9CXIvDOerUomCyx3PlEFmjkavPI7R1QSlki+DeLucz6y1KyL80rY8ZnXkPnOYg0yjW dAKdwXmy3RGXPrKZ5UzD7oqMtezV9fhClDnfDbEh33CHq3HjWtTaC1gxY47zVVO698rl Kjb+g9fGUh1L7Z1OPVFyZUozS7bMs4dqBknTjfv4vOGVeC+eiRD3BjMuC8wCjQ/80+DC VzUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706306662; x=1706911462; 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=44vj1U77cG8ByngsPLkvtVP46j6F/SEPuSA1albtNLM=; b=XK070mZHLGn3kHEy7Wy6LoSiMJl46cJ5q0i/PycXzquPeRB3QxOWBgm7psUi8kCLqO N/fbufZdlDQgmZmEn1L8A7v0Eyq95n1Tc7SG/7HMdfQCVfzIdnniBbqgbSfYfA49YonY azo0y49s3wJNbAILgToavmdgti3r4gtLt1TBDD3Sd5aakKF6T8Jq8voIhSRsc8cFByG6 T5bkBDTYOtLUBwowalEJEGmt44nF7/pSUwAEK7TTTgKCYrBlSZiI2ENnRcp3lsnktx+r HKmfhcpqpDSI1zR41bqdwWCFVWz/Y4g0GCMx9Urxd8xi4Xq+5QZXy/SNpR/Jhz4wh96t 6tbA== X-Gm-Message-State: AOJu0YytcQYn7QZTKgiLBPt9Y8phm2XOAoEp36yvQLC7TlvSMCLQzRGh bQ5x9JxuuGhj8JT8dEM14KP7A9irZ4haTWyeszm4/Mx2KP5TnWiNWvsMJ+IKFg8gRuI1330/5DS O X-Received: by 2002:a05:651c:1a29:b0:2cf:127d:a79f with SMTP id by41-20020a05651c1a2900b002cf127da79fmr334833ljb.51.1706306662283; Fri, 26 Jan 2024 14:04:22 -0800 (PST) Received: from m1x-phil.lan ([176.176.142.39]) by smtp.gmail.com with ESMTPSA id g14-20020a056402180e00b0055920196ddesm1004348edy.54.2024.01.26.14.04.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 26 Jan 2024 14:04:21 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, Thomas Huth , qemu-s390x@nongnu.org, qemu-riscv@nongnu.org, Eduardo Habkost , kvm@vger.kernel.org, qemu-ppc@nongnu.org, Richard Henderson , Vladimir Sementsov-Ogievskiy , Paolo Bonzini , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH v2 02/23] scripts/coccinelle: Add cpu_env.cocci_template script Date: Fri, 26 Jan 2024 23:03:44 +0100 Message-ID: <20240126220407.95022-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240126220407.95022-1-philmd@linaro.org> References: <20240126220407.95022-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::232; envelope-from=philmd@linaro.org; helo=mail-lj1-x232.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é Reviewed-by: Richard Henderson --- MAINTAINERS | 1 + scripts/coccinelle/cpu_env.cocci_template | 92 +++++++++++++++++++++++ 2 files changed, 93 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..462ed418bb --- /dev/null +++ b/scripts/coccinelle/cpu_env.cocci_template @@ -0,0 +1,92 @@ +/* + + 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 + +*/ + +/* Argument is CPUState* */ +@ 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 + +/* + * Argument is not CPUState* but a related QOM object. + * CPU() is not a QOM macro but a cast (See commit 0d6d1ab499). + */ +@ 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 + +/* Both first_cpu/current_cpu are CPUState* */ +@@ +symbol first_cpu; +symbol current_cpu; +@@ +( +- CPU(first_cpu) ++ first_cpu +| +- CPU(current_cpu) ++ current_cpu +) + +/* When single use of 'env', call cpu_env() in place */ +@@ +type CPUArchState; +identifier env; +expression cs; +@@ + { +- CPUArchState *env = cpu_env(cs); + ... when != env +- env ++ cpu_env(cs) + ... when != env + }