PERFORCE change 55776 for review
Julian Elischer
julian at FreeBSD.org
Fri Jun 25 08:00:16 GMT 2004
http://perforce.freebsd.org/chv.cgi?CH=55776
Change 55776 by julian at julian_jules1 on 2004/06/25 07:59:42
Doodling with ULE.. compiles, probably doesn't run.
Affected files ...
.. //depot/projects/nsched/sys/kern/sched_ule.c#8 edit
Differences ...
==== //depot/projects/nsched/sys/kern/sched_ule.c#8 (text+ko) ====
@@ -253,6 +253,14 @@
#define FIRST_KSE_IN_PROC(p) FIRST_KSE_IN_KSEGRP(FIRST_KSEGRP_IN_PROC(p))
static struct kse kse0; /* Primary kse in proc0. */
+static uma_zone_t kse_zone;
+static struct kg_sched kg_sched0;
+static struct td_sched td_sched0;
+
+
+extern struct mtx kse_zombie_lock;
+TAILQ_HEAD(, kse) zombie_kses = TAILQ_HEAD_INITIALIZER(zombie_kses);
+
static struct kse *kse_alloc(void);
static void kse_free(struct kse *ke);
static void kse_stash(struct kse *ke);
@@ -471,19 +479,13 @@
#endif
static void runq_add(struct runq *, struct kse *);
+#if 0
static int runq_check(struct runq *);
+#endif
static struct kse *runq_choose(struct runq *);
static void runq_init(struct runq *);
static void runq_remove(struct runq *, struct kse *);
-
-static void setup_runqs(void);
-static void roundrobin(void *arg);
-static void schedcpu(void);
-static void schedcpu_thread(void);
-static void maybe_resched(struct thread *td);
-static void updatepri(struct ksegrp *kg);
-static void resetpriority(struct ksegrp *kg);
static void sched_add(struct thread *td);
static void sched_rem(struct thread *td);
static struct kse * sched_choose(void);
@@ -1451,23 +1453,34 @@
}
/*
+ * Allocate any resources the scheduler needs to allocate or set up
+ * on a new process at fork() time.
* Penalize the parent for creating a new child and initialize the child's
* priority.
+ * Called from:
+ * fork1()
*/
void
-sched_fork(struct thread *td, struct proc *p1)
+sched_fork(struct thread *td, struct proc *child)
{
-
+ struct thread *newtd;
+ struct kse *newke;
struct proc *p;
+ mtx_assert(&sched_lock, MA_OWNED);
p = td->td_proc;
- mtx_assert(&sched_lock, MA_OWNED);
-
- p1->p_nice = p->p_nice;
- sched_fork_ksegrp(td, FIRST_KSEGRP_IN_PROC(p1));
- sched_fork_kse(td, FIRST_KSE_IN_PROC(p1));
- sched_fork_thread(td, FIRST_THREAD_IN_PROC(p1));
+ child->p_nice = p->p_nice;
+ newtd = FIRST_THREAD_IN_PROC(child);
+ newke = FIRST_KSE_IN_PROC(child);
+ bzero(&newke->ke_startzero,
+ (unsigned) RANGEOF(struct kse, ke_startzero, ke_endzero));
+ newke->ke_state = KES_THREAD;
+ sched_fork_ksegrp(td, FIRST_KSEGRP_IN_PROC(child));
+ newke->ke_thread = newtd;
+ newtd->td_kse = newke;
+ sched_fork_ksegrp(td, FIRST_KSEGRP_IN_PROC(child));
+ sched_fork_kse(td, FIRST_KSE_IN_PROC(child));
}
static void
@@ -1568,7 +1581,7 @@
void
sched_exit_kse(struct kse *ke, struct thread *td)
{
- kseq_load_rem(KSEQ_CPU(child->ke_cpu), td->td_kse);
+ kseq_load_rem(KSEQ_CPU(td->td_kse->ke_cpu), td->td_kse);
}
void
@@ -1981,68 +1994,6 @@
* SUCH DAMAGE.
*/
-/***
-Here is the logic..
-
-If there are N processors, then there are at most N KSEs (kernel
-schedulable entities) working to process threads that belong to a
-KSEGROUP (kg). If there are X of these KSEs actually running at the
-moment in question, then there are at most M (N-X) of these KSEs on
-the run queue, as running KSEs are not on the queue.
-
-Runnable threads are queued off the KSEGROUP in priority order.
-If there are M or more threads runnable, the top M threads
-(by priority) are 'preassigned' to the M KSEs not running. The KSEs take
-their priority from those threads and are put on the run queue.
-
-The last thread that had a priority high enough to have a KSE associated
-with it, AND IS ON THE RUN QUEUE is pointed to by
-kg->kg_last_assigned. If no threads queued off the KSEGROUP have KSEs
-assigned as all the available KSEs are activly running, or because there
-are no threads queued, that pointer is NULL.
-
-When a KSE is removed from the run queue to become runnable, we know
-it was associated with the highest priority thread in the queue (at the head
-of the queue). If it is also the last assigned we know M was 1 and must
-now be 0. Since the thread is no longer queued that pointer must be
-removed from it. Since we know there were no more KSEs available,
-(M was 1 and is now 0) and since we are not FREEING our KSE
-but using it, we know there are STILL no more KSEs available, we can prove
-that the next thread in the ksegrp list will not have a KSE to assign to
-it, so we can show that the pointer must be made 'invalid' (NULL).
-
-The pointer exists so that when a new thread is made runnable, it can
-have its priority compared with the last assigned thread to see if
-it should 'steal' its KSE or not.. i.e. is it 'earlier'
-on the list than that thread or later.. If it's earlier, then the KSE is
-removed from the last assigned (which is now not assigned a KSE)
-and reassigned to the new thread, which is placed earlier in the list.
-The pointer is then backed up to the previous thread (which may or may not
-be the new thread).
-
-When a thread sleeps or is removed, the KSE becomes available and if there
-are queued threads that are not assigned KSEs, the highest priority one of
-them is assigned the KSE, which is then placed back on the run queue at
-the approipriate place, and the kg->kg_last_assigned pointer is adjusted down
-to point to it.
-
-The following diagram shows 2 KSEs and 3 threads from a single process.
-
- RUNQ: --->KSE---KSE--... (KSEs queued at priorities from threads)
- \ \____
- \ \
- KSEGROUP---thread--thread--thread (queued in priority order)
- \ /
- \_______________/
- (last_assigned)
-
-The result of this scheme is that the M available KSEs are always
-queued at the priorities they have inherrited from the M highest priority
-threads for that KSEGROUP. If this situation changes, the KSEs are
-reassigned to keep this true.
-***/
-
-
CTASSERT((RQB_BPW * RQB_LEN) == RQ_NQS);
@@ -2060,9 +2011,6 @@
td->td_kse = NULL;
kse_reassign(ke);
}
- if ((td->td_proc->p_flag & P_NOLOAD) == 0)
- sched_tdcnt--;
-
}
/*
@@ -2079,49 +2027,15 @@
ke = td->td_kse;
- if ((td->td_proc->p_flag & P_NOLOAD) == 0)
- sched_tdcnt--;
-
/* td is about to be freed, but keep it clean */
td->td_kse = NULL;
td->td_last_kse = NULL;
+ sched_exit_kse( td->td_kse, td);
kse_unlink(ke); /* also frees it */
}
-/*
- * Allocate any resources the scheduler needs to allocate or set up
- * on a new process at fork() time.
- * Called from:
- * fork1()
- */
-void
-sched_fork(struct thread *td, struct proc *child)
-{
- struct thread *newtd;
- struct kse *newke;
-
- newtd = FIRST_THREAD_IN_PROC(child);
- newke = FIRST_KSE_IN_PROC(child);
- bzero(&newke->ke_startzero,
- (unsigned) RANGEOF(struct kse, ke_startzero, ke_endzero));
- newke->ke_state = KES_THREAD;
- newke->ke_cpticks = 0;
- sched_fork_ksegrp(td, FIRST_KSEGRP_IN_PROC(child));
- newke->ke_thread = newtd;
- newtd->td_kse = newke;
-}
-
-static uma_zone_t kse_zone;
-
-struct kse kse0;
-static struct kg_sched kg_sched0;
-static struct td_sched td_sched0;
-
-extern struct mtx kse_zombie_lock;
-TAILQ_HEAD(, kse) zombie_kses = TAILQ_HEAD_INITIALIZER(zombie_kses);
-
/*
* Occasionally the scheduler may need to do some GC..
* Called from:
@@ -2204,8 +2118,7 @@
bzero(&newke->ke_startzero,
(unsigned) RANGEOF(struct kse, ke_startzero, ke_endzero));
newke->ke_state = KES_THREAD;
- newke->ke_cpticks = 0;
- sched_fork_kse(td->td_kse, newke);
+ sched_fork_kse(td, newke);
TD_SET_CAN_RUN(newtd);
if ((flags & THR_SUSPENDED) == 0)
@@ -2432,7 +2345,7 @@
bzero(&newke->ke_startzero,
(unsigned) RANGEOF(struct kse, ke_startzero, ke_endzero));
newke->ke_state = KES_THREAD;
- newke->ke_cpticks = 0;
+ sched_fork_kse(curthread, newke);
/* Add engine */
kse_reassign(newke);
mtx_unlock_spin(&sched_lock);
@@ -2940,6 +2853,7 @@
TAILQ_INSERT_TAIL(rqh, ke, ke_procq);
}
+#if 0
/*
* Return true if there are runnable processes of any priority on the run
* queue, false otherwise. Has no side effects, does not modify the run
@@ -2962,6 +2876,7 @@
return (0);
}
+#endif
/*
* Find the highest priority process on the run queue.
More information about the p4-projects
mailing list