From owner-p4-projects@FreeBSD.ORG Mon Aug 14 08:31:33 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 50DD416A4DF; Mon, 14 Aug 2006 08:31:33 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 01B6516A4DE for ; Mon, 14 Aug 2006 08:31:33 +0000 (UTC) (envelope-from cdjones@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id A4BB343D45 for ; Mon, 14 Aug 2006 08:31:32 +0000 (GMT) (envelope-from cdjones@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k7E8VWSZ043870 for ; Mon, 14 Aug 2006 08:31:32 GMT (envelope-from cdjones@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k7E8VWiB043867 for perforce@freebsd.org; Mon, 14 Aug 2006 08:31:32 GMT (envelope-from cdjones@FreeBSD.org) Date: Mon, 14 Aug 2006 08:31:32 GMT Message-Id: <200608140831.k7E8VWiB043867@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to cdjones@FreeBSD.org using -f From: Chris Jones To: Perforce Change Reviews Cc: Subject: PERFORCE change 103817 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Aug 2006 08:31:33 -0000 http://perforce.freebsd.org/chv.cgi?CH=103817 Change 103817 by cdjones@cdjones-impulse on 2006/08/14 08:31:14 Limit jailed KSEs' priorities based on their jails' shares of total jailed CPU shares. (Experimental) Affected files ... .. //depot/projects/soc2006/cdjones_jail/src/sys/kern/sched_hier.c#8 edit Differences ... ==== //depot/projects/soc2006/cdjones_jail/src/sys/kern/sched_hier.c#8 (text+ko) ==== @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -176,6 +177,8 @@ static int forward_wakeup(int cpunum); #endif +static uint32_t total_jail_sched_shares; + static struct kproc_desc sched_kp = { "schedcpu", schedcpu_thread, @@ -227,7 +230,7 @@ SYSCTL_NODE(_kern, OID_AUTO, sched, CTLFLAG_RD, 0, "Scheduler"); -SYSCTL_STRING(_kern_sched, OID_AUTO, name, CTLFLAG_RD, "4BSD", 0, +SYSCTL_STRING(_kern_sched, OID_AUTO, name, CTLFLAG_RD, "HIER", 0, "Scheduler name"); SYSCTL_PROC(_kern_sched, OID_AUTO, quantum, CTLTYPE_INT | CTLFLAG_RW, @@ -540,8 +543,25 @@ schedcpu_thread(void) { int nowake; + struct prison *pr; + u_int32_t nShares = 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. + */ + LIST_FOREACH(pr, &allprison, pr_list) { + nShares += pr->pr_sched_shares; + } + total_jail_sched_shares = nShares; + schedcpu(); tsleep(&nowake, 0, "-", hz); } @@ -579,10 +599,23 @@ resetpriority(struct ksegrp *kg) { register unsigned int newpriority; + struct prison *pr = kg->kg_proc->p_ucred->cr_prison; 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) { + /* + * 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. + */ + newpriority *= pr->pr_sched_shares; + newpriority /= 2*total_jail_sched_shares; + } newpriority = min(max(newpriority, PRI_MIN_TIMESHARE), PRI_MAX_TIMESHARE); kg->kg_user_pri = newpriority;