mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Nicholas Mc Guire <hofrat@osadl.org>
Cc: Michal Marek <mmarek@suse.cz>,
	Masahiro Yamada <yamada.m@jp.panasonic.com>,
	Sam Ravnborg <sam@ravnborg.org>, "H. Peter Alvin" <hpa@zytor.com>,
	Joe Perches <joe@perches.com>,
	John Stultz <john.stultz@linaro.org>,
	Andrew Hunter <ahh@google.com>, Paul Turner <pjt@google.com>,
	Aaron Sierra <asierra@xes-inc.com>,
	Brian Norris <computersforpeace@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3 V2] time: allow gcc to fold constants when using
Date: Wed, 22 Apr 2015 14:00:07 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.11.1504221356340.13914@nanos> (raw)
In-Reply-To: <1428840815-21974-3-git-send-email-hofrat@osadl.org>

On Sun, 12 Apr 2015, Nicholas Mc Guire wrote:
> +extern unsigned long __msecs_to_jiffies(const unsigned int m);
> +#if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
> +static inline unsigned long _msecs_to_jiffies(const unsigned int m)
> +{

This should move the comments explaining the logic for each variant as
well.

> +		return (m + (MSEC_PER_SEC / HZ) - 1) / (MSEC_PER_SEC / HZ);
> +}
> +#elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
> +static inline unsigned long _msecs_to_jiffies(const unsigned int m)
> +{
> +		if (m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
> +			return MAX_JIFFY_OFFSET;
> +		return m * (HZ / MSEC_PER_SEC);
> +}
> +#else
> +static inline unsigned long _msecs_to_jiffies(const unsigned int m)
> +{
> +		if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
> +			return MAX_JIFFY_OFFSET;
> +
> +		return (MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32)
> +			>> MSEC_TO_HZ_SHR32;
> +}
> +#endif
> +static inline unsigned long msecs_to_jiffies(const unsigned int m)
> +{
> +	if (__builtin_constant_p(m)) {
> +		if ((int)m < 0)
> +			return MAX_JIFFY_OFFSET;
> +		return _msecs_to_jiffies(m);
> +	} else
> +		return __msecs_to_jiffies(m);

It'd be nice to have this as two patches:

1) Factor out the code into inline helpers w/o adding anything

2) Add the __builtin_constant_p() check

Thanks,

	tglx

  reply	other threads:[~2015-04-22 12:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-12 12:13 [PATCH 0/3 V2] time: use __builtin_constant_p() in msecs_to_jiffies Nicholas Mc Guire
2015-04-12 12:13 ` [PATCH 1/3 V2] time: move timeconst.h into include/generated Nicholas Mc Guire
2015-04-12 21:35   ` Rob Landley
2015-04-12 12:13 ` [PATCH 2/3 V2] time: allow gcc to fold constants when using Nicholas Mc Guire
2015-04-22 12:00   ` Thomas Gleixner [this message]
2015-04-22 14:18     ` Joe Perches
2015-04-22 15:12       ` Nicholas Mc Guire
2015-04-22 14:36     ` Nicholas Mc Guire
2015-04-22 14:44       ` Thomas Gleixner
2015-04-12 12:13 ` [PATCH 3/3 V2] time: update msecs_to_jiffies doc and move to kernel-doc Nicholas Mc Guire

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=alpine.DEB.2.11.1504221356340.13914@nanos \
    --to=tglx@linutronix.de \
    --cc=ahh@google.com \
    --cc=asierra@xes-inc.com \
    --cc=computersforpeace@gmail.com \
    --cc=hofrat@osadl.org \
    --cc=hpa@zytor.com \
    --cc=joe@perches.com \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mmarek@suse.cz \
    --cc=pjt@google.com \
    --cc=sam@ravnborg.org \
    --cc=yamada.m@jp.panasonic.com \
    /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

all inboxes | Powered by JetHome®