From owner-p4-projects@FreeBSD.ORG Sat Jul 1 07:43:44 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 6118716A50A; Sat, 1 Jul 2006 07:43:43 +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 04E6616A548 for ; Sat, 1 Jul 2006 07:43:43 +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 8033D43F15 for ; Sat, 1 Jul 2006 07:19:20 +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 k617JKvc045239 for ; Sat, 1 Jul 2006 07:19:20 GMT (envelope-from cdjones@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k617JKTv045234 for perforce@freebsd.org; Sat, 1 Jul 2006 07:19:20 GMT (envelope-from cdjones@FreeBSD.org) Date: Sat, 1 Jul 2006 07:19:20 GMT Message-Id: <200607010719.k617JKTv045234@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 100384 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: Sat, 01 Jul 2006 07:43:44 -0000 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 /*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 */