mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sridhar Samudrala <sri@us.ibm.com>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: Edgar Toernig <froese@gmx.de>,
	davem@redhat.com, linux-kernel@vger.kernel.org,
	netdev@oss.sgi.com
Subject: Re: [PATCH] Consolidate multiple implementations of jiffies-msecs conversions.
Date: Mon, 29 Mar 2004 11:57:54 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.58.0403291137360.23386@localhost.localdomain> (raw)
In-Reply-To: <40647E65.7020903@pobox.com>

On Fri, 26 Mar 2004, Jeff Garzik wrote:

> Sridhar Samudrala wrote:
> > On Fri, 26 Mar 2004, Edgar Toernig wrote:
> >
> >
> >>Sridhar Samudrala wrote:
> >>
> >>>The following patch to 2.6.5-rc2 consolidates 6 different implementations
> >>>of msecs to jiffies and 3 different implementation of jiffies to msecs.
> >>>All of them now use the generic msecs_to_jiffies() and jiffies_to_msecs()
> >>>that are added to include/linux/time.h
> >>>[...]
> >>>-#define MSECS(ms)  (((ms)*HZ/1000)+1)
> >>>-return (((ms)*HZ+999)/1000);
> >>>+return (msecs / 1000) * HZ + (msecs % 1000) * HZ / 1000;
> >>
> >>Did you check that all users of the new version will work correctly
> >>with your rounding?  Explicit round-up of delays is often required,
> >>especially when talking to hardware...
> >
> >
> > I don't see any issues with the 2.6 default HZ value of 1000 as they become
> > no-ops and there is no need for any rounding.
> > I guess you are referring to cases when HZ < 1000(ex: 100) and msecs is
> > less than 10. In those cases, the new version returns 0, whereas some of the
> > older versions return 1.
>
> We'll definitely want to return 1 rather than zero, for the uses in my
> drivers, at least...

I have modified msecs_to_jiffies() to do the proper rounding when HZ=100.
Do these work better?

static inline unsigned long msecs_to_jiffies(unsigned long msecs)
{
#if 1000 % HZ == 0
        return (msecs + ((1000 / HZ) - 1)) / (1000 / HZ);
#elif HZ % 1000 == 0
        return msecs * (HZ / 1000);
#else
        return (msecs / 1000) * HZ + (msecs % 1000) * HZ / 1000;
#endif
}

static inline unsigned long jiffies_to_msecs(unsigned long jiffs)
{
#if 1000 % HZ == 0
        return jiffs * (1000 / HZ);
#elif HZ % 1000 == 0
        return jiffs / (HZ / 1000);
#else
        return (jiffs / HZ) * 1000 + (jiffs % HZ) * 1000 / HZ;
#endif
}

Thanks
Sridhar

  reply	other threads:[~2004-03-29 20:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-25 20:17 Sridhar Samudrala
2004-03-25 20:32 ` David S. Miller
2004-03-25 20:36   ` Jeff Garzik
2004-03-25 21:05 ` Bill Rugolsky Jr.
2004-03-25 23:49   ` Sridhar Samudrala
2004-03-26  0:44 ` Edgar Toernig
2004-03-26 18:49   ` Sridhar Samudrala
2004-03-26 19:03     ` Jeff Garzik
2004-03-29 19:57       ` Sridhar Samudrala [this message]
2004-03-26 20:45     ` Edgar Toernig

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=Pine.LNX.4.58.0403291137360.23386@localhost.localdomain \
    --to=sri@us.ibm.com \
    --cc=davem@redhat.com \
    --cc=froese@gmx.de \
    --cc=jgarzik@pobox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@oss.sgi.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®