From owner-p4-projects@FreeBSD.ORG Mon Aug 21 07:14:31 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 6F7D516A4E0; Mon, 21 Aug 2006 07:14:31 +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 2605216A4DA for ; Mon, 21 Aug 2006 07:14:31 +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 F1AB243D73 for ; Mon, 21 Aug 2006 07:14:29 +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 k7L7ETSp036368 for ; Mon, 21 Aug 2006 07:14:29 GMT (envelope-from cdjones@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k7L7ET2H036365 for perforce@freebsd.org; Mon, 21 Aug 2006 07:14:29 GMT (envelope-from cdjones@FreeBSD.org) Date: Mon, 21 Aug 2006 07:14:29 GMT Message-Id: <200608210714.k7L7ET2H036365@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 104657 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, 21 Aug 2006 07:14:31 -0000 http://perforce.freebsd.org/chv.cgi?CH=104657 Change 104657 by cdjones@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; } }