PERFORCE change 190232 for review
Edward Tomasz Napierala
trasz at FreeBSD.org
Sat Mar 19 11:04:23 UTC 2011
http://p4web.freebsd.org/@@190232?ac=10
Change 190232 by trasz at trasz_victim on 2011/03/19 11:04:10
Remove pctcpu; not finished and doesn't quite work. Will get back
to it after RCTL gets integrated into 9-CURRENT.
Affected files ...
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#76 edit
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_rctl.c#39 edit
.. //depot/projects/soc2009/trasz_limits/sys/sys/container.h#27 edit
Differences ...
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#76 (text+ko) ====
@@ -110,8 +110,7 @@
[RUSAGE_NSEMOP] = RUSAGE_RECLAIMABLE | RUSAGE_INHERITABLE | RUSAGE_DENIABLE,
[RUSAGE_NSHM] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY,
[RUSAGE_SHMSIZE] = RUSAGE_RECLAIMABLE | RUSAGE_DENIABLE | RUSAGE_SLOPPY,
- [RUSAGE_WALLCLOCK] = RUSAGE_IN_THOUSANDS,
- [RUSAGE_PCTCPU] = RUSAGE_IN_THOUSANDS | RUSAGE_RECLAIMABLE | RUSAGE_DAMPENED };
+ [RUSAGE_WALLCLOCK] = RUSAGE_IN_THOUSANDS };
static void
container_add(struct container *dest, const struct container *src)
@@ -588,7 +587,7 @@
void
container_proc_exit(struct proc *p)
{
- uint64_t runtime, pctcpu;
+ uint64_t runtime;
PROC_LOCK(p);
/*
@@ -601,9 +600,7 @@
if (runtime < p->p_prev_runtime)
runtime = p->p_prev_runtime;
#endif
- pctcpu = (runtime - p->p_prev_runtime) / 10;
rusage_set(p, RUSAGE_CPU, runtime);
- rusage_add(p, RUSAGE_PCTCPU, pctcpu);
/*
* XXX: Free this some other way.
@@ -664,75 +661,15 @@
}
static void
-rusage_throttle(struct proc *p, int throttle)
-{
- struct thread *td;
- u_char oldpri;
- u_char newpri;
- int type;
-
- PROC_LOCK_ASSERT(p, MA_OWNED);
-
- if (throttle) {
- p->p_throttle++;
- newpri = PRI_MIN_IDLE;
- type = RTP_PRIO_IDLE;
- } else if (p->p_throttle > 0) {
- p->p_throttle--;
- newpri = PRI_MIN_TIMESHARE;
- type = RTP_PRIO_NORMAL;
- } else
- return;
-
- FOREACH_THREAD_IN_PROC(p, td) {
- thread_lock(td);
- /* Mostly copied from rtp_to_pri(). */
- sched_class(td, type); /* XXX fix */
- oldpri = td->td_user_pri;
- sched_user_prio(td, newpri);
- if (TD_IS_RUNNING(td) || TD_CAN_RUN(td))
- sched_prio(td, td->td_user_pri); /* XXX dubious */
- if (TD_ON_UPILOCK(td) && oldpri != newpri)
- umtx_pi_adjust(td, oldpri);
- thread_unlock(td);
- }
-}
-
-/*
- * %CPU is special. Each second we zero out RUSAGE_PCTCPU for all
- * the processes and other containers before calculating %CPU. Reason
- * for this is that we also to update %CPU when process exits,
- * and that would cause the %CPU for per-user or per-jail containers
- * to grow indefinitely.
- */
-static void
-container_dampen_callback(struct container *container, void *arg2, void *arg3)
-{
-
- mtx_lock(&container_lock);
- container->c_resources[RUSAGE_PCTCPU] = 0;
- mtx_unlock(&container_lock);
-}
-
-static void
containerd(void)
{
struct thread *td;
struct proc *p;
struct timeval wallclock;
- uint64_t pctcpu, pctcpu_limit, runtime;
+ uint64_t runtime;
for (;;) {
sx_slock(&allproc_lock);
- /*
- * XXX: There is a window between zeroing the stats and setting
- * them to a proper value.
- */
- loginclass_container_foreach(container_dampen_callback, NULL,
- NULL);
- ui_container_foreach(container_dampen_callback, NULL, NULL);
- prison_container_foreach(container_dampen_callback, NULL,
- NULL);
FOREACH_PROC_IN_SYSTEM(p) {
if (p->p_state != PRS_NORMAL)
@@ -742,7 +679,6 @@
microuptime(&wallclock);
timevalsub(&wallclock, &p->p_stats->p_start);
- pctcpu_limit = rusage_get_available(p, RUSAGE_PCTCPU);
PROC_LOCK(p);
PROC_SLOCK(p);
FOREACH_THREAD_IN_PROC(p, td) {
@@ -759,16 +695,9 @@
if (runtime < p->p_prev_runtime)
runtime = p->p_prev_runtime;
#endif
- pctcpu = (runtime - p->p_prev_runtime) / 10;
p->p_prev_runtime = runtime;
- if (pctcpu > pctcpu_limit)
- rusage_throttle(p, 1);
- else
- rusage_throttle(p, 0);
mtx_lock(&container_lock);
rusage_set_locked(p, RUSAGE_CPU, runtime);
- p->p_container->c_resources[RUSAGE_PCTCPU] = 0;
- rusage_set_locked(p, RUSAGE_PCTCPU, pctcpu);
rusage_set_locked(p, RUSAGE_WALLCLOCK,
wallclock.tv_sec * 1000000 + wallclock.tv_usec);
mtx_unlock(&container_lock);
@@ -787,28 +716,11 @@
SYSINIT(containerd, SI_SUB_CONTAINERD, SI_ORDER_FIRST, kproc_start, &containerd_kp);
static void
-container_proc_fork_sched(void *arg __unused, struct proc *p1,
- struct proc *newproc, int flags)
-{
- uint64_t pctcpu_limit;
-
- /*
- * Newly created process may already be over the %CPU limit. Throttle
- * it immediately after fork instead of waiting for containerd.
- */
- pctcpu_limit = rusage_get_limit(newproc, RUSAGE_PCTCPU);
- if (pctcpu_limit <= 0)
- rusage_throttle(newproc, 1);
-}
-
-static void
container_init(void)
{
container_zone = uma_zcreate("container", sizeof(struct container),
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
- EVENTHANDLER_REGISTER(process_fork, container_proc_fork_sched, NULL,
- EVENTHANDLER_PRI_ANY);
/*
* XXX: Move this somewhere.
*/
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_rctl.c#39 (text+ko) ====
@@ -121,7 +121,6 @@
{ "nshm", RUSAGE_NSHM },
{ "shmsize", RUSAGE_SHMSIZE },
{ "wallclock", RUSAGE_WALLCLOCK },
- { "pctcpu", RUSAGE_PCTCPU },
{ NULL, -1 }};
static struct dict actionnames[] = {
==== //depot/projects/soc2009/trasz_limits/sys/sys/container.h#27 (text+ko) ====
@@ -67,8 +67,7 @@
#define RUSAGE_NSHM 19
#define RUSAGE_SHMSIZE 20
#define RUSAGE_WALLCLOCK 21
-#define RUSAGE_PCTCPU 22
-#define RUSAGE_MAX RUSAGE_PCTCPU
+#define RUSAGE_MAX RUSAGE_WALLCLOCK
/*
* Resource types.
More information about the p4-projects
mailing list