p4-projects@freebsd.org
[Top] [All Lists]

PERFORCE change 100384 for review

Subject: PERFORCE change 100384 for review
From: Chris Jones
Date: Sat, 1 Jul 2006 07:19:20 GMT
http://perforce.freebsd.org/chv.cgi?CH=100384

Change 100384 by cdjones@cdjones-impulse on 2006/07/01 07:18:33

        Create kthread for jail's scheduler on jail() call.  Next milestone: 
add data structures to index processes by jail (per scheduler).

Affected files ...

.. //depot/projects/soc2006/cdjones_jail/src/sys/kern/kern_jail.c#7 edit
.. //depot/projects/soc2006/cdjones_jail/src/sys/sys/jail.h#8 edit

Differences ...

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

@@ -94,10 +94,25 @@
 SYSINIT(prison, SI_SUB_INTRINSIC, SI_ORDER_ANY, init_prison, NULL);
 
 static void
-jsched_dummy(void)
+jsched_td(void *arg)
 {
-  int x;
-  tsleep(&x, 0, "-", hz);
+  struct prison *pr;
+  pr = arg;
+
+  printf("Starting jail scheduler for JID %d\n", pr->pr_id);
+
+  for (;;) {
+    if (pr->pr_scheduler_flags & J_SCHED_TD_DIE) 
+      break;
+
+    printf("jsched: foo\n");
+
+    tsleep(pr, 0, '-', hz);
+  }
+
+  printf("Killing jail scheduler for JID %d\n", pr->pr_id);
+  pr->pr_scheduler_flags = J_SCHED_TD_DEAD;
+  kthread_exit(0);
 }
 
 /*
@@ -116,8 +131,12 @@
        struct jail_attach_args jaa;
        int vfslocked, error, tryprid;
 
-       struct proc *j_sched_proc;
-       struct kproc_desc *j_sched_kp;
+       static struct proc *j_sched_proc;
+       /*      static struct kproc_desc *j_sched_kp = {
+         "j_sched",
+         jsched_dummy,
+         &j_sched_proc
+         }; */
 
        error = copyin(uap->jail, &j, sizeof(j));
        if (error)
@@ -171,67 +190,34 @@
        prisoncount++;
        mtx_unlock(&allprison_mtx);
 
-       /* TODO --- Should probably be an #ifdef SCHED_HIER here. */
-       printf("A");
-       MALLOC(j_sched_kp, struct kproc_desc *, sizeof(struct kproc_desc), 
M_TEMP, M_WAITOK | M_ZERO);
-       printf("B");
-       if (NULL == j_sched_kp)
+       /* TODO #ifdef SCHED_HIER */
+       pr->pr_scheduler_flags = J_SCHED_TD_ACTIVE;
+       if (kthread_create(jsched_td, pr, (void *) j_sched_proc, 0, 0, "jsched 
'%d'", pr->pr_id))
          goto e_dropprref;
-       printf("C");
-       MALLOC(j_sched_kp->arg0, char *, (7 + 6 + 1) * sizeof(char), M_TEMP, 
M_WAITOK | M_ZERO);
-       printf("D");
-       if (!j_sched_kp->arg0)
-         goto e_dropprref;
-       printf("E");
-       snprintf(j_sched_kp->arg0, 7 + 6 + 1, "jsched/%6d", pr->pr_id);
-       printf("F");
-       j_sched_kp->func = jsched_dummy;
-       printf("G");
-       j_sched_kp->global_procpp = &j_sched_proc;
-       printf("H");
-       kproc_start(&j_sched_kp);
-       printf("I");
-       /*      pr->pr_scheduler = (j_sched_kp->global_procpp)->p_pid; */ /* 
TODO - why won't this work? */
-       FREE(j_sched_kp->arg0, M_TEMP);
-       printf("J");
-       FREE(j_sched_kp, M_TEMP);
-       printf("K");
-       /* TODO --- probable #endif */
+       KASSERT(j_sched_proc != NULL, ("NULL j_sched_proc"));
+       pr->pr_scheduler = j_sched_proc;
+       /* TODO #endif */
 
        error = jail_attach(td, &jaa);
-       printf("L");
        if (error)
                goto e_dropprref;
-       printf("M");
        mtx_lock(&pr->pr_mtx);
        pr->pr_ref--;
        mtx_unlock(&pr->pr_mtx);
-       printf("N");
        td->td_retval[0] = jaa.jid;
-       printf("O");
        return (0);
 e_dropprref:
-       printf("P");
-       if (j_sched_kp && j_sched_kp->arg0)
-         FREE(j_sched_kp->arg0, M_TEMP);
-       printf("P1");
-       if (j_sched_kp)
-         FREE(j_sched_kp, M_TEMP);
-       printf("P2");
        mtx_lock(&allprison_mtx);
        LIST_REMOVE(pr, pr_list);
        prisoncount--;
        mtx_unlock(&allprison_mtx);
 e_dropvnref:
-       printf("Q");
        vfslocked = VFS_LOCK_GIANT(pr->pr_root->v_mount);
        vrele(pr->pr_root);
        VFS_UNLOCK_GIANT(vfslocked);
 e_killmtx:
-       printf("R");
        mtx_destroy(&pr->pr_mtx);
        FREE(pr, M_PRISON);
-       printf("Z");
        return (error);
 }
 
@@ -335,6 +321,10 @@
                prisoncount--;
                mtx_unlock(&allprison_mtx);
 
+               /* Tell scheduler to die.  No need to wait for it. */
+               pr->pr_scheduler_flags |= J_SCHED_TD_DIE;
+               wakeup(pr);
+
                TASK_INIT(&pr->pr_task, 0, prison_complete, pr);
                taskqueue_enqueue(taskqueue_thread, &pr->pr_task);
                return;

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

@@ -38,6 +38,10 @@
 #define JAIL_MINIMUM_PRIORITY 1
 #define JAIL_MAXIMUM_PRIORITY 100
 
+#define J_SCHED_TD_ACTIVE 0x01
+#define J_SCHED_TD_DIE    0x02
+#define J_SCHED_TD_DEAD   0x04
+
 #ifndef _KERNEL
 
 int jail(struct jail *);
@@ -74,6 +78,7 @@
 #include <sys/proc.h>
 /*struct proc; */
 
+
 struct prison {
        LIST_ENTRY(prison) pr_list;                     /* (a) all prisons */
        int              pr_id;                         /* (c) prison id */
@@ -88,6 +93,7 @@
        struct mtx       pr_mtx;
        unsigned int     pr_priority;                   /* (p) jail priority */
         struct proc     *pr_scheduler;                  /* (c) scheduler pid */
+        int              pr_scheduler_flags;
 };
 #endif /* _KERNEL || _WANT_PRISON */
 
_______________________________________________
p4-projects@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/p4-projects
To unsubscribe, send any mail to "p4-projects-unsubscribe@xxxxxxxxxxx"

<Prev in Thread] Current Thread [Next in Thread>
  • PERFORCE change 100384 for review, Chris Jones <=