2008-02-15 02:27:27

by Jonathan Lim

[permalink] [raw]
Subject: [PATCH] Provide u64 version of jiffies_to_usecs() in kernel/tsacct.c

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/torvalds/linux-2.6.git

Signed-off-by: Jonathan Lim <[email protected]>

--- a/include/linux/jiffies.h Thu Feb 14 18:04:14 PST 2008
+++ b/include/linux/jiffies.h Thu Feb 14 18:07:17 PST 2008
@@ -42,7 +42,7 @@
/* LATCH is used in the interval timer and ftape setup. */
#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */

-/* Suppose we want to devide two numbers NOM and DEN: NOM/DEN, then we can
+/* Suppose we want to divide two numbers NOM and DEN: NOM/DEN, then we can
* improve accuracy by shifting LSH bits, hence calculating:
* (NOM << LSH) / DEN
* This however means trouble for large NOM, because (NOM << LSH) may no
@@ -204,7 +204,7 @@ extern unsigned long preset_lpj;
* operator if the result is a long long AND at least one of the
* operands is cast to long long (usually just prior to the "*" so as
* not to confuse it into thinking it really has a 64-bit operand,
- * which, buy the way, it can do, but it takes more code and at least 2
+ * which, by the way, it can do, but it takes more code and at least 2
* mpys).

* We also need to be aware that one second in nanoseconds is only a
@@ -269,6 +269,7 @@ extern unsigned long preset_lpj;
*/
extern unsigned int jiffies_to_msecs(const unsigned long j);
extern unsigned int jiffies_to_usecs(const unsigned long j);
+extern u64 jiffies_64_to_usecs(const u64 j);
extern unsigned long msecs_to_jiffies(const unsigned int m);
extern unsigned long usecs_to_jiffies(const unsigned int u);
extern unsigned long timespec_to_jiffies(const struct timespec *value);
--- a/kernel/time.c Thu Feb 14 18:05:12 PST 2008
+++ b/kernel/time.c Thu Feb 14 18:08:08 PST 2008
@@ -268,6 +268,12 @@ unsigned int inline jiffies_to_usecs(con
}
EXPORT_SYMBOL(jiffies_to_usecs);

+u64 jiffies_64_to_usecs(const u64 j)
+{
+ return (j*HZ_TO_USEC_NUM + HZ_TO_USEC_DEN-1) / HZ_TO_USEC_DEN;
+}
+EXPORT_SYMBOL(jiffies_64_to_usecs);
+
/**
* timespec_trunc - Truncate timespec to a granularity
* @t: Timespec
--- a/kernel/tsacct.c Thu Feb 14 18:06:17 PST 2008
+++ b/kernel/tsacct.c Thu Feb 14 18:08:47 PST 2008
@@ -85,8 +85,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_64_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
+ stats->virtmem = jiffies_64_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
mm = get_task_mm(p);
if (mm) {
/* adjust to KB unit */


2008-02-19 20:52:19

by Jonathan Lim

[permalink] [raw]
Subject: Re: [PATCH] Provide u64 version of jiffies_to_usecs() in kernel/tsacct.c

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/torvalds/linux-2.6.git

Signed-off-by: Jonathan Lim <[email protected]>

--- a/include/linux/jiffies.h Thu Feb 14 18:04:14 PST 2008
+++ b/include/linux/jiffies.h Thu Feb 14 18:07:17 PST 2008
@@ -42,7 +42,7 @@
/* LATCH is used in the interval timer and ftape setup. */
#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */

-/* Suppose we want to devide two numbers NOM and DEN: NOM/DEN, then we can
+/* Suppose we want to divide two numbers NOM and DEN: NOM/DEN, then we can
* improve accuracy by shifting LSH bits, hence calculating:
* (NOM << LSH) / DEN
* This however means trouble for large NOM, because (NOM << LSH) may no
@@ -204,7 +204,7 @@ extern unsigned long preset_lpj;
* operator if the result is a long long AND at least one of the
* operands is cast to long long (usually just prior to the "*" so as
* not to confuse it into thinking it really has a 64-bit operand,
- * which, buy the way, it can do, but it takes more code and at least 2
+ * which, by the way, it can do, but it takes more code and at least 2
* mpys).

* We also need to be aware that one second in nanoseconds is only a
@@ -269,6 +269,7 @@ extern unsigned long preset_lpj;
*/
extern unsigned int jiffies_to_msecs(const unsigned long j);
extern unsigned int jiffies_to_usecs(const unsigned long j);
+extern u64 jiffies_64_to_usecs(const u64 j);
extern unsigned long msecs_to_jiffies(const unsigned int m);
extern unsigned long usecs_to_jiffies(const unsigned int u);
extern unsigned long timespec_to_jiffies(const struct timespec *value);
--- a/kernel/time.c Thu Feb 14 18:05:12 PST 2008
+++ b/kernel/time.c Tue Feb 19 12:44:03 PST 2008
@@ -268,6 +268,14 @@ unsigned int inline jiffies_to_usecs(con
}
EXPORT_SYMBOL(jiffies_to_usecs);

+u64 inline jiffies_64_to_usecs(const u64 j)
+{
+ u64 tmp = j*HZ_TO_USEC_NUM + HZ_TO_USEC_DEN-1;
+ do_div(tmp, HZ_TO_USEC_DEN);
+ return tmp;
+}
+EXPORT_SYMBOL(jiffies_64_to_usecs);
+
/**
* timespec_trunc - Truncate timespec to a granularity
* @t: Timespec
--- a/kernel/tsacct.c Thu Feb 14 18:06:17 PST 2008
+++ b/kernel/tsacct.c Thu Feb 14 18:08:47 PST 2008
@@ -85,8 +85,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_64_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
+ stats->virtmem = jiffies_64_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
mm = get_task_mm(p);
if (mm) {
/* adjust to KB unit */

2008-02-19 21:26:42

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] Provide u64 version of jiffies_to_usecs() in kernel/tsacct.c

On Tue, 19 Feb 2008 12:52:46 -0800 (PST) Jonathan Lim 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/torvalds/linux-2.6.git
>
> Signed-off-by: Jonathan Lim <[email protected]>
>
> --- a/include/linux/jiffies.h Thu Feb 14 18:04:14 PST 2008
> +++ b/include/linux/jiffies.h Thu Feb 14 18:07:17 PST 2008
> @@ -42,7 +42,7 @@
> /* LATCH is used in the interval timer and ftape setup. */
> #define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */
>
> -/* Suppose we want to devide two numbers NOM and DEN: NOM/DEN, then we can
> +/* Suppose we want to divide two numbers NOM and DEN: NOM/DEN, then we can
> * improve accuracy by shifting LSH bits, hence calculating:
> * (NOM << LSH) / DEN
> * This however means trouble for large NOM, because (NOM << LSH) may no
> @@ -204,7 +204,7 @@ extern unsigned long preset_lpj;
> * operator if the result is a long long AND at least one of the
> * operands is cast to long long (usually just prior to the "*" so as
> * not to confuse it into thinking it really has a 64-bit operand,
> - * which, buy the way, it can do, but it takes more code and at least 2
> + * which, by the way, it can do, but it takes more code and at least 2
> * mpys).
>
> * We also need to be aware that one second in nanoseconds is only a
> @@ -269,6 +269,7 @@ extern unsigned long preset_lpj;
> */
> extern unsigned int jiffies_to_msecs(const unsigned long j);
> extern unsigned int jiffies_to_usecs(const unsigned long j);
> +extern u64 jiffies_64_to_usecs(const u64 j);
> extern unsigned long msecs_to_jiffies(const unsigned int m);
> extern unsigned long usecs_to_jiffies(const unsigned int u);
> extern unsigned long timespec_to_jiffies(const struct timespec *value);
> --- a/kernel/time.c Thu Feb 14 18:05:12 PST 2008
> +++ b/kernel/time.c Tue Feb 19 12:44:03 PST 2008
> @@ -268,6 +268,14 @@ unsigned int inline jiffies_to_usecs(con
> }
> EXPORT_SYMBOL(jiffies_to_usecs);
>
> +u64 inline jiffies_64_to_usecs(const u64 j)
> +{
> + u64 tmp = j*HZ_TO_USEC_NUM + HZ_TO_USEC_DEN-1;
> + do_div(tmp, HZ_TO_USEC_DEN);

do_div() is:
* The semantics of do_div() are:
*
* uint32_t do_div(uint64_t *n, uint32_t base)

Maybe you want div64_64().

> + return tmp;
> +}
> +EXPORT_SYMBOL(jiffies_64_to_usecs);
> +
> /**
> * timespec_trunc - Truncate timespec to a granularity
> * @t: Timespec
> --- a/kernel/tsacct.c Thu Feb 14 18:06:17 PST 2008
> +++ b/kernel/tsacct.c Thu Feb 14 18:08:47 PST 2008
> @@ -85,8 +85,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_64_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
> + stats->virtmem = jiffies_64_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
> mm = get_task_mm(p);
> if (mm) {
> /* adjust to KB unit */
> --


---
~Randy

2008-02-19 21:59:15

by Jonathan Lim

[permalink] [raw]
Subject: Re: [PATCH] Provide u64 version of jiffies_to_usecs() in

On Tue Feb 19 13:25:25 2008, [email protected] wrote:
>
> > +u64 inline jiffies_64_to_usecs(const u64 j)
> > +{
> > + u64 tmp = j*HZ_TO_USEC_NUM + HZ_TO_USEC_DEN-1;
> > + do_div(tmp, HZ_TO_USEC_DEN);
>
> do_div() is:
> * The semantics of do_div() are:
> *
> * uint32_t do_div(uint64_t *n, uint32_t base)
>
> Maybe you want div64_64().
>
> > + return tmp;
> > +}
> > +EXPORT_SYMBOL(jiffies_64_to_usecs);
> > +

In include/asm-generic/div64.h, div64_64(uint64_t dividend, uint64_t divisor)
just returns (dividend / divisor). Isn't this the same as what I had before
in jiffies_64_to_usecs(), except that the arguments are of type u64?

Jonathan

2008-02-19 22:15:58

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] Provide u64 version of jiffies_to_usecs() in

On Tue, 19 Feb 2008 13:59:27 -0800 (PST) Jonathan Lim wrote:

> On Tue Feb 19 13:25:25 2008, [email protected] wrote:
> >
> > > +u64 inline jiffies_64_to_usecs(const u64 j)
> > > +{
> > > + u64 tmp = j*HZ_TO_USEC_NUM + HZ_TO_USEC_DEN-1;
> > > + do_div(tmp, HZ_TO_USEC_DEN);
> >
> > do_div() is:
> > * The semantics of do_div() are:
> > *
> > * uint32_t do_div(uint64_t *n, uint32_t base)
> >
> > Maybe you want div64_64().
> >
> > > + return tmp;
> > > +}
> > > +EXPORT_SYMBOL(jiffies_64_to_usecs);
> > > +
>
> In include/asm-generic/div64.h, div64_64(uint64_t dividend, uint64_t divisor)
> just returns (dividend / divisor). Isn't this the same as what I had before
> in jiffies_64_to_usecs(), except that the arguments are of type u64?

but the (linker) problem is with X86_32, so don't look at
asm-generic/div64.h. Look at lib/div64.c.

Or use div64() with the correct parameter types.

---
~Randy

2008-02-20 02:16:35

by Jonathan Lim

[permalink] [raw]
Subject: Re: [PATCH] Provide u64 version of jiffies_to_usecs() in kernel/tsacct.c

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.

This version implements a correction to jiffies_64_to_usecs() based on feedback
from Randy Dunlap.

Diff'd against: linux/kernel/git/torvalds/linux-2.6.git

Signed-off-by: Jonathan Lim <[email protected]>

--- a/include/linux/jiffies.h Thu Feb 14 18:04:14 PST 2008
+++ b/include/linux/jiffies.h Thu Feb 14 18:07:17 PST 2008
@@ -42,7 +42,7 @@
/* LATCH is used in the interval timer and ftape setup. */
#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */

-/* Suppose we want to devide two numbers NOM and DEN: NOM/DEN, then we can
+/* Suppose we want to divide two numbers NOM and DEN: NOM/DEN, then we can
* improve accuracy by shifting LSH bits, hence calculating:
* (NOM << LSH) / DEN
* This however means trouble for large NOM, because (NOM << LSH) may no
@@ -204,7 +204,7 @@ extern unsigned long preset_lpj;
* operator if the result is a long long AND at least one of the
* operands is cast to long long (usually just prior to the "*" so as
* not to confuse it into thinking it really has a 64-bit operand,
- * which, buy the way, it can do, but it takes more code and at least 2
+ * which, by the way, it can do, but it takes more code and at least 2
* mpys).

* We also need to be aware that one second in nanoseconds is only a
@@ -269,6 +269,7 @@ extern unsigned long preset_lpj;
*/
extern unsigned int jiffies_to_msecs(const unsigned long j);
extern unsigned int jiffies_to_usecs(const unsigned long j);
+extern u64 jiffies_64_to_usecs(const u64 j);
extern unsigned long msecs_to_jiffies(const unsigned int m);
extern unsigned long usecs_to_jiffies(const unsigned int u);
extern unsigned long timespec_to_jiffies(const struct timespec *value);
--- a/kernel/time.c Thu Feb 14 18:05:12 PST 2008
+++ b/kernel/time.c Tue Feb 19 17:00:11 PST 2008
@@ -268,6 +268,12 @@ unsigned int inline jiffies_to_usecs(con
}
EXPORT_SYMBOL(jiffies_to_usecs);

+u64 jiffies_64_to_usecs(const u64 j)
+{
+ return div64_64(j*HZ_TO_USEC_NUM + HZ_TO_USEC_DEN-1, HZ_TO_USEC_DEN);
+}
+EXPORT_SYMBOL(jiffies_64_to_usecs);
+
/**
* timespec_trunc - Truncate timespec to a granularity
* @t: Timespec
--- a/kernel/tsacct.c Thu Feb 14 18:06:17 PST 2008
+++ b/kernel/tsacct.c Thu Feb 14 18:08:47 PST 2008
@@ -85,8 +85,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_64_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
+ stats->virtmem = jiffies_64_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
mm = get_task_mm(p);
if (mm) {
/* adjust to KB unit */

2008-02-20 03:53:18

by Randy Dunlap

[permalink] [raw]
Subject: Re: [PATCH] Provide u64 version of jiffies_to_usecs() in kernel/tsacct.c

Jonathan Lim 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.
>
> This version implements a correction to jiffies_64_to_usecs() based on feedback
> from Randy Dunlap.
>
> Diff'd against: linux/kernel/git/torvalds/linux-2.6.git
>
> Signed-off-by: Jonathan Lim <[email protected]>
>
> --- a/include/linux/jiffies.h Thu Feb 14 18:04:14 PST 2008
> +++ b/include/linux/jiffies.h Thu Feb 14 18:07:17 PST 2008
> @@ -42,7 +42,7 @@
> /* LATCH is used in the interval timer and ftape setup. */
> #define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */
>
> -/* Suppose we want to devide two numbers NOM and DEN: NOM/DEN, then we can
> +/* Suppose we want to divide two numbers NOM and DEN: NOM/DEN, then we can
> * improve accuracy by shifting LSH bits, hence calculating:
> * (NOM << LSH) / DEN
> * This however means trouble for large NOM, because (NOM << LSH) may no
> @@ -204,7 +204,7 @@ extern unsigned long preset_lpj;
> * operator if the result is a long long AND at least one of the
> * operands is cast to long long (usually just prior to the "*" so as
> * not to confuse it into thinking it really has a 64-bit operand,
> - * which, buy the way, it can do, but it takes more code and at least 2
> + * which, by the way, it can do, but it takes more code and at least 2
> * mpys).
>
> * We also need to be aware that one second in nanoseconds is only a
> @@ -269,6 +269,7 @@ extern unsigned long preset_lpj;
> */
> extern unsigned int jiffies_to_msecs(const unsigned long j);
> extern unsigned int jiffies_to_usecs(const unsigned long j);
> +extern u64 jiffies_64_to_usecs(const u64 j);
> extern unsigned long msecs_to_jiffies(const unsigned int m);
> extern unsigned long usecs_to_jiffies(const unsigned int u);
> extern unsigned long timespec_to_jiffies(const struct timespec *value);
> --- a/kernel/time.c Thu Feb 14 18:05:12 PST 2008
> +++ b/kernel/time.c Tue Feb 19 17:00:11 PST 2008

kernel/time.c needs:
#include <asm/div64.h>

After that, it's
Acked-by: Randy Dunlap <[email protected]>

> @@ -268,6 +268,12 @@ unsigned int inline jiffies_to_usecs(con
> }
> EXPORT_SYMBOL(jiffies_to_usecs);
>
> +u64 jiffies_64_to_usecs(const u64 j)
> +{
> + return div64_64(j*HZ_TO_USEC_NUM + HZ_TO_USEC_DEN-1, HZ_TO_USEC_DEN);
> +}
> +EXPORT_SYMBOL(jiffies_64_to_usecs);
> +
> /**
> * timespec_trunc - Truncate timespec to a granularity
> * @t: Timespec
> --- a/kernel/tsacct.c Thu Feb 14 18:06:17 PST 2008
> +++ b/kernel/tsacct.c Thu Feb 14 18:08:47 PST 2008
> @@ -85,8 +85,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_64_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
> + stats->virtmem = jiffies_64_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
> mm = get_task_mm(p);
> if (mm) {
> /* adjust to KB unit */


--
~Randy

2008-02-25 22:27:32

by Jonathan Lim

[permalink] [raw]
Subject: Re: [PATCH] Provide u64 version of jiffies_to_usecs() in kernel/tsacct.c

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.

This version implements a correction to jiffies_64_to_usecs() based on feedback
from Randy Dunlap.

Diff'd against: linux/kernel/git/torvalds/linux-2.6.git

Signed-off-by: Jonathan Lim <[email protected]>

--- a/include/linux/jiffies.h Thu Feb 14 18:04:14 PST 2008
+++ b/include/linux/jiffies.h Thu Feb 14 18:07:17 PST 2008
@@ -42,7 +42,7 @@
/* LATCH is used in the interval timer and ftape setup. */
#define LATCH ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */

-/* Suppose we want to devide two numbers NOM and DEN: NOM/DEN, then we can
+/* Suppose we want to divide two numbers NOM and DEN: NOM/DEN, then we can
* improve accuracy by shifting LSH bits, hence calculating:
* (NOM << LSH) / DEN
* This however means trouble for large NOM, because (NOM << LSH) may no
@@ -204,7 +204,7 @@ extern unsigned long preset_lpj;
* operator if the result is a long long AND at least one of the
* operands is cast to long long (usually just prior to the "*" so as
* not to confuse it into thinking it really has a 64-bit operand,
- * which, buy the way, it can do, but it takes more code and at least 2
+ * which, by the way, it can do, but it takes more code and at least 2
* mpys).

* We also need to be aware that one second in nanoseconds is only a
@@ -269,6 +269,7 @@ extern unsigned long preset_lpj;
*/
extern unsigned int jiffies_to_msecs(const unsigned long j);
extern unsigned int jiffies_to_usecs(const unsigned long j);
+extern u64 jiffies_64_to_usecs(const u64 j);
extern unsigned long msecs_to_jiffies(const unsigned int m);
extern unsigned long usecs_to_jiffies(const unsigned int u);
extern unsigned long timespec_to_jiffies(const struct timespec *value);
--- a/kernel/time.c Thu Feb 14 18:05:12 PST 2008
+++ b/kernel/time.c Mon Feb 25 14:22:27 PST 2008
@@ -38,6 +38,7 @@

#include <asm/uaccess.h>
#include <asm/unistd.h>
+#include <asm/div64.h>

#include "timeconst.h"

@@ -267,6 +268,12 @@ unsigned int inline jiffies_to_usecs(con
#endif
}
EXPORT_SYMBOL(jiffies_to_usecs);
+
+u64 jiffies_64_to_usecs(const u64 j)
+{
+ return div64_64(j*HZ_TO_USEC_NUM + HZ_TO_USEC_DEN-1, HZ_TO_USEC_DEN);
+}
+EXPORT_SYMBOL(jiffies_64_to_usecs);

/**
* timespec_trunc - Truncate timespec to a granularity
--- a/kernel/tsacct.c Thu Feb 14 18:06:17 PST 2008
+++ b/kernel/tsacct.c Thu Feb 14 18:08:47 PST 2008
@@ -85,8 +85,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_64_to_usecs(p->acct_rss_mem1) * PAGE_SIZE / MB;
+ stats->virtmem = jiffies_64_to_usecs(p->acct_vm_mem1) * PAGE_SIZE / MB;
mm = get_task_mm(p);
if (mm) {
/* adjust to KB unit */

2008-03-12 23:53:41

by Roman Zippel

[permalink] [raw]
Subject: Re: [PATCH] Provide u64 version of jiffies_to_usecs() in kernel/tsacct.c

Hi,

On Monday 25. February 2008, Jonathan Lim wrote:

> +u64 jiffies_64_to_usecs(const u64 j)
> +{
> + return div64_64(j*HZ_TO_USEC_NUM + HZ_TO_USEC_DEN-1, HZ_TO_USEC_DEN);
> +}
> +EXPORT_SYMBOL(jiffies_64_to_usecs);

Please also adapt the "BITS_PER_LONG == 32" part from jiffies_to_usecs(), it
should provide enough resolution to avoid the div64_64() here.

bye, Roman