How to traverse kernel threads?

Mateusz Guzik mjguzik at gmail.com
Fri Mar 27 19:49:26 UTC 2015


On Fri, Mar 27, 2015 at 02:35:55PM -0400, Yue Chen wrote:
> When using the following code on kernel module loading:
> ------------------------------------------------------------------------------------------
> struct thread *td = kdb_thr_first();
> td = kdb_thr_next(td);
> ------------------------------------------------------------------------------------------
> The kernel panics.
> 

Panics how?

Also you can easily see these functions don't lock anything, so it would
be assumed you took appropriate locks.

Except it seems there routines are supposed to be only used when
execution is 'frozen' (e.g. when escaped to the debugger).

> 
> And when printing all threads in proc0 (all kernel threads?):
> ------------------------------------------------------------------------------------------
> struct proc *p = pfind(0);
> FOREACH_THREAD_IN_PROC(p, td) {
>     uprintf("td: %x\n", td);
> }
> 

proc0 is an exported symbol, no need to pfind.

> td = curthread;
> uprintf("cur td: %x\n", td);
> ------------------------------------------------------------------------------------------
> The ``curthread'' (from this kernel module running the above code) is not
> in the 0 process group.
> 

There is no 'curthread from kernel module'.

My guess is you do this work from module initializator, and in that case
curthread is the thread which loads the module, and such a thread is
definitely not linked into proc0.

Still nobody knows what you are trying to do.

-- 
Mateusz Guzik <mjguzik gmail.com>


More information about the freebsd-hackers mailing list