From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29230C4332F for ; Tue, 7 Nov 2023 23:19:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B49246B019F; Tue, 7 Nov 2023 18:19:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AF9646B0248; Tue, 7 Nov 2023 18:19:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9C158280025; Tue, 7 Nov 2023 18:19:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8C3FF6B019F for ; Tue, 7 Nov 2023 18:19:24 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5FBF7B5D55 for ; Tue, 7 Nov 2023 23:19:24 +0000 (UTC) X-FDA: 81432726648.23.5CA8A45 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by imf07.hostedemail.com (Postfix) with ESMTP id 44CDA4000E for ; Tue, 7 Nov 2023 23:19:22 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=inria.fr header.s=dc header.b=R+dEyP+r; spf=pass (imf07.hostedemail.com: domain of julia.lawall@inria.fr designates 192.134.164.83 as permitted sender) smtp.mailfrom=julia.lawall@inria.fr; dmarc=pass (policy=none) header.from=inria.fr ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1699399162; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cBa0zQZbsO89eYHjjLsYK/1rbltQ1z3rYm0sN7tN0X4=; b=pRZT5bJNA43VH8AFAb3dVV0GQH1Xf6ykL1Oc8MZDM/lgC1M6m7DBUCGoE6UudwO3K1zIMZ FZuVtIXgdWZ/UMoBKQSkyxGHNLnFn0H8N0L7kbX4K2BGOsOhJzvz6WjwklcoSSo+CtL7zd AJmSxCBAZBuM2ka4nBCwIWn+ZMg3ghY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1699399162; a=rsa-sha256; cv=none; b=OcI93GmomJP024gv7HShw/NfpYC769RllEdQx5k33V0ghOgagqtBEn946s+HibszPd+bty 2v9VxBkmqtVZlEolLARfBRMoljbh712bB/BtPGWEJDTU0tPTAfUa1LRUJUMB/bGDG+AcSP tAw7x9ijzsecc1r2tAvQCKcNI1b6jnE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=inria.fr header.s=dc header.b=R+dEyP+r; spf=pass (imf07.hostedemail.com: domain of julia.lawall@inria.fr designates 192.134.164.83 as permitted sender) smtp.mailfrom=julia.lawall@inria.fr; dmarc=pass (policy=none) header.from=inria.fr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=cBa0zQZbsO89eYHjjLsYK/1rbltQ1z3rYm0sN7tN0X4=; b=R+dEyP+r6EkVbbTZ/eAkNye93CZxpUYadd7k1Juu/Ow1FsjB6JmRclx7 lCuiFER3mTmM+ClUUYO8s2WA2W2aLAc8yF3bogeURrr+i0tBqDzKSZvM4 oL7N/fht1HEMcaVISKeq1iutIlKG9mrAzwYf2UQZ+Pj/kTSXPYY3c81SJ 0=; X-IronPort-AV: E=Sophos;i="6.03,284,1694728800"; d="scan'208";a="135141790" Received: from 71-219-23-58.chvl.qwest.net (HELO hadrien) ([71.219.23.58]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Nov 2023 00:19:14 +0100 Date: Tue, 7 Nov 2023 18:19:13 -0500 (EST) From: Julia Lawall To: Ankur Arora cc: linux-kernel@vger.kernel.org, tglx@linutronix.de, peterz@infradead.org, torvalds@linux-foundation.org, paulmck@kernel.org, linux-mm@kvack.org, x86@kernel.org, akpm@linux-foundation.org, luto@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, willy@infradead.org, mgorman@suse.de, jon.grimm@amd.com, bharata@amd.com, raghavendra.kt@amd.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com, jgross@suse.com, andrew.cooper3@citrix.com, mingo@kernel.org, bristot@kernel.org, mathieu.desnoyers@efficios.com, geert@linux-m68k.org, glaubitz@physik.fu-berlin.de, anton.ivanov@cambridgegreys.com, mattst88@gmail.com, krypton@ulrich-teichert.org, rostedt@goodmis.org, David.Laight@ACULAB.COM, richard@nod.at, mjguzik@gmail.com, Julia Lawall , Nicolas Palix Subject: Re: [RFC PATCH 57/86] coccinelle: script to remove cond_resched() In-Reply-To: <20231107230822.371443-1-ankur.a.arora@oracle.com> Message-ID: References: <20231107215742.363031-1-ankur.a.arora@oracle.com> <20231107230822.371443-1-ankur.a.arora@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 44CDA4000E X-Rspam-User: X-Stat-Signature: mn3odugpp4km9hijmpnrydqapy7rk7ng X-Rspamd-Server: rspam03 X-HE-Tag: 1699399162-623215 X-HE-Meta: U2FsdGVkX1+URwSAutwHi5Y5dM2w3zYsyfxSGQwVkck/XFOVAGQtSPt25ZgjMWL96DeXCh9U5c/29kqk98ukxGXwBuWjJpqLGxjFAAiii8eerZXmNbc6J4lpDWaPaEioa817xpODoiOqG597UHOXTe5+DDNXE3IEZDTq97OiMm6ZFucxgwSTPB4sIbs0K4+cmEgwtqjwBdnoFEWe75fl8IagntSUv6xbfbOT+jm4/3xm9585T8I2j5lHnxBf62ClQC8sEzY6sbccjjcS2UjskrH5FGGOhosXio1ZzHKhPzjRixrGSZa87c4KZKnoqhsfpJRcabdM4QQtBqUk2D2Va84vfRJEn6y64Oe88wrHdZZ8NmQQOjCG49zi7gW+1YAtv1SE31H78d+MFjYildbRCeZoBLAMCx9g7H0s5CU/XNirztYiLpfW2LRTxC3LQ1aMkCNiLoe1RAsQoMREx6LBoRRHqQXz3/aHREW96zCsYGv1L8sLjqQOCcyHBDEUunqjoo+W9gur/kFOuQi3VTzA1CPjLB9fbgQ0CBLYYuMIWqmADMWuzXrNDTWpSrriEmOJcKjz8e7DlCkJYkvk9+3AhB6zutTtxfmRIpVelDJeisbY7CdTd9gYg4kwr0HADh812l9au/uJLuC3j8jdO5xoRnp/9mQu/159+Cbv9yOMmNqhRuUErwOyer7xh3y4TMU12w+R0F2Y1FHoLc0+fcziOK88oOsBiNsuFaqeZLNn0P2+wJzk9AIEpgCz/b3wPogklLfwYQmF2X1nQ0eFLH8aHwH/ydMplADNlL+eIvFUJG6cOHqhg5zMO9MWZKIH69p52vOGT66DPymWNXL1KzxEhGNs1Pm941vBdjMlXTQGuzF/rqo7lQlMN67JNcFTJvTbCzOqKwRD53MBrQZkiSZENYOVk0gMTtEL69WP4/6DkylvLNkEGs1HYBfEMJC+9K1Seu7Brmf/WJfRI2qAgC7 V6FcVAZo FRKES/PLapPIlq5dKahM9kY9P3L/ItgPxwdhaytu+STgopRSJwJ22YhVFw/D6+mlnPpsSMjRYI4tQXMx4ZDB5Znsz6FPtt9oPh2ZyIpDvoexz0nqK78So104BO01CtOB/Q4pIIiG7sfcNri0UVqw2009+ptBBQ7pMAIT6dWWmSsNLYijPyyJRMoZqmX56+HI03SOyeiv3s+MHrjY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, 7 Nov 2023, Ankur Arora wrote: > Rudimentary script to remove the straight-forward subset of > cond_resched() and allies: > > 1) if (need_resched()) > cond_resched() > > 2) expression*; > cond_resched(); /* or in the reverse order */ > > 3) if (expression) > statement > cond_resched(); /* or in the reverse order */ > > The last two patterns depend on the control flow level to ensure > that the complex cond_resched() patterns (ex. conditioned ones) > are left alone and we only pick up ones which are only minimally > related the neighbouring code. > > Cc: Julia Lawall > Cc: Nicolas Palix > Signed-off-by: Ankur Arora > --- > scripts/coccinelle/api/cond_resched.cocci | 53 +++++++++++++++++++++++ > 1 file changed, 53 insertions(+) > create mode 100644 scripts/coccinelle/api/cond_resched.cocci > > diff --git a/scripts/coccinelle/api/cond_resched.cocci b/scripts/coccinelle/api/cond_resched.cocci > new file mode 100644 > index 000000000000..bf43768a8f8c > --- /dev/null > +++ b/scripts/coccinelle/api/cond_resched.cocci > @@ -0,0 +1,53 @@ > +// SPDX-License-Identifier: GPL-2.0-only > +/// Remove naked cond_resched() statements > +/// > +//# Remove cond_resched() statements when: > +//# - executing at the same control flow level as the previous or the > +//# next statement (this lets us avoid complicated conditionals in > +//# the neighbourhood.) > +//# - they are of the form "if (need_resched()) cond_resched()" which > +//# is always safe. > +//# > +//# Coccinelle generally takes care of comments in the immediate neighbourhood > +//# but might need to handle other comments alluding to rescheduling. > +//# > +virtual patch > +virtual context > + > +@ r1 @ > +identifier r; > +@@ > + > +( > + r = cond_resched(); > +| > +-if (need_resched()) > +- cond_resched(); > +) This rule doesn't make sense. The first branch of the disjunction will never match a a place where the second branch matches. Anyway, in the second branch there is no assignment, so I don't see what the first branch is protecting against. The disjunction is just useless. Whether it is there or or whether only the second brancha is there, doesn't have any impact on the result. > + > +@ r2 @ > +expression E; > +statement S,T; > +@@ > +( > + E; > +| > + if (E) S This case is not needed. It will be matched by the next case. > +| > + if (E) S else T > +| > +) > +-cond_resched(); > + > +@ r3 @ > +expression E; > +statement S,T; > +@@ > +-cond_resched(); > +( > + E; > +| > + if (E) S As above. > +| > + if (E) S else T > +) I have the impression that you are trying to retain some cond_rescheds. Could you send an example of one that you are trying to keep? Overall, the above rules seem a bit ad hoc. You may be keeping some cases you don't want to, or removing some cases that you want to keep. Of course, if you are confident that the job is done with this semantic patch as it is, then that's fine too. julia