From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Mika Kuoppala <mika.kuoppala-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
Cc: ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 1/1] i2c: Prevent priority inversion on top of bus lock
Date: Wed, 16 Sep 2009 13:51:59 +0200 [thread overview]
Message-ID: <20090916135159.0d74f178@hyperion.delvare> (raw)
In-Reply-To: <1253099829-17655-2-git-send-email-mika.kuoppala-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
On Wed, 16 Sep 2009 14:17:09 +0300, Mika Kuoppala wrote:
> Low priority thread holding the i2c bus mutex could block
> more high priority threads to access the bus resulting in
> unacceptable latencies. Change the mutex type to
> rt_mutex preventing priority inversion.
>
> Tested-by: Peter Ujfalusi <peter.ujfalusi-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
> Signed-off-by: Mika Kuoppala <mika.kuoppala-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
> ---
> drivers/i2c/i2c-core.c | 12 ++++++------
> include/linux/i2c.h | 3 +--
> 2 files changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 0e45c29..40f645f 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -548,7 +548,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
> goto out_list;
> }
>
> - mutex_init(&adap->bus_lock);
> + rt_mutex_init(&adap->bus_lock);
>
> /* Set default timeout to 1 second if not already set */
> if (adap->timeout == 0)
> @@ -1018,12 +1018,12 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
> #endif
>
> if (in_atomic() || irqs_disabled()) {
> - ret = mutex_trylock(&adap->bus_lock);
> + ret = rt_mutex_trylock(&adap->bus_lock);
> if (!ret)
> /* I2C activity is ongoing. */
> return -EAGAIN;
> } else {
> - mutex_lock_nested(&adap->bus_lock, adap->level);
> + rt_mutex_lock(&adap->bus_lock);
Hmm, rt_mutex doesn't handle locking model validation as regular
mutexes have? Looks like a regression to me.
> }
>
> /* Retry automatically on arbitration loss */
> @@ -1035,7 +1035,7 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
> if (time_after(jiffies, orig_jiffies + adap->timeout))
> break;
> }
> - mutex_unlock(&adap->bus_lock);
> + rt_mutex_unlock(&adap->bus_lock);
>
> return ret;
> } else {
> @@ -1839,7 +1839,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
> flags &= I2C_M_TEN | I2C_CLIENT_PEC;
>
> if (adapter->algo->smbus_xfer) {
> - mutex_lock(&adapter->bus_lock);
> + rt_mutex_lock(&adapter->bus_lock);
>
> /* Retry automatically on arbitration loss */
> orig_jiffies = jiffies;
> @@ -1853,7 +1853,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
> orig_jiffies + adapter->timeout))
> break;
> }
> - mutex_unlock(&adapter->bus_lock);
> + rt_mutex_unlock(&adapter->bus_lock);
> } else
> res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
> command, protocol, data);
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index f4784c0..ddca85d 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -340,8 +340,7 @@ struct i2c_adapter {
> void *algo_data;
>
> /* data fields that are valid for all devices */
> - u8 level; /* nesting level for lockdep */
> - struct mutex bus_lock;
> + struct rt_mutex bus_lock;
>
> int timeout; /* in jiffies */
> int retries;
--
Jean Delvare
next prev parent reply other threads:[~2009-09-16 11:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-16 11:17 [PATCH 0/1] Better i2c access latencies in high load situations Mika Kuoppala
[not found] ` <1253099829-17655-1-git-send-email-mika.kuoppala-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
2009-09-16 11:17 ` [PATCH 1/1] i2c: Prevent priority inversion on top of bus lock Mika Kuoppala
[not found] ` <1253099829-17655-2-git-send-email-mika.kuoppala-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
2009-09-16 11:51 ` Jean Delvare [this message]
[not found] ` <20090916135159.0d74f178-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-09-16 12:35 ` Mika Kuoppala
2009-09-16 20:32 ` Jean Delvare
2009-09-16 11:49 ` [PATCH 0/1] Better i2c access latencies in high load situations Jean Delvare
[not found] ` <20090916134944.4a329d62-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-09-16 12:08 ` Mika Kuoppala
2009-09-16 20:43 ` Jean Delvare
[not found] ` <20090916224328.47e349ab-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-09-21 13:14 ` Mika Kuoppala
2009-09-21 16:30 ` Jean Delvare
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=20090916135159.0d74f178@hyperion.delvare \
--to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
--cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mika.kuoppala-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.