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_destroy(
lwp_t *l
)
void
kthread_exit(
int ecode
)
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).
pri
, flags
, ci
, func
, arg
, newlp
, fmt
, ...
)
pri
PRI_NONE
,
causing
kthread_create(
)
to select the default priority level.
flags
KTHREAD_IDLE
:
causes the thread to be created in the
LSIDL
(idle) state.
By default, the threads are created in the
LSRUN
(runnable) state, meaning they will begin execution shortly after creation.
KTHREAD_MPSAFE
:
Specifies that the thread does its own locking and so is multiprocessor safe.
If not specified, the global kernel lock will be held whenever the thread is
running (unless explicitly dropped by the thread).
KTHREAD_INTR
:
Specifies that the thread services device interrupts.
This flag is intended for kernel internal use and should not normally be
specified.
KTHREAD_TS
:
Causes the kthread to be created in the SCHED_OTHER class (timeshared).
The threads' 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.
ci
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.
func
)
to properly terminate itself.
arg
).
May be NULL if not required.
newpl
fmt
l
)
LSIDL
(idle) state.
ecode
)
)
returns 0.
Otherwise, the following error values are returned:
EAGAIN
]
EAGAIN
]
RLIMIT_NPROC
on the total number of processes under execution by this
user id would be exceeded.
/usr/src
.
The kthread framework itself is implemented within the file
sys/kern/kern_kthread.c
.
Data structures and function prototypes for the framework are located in
sys/sys/kthread.h
.