kproc_start kproc_shutdown kthread_create kthread_exit kthread_resume kthread_suspend kthread_suspend_check - kernel threads
struct kproc_desc { char *arg0; void (*func)(void); struct proc **global_procpp; };
The structure members are used by
kproc_start ();
as follows:
The
kthread_create ();
function is used to create a kernel thread.
The new thread shares its address space with process 0, the swapper process,
and runs in kernel mode only.
The
Fa func
argument specifies the function that the thread should execute.
The
Fa arg
argument is an arbitrary pointer that is passed in as the only argument to
Fa func
when it is called by the new process.
The
Fa newpp
pointer points to a
struct proc
pointer that is to be updated to point to the newly created process.
If this argument is
NULL
then it is ignored.
The
Fa flags
argument specifies a set of flags as described in
rfork(2).
The
Fa pages
argument specifies the size of the new kernel thread's stack in pages.
If 0 is used, the default kernel stack size is allocated.
The rest of the arguments form a
printf(9)
argument list that is used to build the name of the new thread and is stored
in the
p_comm
member of the new thread's
struct proc
The
kthread_exit ();
function is used to terminate kernel threads.
It should be called by the main function of the kernel thread rather than
letting the main function return to its caller.
The
Fa ecode
argument specifies the exit status of the thread.
While exiting, the function
exit1(9)
will initiate a call to
wakeup(9)
on the thread handle.
The
kthread_resume (,);
kthread_suspend (,);
and
kthread_suspend_check ();
functions are used to suspend and resume a kernel thread.
During the main loop of its execution, a kernel thread that wishes to allow
itself to be suspended should call
kthread_suspend_check ();
passing in
curproc
as the only argument.
This function checks to see if the kernel thread has been asked to suspend.
If it has, it will
tsleep(9)
until it is told to resume.
Once it has been told to resume it will return allowing execution of the
kernel thread to continue.
The other two functions are used to notify a kernel thread of a suspend or
resume request.
The
Fa p
argument points to the
struct proc
of the kernel thread to suspend or resume.
For
kthread_suspend (,);
the
Fa timo
argument specifies a timeout to wait for the kernel thread to acknowledge the
suspend request and suspend itself.
The
kproc_shutdown ();
function is meant to be registered as a shutdown event for kernel threads that
need to be suspended voluntarily during system shutdown so as not to interfere
with system shutdown activities.
The actual suspension of the kernel thread is done with
kthread_suspend (.);
static struct proc *bufdaemonproc; static struct kproc_desc buf_kp = { "bufdaemon", buf_daemon, &bufdaemonproc }; SYSINIT(bufdaemon, SI_SUB_KTHREAD_BUF, SI_ORDER_FIRST, kproc_start, &buf_kp) static void buf_daemon() { ... /* * This process needs to be suspended prior to shutdown sync. */ EVENTHANDLER_REGISTER(shutdown_pre_sync, kproc_shutdown, bufdaemonproc, SHUTDOWN_PRI_LAST); ... for (;;) { kthread_suspend_check(bufdaemonproc); ... } }
The
kthread_create ();
function will fail if:
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |