From nobody Tue Nov 26 16:42:07 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=1706546890; cv=none; d=zohomail.com; s=zohoarc; b=QLiB/b7XsvxpvA2mtpVdPtOZgYlEx9+gJEx51JS7SHaXcAwA18mny234qkS8Wdx40LSuWNOjM1H1+z72ZOTo80GrkKIz1YiNh4VXw9X0ER7gstUP3LT4taGh6xeYd/Q4QzAiSH5twrGbOxhm9Q82oefuf6wiiRGSUpLkN4dOUFM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706546889; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=B6GmB2IPQQ3XezKE8bqOs65jaQBYCmOI4YcRWUsHLHk=; b=ULblYk6apx0lUDD9eJsuEv/p+ng9lY8UDylbpHsqYjoTv4CyB14KfsuAH7KD7f7/AKhnlAgjPpVawV+o0ArYXKdgjiRkFg3Pdr8vyPEu8vdA6XJg5VmtAC5p9xV7nMMJUNp7+BWVpGUUcM8h//lrexrZ+JR/GQuVzvNI+6Csw7k= 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 1706546889991950.8597162633154; Mon, 29 Jan 2024 08:48:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rUUms-00088U-8u; Mon, 29 Jan 2024 11:47:10 -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 1rUUlg-00062B-Jp for qemu-devel@nongnu.org; Mon, 29 Jan 2024 11:46:00 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rUUlb-0003hl-M5 for qemu-devel@nongnu.org; Mon, 29 Jan 2024 11:45:56 -0500 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40ed3101ce3so44774385e9.2 for ; Mon, 29 Jan 2024 08:45:50 -0800 (PST) Received: from m1x-phil.lan ([176.187.219.39]) by smtp.gmail.com with ESMTPSA id b6-20020a05600003c600b0033aed4e3b55sm3381414wrg.102.2024.01.29.08.45.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 29 Jan 2024 08:45:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706546749; x=1707151549; 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=B6GmB2IPQQ3XezKE8bqOs65jaQBYCmOI4YcRWUsHLHk=; b=czbKw03mCMTdRk0AFEO/zBU4kMqdogCSgrY7zp53aSAttdQh7z7VzU42W8FX2jV/5e fNQzi4oc5l3EXpTERwq/CJkDVA3yxlZTAa7S1BB2fKErBt1wP+Wd4Lq1ihIWjPqij9A+ 4cPBQyUQzbQXbsfmw04PGLBCE4pyDmdzG2qd9WhJiCUACFEsjMTutiYql5ayP2jSWcb/ WOVTyxTX+EuXSPKwy7RmW9Fo5S+Wxw+JnaSqgvy6J1jgVpImtuptVBcUndFVHUk7kr9V VKf+e3DVdSL8x1S/nHpyRPt2gAJ8mvEYkq+Lb5iz+nEJ4H3ndSVk/1HGeN0YPmLkyEsb lFyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706546749; x=1707151549; 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=B6GmB2IPQQ3XezKE8bqOs65jaQBYCmOI4YcRWUsHLHk=; b=gpV8je9dqUAw6VJip7VmDzawti3ZTzOT/RZbto5eTbcE2WTOoOjkjx2Tzhg3Df7WYY yOP5hE1miby+J6ojocilEyVeIdSGNZY0fuBKLegSuQb4K3PihVt1Scr1xVDkDQ0Os2kE qUpF8RwCOcCkfIAcTUdAwJPniKC5B0k+EKWhc746ekLTcIg6GDlHJp/WmffBHyYhP4MW 7FvP5oL2H6Iof6AYhT3fu/xLhvw8SFR69AlPc48KzBz0SVFIfv7i8pUeuTfRtEs5Fn0M EnUPboryYL1rLDRvNiRaqugyoeJMmetuCybZ6XCoJ5jMb2xY0en/qYg2QRBp0qhiK/2b daDw== X-Gm-Message-State: AOJu0Yy7qT4/bc1v16RgS7yyK+knztNKa/F/wRXIJ3vAkgd88t4t8rmO 4C3s2klXcp2Sa9Zov2T0kBLz8GrGA6byNhhpa9f1zXscKb3kF7OIe4qZHpGvCJyTN+6JmPUEuP9 j X-Google-Smtp-Source: AGHT+IF/M4JMBgkyz42lTen3ZH5avOQ7AmvAMgZOIUtFFNwiFxYGzMm049Zz6nlzZCQLDXADh4NIrw== X-Received: by 2002:a05:600c:1f83:b0:40e:b1f6:2ed7 with SMTP id je3-20020a05600c1f8300b0040eb1f62ed7mr5943831wmb.32.1706546749731; Mon, 29 Jan 2024 08:45:49 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, qemu-s390x@nongnu.org, Paolo Bonzini , kvm@vger.kernel.org, qemu-ppc@nongnu.org, qemu-arm@nongnu.org, Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 05/29] scripts/coccinelle: Add cpu_env.cocci script Date: Mon, 29 Jan 2024 17:44:47 +0100 Message-ID: <20240129164514.73104-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240129164514.73104-1-philmd@linaro.org> References: <20240129164514.73104-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::331; envelope-from=philmd@linaro.org; helo=mail-wm1-x331.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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1706546891161100005 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=C3=A9 --- MAINTAINERS | 1 + scripts/coccinelle/cpu_env.cocci | 100 +++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 scripts/coccinelle/cpu_env.cocci diff --git a/MAINTAINERS b/MAINTAINERS index dfaca8323e..ca3c8c18ab 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 F: scripts/decodetree.py F: docs/devel/decodetree.rst F: docs/devel/tcg* diff --git a/scripts/coccinelle/cpu_env.cocci b/scripts/coccinelle/cpu_env.= cocci new file mode 100644 index 0000000000..5a70c2211a --- /dev/null +++ b/scripts/coccinelle/cpu_env.cocci @@ -0,0 +1,100 @@ +/* + * 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. + * CPU() macro is a no-op. + * + * SPDX-License-Identifier: GPL-2.0-or-later + * SPDX-FileCopyrightText: Linaro Ltd 2024 + * SPDX-FileContributor: Philippe Mathieu-Daud=C3=A9 + */ + +@@ +type ArchCPU =3D~ "CPU$"; +identifier cpu; +type CPUArchState =3D~ "^CPU"; +identifier env; +@@ + ArchCPU *cpu; + ... + CPUArchState *env =3D &cpu->env; + <... +- &cpu->env ++ env + ...> + + +/* + * Due to commit 8ce5c64499 ("semihosting: Return failure from + * softmmu-uaccess.h functions"), skip functions using softmmu-uaccess.h + * macros (they don't pass 'env' as argument). + */ +@ uaccess_api_used exists @ +identifier semihosting_func =3D~ "^(put|get)_user_[us](al|8|16|32)$"; +@@ + semihosting_func(...) + + +/* + * Argument is CPUState* + */ +@ cpustate_arg depends on !uaccess_api_used @ +identifier cpu; +type ArchCPU =3D~ "CPU$"; +type CPUArchState; +identifier ARCH_CPU =3D~ "CPU$"; +identifier env; +CPUState *cs; +@@ +- ArchCPU *cpu =3D ARCH_CPU(cs); + ... +- CPUArchState *env =3D &cpu->env; ++ CPUArchState *env =3D cpu_env(cs); + ... when !=3D cpu + + +/* + * Argument is not CPUState* but a related QOM object. + * CPU() is not a QOM macro but a cast (See commit 0d6d1ab499). + */ +@ depends on !uaccess_api_used && !cpustate_arg @ +identifier cpu; +type ArchCPU =3D~ "CPU$"; +type CPUArchState; +identifier ARCH_CPU =3D~ "CPU$"; +identifier env; +expression cs; +@@ +- ArchCPU *cpu =3D ARCH_CPU(cs); + ... +- CPUArchState *env =3D &cpu->env; ++ CPUArchState *env =3D cpu_env(CPU(cs)); + ... when !=3D cpu + + +/* When single use of 'env', call cpu_env() in place */ +@ depends on !uaccess_api_used @ +type CPUArchState; +identifier env; +expression cs; +@@ +- CPUArchState *env =3D cpu_env(cs); + ... when !=3D env +- env ++ cpu_env(cs) + ... when !=3D env + + +/* Both first_cpu/current_cpu are extern CPUState* */ +@@ +symbol first_cpu; +symbol current_cpu; +@@ +( +- CPU(first_cpu) ++ first_cpu +| +- CPU(current_cpu) ++ current_cpu +) --=20 2.41.0