From: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
To: Daniel Baluta <daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Cc: jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
knaack.h-Mmb7MZpHnFY@public.gmane.org,
lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org,
pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org,
linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
lucas.demarchi-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org,
ggao-ktqnL0SqcGIj5TC/SZClsA@public.gmane.org,
adi.reus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
cmo-fc6wVz46lShBDgjK7y7TUQ@public.gmane.org,
mwelling-EkmVulN54Sk@public.gmane.org
Subject: Re: [RFC PATCH 9/9] iio: imu: inv_mpu6050: Fix deadlock between i2c adapter lock and mpu lock
Date: Tue, 1 Mar 2016 21:50:52 +0100 [thread overview]
Message-ID: <20160301205052.GD1488@katana> (raw)
In-Reply-To: <1455810794-3188-10-git-send-email-daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 1931 bytes --]
On Thu, Feb 18, 2016 at 05:53:14PM +0200, Daniel Baluta wrote:
> From: Adriana Reus <adriana.reus-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>
> This deadlock occurs if the accel/gyro and the sensor on the auxiliary
> I2C (in my setup it's an ak8975) are working at the same time.
>
> Scenario:
>
> T1 T2
> ==== ====
> inv_mpu6050_read_fifo aux sensor op (eg. ak8975_read_raw)
> | |
> mutex_lock(&indio_dev->mlock) i2c_transfer
> | |
> i2c transaction i2c adapter lock
> | |
> i2c adapter lock i2c_mux_master_xfer
> |
> inv_mpu6050_select_bypass
> |
> mutex_lock(&indio_dev->mlock)
>
> When we operate on an mpu sensor the order of locking is mpu lock
> followed by the i2c adapter lock. However, when we operate the auxiliary
> sensor the order of locking is the other way around.
>
> In order to avoid this enable the bypass mux bit once in the beginning
> and remove the select/deselect_bypass functions.
>
> This patch moves the bypass enabling in a separate function
> that is called once at probe and removes the functionality from
> inv_mpu_select/deselect_bypass.
>
> Another advantage of this approach is that power-wise the mpu chip isn't
> powered up at each auxiliary sensor i2c transaction so if only the
> compass is used this would be more power efficient.
I think the comments (power must be enabled on select) rendered this
solution not acceptable. What about using mutex_trylock in
inv_mpu6050_select_bypass() and returning -EAGAIN if the lock is already
held?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
WARNING: multiple messages have this Message-ID (diff)
From: Wolfram Sang <wsa@the-dreams.de>
To: Daniel Baluta <daniel.baluta@intel.com>
Cc: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de,
pmeerw@pmeerw.net, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
lucas.demarchi@intel.com, srinivas.pandruvada@linux.intel.com,
ggao@invensense.com, adi.reus@gmail.com, cmo@melexis.com,
mwelling@ieee.org
Subject: Re: [RFC PATCH 9/9] iio: imu: inv_mpu6050: Fix deadlock between i2c adapter lock and mpu lock
Date: Tue, 1 Mar 2016 21:50:52 +0100 [thread overview]
Message-ID: <20160301205052.GD1488@katana> (raw)
In-Reply-To: <1455810794-3188-10-git-send-email-daniel.baluta@intel.com>
[-- Attachment #1: Type: text/plain, Size: 1901 bytes --]
On Thu, Feb 18, 2016 at 05:53:14PM +0200, Daniel Baluta wrote:
> From: Adriana Reus <adriana.reus@intel.com>
>
> This deadlock occurs if the accel/gyro and the sensor on the auxiliary
> I2C (in my setup it's an ak8975) are working at the same time.
>
> Scenario:
>
> T1 T2
> ==== ====
> inv_mpu6050_read_fifo aux sensor op (eg. ak8975_read_raw)
> | |
> mutex_lock(&indio_dev->mlock) i2c_transfer
> | |
> i2c transaction i2c adapter lock
> | |
> i2c adapter lock i2c_mux_master_xfer
> |
> inv_mpu6050_select_bypass
> |
> mutex_lock(&indio_dev->mlock)
>
> When we operate on an mpu sensor the order of locking is mpu lock
> followed by the i2c adapter lock. However, when we operate the auxiliary
> sensor the order of locking is the other way around.
>
> In order to avoid this enable the bypass mux bit once in the beginning
> and remove the select/deselect_bypass functions.
>
> This patch moves the bypass enabling in a separate function
> that is called once at probe and removes the functionality from
> inv_mpu_select/deselect_bypass.
>
> Another advantage of this approach is that power-wise the mpu chip isn't
> powered up at each auxiliary sensor i2c transaction so if only the
> compass is used this would be more power efficient.
I think the comments (power must be enabled on select) rendered this
solution not acceptable. What about using mutex_trylock in
inv_mpu6050_select_bypass() and returning -EAGAIN if the lock is already
held?
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2016-03-01 20:50 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-18 15:53 [RFC PATCH 0/9] iio: Fix ABBA deadlock in inv-mpu6050 Daniel Baluta
2016-02-18 15:53 ` [RFC PATCH 1/9] iio: imu: inv_mpu6050: Fix multiline comments style Daniel Baluta
2016-02-21 20:36 ` Jonathan Cameron
2016-02-18 15:53 ` [RFC PATCH 2/9] iio: imu: inv_mpu6050: Fix Yoda conditions Daniel Baluta
[not found] ` <1455810794-3188-3-git-send-email-daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-19 9:09 ` Crt Mori
2016-02-19 9:09 ` Crt Mori
[not found] ` <CAKv63us92Epe0go9JGNScbeOepg3_j8RyW9w2qgN01Jvnj3sUQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-02-21 20:38 ` Jonathan Cameron
2016-02-21 20:38 ` Jonathan Cameron
2016-03-01 21:23 ` Wolfram Sang
2016-03-01 21:23 ` Wolfram Sang
2016-02-18 15:53 ` [RFC PATCH 3/9] iio: imu: inv_mpu6050: Fix newlines to make code easier to read Daniel Baluta
2016-02-21 20:38 ` Jonathan Cameron
2016-02-18 15:53 ` [RFC PATCH 4/9] iio: imu: inv_mpu6050: Remove unnecessary parentheses Daniel Baluta
2016-02-21 20:39 ` Jonathan Cameron
2016-02-18 15:53 ` [RFC PATCH 5/9] iio: imu: inv_mpu6050: Delete space before comma Daniel Baluta
2016-02-18 15:53 ` [RFC PATCH 6/9] iio: imu: inv_mpu6050: Fix code indent for if statement Daniel Baluta
2016-02-21 20:40 ` Jonathan Cameron
2016-02-18 15:53 ` [RFC PATCH 7/9] iio: imu: inv_mpu6050: Fix alignment with open parenthesis Daniel Baluta
[not found] ` <1455810794-3188-8-git-send-email-daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-02-21 20:41 ` Jonathan Cameron
2016-02-21 20:41 ` Jonathan Cameron
[not found] ` <56CA2101.8050805-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2016-02-21 20:59 ` Joe Perches
2016-02-21 20:59 ` Joe Perches
[not found] ` <1456088384.31061.2.camel-6d6DIl74uiNBDgjK7y7TUQ@public.gmane.org>
2016-02-21 21:08 ` Jonathan Cameron
2016-02-21 21:08 ` Jonathan Cameron
2016-02-18 15:53 ` [RFC PATCH 8/9] i2c: i2c-mux: Allow for NULL select callback Daniel Baluta
2016-03-01 20:30 ` Wolfram Sang
2016-03-01 20:38 ` Daniel Baluta
2016-02-18 15:53 ` [RFC PATCH 9/9] iio: imu: inv_mpu6050: Fix deadlock between i2c adapter lock and mpu lock Daniel Baluta
2016-02-18 18:17 ` Srinivas Pandruvada
[not found] ` <1455819430.7375.192.camel-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2016-02-19 20:17 ` Ge Gao
2016-02-19 20:17 ` Ge Gao
2016-02-19 20:17 ` Ge Gao
[not found] ` <1455810794-3188-10-git-send-email-daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2016-03-01 20:50 ` Wolfram Sang [this message]
2016-03-01 20:50 ` Wolfram Sang
2016-03-02 16:33 ` Daniel Baluta
[not found] ` <CAEnQRZAF-tAjDwJkUNEVQXYqWDt7RsH2bH81UBAMUhsoWEt73g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-03-02 17:06 ` Wolfram Sang
2016-03-02 17:06 ` Wolfram Sang
2016-02-21 23:17 ` [RFC PATCH 0/9] iio: Fix ABBA deadlock in inv-mpu6050 Wolfram Sang
2016-02-22 9:43 ` Daniel Baluta
2016-02-26 15:52 ` Daniel Baluta
2016-03-03 23:09 ` Peter Rosin
[not found] ` <1457046598-15367-1-git-send-email-peda-SamgB31n2u5IcsJQ0EH25Q@public.gmane.org>
2016-03-04 10:20 ` Daniel Baluta
2016-03-04 10:20 ` Daniel Baluta
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=20160301205052.GD1488@katana \
--to=wsa-z923lk4zbo2bacvfa/9k2g@public.gmane.org \
--cc=adi.reus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=cmo-fc6wVz46lShBDgjK7y7TUQ@public.gmane.org \
--cc=daniel.baluta-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=ggao-ktqnL0SqcGIj5TC/SZClsA@public.gmane.org \
--cc=jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=knaack.h-Mmb7MZpHnFY@public.gmane.org \
--cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=lucas.demarchi-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=mwelling-EkmVulN54Sk@public.gmane.org \
--cc=pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org \
--cc=srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@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.