Hi, daidong wrote: > I have several questions about the thread scheduling in OpenSolaris, and wish > you could help > me making everything clear: > > 1, in /ust/common/sys/Thread.h, there is a line of code > > "extern struct _kthread t0; /* the scheduler thread */" > > after looking around, i found 't0' was created when the system boots up, > and never exited. It's privilege is 99-3. However, i can not find out which > code it will execute when it is swtched to CPUs. Will t0 run after booting, > or just run once at the very beginning of the system?
t0 is the very first thread in the system, manually constructed out of preallocated (by the compiler) bits. Start by having a look at the (architecture-dependent) mlsetup C function, eg in i86pc/os/mlsetup.c and where it is called from (_locore_start for i86pc); note that immediately after the call to mlsetup we call main() and do not return from main(). In mlsetup you'll see a bunch of code to setup the initial thread t0 - filling in much of the kthread_t to identify it's stack, priority, thread state and also filling in corresponding structures such as members of the boot cpu_t to show it is running t0. When we call main after mlsetup (main is common code; uts/common/os/main.c) we're still on the initial boot cpu with t0 as the running thread (there are no others yet). Here we call or initiate most of the startup activity including starting other cpus, creating other threads etc. Throughout main the boot cpu will continue to run t0 - we've stopped it looking for any other work in mlsetup. Our final action in main is to call sched(): bcopy("sched", PTOU(curproc)->u_psargs, 6); bcopy("sched", PTOU(curproc)->u_comm, 5); sched(); /* NOTREACHED */ hence the description of "scheduler thread". > 2, In /uts/common/disp/Thread.c. > We know that swtch() calls thread_unpin() when current thead > is an interrupt thread, and its interrupted thread is not null. > In thread_unpin(), we use intr_passivate() to get state from > interrupt thread for the one it interrupted. However I only > find intr_passivate() for i386pc architechture. I want to know > does this function have an SPARC code? Where it is? See uts/sun4/ml/interrupt.s: ENTRY_NP(intr_passivate) uts/sun4 is code common to sun4u and sun4v Cheers Gavin _______________________________________________ opensolaris-code mailing list opensolaris-code@opensolaris.org http://mail.opensolaris.org/mailman/listinfo/opensolaris-code