From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422719AbdEZKUs (ORCPT ); Fri, 26 May 2017 06:20:48 -0400 Received: from smtprelay0021.hostedemail.com ([216.40.44.21]:51031 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1761823AbdEZKUq (ORCPT ); Fri, 26 May 2017 06:20:46 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::,RULES_HIT:41:69:355:379:421: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:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3865:3867:3868:3870:3871:4321:4470:5007:6119:7875:10004:10400:10848:11026:11232:11473:11658:11914:12043:12296:12555:12740:12760:12895:13161:13229:13439:14096:14097:14181:14659:14721:21080:21433:21451:21627:30012:30054:30064:30070:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: cat92_32fae818f753 X-Filterd-Recvd-Size: 3187 Message-ID: <1495794020.29207.26.camel@perches.com> Subject: Re: [PATCH] ktime: Simplify ktime_* comparison functions From: Joe Perches To: Mariusz Skamra , linux-kernel@vger.kernel.org Cc: tglx@linutronix.de Date: Fri, 26 May 2017 03:20:20 -0700 In-Reply-To: <1495793358-4593-1-git-send-email-mariuszx.skamra@intel.com> References: <1495793358-4593-1-git-send-email-mariuszx.skamra@intel.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 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 On Fri, 2017-05-26 at 12:09 +0200, Mariusz Skamra wrote: > This simplifies ktime_compare, ktime_after and ktime_before to be defines. > ktime_compare verified on x86_64 machine, gives a code 4 asm instruction > less compared to the previous solution. Time measured is up to 2 times less. > Signed-off-by: Mariusz Skamra > Acked-by: Kuppuswamy Sathyanarayanan > --- > include/linux/ktime.h | 19 +++---------------- > 1 file changed, 3 insertions(+), 16 deletions(-) > > diff --git a/include/linux/ktime.h b/include/linux/ktime.h > index 0c8bd45..3f3dfcd 100644 > --- a/include/linux/ktime.h > +++ b/include/linux/ktime.h > @@ -106,14 +106,7 @@ static inline ktime_t timeval_to_ktime(struct timeval tv) > * cmp1 == cmp2: return 0 > * cmp1 > cmp2: return >0 > */ > -static inline int ktime_compare(const ktime_t cmp1, const ktime_t cmp2) > -{ > - if (cmp1 < cmp2) > - return -1; > - if (cmp1 > cmp2) > - return 1; > - return 0; > -} > +#define ktime_compare(cmp1, cmp2) ktime_sub(cmp1, cmp2) Why not just change ktime_compare to static inline int ktime_compare(const ktime_t cmp1, const ktime_t cmp2) { return ktime_sub(cmp1, cmp2); } > > /** > * ktime_after - Compare if a ktime_t value is bigger than another one. > @@ -122,10 +115,7 @@ static inline int ktime_compare(const ktime_t cmp1, const ktime_t cmp2) > * > * Return: true if cmp1 happened after cmp2. > */ > -static inline bool ktime_after(const ktime_t cmp1, const ktime_t cmp2) > -{ > - return ktime_compare(cmp1, cmp2) > 0; > -} > +#define ktime_after(cmp1, cmp2) (ktime_compare(cmp1, cmp2) > 0) The ktime_after and ktime_before changes shouldn't matter in generated objects. I suggest these conversions from static inline to #define are not changes for the better. > /** > * ktime_before - Compare if a ktime_t value is smaller than another one. > @@ -134,10 +124,7 @@ static inline bool ktime_after(const ktime_t cmp1, const ktime_t cmp2) > * > * Return: true if cmp1 happened before cmp2. > */ > -static inline bool ktime_before(const ktime_t cmp1, const ktime_t cmp2) > -{ > - return ktime_compare(cmp1, cmp2) < 0; > -} > +#define ktime_before(cmp1, cmp2) (ktime_compare(cmp1, cmp2) < 0) > > #if BITS_PER_LONG < 64 > extern s64 __ktime_divns(const ktime_t kt, s64 div);