From owner-p4-projects@FreeBSD.ORG Sun Jul 18 19:20:18 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 17FA71065677; Sun, 18 Jul 2010 19:20:18 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CF7441065675 for ; Sun, 18 Jul 2010 19:20:17 +0000 (UTC) (envelope-from trasz@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id BC98E8FC1D for ; Sun, 18 Jul 2010 19:20:17 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id o6IJKH7x098434 for ; Sun, 18 Jul 2010 19:20:17 GMT (envelope-from trasz@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id o6IJKHs5098432 for perforce@freebsd.org; Sun, 18 Jul 2010 19:20:17 GMT (envelope-from trasz@freebsd.org) Date: Sun, 18 Jul 2010 19:20:17 GMT Message-Id: <201007181920.o6IJKHs5098432@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to trasz@freebsd.org using -f From: Edward Tomasz Napierala To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 181150 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 Jul 2010 19:20:18 -0000 http://p4web.freebsd.org/@@181150?ac=10 Change 181150 by trasz@trasz_victim on 2010/07/18 19:19:38 Fix CPU time accounting. Previous version accounted only for processes with CPU time limit set. Affected files ... .. //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#42 edit Differences ... ==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_resource.c#42 (text+ko) ==== @@ -81,6 +81,10 @@ static struct uidinfo *uilookup(uid_t uid); static void ruxagg_locked(struct rusage_ext *rux, struct thread *td); +#ifdef CONTAINERS +struct callout rusage_cpu_callout; +#endif + /* * Resource controls and accounting. */ @@ -616,16 +620,33 @@ return (error); } +#ifdef CONTAINERS +static void +rusage_cpu_update(void *arg) +{ + struct thread *td; + struct proc *p; + + FOREACH_PROC_IN_SYSTEM(p) { + PROC_SLOCK(p); + FOREACH_THREAD_IN_PROC(p, td) { + ruxagg(p, td); + } + PROC_SUNLOCK(p); + rusage_set(p, RUSAGE_CPU, p->p_rux.rux_runtime / cpu_tickrate()); + } + + callout_reset(&rusage_cpu_callout, hz, rusage_cpu_update, NULL); +} +#endif + +#ifndef CONTAINERS static void lim_cb(void *arg) { struct thread *td; struct proc *p; -#ifdef CONTAINERS - int error; -#else struct rlimit rlim; -#endif p = arg; PROC_LOCK_ASSERT(p, MA_OWNED); @@ -640,10 +661,6 @@ ruxagg(p, td); } PROC_SUNLOCK(p); -#ifdef CONTAINERS - error = rusage_set(p, RUSAGE_CPU, p->p_rux.rux_runtime / cpu_tickrate()); - KASSERT(error == 0, ("rusage_set(p, RUSAGE_CPU, ...) returned error")); -#else if (p->p_rux.rux_runtime > p->p_cpulimit * cpu_tickrate()) { lim_rlimit(p, RLIMIT_CPU, &rlim); if (p->p_rux.rux_runtime >= rlim.rlim_max * cpu_tickrate()) { @@ -654,10 +671,10 @@ psignal(p, SIGXCPU); } } -#endif if ((p->p_flag & P_WEXIT) == 0) callout_reset(&p->p_limco, hz, lim_cb, p); } +#endif /* !CONTAINERS */ #ifdef HRL static void @@ -810,12 +827,14 @@ switch (which) { +#ifndef CONTAINERS case RLIMIT_CPU: if (limp->rlim_cur != RLIM_INFINITY && p->p_cpulimit == RLIM_INFINITY) callout_reset(&p->p_limco, hz, lim_cb, p); p->p_cpulimit = limp->rlim_cur; break; +#endif case RLIMIT_DATA: if (limp->rlim_cur > maxdsiz) limp->rlim_cur = maxdsiz; @@ -1224,8 +1243,10 @@ { p2->p_limit = lim_hold(p1->p_limit); callout_init_mtx(&p2->p_limco, &p2->p_mtx, 0); +#ifndef CONTAINERS if (p1->p_cpulimit != RLIM_INFINITY) callout_reset(&p2->p_limco, hz, lim_cb, p2); +#endif } void @@ -1304,6 +1325,15 @@ uihashtbl = hashinit(maxproc / 16, M_UIDINFO, &uihash); rw_init(&uihashtbl_lock, "uidinfo hash"); + +#ifdef CONTAINERS + /* + * XXX: Piggybacked for now; in the future it should have + * it's own function. + */ + callout_init(&rusage_cpu_callout, 1); + callout_reset(&rusage_cpu_callout, hz, rusage_cpu_update, NULL); +#endif } /*