On Mon, 11 Nov 2002, Linus Torvalds wrote:
> I disagree with the implementation of this (and yes, I would also prefer
> for it to be called "jiffies64_to_clock_t()"):
I'm fine with the name "jiffies_64_to_clock_t()".
I'd like "jiffies64_to_clock_t()" (without the first underscore)
even more, but this is inconsistent with jiffies_64. (And I don't know if
we want to rename the latter now)
> This is wrong. You should really start off by fixing the 32-bit case,
> since even that needs fixing anyway (some interfaces really _are_
> 32-bit, and cannot be expanded).
> It also only works for cases where HZ is a direct multiple of USER_HZ,
> and yes, my original code has the same problem, but that's not a good
> excuse to make it worse. I think it should be fairly straightforward to
> get this right, and have a simple
OK, changed my patch to
+#if (HZ % USER_HZ)==0
# define jiffies_to_clock_t(x) ((x) / (HZ / USER_HZ))
+# define jiffies_to_clock_t(x) ((clock_t) jiffies_64_to_clock_t((u64) x))
+static inline u64 jiffies_64_to_clock_t(u64 x)
+#if (HZ % USER_HZ)==0
+ do_div(x, HZ / USER_HZ);
+ * There are better ways that don't overflow early,
+ * but even this doesn't overflow in hundreds of years
+ * in 64 bits, so..
+ x *= USER_HZ;
+ do_div(x, HZ);
+ return x;
I'll send the full new set of patches off-list. They can also be retrieved
(2/4: fix uptime wrap)
(3/4: 64 bit process start time)
(4/4: use unsigned long for cpu statistics)
> (And yes, the above does not return a clock_t, it returns a 64-bit
> thing, but people who need to can truncate it to clock_t and live with
> the old 497-day overflow of USER_HZ in 32 bits for broken interfaces
> like "clock()". This way the caller can use the same function for both
> the "true 64-bit result" and the truncated case).
Hey, this is just why I renamed it from "jiffies_64_to_clock_t()" to
"jiffies_64_to_user_HZ()" before sending it off :-)
> And then we should just remove the "jiffies_to_clock_t()" thing, I
> suspect. The 49-day overflow is just too soon for comfort, you're
> definitely right about that.
OK, will prepare patch for that later.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to email@example.com
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Fri Nov 15 2002 - 22:00:25 EST