PERFORCE change 104192 for review

Chris Jones cdjones at FreeBSD.org
Wed Aug 16 08:40:32 UTC 2006


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

Change 104192 by cdjones at cdjones-impulse on 2006/08/16 08:39:53

	Keep track of CPU usage per jail.  NOTE: this crashes hard in schedcpu.

Affected files ...

.. //depot/projects/soc2006/cdjones_jail/src/sys/kern/sched_hier.c#10 edit
.. //depot/projects/soc2006/cdjones_jail/src/sys/sys/jail.h#17 edit

Differences ...

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

@@ -178,6 +178,8 @@
 #endif
 
 static uint32_t total_jail_sched_shares;
+extern struct mtx allprison_mtx;
+extern int prisoncount;
 
 static struct kproc_desc sched_kp = {
         "schedcpu",
@@ -438,9 +440,22 @@
 	struct proc *p;
 	struct kse *ke;
 	struct ksegrp *kg;
+	struct prison *pr;
 	int awake, realstathz;
 
 	realstathz = stathz ? stathz : hz;
+	/* 
+	 * Need to acquire each jail's mutex and hold throughout to keep 
+	 * everything out while we recalculate per-jail CPU usage.
+	 * TODO: this is excessively icky.
+	 */
+	mtx_lock(&allprison_mtx);
+	if (prisoncount) {
+		LIST_FOREACH(pr, &allprison, pr_list) {
+			mtx_lock(&pr->pr_mtx);
+			pr->pr_estcpu = 0;
+		}
+	}
 	sx_slock(&allproc_lock);
 	FOREACH_PROC_IN_SYSTEM(p) {
 		/*
@@ -526,6 +541,7 @@
 			if (kg->kg_slptime > 1)
 				continue;
 			kg->kg_estcpu = decay_cpu(loadfac, kg->kg_estcpu);
+			kg->kg_proc->p_ucred->cr_prison->pr_estcpu += kg->kg_estcpu;
 		      	resetpriority(kg);
 			FOREACH_THREAD_IN_GROUP(kg, td) {
 				resetpriority_thread(td, kg);
@@ -534,6 +550,12 @@
 		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);
 }
 
 /*
@@ -545,6 +567,7 @@
 	int nowake;
 	struct prison *pr;
 	u_int32_t nShares = 0;
+	u_int nCpu = 0;
 
 	for (;;) {
   	       /* 
@@ -558,11 +581,13 @@
 		* doing it every second.
 		*/
 		nShares = 0;
+		nCpu = 0;
 	        LIST_FOREACH(pr, &allprison, pr_list) {
-	          printf("schedcpu_thread: prison %p\n", &pr);
-		  nShares += pr->pr_sched_shares;
+	        	printf("schedcpu_thread: prison %p\n", &pr);
+			nShares += pr->pr_sched_shares;
+			nCpu += pr->pr_estcpu;
    	        }
-		printf("schedcpu_thread: %d CPU shares total\n", nShares);
+		printf("schedcpu_thread: %d CPU shares total, %d CPU est. usage\n", nShares, nCpu);
 		total_jail_sched_shares = nShares;
 
 		schedcpu();
@@ -616,11 +641,13 @@
 		   * soft limits available.  Also, the amount of CPU time 
 		   * reserved to unjailed processes really should be sysctl'd.
 		   */ 
-		    printf("resetpriority: reset KSE %p priority\n", &kg);
+		    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);
 		}
 		newpriority = min(max(newpriority, PRI_MIN_TIMESHARE),
 		    PRI_MAX_TIMESHARE);

==== //depot/projects/soc2006/cdjones_jail/src/sys/sys/jail.h#17 (text+ko) ====

@@ -100,6 +100,7 @@
 	struct task	 pr_task;			/* (d) destroy task */
 	struct mtx	 pr_mtx;
 	u_int32_t	 pr_sched_shares;		/* (p) jail priority */
+	u_int		 pr_estcpu;			/* (p) est. cpu of jail */
         struct proc     *pr_scheduler;                  /* (c) scheduler pid */
         int             *pr_scheduler_flags_ptr;        /* (p) communication to scheduler */
         struct proc     *pr_pager;                      /* (c) pager pid */


More information about the p4-projects mailing list