From: visa Date: Mon, 13 Aug 2018 15:26:17 +0000 (+0000) Subject: Simplify the startup of the cleaner, reaper and update threads by X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=643e3253c9409ce2d1e776b6e6d1781ad6c413b9;p=openbsd Simplify the startup of the cleaner, reaper and update threads by passing the main function directly to kthread_create(9). The start_* functions are mere stepping stones nowadays and can be pruned. They used to contain more logic in the pre-kthread era. While here, set `cleanerproc' and `syncerproc' during the thread creation rather than expect the threads to set the proc pointer. Also, rename `sched_sync' to `syncer_thread' to reduce confusion with the scheduler-related functions. OK kettenis@, deraadt@, mpi@ --- diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 397d8f8f2a6..aa4c0a83ef7 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.279 2018/07/20 21:57:26 deraadt Exp $ */ +/* $OpenBSD: init_main.c,v 1.280 2018/08/13 15:26:17 visa Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -137,9 +137,6 @@ long __guard_local __attribute__((section(".openbsd.randomdata"))); int main(void *); void check_console(struct proc *); void start_init(void *); -void start_cleaner(void *); -void start_update(void *); -void start_reaper(void *); void crypto_init(void); void db_ctf_init(void); void prof_init(void); @@ -524,15 +521,15 @@ main(void *framep) panic("fork pagedaemon"); /* Create the reaper daemon kernel thread. */ - if (kthread_create(start_reaper, NULL, &reaperproc, "reaper")) + if (kthread_create(reaper, NULL, &reaperproc, "reaper")) panic("fork reaper"); /* Create the cleaner daemon kernel thread. */ - if (kthread_create(start_cleaner, NULL, NULL, "cleaner")) + if (kthread_create(buf_daemon, NULL, &cleanerproc, "cleaner")) panic("fork cleaner"); /* Create the update daemon kernel thread. */ - if (kthread_create(start_update, NULL, NULL, "update")) + if (kthread_create(syncer_thread, NULL, &syncerproc, "update")) panic("fork update"); /* Create the aiodone daemon kernel thread. */ @@ -745,24 +742,3 @@ start_init(void *arg) printf("init: not found\n"); panic("no init"); } - -void -start_update(void *arg) -{ - sched_sync(curproc); - /* NOTREACHED */ -} - -void -start_cleaner(void *arg) -{ - buf_daemon(curproc); - /* NOTREACHED */ -} - -void -start_reaper(void *arg) -{ - reaper(); - /* NOTREACHED */ -} diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index 6bbf5fb2258..4e1f1dee000 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exit.c,v 1.165 2018/07/13 09:25:23 beck Exp $ */ +/* $OpenBSD: kern_exit.c,v 1.166 2018/08/13 15:26:17 visa Exp $ */ /* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */ /* @@ -376,7 +376,7 @@ proc_free(struct proc *p) * a zombie, and the parent is allowed to read the undead's status. */ void -reaper(void) +reaper(void *arg) { struct proc *p; diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index fc8896f1292..3dcac1eb121 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_bio.c,v 1.185 2017/08/27 01:59:30 beck Exp $ */ +/* $OpenBSD: vfs_bio.c,v 1.186 2018/08/13 15:26:17 visa Exp $ */ /* $NetBSD: vfs_bio.c,v 1.44 1996/06/11 11:15:36 pk Exp $ */ /* @@ -1158,13 +1158,11 @@ buf_get(struct vnode *vp, daddr_t blkno, size_t size) * Buffer cleaning daemon. */ void -buf_daemon(struct proc *p) +buf_daemon(void *arg) { struct buf *bp = NULL; int s, pushed = 0; - cleanerproc = curproc; - s = splbio(); for (;;) { if (bp == NULL || (pushed >= 16 && diff --git a/sys/kern/vfs_sync.c b/sys/kern/vfs_sync.c index 1e8fe91ccdc..ece99ea9a76 100644 --- a/sys/kern/vfs_sync.c +++ b/sys/kern/vfs_sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vfs_sync.c,v 1.59 2018/05/27 06:02:14 visa Exp $ */ +/* $OpenBSD: vfs_sync.c,v 1.60 2018/08/13 15:26:17 visa Exp $ */ /* * Portions of this code are: @@ -133,15 +133,14 @@ vn_syncer_add_to_worklist(struct vnode *vp, int delay) * System filesystem synchronizer daemon. */ void -sched_sync(struct proc *p) +syncer_thread(void *arg) { + struct proc *p = curproc; struct synclist *slp; struct vnode *vp; time_t starttime; int s; - syncerproc = curproc; - for (;;) { starttime = time_second; @@ -183,7 +182,7 @@ sched_sync(struct proc *p) if (vp->v_mount != NULL) printf("mounted on: %s\n", vp->v_mount->mnt_stat.f_mntonname); - panic("sched_sync: fsync failed"); + panic("%s: fsync failed", __func__); } #endif /* DIAGNOSTIC */ /* diff --git a/sys/sys/buf.h b/sys/sys/buf.h index 3805a7a35fa..b468a9ef883 100644 --- a/sys/sys/buf.h +++ b/sys/sys/buf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.h,v 1.106 2017/04/16 14:25:42 beck Exp $ */ +/* $OpenBSD: buf.h,v 1.107 2018/08/13 15:26:17 visa Exp $ */ /* $NetBSD: buf.h,v 1.25 1997/04/09 21:12:17 mycroft Exp $ */ /* @@ -320,7 +320,7 @@ void reassignbuf(struct buf *); void bgetvp(struct vnode *, struct buf *); void buf_replacevnode(struct buf *, struct vnode *); -void buf_daemon(struct proc *); +void buf_daemon(void *); void buf_replacevnode(struct buf *, struct vnode *); int bread_cluster(struct vnode *, daddr_t, int, struct buf **); diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 6f088a5b67d..63aca571c3b 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.h,v 1.255 2018/08/05 14:23:57 beck Exp $ */ +/* $OpenBSD: proc.h,v 1.256 2018/08/13 15:26:17 visa Exp $ */ /* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */ /*- @@ -535,7 +535,7 @@ void resetpriority(struct proc *); void setrunnable(struct proc *); void endtsleep(void *); void unsleep(struct proc *); -void reaper(void); +void reaper(void *); void exit1(struct proc *, int, int); void exit2(struct proc *); int dowait4(struct proc *, pid_t, int *, int, struct rusage *, diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 404a50b05e2..44ed35962f8 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vnode.h,v 1.147 2018/07/13 09:25:23 beck Exp $ */ +/* $OpenBSD: vnode.h,v 1.148 2018/08/13 15:26:17 visa Exp $ */ /* $NetBSD: vnode.h,v 1.38 1996/02/29 20:59:05 cgd Exp $ */ /* @@ -641,7 +641,7 @@ int vn_ioctl(struct file *, u_long, caddr_t, struct proc *); void vn_marktext(struct vnode *); /* vfs_sync.c */ -void sched_sync(struct proc *); +void syncer_thread(void *); void vn_initialize_syncerd(void); void vn_syncer_add_to_worklist(struct vnode *, int);