Re: [PATCH] Re: boot time, process start time, and NOW time

From: Albert Cahalan
Date: Tue Aug 17 2004 - 19:54:13 EST


On Tue, 2004-08-17 at 20:11, john stultz wrote:

> --- 1.62/fs/proc/array.c 2004-08-05 13:36:53 -07:00
> +++ edited/fs/proc/array.c 2004-08-17 17:08:07 -07:00
> @@ -356,7 +356,14 @@
> read_unlock(&tasklist_lock);
>
> /* Temporary variable needed for gcc-2.96 */
> - start_time = jiffies_64_to_clock_t(task->start_time - INITIAL_JIFFIES);
> + /* convert timespec -> nsec*/
> + start_time = (unsigned long long)task->start_time.tv_sec * NSEC_PER_SEC
> + + task->start_time.tv_nsec;
> + /* convert nsec -> ticks */
> + start_time *= HZ;
> + do_div(start_time, NSEC_PER_SEC);
> + /* convert ticks -> USER_HZ ticks */
> + start_time = jiffies_64_to_clock_t(start_time);

This would overflow in about 6 months at 1024 USER_HZ.
Various possible alternatives:

// 6 months to overflow at 1024 USER_HZ
value = ns64 * USER_HZ / BILLION;

// 2 years to overflow at 1024 USER_HZ
// (assuming USER_HZ is always divisible by 4)
value = ns64 * (USER_HZ/4) / (BILLION/4);

// faster, and never overflows (for 100, 128, 1000)
#if ! (BILLION % USER_HZ)
value = ns64 / (BILLION/USER_HZ);
#endif

// 256 years to overflow (for 1024)
#if ! (USER_HZ % 512)
value = ns64 * (USER_HZ/512) / (BILLION/512);
#endif


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/