From: Davidlohr Bueso <dave@stgolabs.net>
To: George Spelvin <linux@horizon.com>
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org
Subject: Re: [PATCH 1/2] sched: lockless wake-queues
Date: Mon, 20 Apr 2015 13:08:20 -0700 [thread overview]
Message-ID: <1429560500.2042.17.camel@stgolabs.net> (raw)
In-Reply-To: <20150420182451.6602.qmail@ns.horizon.com>
On Mon, 2015-04-20 at 14:24 -0400, George Spelvin wrote:
> +struct wake_q_head {
> + struct wake_q_node *first;
> + struct wake_q_node *last;
> +};
> +
> +#define WAKE_Q_TAIL ((struct wake_q_node *) 0x01)
> +
> +#define WAKE_Q(name) \
> + struct wake_q_head name = { WAKE_Q_TAIL, WAKE_Q_TAIL }
>
> Is there some reason you don't use the simpler singly-linked list
> construction with the tail being a pointer to a pointer:
Sure, that would also work.
>
> struct wake_q_head {
> struct wake_q_node *first, **lastp;
> };
>
> #define WAKE_Q(name) \
> struct wake_q_head name = { WAKE_Q_TAIL, &name.first }
>
>
> That removes a conditional from wake_q_add:
>
> +/*
> + * Queue a task for later wake-up by wake_up_q(). If the task is already
> + * queued by someone else, leave it to them to deliver the wakeup.
This is already commented in the cmpxchg.
> + *
> + * This property makes it impossible to guarantee the order of wakeups,
> + * but for efficiency we try to deliver wakeups in the order tasks
> + * are added.
Ok.
> If we didn't mind reversing the order, a LIFO stack
> + * would be simpler.
While true, I don't think it belongs here.
> + */
> +void wake_q_add(struct wake_q_head *head, struct task_struct *task)
> +{
> + struct wake_q_node *node = &task->wake_q;
> +
> + /*
> + * Atomically grab the task, if ->wake_q is !nil already it means
> + * its already queued (either by us or someone else) and will get the
> + * wakeup due to that.
> + *
> + * This cmpxchg() implies a full barrier, which pairs with the write
> + * barrier implied by the wakeup in wake_up_list().
> + */
> + if (cmpxchg(&node->next, NULL, WAKE_Q_TAIL))
> + return;
> +
> + get_task_struct(task);
> +
> + /*
> + * The head is context local, there can be no concurrency.
> + */
> + *head->lastp = node;
> + head->lastp = &node->next;
> +}
>
> It may also be worth commenting the fact that wake_up_q() leaves the
> struct wake_q_head in a corrupt state, so don't try to do it again.
Right, we could re-init the list once the loop is complete, yes. But it
shouldn't matter due to how we use wake-queues.
Thanks,
Davidlohr
next prev parent reply other threads:[~2015-04-20 20:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-20 18:24 George Spelvin
2015-04-20 20:08 ` Davidlohr Bueso [this message]
2015-04-21 1:39 ` George Spelvin
-- strict thread matches above, loose matches on Subject: below --
2015-04-19 19:17 [PATCH 0/2] " Davidlohr Bueso
2015-04-19 19:17 ` [PATCH 1/2] sched: " Davidlohr Bueso
2015-04-20 14:42 ` Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1429560500.2042.17.camel@stgolabs.net \
--to=dave@stgolabs.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@horizon.com \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®