From 496907b08a31334749268b138825808414f5d976 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 29 Jul 2004 09:02:33 +0000 Subject: [PATCH] Move kthread_create() from lwkt_thread.c to kern_kthread.c. Add a new api function, kthread_create_stk(), which allows a custom stack size to be specified. --- sys/kern/kern_kthread.c | 80 ++++++++++++++++++++++++++++++++++++++++- sys/kern/lwkt_thread.c | 53 +-------------------------- sys/sys/kthread.h | 4 ++- 3 files changed, 83 insertions(+), 54 deletions(-) diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c index a81cb10702..b7ae5a0357 100644 --- a/sys/kern/kern_kthread.c +++ b/sys/kern/kern_kthread.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/kern_kthread.c,v 1.5.2.3 2001/12/25 01:51:14 dillon Exp $ - * $DragonFly: src/sys/kern/kern_kthread.c,v 1.9 2003/07/19 21:14:38 dillon Exp $ + * $DragonFly: src/sys/kern/kern_kthread.c,v 1.10 2004/07/29 09:02:33 dillon Exp $ */ #include @@ -39,6 +39,84 @@ #include +/* + * Create a kernel process/thread/whatever. It shares it's address space + * with proc0 - ie: kernel only. 5.x compatible. + * + * NOTE! By default kthreads are created with the MP lock held. A + * thread which does not require the MP lock should release it by calling + * rel_mplock() at the start of the new thread. + */ +int +kthread_create(void (*func)(void *), void *arg, + struct thread **tdp, const char *fmt, ...) +{ + thread_t td; + __va_list ap; + + td = lwkt_alloc_thread(NULL, LWKT_THREAD_STACK, -1); + if (tdp) + *tdp = td; + cpu_set_thread_handler(td, kthread_exit, func, arg); + td->td_flags |= TDF_VERBOSE; +#ifdef SMP + td->td_mpcount = 1; +#endif + + /* + * Set up arg0 for 'ps' etc + */ + __va_start(ap, fmt); + vsnprintf(td->td_comm, sizeof(td->td_comm), fmt, ap); + __va_end(ap); + + /* + * Schedule the thread to run + */ + lwkt_schedule(td); + return 0; +} + +/* + * Same as kthread_create() but you can specify a custom stack size. + */ +int +kthread_create_stk(void (*func)(void *), void *arg, + struct thread **tdp, int stksize, const char *fmt, ...) +{ + thread_t td; + __va_list ap; + + td = lwkt_alloc_thread(NULL, stksize, -1); + if (tdp) + *tdp = td; + cpu_set_thread_handler(td, kthread_exit, func, arg); + td->td_flags |= TDF_VERBOSE; +#ifdef SMP + td->td_mpcount = 1; +#endif + __va_start(ap, fmt); + vsnprintf(td->td_comm, sizeof(td->td_comm), fmt, ap); + __va_end(ap); + + lwkt_schedule(td); + return 0; +} + +/* + * Destroy an LWKT thread. Warning! This function is not called when + * a process exits, cpu_proc_exit() directly calls cpu_thread_exit() and + * uses a different reaping mechanism. + * + * XXX duplicates lwkt_exit() + */ +void +kthread_exit(void) +{ + lwkt_exit(); +} + + /* * Start a kernel process. This is called after a fork() call in * mi_startup() in the file kern/init_main.c. diff --git a/sys/kern/lwkt_thread.c b/sys/kern/lwkt_thread.c index e335c13a7b..a0371705d8 100644 --- a/sys/kern/lwkt_thread.c +++ b/sys/kern/lwkt_thread.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/lwkt_thread.c,v 1.67 2004/07/29 08:55:00 dillon Exp $ + * $DragonFly: src/sys/kern/lwkt_thread.c,v 1.68 2004/07/29 09:02:33 dillon Exp $ */ /* @@ -1284,57 +1284,6 @@ lwkt_exit(void) cpu_thread_exit(); } -/* - * Create a kernel process/thread/whatever. It shares it's address space - * with proc0 - ie: kernel only. 5.x compatible. - * - * NOTE! By default kthreads are created with the MP lock held. A - * thread which does not require the MP lock should release it by calling - * rel_mplock() at the start of the new thread. - */ -int -kthread_create(void (*func)(void *), void *arg, - struct thread **tdp, const char *fmt, ...) -{ - thread_t td; - __va_list ap; - - td = lwkt_alloc_thread(NULL, LWKT_THREAD_STACK, -1); - if (tdp) - *tdp = td; - cpu_set_thread_handler(td, kthread_exit, func, arg); - td->td_flags |= TDF_VERBOSE; -#ifdef SMP - td->td_mpcount = 1; -#endif - - /* - * Set up arg0 for 'ps' etc - */ - __va_start(ap, fmt); - vsnprintf(td->td_comm, sizeof(td->td_comm), fmt, ap); - __va_end(ap); - - /* - * Schedule the thread to run - */ - lwkt_schedule(td); - return 0; -} - -/* - * Destroy an LWKT thread. Warning! This function is not called when - * a process exits, cpu_proc_exit() directly calls cpu_thread_exit() and - * uses a different reaping mechanism. - * - * XXX duplicates lwkt_exit() - */ -void -kthread_exit(void) -{ - lwkt_exit(); -} - #endif /* _KERNEL */ void diff --git a/sys/sys/kthread.h b/sys/sys/kthread.h index 55b210b21d..03bb0d2b9b 100644 --- a/sys/sys/kthread.h +++ b/sys/sys/kthread.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/sys/kthread.h,v 1.2 2000/01/07 08:36:44 luoqi Exp $ - * $DragonFly: src/sys/sys/kthread.h,v 1.6 2003/08/20 07:31:21 rob Exp $ + * $DragonFly: src/sys/sys/kthread.h,v 1.7 2004/07/29 09:02:32 dillon Exp $ */ #ifndef _SYS_KTHREAD_H_ @@ -52,6 +52,8 @@ void kproc_suspend_loop (void); void shutdown_kproc (void *, int); int kthread_create (void (*)(void *), void *, struct thread **, const char *, ...); +int kthread_create_stk (void (*)(void *), void *, struct thread **, + int, const char *, ...); void kthread_exit (void) __dead2; -- 2.41.0