--- On Wed, 8/1/12, David Xu <listlog2...@gmail.com> wrote:

From: David Xu <listlog2...@gmail.com>
Subject: Re: Enumerating sleeping threads
To: "Daniel Rudy" <dr2...@pacbell.net>
Cc: freebsd-hackers@freebsd.org
Date: Wednesday, August 1, 2012, 7:25 PM

On 2012/8/2 10:12, Daniel Rudy wrote:
> Hello,
> 
> What is the best way to enumerate the sleeping threads via
> sleepqueue(9)?  Furthermore, when enumerating the threads that are on
> the run queue, what locks are needed, if any?
sleepqueue hash bucket is private data structure in subr_sleepqueue.c, I think 
you
can not access it outside of the file.
One way to enumerate the sleeping threads is iterating all threads in the 
system,
and check their states.  proc.h contains two macros:
FOREACH_PROC_IN_SYSTEM
FOREACH_THREAD_IN_PROC

To access thread state, you should use thread lock,  call thread_lock()
and thread_unlock(). thread lock is not fixed, it might be sleep-queue's 
spinlock
or per-cpu runqueue lock, there even is a blocked spin-lock for intermediate 
state
change.

> Thank you.
> 


The problem is that I want to avoid using proc.h in this.  I'm considering 
adding a function to subr_sleepqueue.c to export the data structures, or at 
least export a PID list.  The reason why I am doing it this way is security 
related.  

_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Reply via email to