[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Mach context switch





> and i made in boot_script_exec_cmd a kernel_thread for user_bootstrap instead
> of thread_create+thread_start (no doswapin), because i have a kernel_stack=0,
> and cant run user_bootstrap. i think its not corrent (my solution), should i do
> it on active_stack ?

You are supposed to set the value of kernel_stack in stack_attach. That
will get called by thread_invoke when the new thread is scheduled for
the first time (see the "Check that the thread is swapped-in." part
which calls stack_alloc_try(), which calls stack_attach to attached the
allocated stack).
Samuel

i checked and found bug in my init context.
 when free_context accures, free context moves to free stack list, and then, from stack_alloc_try, new thread context should be initialisated  on context from this list. in my case free_list_context points wrong part of context. now all thread context 0x1000 aligned and ok. 

the user_bootstrap has a low priority initially, and after thread_sleep next thread is idle_thread, after - swapin_thread,  after - sched_thread, after that thread_select returnes a point on idle_thread, and i have panic in thread_invoke with bad thread_state. 

now booting looks like:
1. initial startup, init mem, structs and other things. all from startup.c without devices
2. create first thread and call load_context, 
3. load_contextl load  tread_continue, wich calls thread_dispatch, and call swap_function. (on context in free context list)
4. first thread makes idle_thread and 3 kernel threads. idle_thread has context from first thread, other threads have own contexts. 
5. prepare for loading first module, getting ELF head and copy binary part into mem.
6. creating thread for user_bootstrap and call thread_sleep. 
7. idle_thread start, -- idle_thread_continue  -- thread_block 

7* thread_block ---- thread_select --- thread_invoke --- magic thing with thread status ---- switch_context. 
switch_context is a very strange case, this process in mach i misunderstend.usually, switch context needs changing processor state, for getting registers from other context for save it (interrupt or exception), but i didn't see this metod in x86 source. 

8. swapin_thread  --  swapin_thread_continue  --- thread_block

see 7*

9. sched_thread   ---- thread_block 

see 7* 

10. thread select returns point on idle thread_idle and i have panic with wrong thread state. 

so, now i should a plug-in timer for calling   do_runq_scan  from recompute_priorities... 

Reply to: