From 7325bc315f1d4b0f7d782651fe20b9ee7a92db62 Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Tue, 21 Feb 2012 20:19:34 +0100 Subject: [PATCH] kern - Merge two functions to avoid duplicated code. - Merged kthread_create() and kthread_create_cpu() into _kthread_create() thus avoiding some duplicated code. - Set TDF_VERBOSE on threads only under bootverbose. --- sys/kern/kern_kthread.c | 53 +++++++++++++++++++---------------------- sys/sys/kthread.h | 2 ++ 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/sys/kern/kern_kthread.c b/sys/kern/kern_kthread.c index 8a69cc23b3..1d4024c833 100644 --- a/sys/kern/kern_kthread.c +++ b/sys/kern/kern_kthread.c @@ -43,19 +43,20 @@ static struct lwkt_token kpsus_token = LWKT_TOKEN_INITIALIZER(kpsus_token); /* - * Create a kernel process/thread/whatever. It shares it's address space - * with proc0 - ie: kernel only. 5.x compatible. - * - * All kthreads are created as MPSAFE threads. + * Create a new lightweight kernel thread. */ int -kthread_create(void (*func)(void *), void *arg, - struct thread **tdp, const char *fmt, ...) +_kthread_create(void (*func)(void *), void *arg, + struct thread **tdp, int cpu, const char *fmt, ...) { thread_t td; __va_list ap; + int flags = 0; - td = lwkt_alloc_thread(NULL, LWKT_THREAD_STACK, -1, TDF_VERBOSE); + if (bootverbose) + atomic_set_int(&flags, TDF_VERBOSE); + + td = lwkt_alloc_thread(NULL, LWKT_THREAD_STACK, cpu, flags); if (tdp) *tdp = td; cpu_set_thread_handler(td, kthread_exit, func, arg); @@ -73,35 +74,29 @@ kthread_create(void (*func)(void *), void *arg, * Schedule the thread to run */ lwkt_schedule(td); + return 0; } +/* + * Creates a lwkt. No CPU preference. + */ +int +kthread_create(void (*func)(void *), void *arg, + struct thread **tdp, const char *fmt, ...) +{ + return _kthread_create(func, arg, tdp, -1, fmt); +} + +/* + * Creates a lwkt and schedule it to run in a specific CPU. + * + */ int kthread_create_cpu(void (*func)(void *), void *arg, struct thread **tdp, int cpu, const char *fmt, ...) { - thread_t td; - __va_list ap; - - td = lwkt_alloc_thread(NULL, LWKT_THREAD_STACK, cpu, TDF_VERBOSE); - if (tdp) - *tdp = td; - cpu_set_thread_handler(td, kthread_exit, func, arg); - - /* - * Set up arg0 for 'ps' etc - */ - __va_start(ap, fmt); - kvsnprintf(td->td_comm, sizeof(td->td_comm), fmt, ap); - __va_end(ap); - - td->td_ucred = crhold(proc0.p_ucred); - - /* - * Schedule the thread to run - */ - lwkt_schedule(td); - return 0; + return _kthread_create(func, arg, tdp, cpu, fmt); } #if 0 diff --git a/sys/sys/kthread.h b/sys/sys/kthread.h index 3b6d6d9d50..c1dd4de57a 100644 --- a/sys/sys/kthread.h +++ b/sys/sys/kthread.h @@ -59,6 +59,8 @@ int suspend_kproc (struct thread *, int); int resume_kproc (struct thread *); void kproc_suspend_loop (void); void shutdown_kproc (void *, int); +int _kthread_create(void (*)(void *), void *, struct thread **, + int, const char *, ...) __printflike(5, 6); int kthread_create (void (*)(void *), void *, struct thread **, const char *, ...) __printflike(4, 5); int kthread_create_cpu (void (*)(void *), void *, struct thread **, -- 2.41.0