From 63fe9ef05796a86abf73efb71f5069559cdb4afa Mon Sep 17 00:00:00 2001 From: jonathan Date: Sat, 27 Mar 2004 00:42:38 +0000 Subject: [PATCH] Use proper NetBSD conventions for deferred kthread creation, not the other semantics from an earlier incarnation. Call kcont_init() from init_main before device autoconfiguration, so kcont is availble to device drivers if required. Also ensure the kthread process runs any pending continuations once the kthread is finally up and running. For now, use a non-null timeout to poll the queue periodically. Draining any pending requests just before the kthread enters its ltsleep()/kc_run loop is cleaner, but this is the version I tested with an early-in-boot kcont request.) --- sys/kern/init_main.c | 8 ++++++-- sys/kern/kern_kcont.c | 21 ++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 73af48274eee..14952c710d87 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $NetBSD: init_main.c,v 1.233 2004/03/09 02:35:45 junyoung Exp $ */ +/* $NetBSD: init_main.c,v 1.234 2004/03/27 00:42:38 jonathan Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1992, 1993 @@ -71,7 +71,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.233 2004/03/09 02:35:45 junyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.234 2004/03/27 00:42:38 jonathan Exp $"); #include "fs_nfs.h" #include "opt_nfsserver.h" @@ -94,6 +94,7 @@ __KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.233 2004/03/09 02:35:45 junyoung Exp #include #include #include +#include #include #include #include @@ -267,6 +268,9 @@ main(void) /* Initialize sockets. */ soinit(); + /* Initialize kcont. */ + kcont_init(); + /* * The following things must be done before autoconfiguration. */ diff --git a/sys/kern/kern_kcont.c b/sys/kern/kern_kcont.c index 17d2abe90659..062c4024d412 100644 --- a/sys/kern/kern_kcont.c +++ b/sys/kern/kern_kcont.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_kcont.c,v 1.8 2004/03/25 23:02:58 enami Exp $ */ +/* $NetBSD: kern_kcont.c,v 1.9 2004/03/27 00:42:38 jonathan Exp $ */ /* * Copyright 2003 Jonathan Stone. @@ -37,16 +37,18 @@ /* */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_kcont.c,v 1.8 2004/03/25 23:02:58 enami Exp $ "); +__KERNEL_RCSID(0, "$NetBSD: kern_kcont.c,v 1.9 2004/03/27 00:42:38 jonathan Exp $ "); #include #include #include #include #include +#include #include #include #include +#include #include #include /* IPL_*, and schedsoftnet() */ @@ -65,6 +67,7 @@ static __inline struct kc *kcont_dequeue_atomic(kcq_t *kcq); static void kcont_worker(void * /*arg*/); +static void kcont_create_worker(void *); #ifdef __HAVE_GENERIC_SOFT_INTERRUPTS @@ -340,6 +343,14 @@ kcont_run_softserial(void *arg) } #endif /* __HAVE_GENERIC_SOFT_INTERRUPTS */ + +static void +kcont_create_worker(void *arg) +{ + if (kthread_create1(kcont_worker, NULL, NULL, "kcont")) + panic("fork kcont"); +} + /* * Main entrypoint for kcont worker kthreads to execute * a continuation which requested deferral to process context. @@ -352,8 +363,8 @@ kcont_worker(void *arg) (void)arg; /* kill GCC warning */ while (1) { - status = ltsleep(&kcq_process_ctxt, PCATCH, "kcont", 0, NULL); - if (status != 0) + status = ltsleep(&kcq_process_ctxt, PCATCH, "kcont", hz, NULL); + if (status != 0 && status != EWOULDBLOCK) break; kcont_run(&kcq_process_ctxt, NULL, 0, KC_IPL_DEFER_PROCESS); } @@ -395,5 +406,5 @@ kcont_init(void) * locking should have at least one worker kthread per CPU). */ SIMPLEQ_INIT(&kcq_process_ctxt); - kthread_create(kcont_worker, NULL); + kthread_create(kcont_create_worker, NULL); }