tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: workqueue_drain



On Wed, 20 Dec 2017, Ryota Ozaki wrote:

Hi,

workqueue_destroy requires that its queue doesn't have
any works (and no new work will be enqueued anymore)
before being called. Currently users of workqueue have
to ensure the contract by theirselves. It's possible
but it may need to add extra synchronization mechanisms
such as mutex and condvar only for that purpose.

workqueue itself can provide an API to help the routine.
It, say workqueue_drain, waits for all pending works to
finish. With it the caller needs to only ensure that no
new work will be enqueued.

Here is a patch:
 http://www.netbsd.org/~ozaki-r/workqueue_drain.diff
(I will update workqueue.4 once the proposal is accepted.)

And this is a patch that applies workqueue_drain to bridge(4):
 http://www.netbsd.org/~ozaki-r/workqueue_drain-example.diff

If we don't have workqueue_drain we had to add an extra
condvar to wait the workqueue worker of bridge to finish.

Any comments or suggestions?

You could add a new flag bit for WQ_DRAINING when you start to
drain.  Then workqueue_enque() could enforce the "no new work"
with

	KASSERT_MSG((wq->wg_flags & WQ_DRAINING) != 0,
	    "adding work to a draining workqueue")


+------------------+--------------------------+----------------------------+
| Paul Goyette     | PGP Key fingerprint:     | E-mail addresses:          |
| (Retired)        | FA29 0E3B 35AF E8AE 6651 | paul at whooppee dot com   |
| Kernel Developer | 0786 F758 55DE 53BA 7731 | pgoyette at netbsd dot org |
+------------------+--------------------------+----------------------------+


Home | Main Index | Thread Index | Old Index