Date: Sun, 18 Jul 2010 19:20:17 GMT From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 181150 for review Message-ID: <201007181920.o6IJKHs5098432@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 } /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007181920.o6IJKHs5098432>