PERFORCE change 104369 for review

Chris Jones cdjones at FreeBSD.org
Thu Aug 17 08:45:44 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=104369

Change 104369 by cdjones at cdjones-impulse on 2006/08/17 08:45:40

	Remove lock order reversal, make skew formula vary with proportionate CPU usage and proportionate share allocation.  Further tweaking required, and then actually hooking it into the priority-setting bit can be done.

Affected files ...

.. //depot/projects/soc2006/cdjones_jail/src/sys/kern/sched_hier.c#13 edit

Differences ...

==== //depot/projects/soc2006/cdjones_jail/src/sys/kern/sched_hier.c#13 (text+ko) ====

@@ -450,6 +450,7 @@
 	 * everything out while we recalculate per-jail CPU usage.
 	 * TODO: this is excessively icky.
 	 */
+	sx_slock(&allproc_lock);
 	mtx_lock(&allprison_mtx);
 	if (prisoncount) {
 		LIST_FOREACH(pr, &allprison, pr_list) {
@@ -457,7 +458,6 @@
 			pr->pr_estcpu = 0;
 		}
 	}
-	sx_slock(&allproc_lock);
 	total_est_cpu = 0;
 	FOREACH_PROC_IN_SYSTEM(p) {
 		/*
@@ -554,13 +554,13 @@
 		} /* end of ksegrp loop */
 		mtx_unlock_spin(&sched_lock);
 	} /* end of process loop */
-	sx_sunlock(&allproc_lock);
 	if (prisoncount) {
 		LIST_FOREACH(pr, &allprison, pr_list) {
 			mtx_unlock(&pr->pr_mtx);
 		}
 	}
 	mtx_unlock(&allprison_mtx);
+	sx_sunlock(&allproc_lock);
 }
 
 /*
@@ -589,7 +589,6 @@
 		nShares = 0;
 		nCpu = 0;
 	        LIST_FOREACH(pr, &allprison, pr_list) {
-	        	printf("schedcpu_thread: prison %p\n", &pr);
 			nShares += pr->pr_sched_shares;
 			nCpu += pr->pr_estcpu;
    	        }
@@ -650,13 +649,19 @@
 		   * soft limits available.  Also, the amount of CPU time 
 		   * reserved to unjailed processes really should be sysctl'd.
 		   */ 
-		    register unsigned int np = newpriority;
-		    newpriority *= pr->pr_sched_shares;
-                    KASSERT(0 != total_jail_sched_shares, 
-		            "no jail sched shares when a jail exists?!");
-		    newpriority /= 2*total_jail_sched_shares;
-		    printf("resetpriority: reset KSE %p from %d to %d\n",
-			   &kg, np, newpriority);
+			register unsigned int np = newpriority;
+			register unsigned int skew = PRI_MAX_TIMESHARE;
+			skew -= PRI_MIN_TIMESHARE;
+			skew /= 16;
+
+			skew *= pr->pr_sched_shares;
+			skew *= pr->pr_estcpu;
+			/* avoid divide-by-zero hazards */
+			skew /= max(total_jail_sched_shares, 1);
+			skew /= max(total_est_cpu, 1);
+
+			printf("resetpriority: skewing KSE %p to %d from %d\n",
+				&kg, np + skew, np);
 		}
 		newpriority = min(max(newpriority, PRI_MIN_TIMESHARE),
 		    PRI_MAX_TIMESHARE);


More information about the p4-projects mailing list