1 /* $NetBSD: threads.c,v 1.5 2009/12/03 12:16:36 pooka Exp $ */
4 * Copyright (c) 2007-2009 Antti Kantee. All Rights Reserved.
6 * Development of this software was supported by
7 * The Finnish Cultural Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __KERNEL_RCSID(0, "$NetBSD: threads.c,v 1.5 2009/12/03 12:16:36 pooka Exp $");
34 #include <sys/param.h>
36 #include <sys/kthread.h>
37 #include <sys/systm.h>
39 #include <machine/stdarg.h>
41 #include <rump/rumpuser.h>
43 #include "rump_private.h"
52 threadbouncer(void *arg
)
54 struct kthdesc
*k
= arg
;
55 struct lwp
*l
= k
->mylwp
;
63 /* schedule ourselves */
64 rumpuser_set_curlwp(l
);
67 if ((curlwp
->l_pflag
& LP_MPSAFE
) == 0)
72 panic("unreachable, should kthread_exit()");
76 kthread_create(pri_t pri
, int flags
, struct cpu_info
*ci
,
77 void (*func
)(void *), void *arg
, lwp_t
**newlp
, const char *fmt
, ...)
79 char thrstore
[MAXCOMLEN
];
80 const char *thrname
= NULL
;
89 vsnprintf(thrstore
, sizeof(thrstore
), fmt
, ap
);
95 * We don't want a module unload thread.
96 * (XXX: yes, this is a kludge too, and the kernel should
97 * have a more flexible method for configuring which threads
100 if (strcmp(thrstore
, "modunload") == 0) {
106 if (strcmp(thrstore
, "vrele") == 0) {
107 printf("rump warning: threads not enabled, not starting"
110 } else if (strcmp(thrstore
, "cachegc") == 0) {
111 printf("rump warning: threads not enabled, not starting"
112 " namecache g/c thread\n");
114 } else if (strcmp(thrstore
, "nfssilly") == 0) {
115 printf("rump warning: threads not enabled, not enabling"
116 " nfs silly rename\n");
118 } else if (strcmp(thrstore
, "unpgc") == 0) {
119 printf("rump warning: threads not enabled, not enabling"
120 " UNP garbage collection\n");
122 } else if (strncmp(thrstore
, "xcall", sizeof("xcall")-1) == 0) {
123 printf("rump warning: threads not enabled, CPU xcall"
124 " not functional\n");
127 panic("threads not available, setenv RUMP_THREADS 1");
129 KASSERT(fmt
!= NULL
);
131 k
= rumpuser_malloc(sizeof(struct kthdesc
), 0);
134 k
->mylwp
= l
= rump_lwp_alloc(0, rump_nextlid());
135 if (flags
& KTHREAD_MPSAFE
)
136 l
->l_pflag
|= LP_MPSAFE
;
137 if (flags
& KTHREAD_INTR
)
138 l
->l_pflag
|= LP_INTR
;
140 l
->l_pflag
|= LP_BOUND
;
143 rv
= rumpuser_thread_create(threadbouncer
, k
, thrname
);
153 kthread_exit(int ecode
)
156 if ((curlwp
->l_pflag
& LP_MPSAFE
) == 0)
157 KERNEL_UNLOCK_LAST(NULL
);
158 rump_lwp_release(curlwp
);
160 rumpuser_thread_exit();