Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751933AbbDBNLy (ORCPT ); Thu, 2 Apr 2015 09:11:54 -0400 Received: from smtprelay0180.hostedemail.com ([216.40.44.180]:42970 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750828AbbDBNLw (ORCPT ); Thu, 2 Apr 2015 09:11:52 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 40,2.5,0,,d41d8cd98f00b204,joe@perches.com,:::::::::,RULES_HIT:41:355:379:541:599:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2197:2199:2393:2559:2562:2693:2828:2903:3138:3139:3140:3141:3142:3352:3622:3653:3865:3866:3867:3868:3870:3871:3872:3873:3874:4321:4605:5007:6119:6261:7903:8660:10011:10400:10848:11026:11232:11473:11658:11914:12043:12438:12517:12519:12679:12740:13019:13069:13148:13230:13255:13311:13357:14096:14097:21080,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:1:0 X-HE-Tag: bell79_2d1f01a5c6b5f X-Filterd-Recvd-Size: 2173 Message-ID: <1427980306.23434.9.camel@perches.com> Subject: Re: [PATCH RFC] allow constant folding in msecs_to_jiffies where possible for gcc From: Joe Perches To: Nicholas Mc Guire Cc: John Stultz , Thomas Gleixner , Aaron Sierra , linux-kernel@vger.kernel.org Date: Thu, 02 Apr 2015 06:11:46 -0700 In-Reply-To: <1427956634-32109-1-git-send-email-hofrat@osadl.org> References: <1427956634-32109-1-git-send-email-hofrat@osadl.org> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.10-0ubuntu1~14.10.1 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: 1465 Lines: 38 On Thu, 2015-04-02 at 08:37 +0200, Nicholas Mc Guire wrote: > A number of cleanup patches where switching var * HZ / 1000 > constructs to msecs_to_jiffies(var) to ensure that all corener > cases are handled properly. The downside of this though is that > it now uses a function call and also was not performing > constant folding where it was originally possible. > > msecs_to_jiffies() will calculate jiffies even if constants are > passed in that could be handled by constant folding at compile time > using __builtin_constant_p() gcc can optimize the constant case > again. OK, but how could this actually work? This code isn't visible in a module at compile time, so how could the compiler actually optimize the function call away? Look at the disassembly for any object that uses msecs_to_jiffies(). For instance: drivers/bluetooth/hci_vhci.o schedule_delayed_work(&data->open_timeout, msecs_to_jiffies(1000)); 60d: bf e8 03 00 00 mov $0x3e8,%edi 612: e8 00 00 00 00 callq 617 613: R_X86_64_PC32 msecs_to_jiffies-0x4 You need to make this code either a macro or static inline in jiffies.h, and for that the kernel/timeconst.h file needs to be available. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/