<feed xmlns='http://www.w3.org/2005/Atom'>
<title>wireguard-openbsd/sys/kern/kern_task.c, branch jd/queueboosts</title>
<subtitle>WireGuard implementation for the OpenBSD kernel</subtitle>
<id>https://git.zx2c4.com/wireguard-openbsd/atom/sys/kern/kern_task.c?h=jd%2Fqueueboosts</id>
<link rel='self' href='https://git.zx2c4.com/wireguard-openbsd/atom/sys/kern/kern_task.c?h=jd%2Fqueueboosts'/>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/'/>
<updated>2020-06-11T06:06:55Z</updated>
<entry>
<title>whitespace and speeling fix in a comment. no functional change.</title>
<updated>2020-06-11T06:06:55Z</updated>
<author>
<name>dlg</name>
<email>dlg@openbsd.org</email>
</author>
<published>2020-06-11T06:06:55Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=c3947ab6809e882afd84a50be3f118fa48d73694'/>
<id>urn:sha1:c3947ab6809e882afd84a50be3f118fa48d73694</id>
<content type='text'>
</content>
</entry>
<entry>
<title>make taskq_barrier wait for pending tasks, not just the running tasks.</title>
<updated>2020-06-11T06:03:54Z</updated>
<author>
<name>dlg</name>
<email>dlg@openbsd.org</email>
</author>
<published>2020-06-11T06:03:54Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=1330a2b357f6b959a5fb5d7d65fb6cb7670ea87b'/>
<id>urn:sha1:1330a2b357f6b959a5fb5d7d65fb6cb7670ea87b</id>
<content type='text'>
I wrote taskq_barrier with the behaviour described in the manpage:

 taskq_barrier() guarantees that any task that was running on the tq taskq
 when the barrier was called has finished by the time the barrier returns.

Note that it talks about the currently running task, not pending tasks.

It just so happens that the original implementation just used task_add
to put a condvar on the list and waited for it to run. Because task_add
uses TAILQ_INSERT_TAIL, you ended up waiting for all pending to work to
run too, not just the currently running task.

The new implementation took advantage of already holding the lock and
used TAILQ_INSERT_HEAD to put the barrier work at the front of the queue
so it would run next, which is closer to the stated behaviour.

Using the tail insert here restores the previous accidental behaviour.

jsg@ points out the following:

&gt; The linux functions like flush_workqueue() we use this for in drm want
&gt; to wait on all scheduled work not just currently running.
&gt;
&gt; ie a comment from one of the linux functions:
&gt;
&gt; /**
&gt; * flush_workqueue - ensure that any scheduled work has run to completion.
&gt; * @wq: workqueue to flush
&gt; *
&gt; * This function sleeps until all work items which were queued on entry
&gt; * have finished execution, but it is not livelocked by new incoming ones.
&gt; */
&gt;
&gt; our implementation of this in drm is
&gt;
&gt; void
&gt; flush_workqueue(struct workqueue_struct *wq)
&gt; {
&gt;	if (cold)
&gt;		return;
&gt;
&gt;	taskq_barrier((struct taskq *)wq);
&gt; }

I don't think it's worth complicating the taskq API, so I'm just
going to make taskq_barrier wait for pending work too.

tested by tb@
ok jsg@
</content>
</entry>
<entry>
<title>add support for running taskq_barrier from a task inside the taskq.</title>
<updated>2020-06-07T23:23:30Z</updated>
<author>
<name>dlg</name>
<email>dlg@openbsd.org</email>
</author>
<published>2020-06-07T23:23:30Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=ba6141230e521e0e88295f6eff6b83b7b2c89b38'/>
<id>urn:sha1:ba6141230e521e0e88295f6eff6b83b7b2c89b38</id>
<content type='text'>
this is required for an upcoming drm update, where the linux workqueue
api that supports this is mapped to our taskq api.

this main way taskqs support that is to have the taskq worker threads
record thir curproc on the taskq, so taskq_barrier calls can iterate
over that list looking for their own curproc. if a barriers curproc
is in the list, it must be running inside the taskq, and should
pretend that it's a barrier task.

this also supports concurrent barrier calls by having the taskq
recognise the situation and have the barriers work together rather
than deadlocking. they end up trying to share the work of getting
the barrier tasks onto the workers. once all the workers (or in tq
barriers) have rendezvoused the barrier calls unwind, and the last
one out lets the other barriers and barrier tasks return.

all this barrier logic is implemented in the barrier code, it takes
the existing multiworker handling out of the actual taskq loop.

thanks to jsg@ for testing this and previous versions of the diff.
ok visa@ kettenis@
</content>
</entry>
<entry>
<title>Convert infinite sleeps to {m,t}sleep_nsec(9).</title>
<updated>2019-12-19T17:40:10Z</updated>
<author>
<name>mpi</name>
<email>mpi@openbsd.org</email>
</author>
<published>2019-12-19T17:40:10Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=babb761de1ba2d43bc3717c713c02b0d14e11db2'/>
<id>urn:sha1:babb761de1ba2d43bc3717c713c02b0d14e11db2</id>
<content type='text'>
ok visa@
</content>
</entry>
<entry>
<title>Make taskq_barrier(9) work for multi-threaded task queues.</title>
<updated>2019-06-23T12:56:10Z</updated>
<author>
<name>kettenis</name>
<email>kettenis@openbsd.org</email>
</author>
<published>2019-06-23T12:56:10Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=cf12935a7990399886941bdebfbc360358bed85b'/>
<id>urn:sha1:cf12935a7990399886941bdebfbc360358bed85b</id>
<content type='text'>
ok visa@
</content>
</entry>
<entry>
<title>add WITNESS support to barriers modelled on the timeout stuff visa did.</title>
<updated>2019-04-28T04:20:40Z</updated>
<author>
<name>dlg</name>
<email>dlg@openbsd.org</email>
</author>
<published>2019-04-28T04:20:40Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=60aa962e73cae02e1e20bd0158dfeeaca6adff42'/>
<id>urn:sha1:60aa962e73cae02e1e20bd0158dfeeaca6adff42</id>
<content type='text'>
if a taskq takes a lock, and something holding that lock calls
taskq_barrier, there's a potential deadlock. detect this as a lock
order problem when witness is enable. task_del conditionally followed
by taskq_barrier is a common pattern, so add a taskq_del_barrier
wrapper for it that unconditionally checks for the deadlock, like
timeout_del_barrier.

ok visa@
</content>
</entry>
<entry>
<title>deprecate TASKQ_CANTSLEEP since nothing uses it anymore</title>
<updated>2019-04-01T03:23:45Z</updated>
<author>
<name>dlg</name>
<email>dlg@openbsd.org</email>
</author>
<published>2019-04-01T03:23:45Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=f07ea34c5e75e667c4e41a91aafd29a377670d41'/>
<id>urn:sha1:f07ea34c5e75e667c4e41a91aafd29a377670d41</id>
<content type='text'>
if we ever want it back, it's in the attic.

ok mpi@ visa@ kettenis@
</content>
</entry>
<entry>
<title>add task_pending</title>
<updated>2018-12-16T03:36:02Z</updated>
<author>
<name>dlg</name>
<email>dlg@openbsd.org</email>
</author>
<published>2018-12-16T03:36:02Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=ff4a31df00d60e7bdbdb7aa285f60033f5a00e26'/>
<id>urn:sha1:ff4a31df00d60e7bdbdb7aa285f60033f5a00e26</id>
<content type='text'>
jsg@ wants this for drm, and i've had a version of it in diffs sine
2016, but obviously havent needed to use it just yet.

task_pending is modelled on timeout_pending, and tells you if the
task is on a list waiting to execute.

ok jsg@
</content>
</entry>
<entry>
<title>replace the bare sleep state handling in barriers with wait cond code</title>
<updated>2017-12-14T00:45:16Z</updated>
<author>
<name>dlg</name>
<email>dlg@openbsd.org</email>
</author>
<published>2017-12-14T00:45:16Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=5241d0f41bff911dddbb0bdb0cb1324af43d23a7'/>
<id>urn:sha1:5241d0f41bff911dddbb0bdb0cb1324af43d23a7</id>
<content type='text'>
</content>
</entry>
<entry>
<title>add taskq_barrier</title>
<updated>2017-11-13T23:52:49Z</updated>
<author>
<name>dlg</name>
<email>dlg@openbsd.org</email>
</author>
<published>2017-11-13T23:52:49Z</published>
<link rel='alternate' type='text/html' href='https://git.zx2c4.com/wireguard-openbsd/commit/?id=6f1a6781a83b125d8a38dc0a8774fc2037fe151f'/>
<id>urn:sha1:6f1a6781a83b125d8a38dc0a8774fc2037fe151f</id>
<content type='text'>
taskq_barrier guarantees that any task that was running on the taskq
has finished by the time taskq_barrier returns. it is similar to
intr_barrier.

this is needed for use in ifq_barrier as part of an upcoming change.
</content>
</entry>
</feed>
