KTHREAD(9) | Kernel Developer's Manual | KTHREAD(9) |
kthread_create
, kthread_exit
,
kthread_join
,
kthread_fpu_enter
,
kthread_fpu_exit
—
#include <sys/kthread.h>
int
kthread_create
(pri_t
pri, int flags,
struct cpu_info *ci,
void (*func)(void *),
void *arg,
lwp_t **newlp,
const char *fmt,
...);
void
kthread_exit
(int
ecode);
int
kthread_join
(lwp_t
*l);
int
kthread_fpu_enter
();
void
kthread_fpu_exit
(int
s);
Any process can request the creation of a new kernel thread. Kernel threads are not swapped out during memory congestion. The VM space and limits are shared with proc0 (usually swapper).
If the machine has any per-CPU floating-point units or SIMD vector
units that are normally available to user threads, they can be used by
kthreads between kthread_fpu_enter
() and
kthread_fpu_exit
().
kthread_create
(pri,
flags, ci,
func, arg,
newlp, fmt,
...)PRI_NONE
, causing
kthread_create
() to select the default
priority level.NULL
, the
thread will be created bound to the CPU specified by
ci, meaning that it will only ever execute on
that CPU. By default, the threads are free to execute on any CPU in
the system.kthread_exit
() to properly terminate
itself.func
(). May be
NULL
if not required.NULL
, unless
KTHREAD_MUSTJOIN
is specified in
flags.NULL
.The following flags are defined.
KTHREAD_IDLE
LSIDL
(idle) state. By default, the threads are created in the
LSRUN
(runnable) state, meaning they will
begin execution shortly after creation.KTHREAD_MPSAFE
KTHREAD_INTR
KTHREAD_TS
SCHED_OTHER
class (timeshared). The thread's
priority will be dynamically adjusted by the scheduler. Increased
activity by the kthread will cause its priority to fall; decreased
activity will cause its priority to rise. By default, kthreads are
created in the SCHED_RR
class, with a fixed
priority specified by pri. Threads in the
SCHED_RR
class do not have their priority
dynamically adjusted by the scheduler.KTHREAD_MUSTJOIN
kthread_exit
() will wait until
kthread_join
() will be called.kthread_exit
(ecode)kthread_join
(l)KTHREAD_MUSTJOIN
flag and would wait on
kthread_exit.kthread_fpu_enter
()kthread_fpu_exit
() when done.
Matching pairs of kthread_fpu_enter
()
and kthread_fpu_exit
() may be nested.
kthread_fpu_exit
(s)kthread_fpu_enter
() that returned
s.
On the last kthread_fpu_exit
(), zero
all the units' registers to avoid leaking secrets — such units
are often used for cryptography.
kthread_create
() returns 0.
Otherwise, the following error values are returned:
EAGAIN
]RLIMIT_NPROC
on the total number of
processes under execution by this user id would be exceeded.April 21, 2015 | NetBSD 10.1 |