Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753413AbcLNA1k (ORCPT ); Tue, 13 Dec 2016 19:27:40 -0500 Received: from smtprelay0033.hostedemail.com ([216.40.44.33]:43288 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751014AbcLNA1i (ORCPT ); Tue, 13 Dec 2016 19:27:38 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2828:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:5007:6119:7903:10004:10400:10848:11026:11232:11473:11658:11914:12043:12296:12438:12663:12740:12760:13439:14181:14659:14721:21080:21433:21434:21451:30051:30054:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: class98_24f53bb3aa339 X-Filterd-Recvd-Size: 3236 Message-ID: <1481675252.29291.39.camel@perches.com> Subject: Re: [PATCH] doc: add note on usleep_range range From: Joe Perches To: Nicholas Mc Guire , Jani Nikula Cc: Nicholas Mc Guire , Thomas Gleixner , Jonathan Corbet , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Dan Carpenter , Julia Lawall Date: Tue, 13 Dec 2016 16:27:32 -0800 In-Reply-To: <20161213091912.GA6347@osadl.at> References: <1481601523-14004-1-git-send-email-hofrat@osadl.org> <87r35ctcrp.fsf@intel.com> <20161213091912.GA6347@osadl.at> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.1-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2153 Lines: 50 a, On Tue, 2016-12-13 at 09:19 +0000, Nicholas Mc Guire wrote: > On Tue, Dec 13, 2016 at 11:10:50AM +0200, Jani Nikula wrote: > > On Tue, 13 Dec 2016, Nicholas Mc Guire wrote: > > > useleep_range() with a delta of 0 makes no sense and only prevents the > > > timer subsystem from optimizing interrupts. As any user of usleep_range() > > > is in non-atomic context the timer jitter is in the range of 10s of > > > microseconds anyway. > > > > > > This adds a note making it clear that a range of 0 is a bad idea. > > > > So I don't really have anything to do with the timer subsystem, I'm just > > their "consumer", so take this with a grain of salt. > > > > Documentation is good, but I don't think this will be enough. > > > > I think the only thing that will work is to detect and complain about > > things like this automatically. Some ideas: > > > > * WARN_ON(min == max) or WARN_ON_ONCE(min == max) in usleep_range() > > might be drastic, but it would get the job done eventually. > > > > * If you want to avoid the runtime overhead (and complaints about the > > backtraces), you could wrap usleep_range() in a macro that does > > BUILD_BUG_ON(min == max) if the parameters are build time constants > > (they usually are). But you'd have to fix all the problem cases first. > > > > * You could try (to persuade Julia or Dan) to come up with a > > cocci/smatch check for usleep_range() calls where min == max, so we > > could get bug reports for this. This probably works on expressions, so > > this would catch also cases where the parameters aren't built timea, > > constants. You could also add a macro for usleep_range like #define usleep_range(a, b) \ ({ \ if (__builtin_constant_p(a) && __builtin_constant_p(b)) { \ if (a == b) \ __compiletime_warning("Better to use usleep_range with different values"); \ else if (a > b) \ __compiletime_error("usleep_range uses smaller value first"); \ } \ usleep_range(a, b); \ }) and add parentheses around the actual function definition for usleep_range in kernel/time/timer.c so the macro works and these messages get emitted at compile-time.