2010/5/1 Kostik Belousov <kostik...@gmail.com>: > On Sat, May 01, 2010 at 04:47:36PM +0200, Attilio Rao wrote: >> 2010/5/1 Konstantin Belousov <k...@freebsd.org>: >> > Author: kib >> > Date: Sat May 1 14:46:17 2010 >> > New Revision: 207468 >> > URL: http://svn.freebsd.org/changeset/base/207468 >> > >> > Log: >> > Extract thread_lock()/ruxagg()/thread_unlock() fragment into utility >> > function ruxagg_tlock(). >> > Convert the definition of kern_getrusage() to ANSI C. >> > >> >> I would have preferred a different naming for this, as the well known >> _locked version we have of many functions. > > But this is not the case there, because I did not renamed ruxagg(). > It would be ruxagg()->ruxagg_unlocked() and ruxagg_tlock()->ruxagg().
Yes, this is exactly what I wanted to happen. > My biggest question with the patch is I am not sure whether to apply > the same checks for tu in calctru() as it is done for tu in calcru1(). > Any suggestions ? I think that the checks may be present (the process-scope one is just an aggregate of the threads' one, thus the same conditions apply. > diff --git a/lib/libc/sys/getrusage.2 b/lib/libc/sys/getrusage.2 > index bdf5d45..423503f 100644 > --- a/lib/libc/sys/getrusage.2 > +++ b/lib/libc/sys/getrusage.2 > @@ -28,7 +28,7 @@ > .\" @(#)getrusage.2 8.1 (Berkeley) 6/4/93 > .\" $FreeBSD$ > .\" > -.Dd June 4, 1993 > +.Dd May 1, 2010 > .Dt GETRUSAGE 2 > .Os > .Sh NAME > @@ -42,6 +42,7 @@ > .In sys/resource.h > .Fd "#define RUSAGE_SELF 0" > .Fd "#define RUSAGE_CHILDREN -1" > +.Fd "#define RUSAGE_THREAD 1" > .Ft int > .Fn getrusage "int who" "struct rusage *rusage" > .Sh DESCRIPTION > @@ -49,11 +50,12 @@ The > .Fn getrusage > system call > returns information describing the resources utilized by the current > -process, or all its terminated child processes. > +thread, the current process, or all its terminated child processes. > The > .Fa who > argument is either > -.Dv RUSAGE_SELF > +.Dv RUSAGE_THREAD , > +.Dv RUSAGE_SELF , > or > .Dv RUSAGE_CHILDREN . > The buffer to which > @@ -175,6 +177,10 @@ The > .Fn getrusage > system call appeared in > .Bx 4.2 . > +The > +.Dv RUSAGE_THREAD > +facility first appeared in > +.Fx 8.1 . > .Sh BUGS > There is no way to obtain information about a child process > that has not yet terminated. > diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c > index a3ed75d..8e7fdb6 100644 > --- a/sys/kern/kern_resource.c > +++ b/sys/kern/kern_resource.c > @@ -921,6 +921,31 @@ calcru1(struct proc *p, struct rusage_ext *ruxp, struct > timeval *up, > sp->tv_usec = su % 1000000; > } > > +static void > +calctru(struct thread *td) > +{ > + /* {user, system, interrupt, total} {ticks, usec}: */ > + u_int64_t ut, uu, st, su, it, tt, tu; > + > + tu = cputick2usec(td->td_incruntime); > + ut = td->td_uticks; > + it = td->td_iticks; > + st = td->td_sticks; > + > + tt = ut + st + it; > + if (tt == 0) { > + /* Avoid divide by zero */ > + st = 1; > + tt = 1; > + } > + uu = td->td_ru.ru_utime.tv_usec + (ut * tu) / tt; > + su = td->td_ru.ru_stime.tv_usec + (st * tu) / tt; > + td->td_ru.ru_utime.tv_sec += uu / 1000000; > + td->td_ru.ru_utime.tv_usec = uu % 1000000; > + td->td_ru.ru_stime.tv_sec += su / 1000000; > + td->td_ru.ru_stime.tv_usec = su % 1000000; > +} > + > #ifndef _SYS_SYSPROTO_H_ > struct getrusage_args { > int who; The comment on the top of calctru() might be removed. > @@ -961,6 +986,13 @@ kern_getrusage(struct thread *td, int who, struct rusage > *rup) > calccru(p, &rup->ru_utime, &rup->ru_stime); > break; > > + case RUSAGE_THREAD: > + PROC_SLOCK(p); > + ruxagg_tlock(p, td); > + PROC_SUNLOCK(p); > + *rup = td->td_ru; > + break; > + > default: > error = EINVAL; > } > @@ -1010,6 +1042,12 @@ ruxagg(struct rusage_ext *rux, struct thread *td) > rux->rux_uticks += td->td_uticks; > rux->rux_sticks += td->td_sticks; > rux->rux_iticks += td->td_iticks; > + > + /* > + * Update thread rusage before ticks counters cleaning. > + */ > + calctru(td); > + > td->td_incruntime = 0; > td->td_uticks = 0; > td->td_iticks = 0; The comment might be single-line and the extra white line after calctru() is not due. Thanks, Attilio -- Peace can only be achieved by understanding - A. Einstein _______________________________________________ svn-src-head@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"