public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nishanth Aravamudan <nacc@us.ibm.com>
To: Pavel Machek <pavel@ucw.cz>
Cc: Dave Hansen <haveblue@us.ibm.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs
Date: Sat, 16 Jul 2005 17:44:27 -0700	[thread overview]
Message-ID: <20050717004427.GB5865@us.ibm.com> (raw)
In-Reply-To: <20050715121424.GA1775@elf.ucw.cz>

On 15.07.2005 [14:14:25 +0200], Pavel Machek wrote:
> Hi!
> 
> > > > +static inline u64 jiffies_to_nsecs(const unsigned long j)
> > > > +{
> > > > +#if HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ)
> > > > +	return (NSEC_PER_SEC / HZ) * (u64)j;
> > > > +#elif HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC)
> > > > +	return ((u64)j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
> > > > +#else
> > > > +	return ((u64)j * NSEC_PER_SEC) / HZ;
> > > > +#endif
> > > > +}
> > > 
> > > That might look a little better something like:
> > > 
> > > static inline u64 jiffies_to_nsecs(const unsigned long __j)
> > > {
> > > 	u64 j = __j;
> > > 
> > > 	if (HZ <= NSEC_PER_SEC && !(NSEC_PER_SEC % HZ))
> > > 		return (NSEC_PER_SEC / HZ) * j;
> > > 	else if (HZ > NSEC_PER_SEC && !(HZ % NSEC_PER_SEC))
> > > 		return (j + (HZ / NSEC_PER_SEC) - 1)/(HZ / NSEC_PER_SEC);
> > > 	else
> > > 		return (j * NSEC_PER_SEC) / HZ;
> > > }
> > > 
> > > Compilers are smart :)
> > 
> > Well, I was trying to keep it similar to the other conversion functions.
> > I guess the compiler can evaluate the conditional full of constants at
> > compile-time regardless of whether it is #if or if ().
> > 
> > I can make these changes if others would like them as well.
> 
> Yes, please. And feel free to convert nearby functions, too ;-).

I have a patch to make this change for all the jiffies <--> human-time
functions, but have a problem. I noticed that these functions, in the
if/else form (as opposed to #if/#else) will warn about division-by-zero
problems, as (HZ / MSEC_PER_SEC), (HZ / USEC_PER_SEC) & (HZ /
NSEC_PER_SEC) are all 0 if HZ < 1000 (which, of course, is the default
now :) ). Any suggestions? Just leave the functions as is? Even then,
I'm going to update this patch to use USEC_PER_SEC and MSEC_PER_SEC in
the other conversion functions like I use NSEC_PER_SEC in the first
version.

Thanks,
Nish

  reply	other threads:[~2005-07-17  0:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-14 20:26 [RFC][PATCH 0/4] new human-time soft-timer subsystem Nishanth Aravamudan
2005-07-14 20:28 ` [RFC][PATCH 1/4] add jiffies_to_nsecs() helper and fix up size of usecs Nishanth Aravamudan
2005-07-14 20:54   ` Dave Hansen
2005-07-14 21:03     ` Nishanth Aravamudan
2005-07-15 12:14       ` Pavel Machek
2005-07-17  0:44         ` Nishanth Aravamudan [this message]
2005-07-14 20:40 ` [RFC][PATCH 2/4] human-time soft-timer core changes Nishanth Aravamudan
2005-07-18 21:53   ` [RFC][UPDATE PATCH " Nishanth Aravamudan
2005-07-14 20:41 ` [RFC][PATCH 3/4] new human-time schedule_timeout() functions Nishanth Aravamudan
2005-07-14 20:43 ` [RFC][PATCH 4/4] convert sys_nanosleep() to use set_timer_nsecs() Nishanth Aravamudan
2005-07-14 22:28 ` [RFC][PATCH 0/4] new human-time soft-timer subsystem Roman Zippel
2005-07-17  0:53   ` Nishanth Aravamudan

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=20050717004427.GB5865@us.ibm.com \
    --to=nacc@us.ibm.com \
    --cc=haveblue@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /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