Messages in this thread | | | Subject | Re: [PATCH] Re: boot time, process start time, and NOW time | From | Albert Cahalan <> | Date | 17 Aug 2004 18:45:54 -0400 |
| |
On Tue, 2004-08-17 at 21:09, john stultz wrote: > On Tue, 2004-08-17 at 15:19, Albert Cahalan wrote: > > 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: > > Everybody sing: Thanks, nice catch/Here's an updated patch! > > -john > > ===== fs/proc/array.c 1.62 vs edited ===== > --- 1.62/fs/proc/array.c 2004-08-05 13:36:53 -07:00 > +++ edited/fs/proc/array.c 2004-08-17 18:03:55 -07:00 > @@ -356,7 +356,13 @@ > 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 */ > + do_div(start_time, NSEC_PER_SEC/HZ); > + /* convert ticks -> USER_HZ ticks */ > + start_time = jiffies_64_to_clock_t(start_time);
NSEC_PER_SEC/HZ isn't an integer when HZ is 1024. Also, you're doing two conversions. You can go directly from nanoseconds to USER_HZ, without using HZ at all.
I think you really need the #if for this. It could go in a header if you like, creating a timespec_to_clock_t macro for use in proc.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |