public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: George Anzinger <george@mvista.com>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Roland McGrath <roland@redhat.com>,
	Hugh Dickins <hugh@veritas.com>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	Andrew Morton <akpm@osdl.org>,
	Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] cputime.h seems to assume HZ==1000
Date: Wed, 19 Jan 2005 16:18:03 -0800	[thread overview]
Message-ID: <41EEF8BB.1000302@mvista.com> (raw)
In-Reply-To: <Pine.LNX.4.58.0501171840560.8178@ppc970.osdl.org>

Linus Torvalds wrote:
> 
> On Mon, 17 Jan 2005, Roland McGrath wrote:
> 
>>Shouldn't msecs mean msecs, not secs/HZ?
> 
> 
> Hmm, sure, but why go through "msecs" at all?
> 
> 
>>--- linux-2.6/include/asm-generic/cputime.h
>>+++ linux-2.6/include/asm-generic/cputime.h
>>@@ -35,8 +35,8 @@ typedef u64 cputime64_t;
>> /*
>>  * Convert cputime to seconds and back.
>>  */
>>-#define cputime_to_secs(__ct)		(jiffies_to_msecs(__ct) / HZ)
>>-#define secs_to_cputime(__secs)		(msecs_to_jiffies(__secs * HZ))
>>+#define cputime_to_secs(__ct)		(jiffies_to_msecs(__ct) / 1000)
>>+#define secs_to_cputime(__secs)		(msecs_to_jiffies(__secs * 1000))
> 
> 
> iow, why not
> 
> 	#define cputime_to_secs(jif)	((jif) / HZ)
> 	#define secs_to_cputime(sec)	((sec) * HZ)
> 
> which avoids double rounding issues etc.

If we care, the jiffies_to_msecs() code is in include/linux/jiffies.h just prior 
to other conversion code that does NOT make the assumtion that HZ is exact.  To 
be exact:

static inline long cputime_to_secs(unsigned long jif)
{
	int t;
	u64 result = (u64)jif * TICK_NSEC;
	t = do_div(result ,NSEC_PER_SEC);
	return (u32)result + t ? 1:0;      /* round up if not exact */
}
#define secs_to_cputime(sec) (((U64) sec * SEC_CONVERSION) >> SEC_JIFFIE_SC)

This last assumes sec worth of jiffies will actually fit in a long...

-- 
George Anzinger   george@mvista.com
High-res-timers:  http://sourceforge.net/projects/high-res-timers/


      reply	other threads:[~2005-01-20  0:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-18  1:57 [PATCH] cputime.h seems to assume HZ==1000 Roland McGrath
2005-01-18  2:46 ` Linus Torvalds
2005-01-20  0:18   ` George Anzinger [this message]

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=41EEF8BB.1000302@mvista.com \
    --to=george@mvista.com \
    --cc=akpm@osdl.org \
    --cc=hugh@veritas.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@redhat.com \
    --cc=schwidefsky@de.ibm.com \
    --cc=torvalds@osdl.org \
    /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