PERFORCE change 188108 for review
Edward Tomasz Napierala
trasz at FreeBSD.org
Sun Jan 23 19:42:32 UTC 2011
http://p4web.freebsd.org/@@188108?ac=10
Change 188108 by trasz at trasz_victim on 2011/01/23 19:42:24
Don't use %CPU value calculated by the scheduler (sched_pctcpu());
it's averaged over some time and thus not really suitable for what
I need here. Instead, calculate %CPU from runtime.
Affected files ...
.. //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#60 edit
.. //depot/projects/soc2009/trasz_limits/sys/sys/proc.h#29 edit
Differences ...
==== //depot/projects/soc2009/trasz_limits/sys/kern/kern_container.c#60 (text+ko) ====
@@ -765,11 +765,10 @@
static void
containerd(void)
{
- int pctcpu;
struct thread *td;
struct proc *p;
struct timeval wallclock;
- uint64_t pctcpu_limit;
+ uint64_t pctcpu, pctcpu_limit, runtime;
for (;;) {
loginclass_container_foreach(container_dampen_callback, &hz,
@@ -779,27 +778,35 @@
sx_slock(&allproc_lock);
FOREACH_PROC_IN_SYSTEM(p) {
- pctcpu_limit = rusage_get_limit(p, RUSAGE_PCTCPU);
- pctcpu = 0;
+ 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) {
ruxagg(p, td);
thread_lock(td);
- pctcpu += sched_pctcpu(td);
thread_unlock(td);
}
+ runtime = cputick2usec(p->p_rux.rux_runtime);
PROC_SUNLOCK(p);
- pctcpu = ((pctcpu * 10000 + FSCALE / 2) >> FSHIFT) / 100;
+#ifdef notyet
+ KASSERT(runtime >= p->p_prev_runtime,
+ ("runtime < p_prev_runtime"));
+#else
+ if (runtime < p->p_prev_runtime)
+ runtime = p->p_prev_runtime;
+#endif
+ pctcpu = (runtime - p->p_prev_runtime) / 10000;
+ p->p_prev_runtime = runtime;
if (pctcpu > pctcpu_limit)
rusage_throttle(p, 1);
else
rusage_throttle(p, 0);
- microuptime(&wallclock);
- timevalsub(&wallclock, &p->p_stats->p_start);
- rusage_set(p, RUSAGE_WALLCLOCK, wallclock.tv_sec * 1000000 + wallclock.tv_usec);
+ rusage_set(p, RUSAGE_CPU, runtime);
rusage_set(p, RUSAGE_PCTCPU, pctcpu);
- rusage_set(p, RUSAGE_CPU, cputick2usec(p->p_rux.rux_runtime));
+ rusage_set(p, RUSAGE_WALLCLOCK,
+ wallclock.tv_sec * 1000000 + wallclock.tv_usec);
PROC_UNLOCK(p);
}
sx_sunlock(&allproc_lock);
==== //depot/projects/soc2009/trasz_limits/sys/sys/proc.h#29 (text+ko) ====
@@ -526,6 +526,7 @@
int p_boundary_count;/* (c) Num threads at user boundary */
int p_pendingcnt; /* how many signals are pending */
struct itimers *p_itimers; /* (c) POSIX interval timers. */
+ uint64_t p_prev_runtime; /* (c) Resource usage accounting. */
/* End area that is zeroed on creation. */
#define p_endzero p_magic
@@ -559,7 +560,7 @@
LIST_HEAD(, mqueue_notifier) p_mqnotifier; /* (c) mqueue notifiers.*/
struct kdtrace_proc *p_dtrace; /* (*) DTrace-specific data. */
struct cv p_pwait; /* (*) wait cv for exit/exec */
- struct container p_container; /* (*) resource usage accounting */
+ struct container p_container; /* (*) Resource usage accounting. */
};
#define p_session p_pgrp->pg_session
More information about the p4-projects
mailing list