* [PATCH] UBI: Replace yield() with cond_resched()
@ 2012-05-08 8:26 Richard Weinberger
2012-05-08 8:31 ` Peter Zijlstra
2012-05-08 9:02 ` Artem Bityutskiy
0 siblings, 2 replies; 6+ messages in thread
From: Richard Weinberger @ 2012-05-08 8:26 UTC (permalink / raw)
To: linux-mtd; +Cc: peterz, Richard Weinberger, dwmw2, linux-kernel, dedekind1
The comment above yield()'s definition says:
* If you want to use yield() to wait for something, use wait_event().
* If you want to use yield() to be 'nice' for others, use cond_resched().
* If you still want to use yield(), do not!
The yield() usage of UBI really looks like the "be nice for others" case,
so use cond_resched().
Signed-off-by: Richard Weinberger <richard@nod.at>
CC: peterz@infradead.org
---
drivers/mtd/ubi/io.c | 6 +++---
drivers/mtd/ubi/wl.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 43f1a00..a125ef6 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -192,7 +192,7 @@ retry:
dbg_io("error %d%s while reading %d bytes from PEB "
"%d:%d, read only %zd bytes, retry",
err, errstr, len, pnum, offset, read);
- yield();
+ cond_resched();
goto retry;
}
@@ -366,7 +366,7 @@ retry:
if (retries++ < UBI_IO_RETRIES) {
dbg_io("error %d while erasing PEB %d, retry",
err, pnum);
- yield();
+ cond_resched();
goto retry;
}
ubi_err("cannot erase PEB %d, error %d", pnum, err);
@@ -384,7 +384,7 @@ retry:
if (ei.state == MTD_ERASE_FAILED) {
if (retries++ < UBI_IO_RETRIES) {
dbg_io("error while erasing PEB %d, retry", pnum);
- yield();
+ cond_resched();
goto retry;
}
ubi_err("cannot erase PEB %d", pnum);
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 7c1a9bf..f2f9056 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1243,7 +1243,7 @@ retry:
*/
spin_unlock(&ubi->wl_lock);
dbg_wl("the PEB %d is not in proper tree, retry", pnum);
- yield();
+ cond_resched();
goto retry;
}
--
1.7.6.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] UBI: Replace yield() with cond_resched()
2012-05-08 8:26 [PATCH] UBI: Replace yield() with cond_resched() Richard Weinberger
@ 2012-05-08 8:31 ` Peter Zijlstra
2012-05-08 9:02 ` Artem Bityutskiy
1 sibling, 0 replies; 6+ messages in thread
From: Peter Zijlstra @ 2012-05-08 8:31 UTC (permalink / raw)
To: Richard Weinberger; +Cc: dwmw2, linux-mtd, linux-kernel, dedekind1
On Tue, 2012-05-08 at 10:26 +0200, Richard Weinberger wrote:
> The comment above yield()'s definition says:
> * If you want to use yield() to wait for something, use wait_event().
> * If you want to use yield() to be 'nice' for others, use cond_resched().
> * If you still want to use yield(), do not!
Oh wow, someone actually reads comments, sweet!!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] UBI: Replace yield() with cond_resched()
2012-05-08 8:26 [PATCH] UBI: Replace yield() with cond_resched() Richard Weinberger
2012-05-08 8:31 ` Peter Zijlstra
@ 2012-05-08 9:02 ` Artem Bityutskiy
2012-05-08 10:59 ` Richard Weinberger
1 sibling, 1 reply; 6+ messages in thread
From: Artem Bityutskiy @ 2012-05-08 9:02 UTC (permalink / raw)
To: Richard Weinberger; +Cc: peterz, dwmw2, linux-mtd, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1205 bytes --]
On Tue, 2012-05-08 at 10:26 +0200, Richard Weinberger wrote:
> The comment above yield()'s definition says:
> * If you want to use yield() to wait for something, use wait_event().
> * If you want to use yield() to be 'nice' for others, use cond_resched().
> * If you still want to use yield(), do not!
>
> The yield() usage of UBI really looks like the "be nice for others" case,
> so use cond_resched().
>
> Signed-off-by: Richard Weinberger <richard@nod.at>
> CC: peterz@infradead.org
I guess we would better sleep for a couple of hundreds of milliseconds
instead.
The purpose was different. If we have I/O error, we hope it is a
transient failure. E.g., the HW is temporary unavailable because of an
internal issue. And with yield() we hoped to schedule away for longer
time than usual and let other processes which may affect that HW go
forward and do something.
But whole this thing does not have any solid real-case basis, just
something which looked sane to do to me.
Someone on the list also questioned the entire re-tries, but he did not
care enough to send a tested patch. But this is a separate and
independent issue.
--
Best Regards,
Artem Bityutskiy
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] UBI: Replace yield() with cond_resched()
2012-05-08 9:02 ` Artem Bityutskiy
@ 2012-05-08 10:59 ` Richard Weinberger
2012-05-08 13:23 ` Artem Bityutskiy
0 siblings, 1 reply; 6+ messages in thread
From: Richard Weinberger @ 2012-05-08 10:59 UTC (permalink / raw)
To: dedekind1; +Cc: peterz, dwmw2, linux-mtd, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1150 bytes --]
Am 08.05.2012 11:02, schrieb Artem Bityutskiy:
> On Tue, 2012-05-08 at 10:26 +0200, Richard Weinberger wrote:
>> The comment above yield()'s definition says:
>> * If you want to use yield() to wait for something, use wait_event().
>> * If you want to use yield() to be 'nice' for others, use cond_resched().
>> * If you still want to use yield(), do not!
>>
>> The yield() usage of UBI really looks like the "be nice for others" case,
>> so use cond_resched().
>>
>> Signed-off-by: Richard Weinberger <richard@nod.at>
>> CC: peterz@infradead.org
>
> I guess we would better sleep for a couple of hundreds of milliseconds
> instead.
So, you'd prefer a msleep_interruptible(500) instead of yield() in this case?
> The purpose was different. If we have I/O error, we hope it is a
> transient failure. E.g., the HW is temporary unavailable because of an
> internal issue. And with yield() we hoped to schedule away for longer
> time than usual and let other processes which may affect that HW go
> forward and do something.
Okay, yield() is clearly the wrong choice here.
cond_resched() is better.
Thanks,
//richard
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] UBI: Replace yield() with cond_resched()
2012-05-08 13:23 ` Artem Bityutskiy
@ 2012-05-08 13:22 ` Peter Zijlstra
0 siblings, 0 replies; 6+ messages in thread
From: Peter Zijlstra @ 2012-05-08 13:22 UTC (permalink / raw)
To: dedekind1; +Cc: Richard Weinberger, linux-mtd, dwmw2, linux-kernel
On Tue, 2012-05-08 at 16:23 +0300, Artem Bityutskiy wrote:
> On Tue, 2012-05-08 at 12:59 +0200, Richard Weinberger wrote:
> > > The purpose was different. If we have I/O error, we hope it is a
> > > transient failure. E.g., the HW is temporary unavailable because of an
> > > internal issue. And with yield() we hoped to schedule away for longer
> > > time than usual and let other processes which may affect that HW go
> > > forward and do something.
> >
> > Okay, yield() is clearly the wrong choice here.
> > cond_resched() is better.
>
> I do not think it is better. Yes, for I/O I'd suggest
> msleep_interruptible(200) instead.
At least document the intent of that random sleep. Otherwise we'll be
having this same discussion again in a few years or so ;-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] UBI: Replace yield() with cond_resched()
2012-05-08 10:59 ` Richard Weinberger
@ 2012-05-08 13:23 ` Artem Bityutskiy
2012-05-08 13:22 ` Peter Zijlstra
0 siblings, 1 reply; 6+ messages in thread
From: Artem Bityutskiy @ 2012-05-08 13:23 UTC (permalink / raw)
To: Richard Weinberger; +Cc: peterz, dwmw2, linux-mtd, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 604 bytes --]
On Tue, 2012-05-08 at 12:59 +0200, Richard Weinberger wrote:
> > The purpose was different. If we have I/O error, we hope it is a
> > transient failure. E.g., the HW is temporary unavailable because of an
> > internal issue. And with yield() we hoped to schedule away for longer
> > time than usual and let other processes which may affect that HW go
> > forward and do something.
>
> Okay, yield() is clearly the wrong choice here.
> cond_resched() is better.
I do not think it is better. Yes, for I/O I'd suggest
msleep_interruptible(200) instead.
--
Best Regards,
Artem Bityutskiy
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-05-08 13:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-08 8:26 [PATCH] UBI: Replace yield() with cond_resched() Richard Weinberger
2012-05-08 8:31 ` Peter Zijlstra
2012-05-08 9:02 ` Artem Bityutskiy
2012-05-08 10:59 ` Richard Weinberger
2012-05-08 13:23 ` Artem Bityutskiy
2012-05-08 13:22 ` Peter Zijlstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox