PERFORCE change 104657 for review
Chris Jones
cdjones at FreeBSD.org
Mon Aug 21 07:14:31 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=104657
Change 104657 by cdjones at cdjones-impulse on 2006/08/21 07:14:22
Only affect processes when kern.sched.limit_jail_cpu sysctl set.
Affected files ...
.. //depot/projects/soc2006/cdjones_jail/src/sys/kern/sched_hier.c#19 edit
Differences ...
==== //depot/projects/soc2006/cdjones_jail/src/sys/kern/sched_hier.c#19 (text+ko) ====
@@ -295,8 +295,14 @@
&sched_kgfollowons, 0,
"number of followons done in a ksegrp");
+static int sched_limitjailcpu = 0;
+SYSCTL_INT(_kern_sched, OID_AUTO, limit_jail_cpu,
+ CTLFLAG_RW,
+ &sched_limitjailcpu, 0,
+ "limit jailed process cpu usage");
+
static int sched_unjailedProcessShares = 0;
-SYSCTL_INT(_kern_sched, OID_AUTO, unjailedprocessshares,
+SYSCTL_INT(_kern_sched, OID_AUTO, system_cpu_shares,
CTLTYPE_INT | CTLFLAG_RW,
&sched_unjailedProcessShares, 0,
"number of shares to allocate to unjailed processes");
@@ -549,10 +555,11 @@
continue;
kg->kg_estcpu = decay_cpu(loadfac, kg->kg_estcpu);
total_est_cpu += kg->kg_estcpu;
- if (NULL != kg->kg_proc->p_ucred &&
+ if (sched_limitjailcpu &&
+ NULL != kg->kg_proc->p_ucred &&
NULL != kg->kg_proc->p_ucred->cr_prison)
kg->kg_proc->p_ucred->cr_prison->pr_estcpu +=
- kg->kg_estcpu;
+ kg->kg_estcpu;
resetpriority(kg);
FOREACH_THREAD_IN_GROUP(kg, td) {
resetpriority_thread(td, kg);
@@ -575,23 +582,25 @@
u_int32_t shares = 0;
for (;;) {
- /*
- * Update total jail CPU shares in case they've changed.
- * Safe to read pr_sched_shares without mutex because
- * in worst case, we get a bogus value which will be
- * corrected on the next pass.
- *
- * TODO: this should be done by forcing a recalculation
- * when jail CPU shares are added / changed, rather than
- * doing it every second.
- */
- shares = sched_unjailedProcessShares;
- LIST_FOREACH(pr, &allprison, pr_list) {
- shares += pr->pr_sched_shares;
- }
- total_cpu_sched_shares = shares;
- counter++;
-
+ if (sched_limitjailcpu) {
+ /*
+ * Update total jail CPU shares in case they've changed.
+ * Safe to read pr_sched_shares without mutex because
+ * in worst case, we get a bogus value which will be
+ * corrected on the next pass.
+ *
+ * TODO: this should be done by forcing a recalculation
+ * when jail CPU shares are added / changed, rather than
+ * doing it every secondc.
+ */
+
+ shares = sched_unjailedProcessShares;
+ LIST_FOREACH(pr, &allprison, pr_list) {
+ shares += pr->pr_sched_shares;
+ }
+ total_cpu_sched_shares = shares;
+ }
+
schedcpu();
tsleep(&nowake, 0, "-", hz);
}
@@ -635,19 +644,16 @@
if (kg->kg_pri_class == PRI_TIMESHARE) {
newpriority = PUSER + kg->kg_estcpu / INVERSE_ESTCPU_WEIGHT +
- NICE_WEIGHT * (kg->kg_proc->p_nice - PRIO_MIN);
- if (NULL == pr) {
- newpriority = min(max(newpriority, PRI_MIN_TIMESHARE),
- PRI_MAX_TIMESHARE);
- } else {
- /*
- * Skew the priority by the jail's share of CPU resources.
- * The unjailed processes get half the CPU time.
- *
- * TODO: this is a hard limit. We should really also have
- * soft limits available. Also, the amount of CPU time
- * reserved to unjailed processes really should be sysctl'd.
- */
+ NICE_WEIGHT * (kg->kg_proc->p_nice - PRIO_MIN);
+ if (sched_limitjailcpu && NULL != pr) {
+ /*
+ * Skew the priority by the jail's share of CPU resources.
+ * The unjailed processes get half the CPU time.
+ *
+ * TODO: this is a hard limit. We should really also have
+ * soft limits available. Also, the amount of CPU time
+ * reserved to unjailed processes really should be sysctl'd.
+ */
register unsigned int np = newpriority;
register unsigned int skew;
skew = pr->pr_estcpu * total_cpu_sched_shares;
@@ -656,15 +662,19 @@
/* wait your turn until your cpu usage's proportionate */
newpriority = PRI_MAX_IDLE;
} else {
- newpriority = min(max(newpriority, PRI_MIN_TIMESHARE),
- PRI_MAX_TIMESHARE);
+ newpriority = min(max(newpriority, PRI_MIN_TIMESHARE),
+ PRI_MAX_TIMESHARE);
}
printf("skew KSE %p (%d / %d cpu, %d / %d shares) from %d to %d\n",
- &kg, pr->pr_estcpu, total_est_cpu,
- pr->pr_sched_shares,
- total_cpu_sched_shares,
- np, newpriority);
+ &kg, pr->pr_estcpu, total_est_cpu,
+ pr->pr_sched_shares,
+ total_cpu_sched_shares,
+ np, newpriority);
+ } else {
+ newpriority = min(max(newpriority, PRI_MIN_TIMESHARE),
+ PRI_MAX_TIMESHARE);
}
+
kg->kg_user_pri = newpriority;
}
}
More information about the p4-projects
mailing list