From owner-svn-src-stable@FreeBSD.ORG Tue May 11 13:18:42 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5ACBA106578F; Tue, 11 May 2010 13:18:42 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [69.147.83.44]) by mx1.freebsd.org (Postfix) with ESMTP id 4A6FB8FC20; Tue, 11 May 2010 13:18:42 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o4BDIgPx091703; Tue, 11 May 2010 13:18:42 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o4BDIgRb091693; Tue, 11 May 2010 13:18:42 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201005111318.o4BDIgRb091693@svn.freebsd.org> From: Konstantin Belousov Date: Tue, 11 May 2010 13:18:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r207916 - in stable/8/sys: kern sys X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2010 13:18:42 -0000 Author: kib Date: Tue May 11 13:18:41 2010 New Revision: 207916 URL: http://svn.freebsd.org/changeset/base/207916 Log: MFC r207468: Extract thread_lock()/ruxagg()/thread_unlock() fragment into utility function ruxagg_tlock(). Convert the definition of kern_getrusage() to ANSI C. MFC r207602: Implement RUSAGE_THREAD. Add td_rux to keep extended runtime and ticks information for thread to allow calcru1() (re)use. Rename ruxagg()->ruxagg_locked(), ruxagg_tlock()->ruxagg() [1]. The ruxagg_locked() function no longer clears thread ticks nor td_incruntime. Not an MFC: the td_rux is added to the end of struct thread to keep the KBI. Explicit bzero() of td_rux is added to new thread initialization points. Modified: stable/8/sys/kern/kern_fork.c stable/8/sys/kern/kern_kthread.c stable/8/sys/kern/kern_resource.c stable/8/sys/kern/kern_thr.c stable/8/sys/kern/kern_thread.c stable/8/sys/sys/proc.h stable/8/sys/sys/resource.h stable/8/sys/sys/resourcevar.h Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) stable/8/sys/geom/sched/ (props changed) Modified: stable/8/sys/kern/kern_fork.c ============================================================================== --- stable/8/sys/kern/kern_fork.c Tue May 11 12:07:40 2010 (r207915) +++ stable/8/sys/kern/kern_fork.c Tue May 11 13:18:41 2010 (r207916) @@ -531,6 +531,7 @@ again: bzero(&td2->td_startzero, __rangeof(struct thread, td_startzero, td_endzero)); + bzero(&td2->td_rux, sizeof(td2->td_rux)); bcopy(&td->td_startcopy, &td2->td_startcopy, __rangeof(struct thread, td_startcopy, td_endcopy)); Modified: stable/8/sys/kern/kern_kthread.c ============================================================================== --- stable/8/sys/kern/kern_kthread.c Tue May 11 12:07:40 2010 (r207915) +++ stable/8/sys/kern/kern_kthread.c Tue May 11 13:18:41 2010 (r207916) @@ -262,6 +262,7 @@ kthread_add(void (*func)(void *), void * bzero(&newtd->td_startzero, __rangeof(struct thread, td_startzero, td_endzero)); + bzero(&newtd->td_rux, sizeof(newtd->td_rux)); /* XXX check if we should zero. */ bcopy(&oldtd->td_startcopy, &newtd->td_startcopy, __rangeof(struct thread, td_startcopy, td_endcopy)); Modified: stable/8/sys/kern/kern_resource.c ============================================================================== --- stable/8/sys/kern/kern_resource.c Tue May 11 12:07:40 2010 (r207915) +++ stable/8/sys/kern/kern_resource.c Tue May 11 13:18:41 2010 (r207916) @@ -76,6 +76,7 @@ static void calcru1(struct proc *p, stru struct timeval *up, struct timeval *sp); static int donice(struct thread *td, struct proc *chgp, int n); static struct uidinfo *uilookup(uid_t uid); +static void ruxagg(struct proc *p, struct thread *td); /* * Resource controls and accounting. @@ -629,9 +630,7 @@ lim_cb(void *arg) return; PROC_SLOCK(p); FOREACH_THREAD_IN_PROC(p, td) { - thread_lock(td); - ruxagg(&p->p_rux, td); - thread_unlock(td); + ruxagg(p, td); } PROC_SUNLOCK(p); if (p->p_rux.rux_runtime > p->p_cpulimit * cpu_tickrate()) { @@ -842,9 +841,7 @@ calcru(struct proc *p, struct timeval *u FOREACH_THREAD_IN_PROC(p, td) { if (td->td_incruntime == 0) continue; - thread_lock(td); - ruxagg(&p->p_rux, td); - thread_unlock(td); + ruxagg(p, td); } calcru1(p, &p->p_rux, up, sp); } @@ -945,10 +942,7 @@ getrusage(td, uap) } int -kern_getrusage(td, who, rup) - struct thread *td; - int who; - struct rusage *rup; +kern_getrusage(struct thread *td, int who, struct rusage *rup) { struct proc *p; int error; @@ -967,6 +961,16 @@ kern_getrusage(td, who, rup) calccru(p, &rup->ru_utime, &rup->ru_stime); break; + case RUSAGE_THREAD: + PROC_SLOCK(p); + ruxagg(p, td); + PROC_SUNLOCK(p); + thread_lock(td); + *rup = td->td_ru; + calcru1(p, &td->td_rux, &rup->ru_utime, &rup->ru_stime); + thread_unlock(td); + break; + default: error = EINVAL; } @@ -1007,7 +1011,7 @@ ruadd(struct rusage *ru, struct rusage_e * Aggregate tick counts into the proc's rusage_ext. */ void -ruxagg(struct rusage_ext *rux, struct thread *td) +ruxagg_locked(struct rusage_ext *rux, struct thread *td) { THREAD_LOCK_ASSERT(td, MA_OWNED); @@ -1016,10 +1020,20 @@ ruxagg(struct rusage_ext *rux, struct th rux->rux_uticks += td->td_uticks; rux->rux_sticks += td->td_sticks; rux->rux_iticks += td->td_iticks; +} + +static void +ruxagg(struct proc *p, struct thread *td) +{ + + thread_lock(td); + ruxagg_locked(&p->p_rux, td); + ruxagg_locked(&td->td_rux, td); td->td_incruntime = 0; td->td_uticks = 0; td->td_iticks = 0; td->td_sticks = 0; + thread_unlock(td); } /* @@ -1036,9 +1050,7 @@ rufetch(struct proc *p, struct rusage *r *ru = p->p_ru; if (p->p_numthreads > 0) { FOREACH_THREAD_IN_PROC(p, td) { - thread_lock(td); - ruxagg(&p->p_rux, td); - thread_unlock(td); + ruxagg(p, td); rucollect(ru, &td->td_ru); } } Modified: stable/8/sys/kern/kern_thr.c ============================================================================== --- stable/8/sys/kern/kern_thr.c Tue May 11 12:07:40 2010 (r207915) +++ stable/8/sys/kern/kern_thr.c Tue May 11 13:18:41 2010 (r207916) @@ -199,6 +199,7 @@ create_thread(struct thread *td, mcontex bzero(&newtd->td_startzero, __rangeof(struct thread, td_startzero, td_endzero)); + bzero(&newtd->td_rux, sizeof(newtd->td_rux)); bcopy(&td->td_startcopy, &newtd->td_startcopy, __rangeof(struct thread, td_startcopy, td_endcopy)); newtd->td_proc = td->td_proc; Modified: stable/8/sys/kern/kern_thread.c ============================================================================== --- stable/8/sys/kern/kern_thread.c Tue May 11 12:07:40 2010 (r207915) +++ stable/8/sys/kern/kern_thread.c Tue May 11 13:18:41 2010 (r207916) @@ -432,7 +432,7 @@ thread_exit(void) PROC_UNLOCK(p); thread_lock(td); /* Save our tick information with both the thread and proc locked */ - ruxagg(&p->p_rux, td); + ruxagg_locked(&p->p_rux, td); PROC_SUNLOCK(p); td->td_state = TDS_INACTIVE; #ifdef WITNESS Modified: stable/8/sys/sys/proc.h ============================================================================== --- stable/8/sys/sys/proc.h Tue May 11 12:07:40 2010 (r207915) +++ stable/8/sys/sys/proc.h Tue May 11 13:18:41 2010 (r207916) @@ -239,7 +239,7 @@ struct thread { u_int td_estcpu; /* (t) estimated cpu utilization */ int td_slptick; /* (t) Time at sleep. */ int td_blktick; /* (t) Time spent blocked. */ - struct rusage td_ru; /* (t) rusage information */ + struct rusage td_ru; /* (t) rusage information. */ uint64_t td_incruntime; /* (t) Cpu ticks to transfer to proc. */ uint64_t td_runtime; /* (t) How many cpu ticks we've run. */ u_int td_pticks; /* (t) Statclock hits for profiling */ @@ -302,6 +302,7 @@ struct thread { int td_errno; /* Error returned by last syscall. */ struct vnet *td_vnet; /* (k) Effective vnet. */ const char *td_vnet_lpush; /* (k) Debugging vnet push / pop. */ + struct rusage_ext td_rux; /* (t) Internal rusage information. */ }; struct mtx *thread_lock_block(struct thread *); Modified: stable/8/sys/sys/resource.h ============================================================================== --- stable/8/sys/sys/resource.h Tue May 11 12:07:40 2010 (r207915) +++ stable/8/sys/sys/resource.h Tue May 11 13:18:41 2010 (r207916) @@ -56,6 +56,7 @@ #define RUSAGE_SELF 0 #define RUSAGE_CHILDREN -1 +#define RUSAGE_THREAD 1 struct rusage { struct timeval ru_utime; /* user time used */ Modified: stable/8/sys/sys/resourcevar.h ============================================================================== --- stable/8/sys/sys/resourcevar.h Tue May 11 12:07:40 2010 (r207915) +++ stable/8/sys/sys/resourcevar.h Tue May 11 13:18:41 2010 (r207916) @@ -131,7 +131,7 @@ void rucollect(struct rusage *ru, struc void rufetch(struct proc *p, struct rusage *ru); void rufetchcalc(struct proc *p, struct rusage *ru, struct timeval *up, struct timeval *sp); -void ruxagg(struct rusage_ext *rux, struct thread *td); +void ruxagg_locked(struct rusage_ext *rux, struct thread *td); int suswintr(void *base, int word); struct uidinfo *uifind(uid_t uid);