From owner-svn-src-all@FreeBSD.ORG Sat May 1 15:13:44 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 25EEC1065672; Sat, 1 May 2010 15:13:44 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 96A318FC19; Sat, 1 May 2010 15:13:43 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id o41FDdxI014413 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 1 May 2010 18:13:39 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id o41FDd2u049562; Sat, 1 May 2010 18:13:39 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id o41FDdCh049561; Sat, 1 May 2010 18:13:39 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sat, 1 May 2010 18:13:39 +0300 From: Kostik Belousov To: Attilio Rao Message-ID: <20100501151339.GZ2391@deviant.kiev.zoral.com.ua> References: <201005011446.o41EkIa6051907@svn.freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="5FDiZl1vRbLRjwwc" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_50, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r207468 - head/sys/kern X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 May 2010 15:13:44 -0000 --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 : > > 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--