What is the best way to make a kernel thread goto sleep for a specified amount of time and relinquish the processor for the rest of the tick? Some of the research that I have done on this (forums (here), google, pause(9), etc) suggests using pause(9) to sleep the thread. However, the man page says the following:
Pause(9) however will not wake back up until the timeout expires. This is not a viable solution as this is running inside a KLM. So if the module unloads, the thread is still sleeping so the unload has to wait, or the kernel will panic. Looking at wake(9) and tsleep(9), there is one parameter that I am not sure of. The explaination in the man page is as follows:
Which I find somewhat vague and confusing. Is the address just some random address that is used or does it actually point to something? A struct or int perhaps? I will continue digging through the source code, but if someone could explain to me what chan really is, I would be grateful.
Thank you.
The pause() function is a wrapper around tsleep(9) that suspends execution of the current thread for the indicated timeout. The thread can not be awakened early by signals or calls to wakeup() or wakeup_one().
Pause(9) however will not wake back up until the timeout expires. This is not a viable solution as this is running inside a KLM. So if the module unloads, the thread is still sleeping so the unload has to wait, or the kernel will panic. Looking at wake(9) and tsleep(9), there is one parameter that I am not sure of. The explaination in the man page is as follows:
The parameter chan is an arbitrary address that uniquely identifies the event on which the thread is being put to sleep. All threads sleeping on a single chan are woken up later by wakeup(), often called from inside an interrupt routine, to indicate that the resource the thread was blocking on is available now.
Which I find somewhat vague and confusing. Is the address just some random address that is used or does it actually point to something? A struct or int perhaps? I will continue digging through the source code, but if someone could explain to me what chan really is, I would be grateful.
Thank you.