lkml.org 
[lkml]   [2004]   [Aug]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH] Re: boot time, process start time, and NOW time
From
Date
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/

\
 
 \ /
  Last update: 2005-03-22 14:05    [W:0.118 / U:0.312 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site