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


Groups > linux.kernel > #1244514 > unrolled thread

Re: [PATCH v1 3/8] sched/completion: convert completions to use simple wait queues

Started byDaniel Wagner <daniel.wagner@bmw-carit.de>
First post2015-10-12 11:20 +0200
Last post2015-10-12 14:50 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v1 3/8] sched/completion: convert completions to use  simple wait queues Daniel Wagner <daniel.wagner@bmw-carit.de> - 2015-10-12 11:20 +0200
    Re: [PATCH v1 3/8] sched/completion: convert completions to use  simple wait queues Daniel Wagner <daniel.wagner@bmw-carit.de> - 2015-10-12 12:10 +0200
      Re: [PATCH v1 3/8] sched/completion: convert completions to use  simple wait queues Peter Zijlstra <peterz@infradead.org> - 2015-10-12 14:00 +0200
        Re: [PATCH v1 3/8] sched/completion: convert completions to use  simple wait queues Daniel Wagner <daniel.wagner@bmw-carit.de> - 2015-10-12 14:50 +0200

#1244514 — Re: [PATCH v1 3/8] sched/completion: convert completions to use simple wait queues

FromDaniel Wagner <daniel.wagner@bmw-carit.de>
Date2015-10-12 11:20 +0200
SubjectRe: [PATCH v1 3/8] sched/completion: convert completions to use simple wait queues
Message-ID<qiHqW-2Xd-13@gated-at.bofh.it>
On 09/09/2015 04:26 PM, Peter Zijlstra wrote:
> On Wed, Sep 09, 2015 at 02:05:29PM +0200, Daniel Wagner wrote:
>> @@ -50,10 +50,10 @@ void complete_all(struct completion *x)
>>  {
>>  	unsigned long flags;
>>  
>> -	spin_lock_irqsave(&x->wait.lock, flags);
>> +	raw_spin_lock_irqsave(&x->wait.lock, flags);
>>  	x->done += UINT_MAX/2;
>> -	__wake_up_locked(&x->wait, TASK_NORMAL, 0);
>> -	spin_unlock_irqrestore(&x->wait.lock, flags);
>> +	swake_up_locked(&x->wait);
>> +	raw_spin_unlock_irqrestore(&x->wait.lock, flags);
>>  }
>>  EXPORT_SYMBOL(complete_all);
> 
> I don't think that's correct; __wake_up_locked(.nr=0) would wake all
> waiters, where swake_up_locked() will only wake one.

I read that x->done should be protected via wait.lock during the whole
operation. swake_up_all() will release and reacquire the lock while
processing the all waiters. So we need to get

Could we play a trick like setting the highest bit in done for
indicating the complete_all() operation. The UINT_MAX/2 update looks
like do this by setting a value which has the biggest offset from 0 (but
why adding instead of just going for assigning...).

cheers,
daniel

--
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/

[toc] | [next] | [standalone]


#1244564

FromDaniel Wagner <daniel.wagner@bmw-carit.de>
Date2015-10-12 12:10 +0200
Message-ID<qiIdl-488-35@gated-at.bofh.it>
In reply to#1244514
On 10/12/2015 11:17 AM, Daniel Wagner wrote:
> On 09/09/2015 04:26 PM, Peter Zijlstra wrote:
>> On Wed, Sep 09, 2015 at 02:05:29PM +0200, Daniel Wagner wrote:
>>> @@ -50,10 +50,10 @@ void complete_all(struct completion *x)
>>>  {
>>>  	unsigned long flags;
>>>  
>>> -	spin_lock_irqsave(&x->wait.lock, flags);
>>> +	raw_spin_lock_irqsave(&x->wait.lock, flags);
>>>  	x->done += UINT_MAX/2;
>>> -	__wake_up_locked(&x->wait, TASK_NORMAL, 0);
>>> -	spin_unlock_irqrestore(&x->wait.lock, flags);
>>> +	swake_up_locked(&x->wait);
>>> +	raw_spin_unlock_irqrestore(&x->wait.lock, flags);
>>>  }
>>>  EXPORT_SYMBOL(complete_all);
>>
>> I don't think that's correct; __wake_up_locked(.nr=0) would wake all
>> waiters, where swake_up_locked() will only wake one.
> 
> I read that x->done should be protected via wait.lock during the whole
> operation. swake_up_all() will release and reacquire the lock while
> processing the all waiters. So we need to get
> 
> Could we play a trick like setting the highest bit in done for
> indicating the complete_all() operation. The UINT_MAX/2 update looks
> like do this by setting a value which has the biggest offset from 0 (but
> why adding instead of just going for assigning...).


I had something like this here in mind:

diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
index b020159..c03d4de 100644
--- a/kernel/sched/completion.c
+++ b/kernel/sched/completion.c
@@ -14,6 +14,9 @@
 #include <linux/sched.h>
 #include <linux/completion.h>

+#define COMPLETION_DONE_ALL (1UL << 31)
+#define COMPLETION_DONE_MASK (COMPLETION_DONE_ALL - 1)
+
 /**
  * complete: - signals a single thread waiting on this completion
  * @x:  holds the state of this particular completion
@@ -31,7 +34,7 @@ void complete(struct completion *x)
 	unsigned long flags;

 	raw_spin_lock_irqsave(&x->wait.lock, flags);
-	x->done++;
+	x->done = (x->done + 1) & COMPLETION_DONE_MASK;
 	swake_up_locked(&x->wait);
 	raw_spin_unlock_irqrestore(&x->wait.lock, flags);
 }
@@ -51,9 +54,9 @@ void complete_all(struct completion *x)
 	unsigned long flags;

 	raw_spin_lock_irqsave(&x->wait.lock, flags);
-	x->done += UINT_MAX/2;
-	swake_up_locked(&x->wait);
+	x->done |= COMPLETION_DONE_ALL;
 	raw_spin_unlock_irqrestore(&x->wait.lock, flags);
+	swake_up_all(&x->wait);
 }
 EXPORT_SYMBOL(complete_all);

@@ -79,7 +82,7 @@ do_wait_for_common(struct completion *x,
 		if (!x->done)
 			return timeout;
 	}
-	x->done--;
+	x->done = (x->done - 1) & COMPLETION_DONE_MASK;
 	return timeout ?: 1;
 }

@@ -281,7 +284,7 @@ bool try_wait_for_completion(struct completion *x)
 	if (!x->done)
 		ret = 0;
 	else
-		x->done--;
+		x->done = (x->done - 1) & COMPLETION_DONE_MASK;
 	raw_spin_unlock_irqrestore(&x->wait.lock, flags);
 	return ret;
 }

--
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/

[toc] | [prev] | [next] | [standalone]


#1244620

FromPeter Zijlstra <peterz@infradead.org>
Date2015-10-12 14:00 +0200
Message-ID<qiJVL-6sh-1@gated-at.bofh.it>
In reply to#1244564
On Mon, Oct 12, 2015 at 12:03:06PM +0200, Daniel Wagner wrote:
> On 10/12/2015 11:17 AM, Daniel Wagner wrote:
> > On 09/09/2015 04:26 PM, Peter Zijlstra wrote:
> >> On Wed, Sep 09, 2015 at 02:05:29PM +0200, Daniel Wagner wrote:
> >>> @@ -50,10 +50,10 @@ void complete_all(struct completion *x)
> >>>  {
> >>>  	unsigned long flags;
> >>>  
> >>> -	spin_lock_irqsave(&x->wait.lock, flags);
> >>> +	raw_spin_lock_irqsave(&x->wait.lock, flags);
> >>>  	x->done += UINT_MAX/2;
> >>> -	__wake_up_locked(&x->wait, TASK_NORMAL, 0);
> >>> -	spin_unlock_irqrestore(&x->wait.lock, flags);
> >>> +	swake_up_locked(&x->wait);
> >>> +	raw_spin_unlock_irqrestore(&x->wait.lock, flags);
> >>>  }
> >>>  EXPORT_SYMBOL(complete_all);
> >>
> >> I don't think that's correct; __wake_up_locked(.nr=0) would wake all
> >> waiters, where swake_up_locked() will only wake one.
> > 
> > I read that x->done should be protected via wait.lock during the whole
> > operation. swake_up_all() will release and reacquire the lock while
> > processing the all waiters. So we need to get
> > 
> > Could we play a trick like setting the highest bit in done for
> > indicating the complete_all() operation. The UINT_MAX/2 update looks
> > like do this by setting a value which has the biggest offset from 0 (but
> > why adding instead of just going for assigning...).
> 
> 
> I had something like this here in mind:

I'm not exactly sure what problem you're trying to solve here.. The fact
that we cannot call swake_all() while holding &x->wait.lock, or the fact
that complete_all() is typically called from a context which cannot do
swake_all() either?

Note:

Documentation/scheduler/completion.txt:complete() and complete_all() can be called in hard-irq/atomic context safely.

Which is very much _NOT_ true of swake_all().
--
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/

[toc] | [prev] | [next] | [standalone]


#1244653

FromDaniel Wagner <daniel.wagner@bmw-carit.de>
Date2015-10-12 14:50 +0200
Message-ID<qiKI9-7EQ-1@gated-at.bofh.it>
In reply to#1244620
On 10/12/2015 01:58 PM, Peter Zijlstra wrote:
> On Mon, Oct 12, 2015 at 12:03:06PM +0200, Daniel Wagner wrote:
>> On 10/12/2015 11:17 AM, Daniel Wagner wrote:
>>> On 09/09/2015 04:26 PM, Peter Zijlstra wrote:
>>>> On Wed, Sep 09, 2015 at 02:05:29PM +0200, Daniel Wagner wrote:
>>>>> @@ -50,10 +50,10 @@ void complete_all(struct completion *x)
>>>>>  {
>>>>>  	unsigned long flags;
>>>>>  
>>>>> -	spin_lock_irqsave(&x->wait.lock, flags);
>>>>> +	raw_spin_lock_irqsave(&x->wait.lock, flags);
>>>>>  	x->done += UINT_MAX/2;
>>>>> -	__wake_up_locked(&x->wait, TASK_NORMAL, 0);
>>>>> -	spin_unlock_irqrestore(&x->wait.lock, flags);
>>>>> +	swake_up_locked(&x->wait);
>>>>> +	raw_spin_unlock_irqrestore(&x->wait.lock, flags);
>>>>>  }
>>>>>  EXPORT_SYMBOL(complete_all);
>>>>
>>>> I don't think that's correct; __wake_up_locked(.nr=0) would wake all
>>>> waiters, where swake_up_locked() will only wake one.
>>>
>>> I read that x->done should be protected via wait.lock during the whole
>>> operation. swake_up_all() will release and reacquire the lock while
>>> processing the all waiters. So we need to get
>>>
>>> Could we play a trick like setting the highest bit in done for
>>> indicating the complete_all() operation. The UINT_MAX/2 update looks
>>> like do this by setting a value which has the biggest offset from 0 (but
>>> why adding instead of just going for assigning...).
>>
>>
>> I had something like this here in mind:
> 
> I'm not exactly sure what problem you're trying to solve here.. The fact
> that we cannot call swake_all() while holding &x->wait.lock, or the fact
> that complete_all() is typically called from a context which cannot do
> swake_all() either?

The first one.

> Note:
> 
> Documentation/scheduler/completion.txt:complete() and complete_all() can be called in hard-irq/atomic context safely.
> 
> Which is very much _NOT_ true of swake_all().

Heh and I thought I got this right.

Looks like completion.c cannot use swait here. Or do you have an idea
how to do it? I was thinking on deferring the wake all call from
hard-irq/atomic but I guess this something to avoided.

cheers,
daniel
--
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/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web