From 5241d0f41bff911dddbb0bdb0cb1324af43d23a7 Mon Sep 17 00:00:00 2001 From: dlg Date: Thu, 14 Dec 2017 00:45:16 +0000 Subject: [PATCH] replace the bare sleep state handling in barriers with wait cond code --- sys/kern/kern_task.c | 18 ++++++------------ sys/kern/kern_timeout.c | 12 ++++-------- sys/net/ifq.c | 12 ++++-------- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/sys/kern/kern_task.c b/sys/kern/kern_task.c index feaa7bed5cd..5c4f15903f5 100644 --- a/sys/kern/kern_task.c +++ b/sys/kern/kern_task.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_task.c,v 1.21 2017/11/13 23:52:49 dlg Exp $ */ +/* $OpenBSD: kern_task.c,v 1.22 2017/12/14 00:45:16 dlg Exp $ */ /* * Copyright (c) 2013 David Gwynne @@ -183,25 +183,19 @@ taskq_create_thread(void *arg) void taskq_barrier(struct taskq *tq) { - struct sleep_state sls; - unsigned int notdone = 1; - struct task t = TASK_INITIALIZER(taskq_barrier_task, ¬done); + struct cond c = COND_INITIALIZER(); + struct task t = TASK_INITIALIZER(taskq_barrier_task, &c); task_add(tq, &t); - while (notdone) { - sleep_setup(&sls, ¬done, PWAIT, "tqbar"); - sleep_finish(&sls, notdone); - } + cond_wait(&c, "tqbar"); } void taskq_barrier_task(void *p) { - unsigned int *notdone = p; - - *notdone = 0; - wakeup_one(notdone); + struct cond *c = p; + cond_signal(c); } void diff --git a/sys/kern/kern_timeout.c b/sys/kern/kern_timeout.c index 00565e8a909..757663ebd8a 100644 --- a/sys/kern/kern_timeout.c +++ b/sys/kern/kern_timeout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_timeout.c,v 1.51 2017/11/24 02:36:53 dlg Exp $ */ +/* $OpenBSD: kern_timeout.c,v 1.52 2017/12/14 00:45:16 dlg Exp $ */ /* * Copyright (c) 2001 Thomas Nordin * Copyright (c) 2000-2001 Artur Grabowski @@ -334,11 +334,10 @@ timeout_barrier(struct timeout *to) splx(splsoftclock()); KERNEL_UNLOCK(); } else { - int wait = 1; + struct cond c = COND_INITIALIZER(); struct timeout barrier; - struct sleep_state sls; - timeout_set_proc(&barrier, timeout_proc_barrier, &wait); + timeout_set_proc(&barrier, timeout_proc_barrier, &c); mtx_enter(&timeout_mutex); barrier.to_flags |= TIMEOUT_ONQUEUE; @@ -347,10 +346,7 @@ timeout_barrier(struct timeout *to) wakeup_one(&timeout_proc); - while (wait) { - sleep_setup(&sls, &wait, PSWP, "tmobar"); - sleep_finish(&sls, wait); - } + cond_wait(&c, "tmobar"); } } diff --git a/sys/net/ifq.c b/sys/net/ifq.c index 4c6d89437a4..22eba971297 100644 --- a/sys/net/ifq.c +++ b/sys/net/ifq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ifq.c,v 1.15 2017/11/14 08:44:11 dlg Exp $ */ +/* $OpenBSD: ifq.c,v 1.16 2017/12/14 00:45:16 dlg Exp $ */ /* * Copyright (c) 2015 David Gwynne @@ -133,9 +133,8 @@ ifq_restart_task(void *p) void ifq_barrier(struct ifqueue *ifq) { - struct sleep_state sls; - unsigned int notdone = 1; - struct task t = TASK_INITIALIZER(ifq_barrier_task, ¬done); + struct cond c = COND_INITIALIZER(); + struct task t = TASK_INITIALIZER(ifq_barrier_task, &c); /* this should only be called from converted drivers */ KASSERT(ISSET(ifq->ifq_if->if_xflags, IFXF_MPSAFE)); @@ -145,10 +144,7 @@ ifq_barrier(struct ifqueue *ifq) ifq_serialize(ifq, &t); - while (notdone) { - sleep_setup(&sls, ¬done, PWAIT, "ifqbar"); - sleep_finish(&sls, notdone); - } + cond_wait(&c, "ifqbar"); } void -- 2.20.1