Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1594749 > unrolled thread

[PATCH] sched: Wake up all non-exclusive waiters in __wake_up_common()

Started byByungchul Park <byungchul.park@lge.com>
First post2017-03-08 01:40 +0100
Last post2017-03-10 08:10 +0100
Articles 2 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] sched: Wake up all non-exclusive waiters in __wake_up_common() Byungchul Park <byungchul.park@lge.com> - 2017-03-08 01:40 +0100
    Re: [PATCH] sched: Wake up all non-exclusive waiters in  __wake_up_common() Byungchul Park <byungchul.park@lge.com> - 2017-03-10 08:10 +0100

#1594749 — [PATCH] sched: Wake up all non-exclusive waiters in __wake_up_common()

FromByungchul Park <byungchul.park@lge.com>
Date2017-03-08 01:40 +0100
Subject[PATCH] sched: Wake up all non-exclusive waiters in __wake_up_common()
Message-ID<tixO1-76a-13@gated-at.bofh.it>
__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 <byungchul.park@lge.com>
---
 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

[toc] | [next] | [standalone]


#1596689 — Re: [PATCH] sched: Wake up all non-exclusive waiters in __wake_up_common()

FromByungchul Park <byungchul.park@lge.com>
Date2017-03-10 08:10 +0100
SubjectRe: [PATCH] sched: Wake up all non-exclusive waiters in __wake_up_common()
Message-ID<tjmQx-cH-3@gated-at.bofh.it>
In reply to#1594749
On Wed, Mar 08, 2017 at 09:21:52AM +0900, Byungchul Park wrote:
> __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.

I'm wondering if I was wrong. Am I wrong?

> 
> Signed-off-by: Byungchul Park <byungchul.park@lge.com>
> ---
>  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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web