Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755271AbbDTSY4 (ORCPT ); Mon, 20 Apr 2015 14:24:56 -0400 Received: from ns.horizon.com ([71.41.210.147]:63346 "HELO ns.horizon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751764AbbDTSYx (ORCPT ); Mon, 20 Apr 2015 14:24:53 -0400 Date: 20 Apr 2015 14:24:51 -0400 Message-ID: <20150420182451.6602.qmail@ns.horizon.com> From: "George Spelvin" To: dave@stgolabs.net Subject: Re: [PATCH 1/2] sched: lockless wake-queues Cc: linux@horizon.com, linux-kernel@vger.kernel.org, peterz@infradead.org Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1990 Lines: 63 +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: 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 property makes it impossible to guarantee the order of wakeups, + * but for efficiency we try to deliver wakeups in the order tasks + * are added. If we didn't mind reversing the order, a LIFO stack + * would be simpler. + */ +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. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/