From: "H. Peter Anvin" <hpa@zytor.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jonathan Lim <jlim@sgi.com>, linux-kernel@vger.kernel.org, jlan@sgi.com
Subject: Re: [PATCH] Provide u64 version of jiffies_to_usecs() in kernel/tsacct.c
Date: Wed, 02 Jan 2008 16:36:47 -0800 [thread overview]
Message-ID: <477C2E1F.2040307@zytor.com> (raw)
In-Reply-To: <20080102162338.c67769af.akpm@linux-foundation.org>
Andrew Morton wrote:
> On Fri, 28 Dec 2007 13:26:07 -0800 (PST) Jonathan Lim <jlim@sgi.com> wrote:
>
>> It's possible that the values used in and returned from jiffies_to_usecs() are
>> incorrect because of truncation when variables of type u64 are involved. So a
>> function specific to that type is used instead.
>>
>> Diff'd against: linux/kernel/git/stable/linux-2.6.23.y.git
>>
>> Signed-off-by: Jonathan Lim <jlim@sgi.com>
>>
>> --- a/kernel/tsacct.c 2007-12-28 11:58:05.182065029 -0800
>> +++ b/kernel/tsacct.c 2007-12-28 11:57:37.949013675 -0800
>> @@ -71,6 +71,17 @@ void bacct_add_tsk(struct taskstats *sta
>>
>> #ifdef CONFIG_TASK_XACCT
>>
>> +static inline u64 jiffies_to_usecs_u64(const u64 j)
>> +{
>> +#if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
>> + return (USEC_PER_SEC / HZ) * j;
>> +#elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
>> + return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC);
>> +#else
>> + return (j * USEC_PER_SEC) / HZ;
>> +#endif
>> +}
>> +
>> #define KB 1024
>> #define MB (1024*KB)
>> /*
>> @@ -81,8 +92,8 @@ void xacct_add_tsk(struct taskstats *sta
>> struct mm_struct *mm;
>>
>> /* convert pages-jiffies to Mbyte-usec */
>> - stats->coremem = jiffies_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
>> - stats->virtmem = jiffies_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
>> + stats->coremem = jiffies_to_usecs_u64(p->acct_rss_mem1) * PAGE_SIZE / MB;
>> + stats->virtmem = jiffies_to_usecs_u64(p->acct_vm_mem1) * PAGE_SIZE / MB;
>> mm = get_task_mm(p);
>> if (mm) {
>> /* adjust to KB unit */
>
> Fair enough. But I guess that new function should be a kernel-wide thing
> because surely other users will turn up.
>
> Peter has been working on the accuracy of some of these conversion
> functions and might need to know about this change?
Yes, the function should be coded using the new #defines produced by
timeconst.h; that way you end up avoiding a possible overflow in the
multiplication.
I believe all three cases can be folded, then, to:
return (j*HZ_TO_USEC_NUM + HZ_TO_USEC_DEN-1) / HZ_TO_USEC_DEN;
I would also like to observe that the roundoff behaviour of the function
above is inconsistent; in case 2 it will round up, but in case 3 it
will round down. The line proposed above has round up behaviour.
-hpa
next prev parent reply other threads:[~2008-01-03 0:37 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <200801022103.m02L3oL1051764@sabah.engr.sgi.com>
2008-01-03 0:23 ` [PATCH] Provide u64 version of jiffies_to_usecs() in kernel/tsacct.c Andrew Morton
2008-01-03 0:36 ` H. Peter Anvin [this message]
2008-01-03 1:06 ` Jonathan Lim
2008-01-03 1:13 ` H. Peter Anvin
2008-02-15 2:27 Jonathan Lim
[not found] <no.id>
2008-01-08 1:04 ` Jonathan Lim
2008-02-19 20:52 ` Jonathan Lim
2008-02-19 21:25 ` Randy Dunlap
2008-02-20 2:17 ` Jonathan Lim
2008-02-20 3:52 ` Randy Dunlap
2008-02-25 22:27 ` Jonathan Lim
2008-03-12 23:53 ` Roman Zippel
2008-04-18 21:54 ` Jonathan Lim
-- strict thread matches above, loose matches on Subject: below --
2007-12-28 21:26 Jonathan Lim
2007-12-29 4:52 ` H. Peter Anvin
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=477C2E1F.2040307@zytor.com \
--to=hpa@zytor.com \
--cc=akpm@linux-foundation.org \
--cc=jlan@sgi.com \
--cc=jlim@sgi.com \
--cc=linux-kernel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).