Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754518AbcLNGL4 (ORCPT ); Wed, 14 Dec 2016 01:11:56 -0500 Received: from smtprelay0169.hostedemail.com ([216.40.44.169]:57288 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750889AbcLNGLy (ORCPT ); Wed, 14 Dec 2016 01:11:54 -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:1605:1711:1730:1747:1777:1792:2393:2553:2559:2562:2693:2828:3138:3139:3140:3141:3142:3622: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:30012: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:1,LUA_SUMMARY:none X-HE-Tag: geese27_7c9e4b224011f X-Filterd-Recvd-Size: 3939 Message-ID: <1481695854.29291.47.camel@perches.com> Subject: Re: [PATCH] doc: add note on usleep_range range From: Joe Perches To: Nicholas Mc Guire Cc: Jani Nikula , 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 22:10:54 -0800 In-Reply-To: <20161214003733.GA14088@osadl.at> References: <1481601523-14004-1-git-send-email-hofrat@osadl.org> <87r35ctcrp.fsf@intel.com> <20161213091912.GA6347@osadl.at> <1481675252.29291.39.camel@perches.com> <20161214003733.GA14088@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: 2766 Lines: 64 On Wed, 2016-12-14 at 00:37 +0000, Nicholas Mc Guire wrote: > On Tue, Dec 13, 2016 at 04:27:32PM -0800, Joe Perches wrote: > > 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); \ > > }) > > > > thanks for that "template" > > > 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. > > > > while compiletime warnings are a way to go I think that an > external tool is more effective than anoying eveyone during > build I don't. Annoying people at build-time is probably _the single most_ effective way to get source code defects fixed.