rump_lwproc(3)
- NetBSD Manual Pages
RUMP_LWPROC(3) NetBSD Library Functions Manual RUMP_LWPROC(3)
NAME
rump_lwproc -- rump kernel process/lwp management
LIBRARY
rump kernel (librump, -lrump)
SYNOPSIS
#include <rump/rump.h>
int
rump_pub_lwproc_rfork(int flags);
int
rump_pub_lwproc_newlwp(pid_t pid);
void
rump_pub_lwproc_switch(struct lwp *l);
void
rump_pub_lwproc_releaselwp();
struct lwp *
rump_pub_lwproc_curlwp();
DESCRIPTION
In a normal operating system model a process is a resource container and
a thread (lwp) is the execution context. Every lwp is associated with
exactly one process, and a process is associated with one or more lwps.
The current lwp (curlwp) indicates the current process and determines
which resources, such as UID/GID, current working directory, and file
descriptor table, are currently used. These basic principles apply to
rump kernels as well, but since a rump kernel uses the host's thread and
process context directly, the rules for how thread context is determined
are different.
In the rump kernel model, each host thread (implemented for example with
pthreads) is either bound to a rump kernel lwp or accesses the rump ker-
nel with an implicit thread context associated with pid 1. An implicit
thread context is created every time the rump kernel is entered and dis-
banded upon exit. While convenient for occasional calls, creating an
implicit thread uses a shared resource which can become highly contended
in a multithreaded situation. It is therefore recommended that dedicated
threads are created.
The association between host threads and the rump kernel curlwp is left
to the caller. It is possible to create a dedicated host thread for
every rump kernel lwp or multiplex them on top of a single host thread.
After rump kernel lwps have been created, switching curlwp is very cheap
-- faster than a thread context switch on the host. In case multiple
lwps/processes are created, it is the caller's responsibility to keep
track of them and release them when they are no longer necessary. Like
other rump kernel resources, procs/lwps will be released when the process
hosting the rump kernel exits.
rump_pub_lwproc_rfork()
Create a process, one lwp inside it and set curlwp to the new lwp.
The flags parameter controls how file descriptors are inherited
from the parent. By default (flags=0) file descriptors are shared.
Other options are:
RUMP_RFFDG Copy file descriptors from parent. This is what
fork(2) does.
RUMP_RFCFDG File descriptors neither copied nor shared, i.e. new
process does not have access to the parent's file
descriptors.
This routine returns 0 for success or an errno indicating the rea-
son for failure. The new process id can be retrieved in the normal
fashion by calling rump_sys_getpid().
rump_pub_lwproc_newlwp(pid)
Create a new lwp attached to the process specified by pid. Sets
curlwp to the new lwp. This routine returns 0 for success or an
errno indicating the reason for failure.
rump_pub_lwproc_switch(l)
Sets curlwp to l. In case the new thread is associated with a dif-
ferent process than the current one, the process context is also
switched. The special value NULL sets curlwp to implicit context.
Switching to an already running lwp, i.e. attempting to use the
same curlwp in two host threads simultaneously causes a fatal
error.
rump_pub_lwproc_releaselwp()
Release curlwp and set curlwp to context. In case curlwp was the
last thread inside the current process, the process container is
also released. Calling this routine without a dedicated curlwp is
a fatal error.
rump_pub_lwproc_curlwp()
Returns curlwp or NULL if the current context is an implicit con-
text.
SEE ALSO
getpid(2), rump(3)
HISTORY
rump_lwproc first appeared in NetBSD 6.0.
NetBSD 7.1_STABLE January 2, 2011 NetBSD 7.1_STABLE
Powered by man-cgi (2024-03-20).
Maintained for NetBSD
by Kimmo Suominen.
Based on man-cgi by Panagiotis Christias.