From: Nicholas Mc Guire <hofrat@osadl.org>
To: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: Gilles Muller <Gilles.Muller@lip6.fr>,
Nicolas Palix <nicolas.palix@imag.fr>,
Michal Marek <mmarek@suse.com>,
Thomas Gleixner <tglx@linutronix.de>,
cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org,
Nicholas Mc Guire <hofrat@osadl.org>
Subject: [PATCH] Coccinelle: uslee_range: ensure delta not zero
Date: Tue, 13 Dec 2016 11:23:20 +0100 [thread overview]
Message-ID: <1481624600-29057-1-git-send-email-hofrat@osadl.org> (raw)
usleep_range() min==max makes little sense at last for non-RT, so issue
a warning if delta is 0.
Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---
As of 4.9.0 this finds about 20 cases - all of which look like the
should be passing a range.
Patch is against 4.9.0 (localversion-next is next-20161213)
scripts/coccinelle/api/bad_usleep_range.cocci | 55 +++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
create mode 100644 scripts/coccinelle/api/bad_usleep_range.cocci
diff --git a/scripts/coccinelle/api/bad_usleep_range.cocci b/scripts/coccinelle/api/bad_usleep_range.cocci
new file mode 100644
index 0000000..7e05f3e
--- /dev/null
+++ b/scripts/coccinelle/api/bad_usleep_range.cocci
@@ -0,0 +1,55 @@
+/// bad uslee_range - warn if min == max
+//
+//The problem is that usleep_range is calculating the delay by
+// exp = ktime_add_us(ktime_get(), min)
+// delta = (u64)(max - min) * NSEC_PER_USEC
+//so delta is set to 0 if min==max
+//and then calls
+// schedule_hrtimeout_range(exp, 0,...)
+//effectively this means that the clock subsystem has no room to
+//optimize. usleep_range() is in non-atomic context so a 0 range
+//makes very little sense as the task can be preempted anyway so
+//there is no guarantee that the 0 range would be adding much
+//precision - it just removes optimization potential, so it probably
+//never really makes sense for any non-RT systems.
+//
+//see: Documentation/timers/timers-howto.txt and
+//Link: http://lkml.org/lkml/2016/11/29/54 for some notes on
+// when mdelay might not be a suitable replacement
+//
+// Confidence: Moderate
+// Copyright: (C) 2016 Nicholas Mc Guire, OSADL. GPLv2.
+// Comments:
+// Options: --no-includes --include-headers
+
+virtual org
+virtual report
+
+@nullrange@
+expression E;
+constant C;
+position p;
+@@
+
+<+...
+(
+ usleep_range@p(C,C)
+|
+ usleep_range@p(E,E)
+)
+...+>
+
+
+@script:python depends on org@
+p << nullrange.p;
+range << nullrange.C;
+@@
+
+cocci.print_main("WARNING: inefficient usleep_range with range 0 (min==max)",p)
+
+@script:python depends on report@
+p << nullrange.p;
+@@
+
+coccilib.report.print_report(p[0],"WARNING: inefficient usleep_range with range 0 (min==max)")
+
--
2.1.4
next reply other threads:[~2016-12-13 10:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-13 10:23 Nicholas Mc Guire [this message]
2016-12-13 12:09 ` Julia Lawall
2016-12-13 12:31 ` Nicholas Mc Guire
2016-12-13 15:10 ` Julia Lawall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1481624600-29057-1-git-send-email-hofrat@osadl.org \
--to=hofrat@osadl.org \
--cc=Gilles.Muller@lip6.fr \
--cc=Julia.Lawall@lip6.fr \
--cc=cocci@systeme.lip6.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=mmarek@suse.com \
--cc=nicolas.palix@imag.fr \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®