Date: Sun, 11 Apr 2004 01:33:21 -0700 (PDT) From: Julian Elischer <julian@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 50822 for review Message-ID: <200404110833.i3B8XL2A007494@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=50822 Change 50822 by julian@julian_jules1 on 2004/04/11 01:33:04 save, having played around a bit with who inits what amd when. Affected files ... .. //depot/projects/nsched/sys/i386/i386/machdep.c#4 edit .. //depot/projects/nsched/sys/kern/init_main.c#6 edit .. //depot/projects/nsched/sys/kern/kern_proc.c#4 edit .. //depot/projects/nsched/sys/kern/kern_thread.c#6 edit .. //depot/projects/nsched/sys/kern/sched_4bsd.c#4 edit .. //depot/projects/nsched/sys/sys/sched.h#3 edit Differences ... ==== //depot/projects/nsched/sys/i386/i386/machdep.c#4 (text+ko) ==== @@ -1957,11 +1957,9 @@ atdevbase = ISA_HOLE_START + KERNBASE; /* - * Just link a few things here. Full linkage will occur later. + * Link a few more bits of the proc0 together. */ - thread0.td_proc = &proc0; - ksegrp0.kg_proc = &proc0; - thread0.td_ksegrp = &ksegrp0; + proc_linkup(&proc0, &ksegrp0, &thread0); metadata_missing = 0; if (bootinfo.bi_modulep) { ==== //depot/projects/nsched/sys/kern/init_main.c#6 (text+ko) ==== @@ -332,15 +332,15 @@ p->p_magic = P_MAGIC; /* - * Initialize thread, process and pgrp structures. - * Note, proc_linkup calls scheduler init routines for - * per-thread and per-ksegrp schedular areas which will undo - * what schedinit() does, but that requires that schedinit has run - * so schedinit calls proc_linkup. - * XXXKSE needs cleaning up. + * Initialize thread, process and ksegrp structures. */ procinit(); /* set up proc zone */ threadinit(); /* set up thead, upcall and KSEGRP zones */ + + /* + * initialise scheduler resources. + * Add scheduler specific parts to proc, ksegrp, thread as needed. + */ schedinit(); /* scheduler gets its house in order */ /* ==== //depot/projects/nsched/sys/kern/kern_proc.c#4 (text+ko) ==== ==== //depot/projects/nsched/sys/kern/kern_thread.c#6 (text+ko) ==== @@ -169,7 +169,6 @@ td->td_state = TDS_INACTIVE; td->td_oncpu = NOCPU; td->td_critnest = 1; - sched_newthread(td); } /* @@ -220,6 +219,7 @@ /* NOTREACHED */ } #endif + sched_init_thread(td); /* ready for use (again) */ } /* @@ -231,11 +231,12 @@ struct thread *td; td = (struct thread *)mem; + td->td_sched = (struct td_sched *)&td[1]; vm_thread_new(td, 0); cpu_thread_setup(td); td->td_sleepqueue = sleepq_alloc(); td->td_turnstile = turnstile_alloc(); - td->td_sched = (struct td_sched *)&td[1]; + sched_init_thread(td); } @@ -262,7 +263,16 @@ struct ksegrp *kg; kg = (struct ksegrp *)mem; - sched_newkseg(kg); +} + + +static void +ksegrp_dtor(void *mem, int size, void *arg) +{ + struct ksegrp *kg; + + kg = (struct ksegrp *)mem; + sched_init_ksegrp(kg); /* recycle, ready to use again */ } /* @@ -275,8 +285,14 @@ kg = (struct ksegrp *)mem; kg->kg_sched = (struct kg_sched *)&kg[1]; + sched_init_ksegrp(kg); } +/* + * This links a ksegrp to a proc. + * Avoid doing anything fancy as it's also called right at + * the "big Bang" to link up proc0. (before vm is set up) + */ void ksegrp_link(struct ksegrp *kg, struct proc *p) { @@ -369,6 +385,9 @@ /* * For a newly created process, * link up all the structures and its initial threads etc. + * + * Avoid doing anything fancy as it's also called right at + * the "big Bang" to link up proc0. (before vm is set up) */ void proc_linkup(struct proc *p, struct ksegrp *kg, struct thread *td) @@ -382,8 +401,6 @@ ksegrp_link(kg, p); thread_link(td, kg); - sched_newthread(td); - sched_newkseg(kg); } #ifndef _SYS_SYSPROTO_H_ @@ -842,7 +859,7 @@ tid_zone = uma_zcreate("TID", sizeof(struct tid_bitmap_part), NULL, NULL, NULL, NULL, UMA_ALIGN_CACHE, 0); ksegrp_zone = uma_zcreate("KSEGRP", sched_sizeof_ksegrp(), - ksegrp_ctor, NULL, ksegrp_init, NULL, + ksegrp_ctor, ksegrp_dtor, ksegrp_init, NULL, UMA_ALIGN_CACHE, 0); upcall_zone = uma_zcreate("UPCALL", sizeof(struct kse_upcall), NULL, NULL, NULL, NULL, UMA_ALIGN_CACHE, 0); @@ -1322,6 +1339,9 @@ * set up anything that needs to be initialized for it to * be used by the process. * + * Avoid doing anything fancy as it's also called right at + * the "big Bang" to link up proc0. (before vm is set up) + * * Note that we do not link to the proc's ucred here. * The thread is linked as if running but no KSE assigned. */ @@ -1456,7 +1476,7 @@ bcopy(&td->td_startcopy, &td2->td_startcopy, (unsigned) RANGEOF(struct thread, td_startcopy, td_endcopy)); thread_link(td2, ku->ku_ksegrp); - sched_newthread(td2); + sched_init_thread(td2); /* inherit blocked thread's context */ cpu_set_upcall(td2, td); /* Let the new thread become owner of the upcall */ @@ -1468,7 +1488,7 @@ td2->td_inhibitors = 0; SIGFILLSET(td2->td_sigmask); SIG_CANTMASK(td2->td_sigmask); - sched_newthread(td2); + sched_init_thread(td2); sched_fork_thread(td, td2); return (td2); /* bogus.. should be a void function */ } ==== //depot/projects/nsched/sys/kern/sched_4bsd.c#4 (text+ko) ==== @@ -112,7 +112,7 @@ }; /* flags kept in ke_flags */ -#define KEF_BOUND 0x00001 /* Stuck on a thread.. (as per normal procs) */ +#define KEF_BOUND 0x00001 /* Stuck on a cpu.. long term */ #define KEF_EXIT 0x00002 /* KSE is being killed. */ #define KEF_DIDRUN 0x00004 /* KSE actually ran. */ @@ -1002,7 +1002,7 @@ static struct td_sched td_sched0; static struct kse * kse_alloc(void); -static void kse_link(struct proc *p, struct kse *ke, struct ksegrp *kg); +static void kse_link(struct kse *ke, struct ksegrp *kg); static void kse_unlink(struct kse *ke); extern struct mtx kse_zombie_lock; @@ -1036,14 +1036,19 @@ ksegrp0.kg_sched = &kg_sched0; proc0.p_sched = NULL; /* XXX */ thread0.td_sched = &td_sched0; - - proc_linkup(&proc0, &ksegrp0, &thread0); - kse_link(&proc0, &kse0, &ksegrp0); + + /* + * and link in our own per scheduler struct + */ + kse_link(&kse0, &ksegrp0); + /* + * and set it up as if BOUND and running + */ kse0.ke_thread = &thread0; thread0.td_kse = &kse0; /* we are running */ kse0.ke_state = KES_THREAD; - kse_zone = uma_zcreate("KSE", sched_sizeof_kse(), + kse_zone = uma_zcreate("KSE", sizeof (struct kse), NULL, NULL, NULL, NULL, UMA_ALIGN_CACHE, 0); } @@ -1065,7 +1070,7 @@ mtx_lock_spin(&sched_lock); thread_link(td0, td->td_ksegrp); - kse_link(td->td_proc, ke0, td->td_ksegrp); + kse_link(ke0, td->td_ksegrp); /* Bind this thread and kse together. */ td0->td_kse = ke0; @@ -1131,26 +1136,33 @@ * KSE is linked into kse group. */ void -kse_link(struct proc *p, struct kse *ke, struct ksegrp *kg) +kse_link( struct kse *ke, struct ksegrp *kg) { TAILQ_INSERT_HEAD(&kg->kg_kseq, ke, ke_kglist); kg->kg_kses++; ke->ke_state = KES_UNQUEUED; - ke->ke_proc = p; + ke->ke_proc = kg->kg_proc; /* really just a shortcut */ ke->ke_ksegrp = kg; ke->ke_thread = NULL; ke->ke_oncpu = NOCPU; ke->ke_flags = 0; } +/* + * Allocate scheduler per-process resources. + * The thread and ksegrp have already been linked in. + */ int sched_newproc(struct proc *p, struct ksegrp *kg, struct thread *td) { struct kse *ke; + /* + * For a new process, allocate a single KSE to the ksegrp. + */ ke = kse_alloc(); if (ke) { - kse_link(p, ke, kg); + kse_link(ke, kg); td->td_kse = ke; ke->ke_thread = td; return (0); @@ -1158,9 +1170,8 @@ return (ENOMEM ); } -/* Assumes kg->kg_sched is already set up */ void -sched_newkseg(struct ksegrp *kg) +sched_init_ksegrp(struct ksegrp *kg) { TAILQ_INIT(&kg->kg_kseq); /* all kses in ksegrp */ @@ -1172,7 +1183,7 @@ /* Assumes td->td_sched is already set up */ void -sched_newthread(struct thread *td) +sched_init_thread(struct thread *td) { td->td_last_kse = NULL; td->td_kse = NULL; @@ -1298,7 +1309,7 @@ mtx_unlock_spin(&sched_lock); #endif mtx_lock_spin(&sched_lock); - kse_link(kg->kg_proc, newke, kg); + kse_link(newke, kg); sched_fork_kse(curthread, newke); /* Add engine */ kse_reassign(newke); ==== //depot/projects/nsched/sys/sys/sched.h#3 (text+ko) ==== @@ -121,7 +121,7 @@ int sched_newproc(struct proc *p, struct ksegrp *kg, struct thread *td); void sched_GC(void); void sched_set_concurrancy(struct ksegrp *kg, int concurrancy); -void sched_newkseg(struct ksegrp *kg); -void sched_newthread(struct thread *td); +void sched_init_ksegrp(struct ksegrp *kg); +void sched_init_thread(struct thread *td); void sched_clean_ksegrp(struct ksegrp *kg, struct thread *td); #endif /* !_SYS_SCHED_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200404110833.i3B8XL2A007494>