From: Thomas Gleixner <tglx@linutronix.de>
To: Jean Delvare <khali@linux-fr.org>
Cc: Sven-Thorsten Dietrich <sven@thebigcorporation.com>,
Leon Woestenberg <leon.woestenberg@gmail.com>,
linux-i2c@vger.kernel.org,
rt-users <linux-rt-users@vger.kernel.org>,
"Ben Dooks (embedded platforms)" <ben-linux@fluff.org>,
Peter Zijlstra <peterz@infradead.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: yield() in i2c non-happy paths hits BUG under -rt patch
Date: Fri, 13 Nov 2009 23:03:39 +0100 (CET) [thread overview]
Message-ID: <alpine.LFD.2.00.0911132139560.24119@localhost.localdomain> (raw)
In-Reply-To: <20091112211255.09cd884a@hyperion.delvare>
Jean,
On Thu, 12 Nov 2009, Jean Delvare wrote:
> As far as I can see, yield() doesn't have clear semantics attached.
> It's more of a utility function everyone could use as they see fit. In
> that respect, I understand your concerns about the coders' expectations
> and how they could be dismissed by RT. OTOH, I don't think that asking
> all developers to get rid of yield() because it _may not be_
> RT-compliant will lead you anywhere.
>
> In the 3 occurrences I've looked at, yield() is used as a way to
> busy-wait in a multitask-friendly way. What other use cases do you
> expect? I've never seen yield() used as a way to avoid deadlocks, which
> seems to be what you fear. I guess it could statistically be used that
> way, but obviously I wouldn't recommend it. Anything else?
>
> I would recommend that you audit the various use cases of yield(), and
> then offer replacements for the cases which are RT-unfriendly, leaving
> the rest alone and possibly clarifying the intended use of yield() to
> avoid future problems.
>
> In the i2c-algo-bit case, which started this thread, I can't really see
> what "something more explicit of an implementation" would be. yield()
> is as optimum as you can get, only delaying the processing if other
> tasks want to run. A sleep or a delay would delay the processing
> unconditionally, for an arbitrary amount of time, with no good reason.
> Removing yield() would increase the latency. This particular feature of
> i2c-algo-bit isn't necessarily terribly useful, but the code does the
> right thing, regardless of RT, so I just can't see any reason to change
> it.
The problem with yield() is not RT specific. Let's just look at the
yield semantics in mainline:
>From kernel/sched_fair.c
unsigned int __read_mostly sysctl_sched_compat_yield;
...
static void yield_task_fair(struct rq *rq)
{
if (likely(!sysctl_sched_compat_yield) && curr->policy != SCHED_BATCH) {
...
return;
}
}
So even in mainline yield() is doing nothing vs. latencies and is not
multitask friendly by default. It's just not complaining about it.
yield itself is a design failure in almost all of its aspects. It's
the poor mans replacement for proper async notification.
Q: Why put people yield() into their code ?
A: Because:
- it is less nasty than busy waiting for a long time
- it works better
- it solves the hang
- it happened to be in the driver they copied
- ....
At least 90% of the in kernel users of yield() are either a bug or a
design problem or lack of understanding or all of those.
I can see the idea of using yield() to let other tasks making progress
in situations where the hardware is a design failure as well,
e.g. bitbang devices. But if we have to deal with hardware which is
crap by design yield() is the worst of all answers simply due to its
horrible semantics.
Let's look at the code in question:
for (i = 0; i <= retries; i++) {
ret = i2c_outb(i2c_adap, addr);
if (ret == 1 || i == retries)
break;
bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n");
i2c_stop(adap);
udelay(adap->udelay);
yield();
We are in the error path as we failed to communicate with the device
in the first place. So there a two scenarios:
1) the device is essential for the boot process:
you have hit a problem anyway
2) this is just some random device probing:
who cares ?
So in both cases the following change is a noop vs. latency and
whatever your concerns are:
- udelay(adap->udelay);
- yield();
+ msleep(1);
Thanks,
tglx
next prev parent reply other threads:[~2009-11-13 22:03 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-07 19:01 yield() in i2c non-happy paths hits BUG under -rt patch Leon Woestenberg
[not found] ` <c384c5ea0911071101u7415d37o2611c542e5fae309-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-11-07 20:01 ` Jean Delvare
[not found] ` <20091107210147.3e754278-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-11-08 18:57 ` Sven-Thorsten Dietrich
[not found] ` <4AF7148C.9090706-IsH+rWyeNGyzjR9+/8zPv5owlv4uC7bZ@public.gmane.org>
2009-11-12 20:12 ` Jean Delvare
2009-11-13 22:03 ` Thomas Gleixner [this message]
2009-11-14 18:02 ` Jean Delvare
[not found] ` <alpine.LFD.2.00.0911132139560.24119-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-11-16 15:56 ` Mark Brown
[not found] ` <20091116155606.GC29479-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2009-11-18 0:50 ` Leon Woestenberg
2009-11-18 1:05 ` Alan Cox
[not found] ` <20091118010520.4cd397d4-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2009-11-18 16:28 ` Leon Woestenberg
2009-11-18 16:52 ` Jean Delvare
[not found] ` <20091118175202.490989d8-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-11-18 20:36 ` Thomas Gleixner
2009-11-19 12:05 ` Jean Delvare
[not found] ` <20091119130526.23a69b85-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-11-19 12:59 ` Alan Cox
[not found] ` <20091119125906.6ad00edd-qBU/x9rampVanCEyBjwyrvXRex20P6io@public.gmane.org>
2009-11-19 13:06 ` Peter Zijlstra
2009-11-19 14:00 ` Jean Delvare
2009-11-19 14:15 ` Peter Zijlstra
2009-11-19 13:11 ` Thomas Gleixner
2009-11-19 13:21 ` Peter Zijlstra
2009-11-19 13:22 ` Thomas Gleixner
2009-11-19 13:18 ` Peter Zijlstra
2009-11-18 20:46 ` [PATCH] cleanup sched_yield (sys)call nesting Sven-Thorsten Dietrich
[not found] ` <1258577194.12429.86.camel-ZUMNgey8dAdBci4yedNfAfz91O0DMRRp0E9HWUfgJXw@public.gmane.org>
2009-11-18 20:56 ` Thomas Gleixner
[not found] ` <alpine.LFD.2.00.0911182153010.24119-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-11-18 21:04 ` Sven-Thorsten Dietrich
2009-11-18 21:34 ` Thomas Gleixner
[not found] ` <alpine.LFD.2.00.0911182233510.24119-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-11-19 4:48 ` Sven-Thorsten Dietrich
[not found] ` <1258606116.25022.57.camel-ZUMNgey8dAdBci4yedNfAfz91O0DMRRp0E9HWUfgJXw@public.gmane.org>
2009-11-19 10:36 ` Thomas Gleixner
2009-11-19 3:20 ` Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LFD.2.00.0911132139560.24119@localhost.localdomain \
--to=tglx@linutronix.de \
--cc=ben-linux@fluff.org \
--cc=khali@linux-fr.org \
--cc=leon.woestenberg@gmail.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=sven@thebigcorporation.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox