Date: Sat, 1 May 2010 18:13:39 +0300 From: Kostik Belousov <kostikbel@gmail.com> To: Attilio Rao <attilio@freebsd.org> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r207468 - head/sys/kern Message-ID: <20100501151339.GZ2391@deviant.kiev.zoral.com.ua> In-Reply-To: <AANLkTin7fGpDpQPfAp0o599b4wc6KpJw_a3qwC4taWbG@mail.gmail.com> References: <201005011446.o41EkIa6051907@svn.freebsd.org> <AANLkTin7fGpDpQPfAp0o599b4wc6KpJw_a3qwC4taWbG@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--5FDiZl1vRbLRjwwc Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, May 01, 2010 at 04:47:36PM +0200, Attilio Rao wrote: > 2010/5/1 Konstantin Belousov <kib@freebsd.org>: > > Author: kib > > Date: Sat May =9A1 14:46:17 2010 > > New Revision: 207468 > > URL: http://svn.freebsd.org/changeset/base/207468 > > > > Log: > > =9AExtract thread_lock()/ruxagg()/thread_unlock() fragment into utility > > =9Afunction ruxagg_tlock(). > > =9AConvert the definition of kern_getrusage() to ANSI C. > > >=20 > 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(). I think it is better to keep existing interface of ruxagg() under the same name. Would you be interested in looking at the real patch that implements RUSAGE_THREAD ? 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 ? 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, struc= t timeval *up, sp->tv_usec =3D su % 1000000; } =20 +static void +calctru(struct thread *td) +{ + /* {user, system, interrupt, total} {ticks, usec}: */ + u_int64_t ut, uu, st, su, it, tt, tu; + + tu =3D cputick2usec(td->td_incruntime); + ut =3D td->td_uticks; + it =3D td->td_iticks; + st =3D td->td_sticks; + + tt =3D ut + st + it; + if (tt =3D=3D 0) { + /* Avoid divide by zero */ + st =3D 1; + tt =3D 1; + } + uu =3D td->td_ru.ru_utime.tv_usec + (ut * tu) / tt; + su =3D td->td_ru.ru_stime.tv_usec + (st * tu) / tt; + td->td_ru.ru_utime.tv_sec +=3D uu / 1000000; + td->td_ru.ru_utime.tv_usec =3D uu % 1000000; + td->td_ru.ru_stime.tv_sec +=3D su / 1000000; + td->td_ru.ru_stime.tv_usec =3D su % 1000000; +} + #ifndef _SYS_SYSPROTO_H_ struct getrusage_args { int who; @@ -961,6 +986,13 @@ kern_getrusage(struct thread *td, int who, struct rusa= ge *rup) calccru(p, &rup->ru_utime, &rup->ru_stime); break; =20 + case RUSAGE_THREAD: + PROC_SLOCK(p); + ruxagg_tlock(p, td); + PROC_SUNLOCK(p); + *rup =3D td->td_ru; + break; + default: error =3D EINVAL; } @@ -1010,6 +1042,12 @@ ruxagg(struct rusage_ext *rux, struct thread *td) rux->rux_uticks +=3D td->td_uticks; rux->rux_sticks +=3D td->td_sticks; rux->rux_iticks +=3D td->td_iticks; + + /* + * Update thread rusage before ticks counters cleaning. + */ + calctru(td); + td->td_incruntime =3D 0; td->td_uticks =3D 0; td->td_iticks =3D 0; diff --git a/sys/sys/resource.h b/sys/sys/resource.h index 9af96af..e703744 100644 --- a/sys/sys/resource.h +++ b/sys/sys/resource.h @@ -56,6 +56,7 @@ =20 #define RUSAGE_SELF 0 #define RUSAGE_CHILDREN -1 +#define RUSAGE_THREAD 1 =20 struct rusage { struct timeval ru_utime; /* user time used */ --5FDiZl1vRbLRjwwc Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (FreeBSD) iEYEARECAAYFAkvcRSMACgkQC3+MBN1Mb4gaJgCfcFfnsXx/02CVW6aIagvi1iyr OUoAmwRdIi7b9TNhd7m1vXQc5N1KeDMV =Egi5 -----END PGP SIGNATURE----- --5FDiZl1vRbLRjwwc--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100501151339.GZ2391>