The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Mariusz Skamra <mariuszx.skamra@intel.com>, linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de
Subject: Re: [PATCH] ktime: Simplify ktime_* comparison functions
Date: Fri, 26 May 2017 03:20:20 -0700	[thread overview]
Message-ID: <1495794020.29207.26.camel@perches.com> (raw)
In-Reply-To: <1495793358-4593-1-git-send-email-mariuszx.skamra@intel.com>

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 <mariuszx.skamra@intel.com>
> Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@intel.com>
> ---
>  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);

  reply	other threads:[~2017-05-26 10:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-26 10:09 [PATCH] ktime: Simplify ktime_* comparison functions Mariusz Skamra
2017-05-26 10:20 ` Joe Perches [this message]
2017-05-26 10:31 ` Thomas Gleixner

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=1495794020.29207.26.camel@perches.com \
    --to=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mariuszx.skamra@intel.com \
    --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