Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3313079ybl; Sun, 1 Sep 2019 10:25:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6ahoy01891r5ln0gFhAjONQOzKdUgOSq2/zV/wckQDgPaq5vI0ASTOMcfB/xPBXGiK6e8 X-Received: by 2002:a62:e10f:: with SMTP id q15mr2923795pfh.34.1567358754291; Sun, 01 Sep 2019 10:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567358754; cv=none; d=google.com; s=arc-20160816; b=b+BDzBqtiqIR6a9ort8UPUXkp71OUMXHkEYkuBuGKDlqVSzsFN5eYPqvaN4fs6gmnE kx63X3Ms1GZsNDvtqV3z8CX/qbEAwTpBEb5SpwMdoiFs4BRJ7XAXHTs7Xezjf0MwEZxM AUXlfeOICr7QdCg+xxhLCxdwFTyhV3+kGse0xlMX4EnU8DLeo0sVMBh2QUxXHwjVpHba ozleZUhMA9CW5tu+EN7G5z/cMPVh3IhlUBqLQIYjTfb020m9UpfOJQEFy7Gg/5mVgt4E Hh9NRVCLwsSMfEDh0cmwTudt65wVE0MlJlnsDFFp3v2O8b75KQaanLVHgHFKezFi0a7c xdnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=e+lhMEwAlE6McjSAcQbY0LmwER5CWMyq4H3dggr5wIM=; b=JYbybhfBzojERtA+0uEkVoLkYwsfPpp4ZdyzKj/vn724TqOQG+EJ1zkDgnD8xENmrM SQz+AZkTnLGl66dD3zptWiwadwylXheAMCCx4J90+jk5bUgy47oAywW36sZ52XO5qM2P Ci95PMkaHzCaFYMitni3sVK8GrVOeThGNE1qbpyL9aMIadSxbKBp+H1HmlpqyDah/NM8 Zq13Bxu4ze1MvbK9WgmASZ18ssD7zUceQeKlYWAct8FQRCY06oVc+DH8q/vgXlaYKAOk L5cDXtTPxFpsnX42I//zkJM/4wMnfonW6mF8/w4enazAH/C43dEp/SCb2mZijBHUl142 mESQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id az8si10041665plb.34.2019.09.01.10.25.25; Sun, 01 Sep 2019 10:25:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729018AbfIARYH (ORCPT + 99 others); Sun, 1 Sep 2019 13:24:07 -0400 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:39115 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728570AbfIARYG (ORCPT ); Sun, 1 Sep 2019 13:24:06 -0400 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id D5A4181500; Sun, 1 Sep 2019 19:23:50 +0200 (CEST) Date: Sun, 1 Sep 2019 19:24:03 +0200 From: Pavel Machek To: Joe Perches Cc: Denis Efremov , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org, Julia Lawall , Gilles Muller , Nicolas Palix , Michal Marek Subject: Re: [PATCH] scripts: coccinelle: check for !(un)?likely usage Message-ID: <20190901172403.GA1047@bug> References: <20190825130536.14683-1-efremov@linux.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi! > > This patch adds coccinelle script for detecting !likely and !unlikely > > usage. It's better to use unlikely instead of !likely and vice versa. > > Please explain _why_ is it better in the changelog. > > btw: there are relatively few uses like this in the kernel. > > $ git grep -P '!\s*(?:un)?likely\s*\(' | wc -l > 40 > > afaict: It may save 2 bytes of x86/64 object code. > > For instance: > > $ diff -urN kernel/tsacct.lst.old kernel/tsacct.lst.new|less > --- kernel/tsacct.lst.old 2019-08-25 09:21:39.936570183 -0700 > +++ kernel/tsacct.lst.new 2019-08-25 09:22:20.774324886 -0700 > @@ -24,158 +24,153 @@ > 15: 48 89 fb mov %rdi,%rbx > u64 time, delta; > > - if (!likely(tsk->mm)) > + if (unlikely(tsk->mm)) Are you sure this is equivalent? Pavel > 18: 4c 8d ab 28 02 00 00 lea 0x228(%rbx),%r13 > 1f: e8 00 00 00 00 callq 24 <__acct_update_integrals+0x24> > 20: R_X86_64_PLT32 __sanitizer_cov_trace_pc-0x4 > 24: 4c 89 ef mov %r13,%rdi > 27: e8 00 00 00 00 callq 2c <__acct_update_integrals+0x2c> > 28: R_X86_64_PLT32 __asan_load8_noabort-0x4 > - 2c: 4c 8b bb 28 02 00 00 mov 0x228(%rbx),%r15 > - 33: 4d 85 ff test %r15,%r15 > - 36: 74 34 je 6c <__acct_update_integrals+0x6c> > + 2c: 48 83 bb 28 02 00 00 cmpq $0x0,0x228(%rbx) > + 33: 00 > + 34: 75 34 jne 6a <__acct_update_integrals+0x6a> > return; > > And here's a possible equivalent checkpatch test. > --- > scripts/checkpatch.pl | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index 287fe73688f0..364603ad1a47 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -6529,6 +6529,24 @@ sub process { > "Using $1 should generally have parentheses around the comparison\n" . $herecurr); > } > > +# !(likely|unlikely)(condition) use should be (unlikely|likely)(condition) > + if ($perl_version_ok && > + $line =~ /(\!\s*((?:un)?likely))\s*$balanced_parens/) { > + my $match = $1; > + my $type = $2; > + my $reverse; > + if ($type eq "likely") { > + $reverse = "unlikely"; > + } else { > + $reverse = "likely"; > + } > + if (WARN("LIKELY_MISUSE", > + "Prefer $reverse over $match\n" . $herecurr) && > + $fix) { > + $fixed[$fixlinenr] =~ s/\Q$match\E\s*\(/$reverse(/; > + } > + } > + > # whine mightly about in_atomic > if ($line =~ /\bin_atomic\s*\(/) { > if ($realfile =~ m@^drivers/@) { > -- (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html