From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933621AbdCHAjX (ORCPT ); Tue, 7 Mar 2017 19:39:23 -0500 Received: from LGEAMRELO11.lge.com ([156.147.23.51]:34248 "EHLO lgeamrelo11.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933481AbdCHAjH (ORCPT ); Tue, 7 Mar 2017 19:39:07 -0500 X-Original-SENDERIP: 156.147.1.121 X-Original-MAILFROM: byungchul.park@lge.com X-Original-SENDERIP: 165.244.249.26 X-Original-MAILFROM: byungchul.park@lge.com X-Original-SENDERIP: 10.177.222.33 X-Original-MAILFROM: byungchul.park@lge.com From: Byungchul Park To: , CC: , Subject: [PATCH] sched: Wake up all non-exclusive waiters in __wake_up_common() Date: Wed, 8 Mar 2017 09:21:52 +0900 Message-ID: <1488932512-18999-1-git-send-email-byungchul.park@lge.com> X-Mailer: git-send-email 1.9.1 X-MIMETrack: Itemize by SMTP Server on LGEKRMHUB06/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2017/03/08 09:22:12, Serialize by Router on LGEKRMHUB06/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2017/03/08 09:22:12, Serialize complete at 2017/03/08 09:22:12 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __wake_up_common() should wake up all non-exclusive waiters and exclusive waiters as many as nr_exclusive, but currently it does not. Consider a wait queue like the following for example: A(exclusive) -> B(non-exclusive) -> C(non-exclusive) Current code will wake up only A when nr_exclusive = 1, but has to wake up A, B and C. Make it do as we expect. Signed-off-by: Byungchul Park --- kernel/sched/wait.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/kernel/sched/wait.c b/kernel/sched/wait.c index 9453efe..0ea1083 100644 --- a/kernel/sched/wait.c +++ b/kernel/sched/wait.c @@ -67,12 +67,23 @@ static void __wake_up_common(wait_queue_head_t *q, unsigned int mode, { wait_queue_t *curr, *next; + /* + * We use nr_exclusive = 0 to wake up all no matter whether + * WQ_FLAG_EXCLUSIVE is set. However, we have to distinguish + * between the case and having finished all exclusive wake-up. + * So make nr_exclusive non-zero in advance in the former case. + */ + nr_exclusive = nr_exclusive ?: -1; + list_for_each_entry_safe(curr, next, &q->task_list, task_list) { unsigned flags = curr->flags; + if ((flags & WQ_FLAG_EXCLUSIVE) && !nr_exclusive) + continue; + if (curr->func(curr, mode, wake_flags, key) && - (flags & WQ_FLAG_EXCLUSIVE) && !--nr_exclusive) - break; + (flags & WQ_FLAG_EXCLUSIVE)) + nr_exclusive--; } } -- 1.9.1