From: Jean Delvare <khali@linux-fr.org>
To: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: David Miller <davem@davemloft.net>, <netdev@vger.kernel.org>,
linux-next@vger.kernel.org, linux-kernel@vger.kernel.org,
Mika Kuoppala <mika.kuoppala@nokia.com>,
Ben Hutchings <bhutchings@solarflare.com>,
Linux I2C <linux-i2c@vger.kernel.org>
Subject: Shared i2c adapter locking (Was: linux-next: manual merge of the net tree with the i2c tree)
Date: Thu, 29 Oct 2009 15:43:17 +0100 [thread overview]
Message-ID: <20091029154317.651904b9@hyperion.delvare> (raw)
In-Reply-To: <20091026133757.7cf87e49.sfr@canb.auug.org.au>
Hi Stephen,
On Mon, 26 Oct 2009 13:37:57 +1100, Stephen Rothwell wrote:
> Today's linux-next merge of the net tree got a conflict in
> drivers/net/sfc/sfe4001.c between commit
> 3f7c0648f727a6d5baf6117653e4001dc877b90b ("i2c: Prevent priority
> inversion on top of bus lock") from the i2c tree and commit
> c9597d4f89565b6562bd3026adbe6eac6c317f47 ("sfc: Merge sfe4001.c into
> falcon_boards.c") from the net tree.
>
> I have applied the following merge fixup patch (after removing
> drivers/net/sfc/sfe4001.c) and can carry it as necessary.
Thanks for fixing it. The core problem here IMHO is that the sfc
network driver touches i2c internals which it would rather leave alone.
This is the only driver I know of which does this.
I can think of 3 different ways to address the issue.
Method #1: add a public API to grab/release an I2C segment.
void i2c_adapter_lock(struct i2c_adapter *adapter)
{
rt_mutex_lock(&adapter->bus_lock);
}
void i2c_adapter_unlock(struct i2c_adapter *adapter)
{
rt_mutex_unlock(&adapter->bus_lock);
}
It has the advantage of simplicity. The problem is that it is not
symmetric. Whatever shares the pins with I2C, I2C is considered the
main user in that its mutex is used to guarantee mutual exclusion. If
the other subsystem also has a mandatory locking mechanism, there will
have to be a decision on who is locked first. If not all drivers agree,
lockdep will get confused.
Method #2: let the driver implement its own "main" locking, and have
all pin users (i2c etc.) take it in addition to any subsystem-specific
mutex. As far as the sfc network driver is concerned, that would mean
adding pre-xfer and post-xfer hooks to i2c-algo-bit, where the "main"
mutex in question would be taken resp. released.
It has the advantage of symmetry. The problem is performance, as
regular operation will require to take and release two mutexes instead
of just one. But it is a fairly generic approach which could solve
other issues too.
Method #3: let individual bus drivers implement segment locking
themselves, with custom locking/unlocking hooks. This way, a device
sharing pins between several functions can have its own mutex
protecting these pins globally, and all user subsystems (i2c etc.) use
this single mutex.
It has the advantage of performance and symmetry, at the price of
fragility. If the i2c bus driver implements locking improperly... I am
also worried by inconsistencies that may arise, if different i2c
adapters are protected by different mutex types (mutex vs. real-time
mutex vs. spinlock etc.) but maybe this will be seen as an advantage
rather than a problem.
I'm not really sure if I have a preference yet, so please speak up if
you do.
--
Jean Delvare
next prev parent reply other threads:[~2009-10-29 14:43 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-26 2:37 linux-next: manual merge of the net tree with the i2c tree Stephen Rothwell
2009-10-26 13:46 ` Ben Hutchings
2009-10-29 14:43 ` Jean Delvare [this message]
2009-10-29 15:09 ` Shared i2c adapter locking (Was: linux-next: manual merge of the net tree with the i2c tree) Ben Hutchings
2009-11-05 13:11 ` Shared i2c adapter locking Jean Delvare
2009-11-05 13:57 ` Ben Hutchings
[not found] ` <1257429444.2793.2.camel-xQnnTUlwzDrdvaEqJLTMTA9jg9n5Vt1AMm0uRHvK7Nw@public.gmane.org>
2009-11-05 14:07 ` Jean Delvare
2009-11-17 8:33 ` Stephen Rothwell
[not found] ` <20091117193313.b750804e.sfr-3FnU+UHB4dNDw9hX6IcOSA@public.gmane.org>
2009-11-17 9:35 ` Jean Delvare
2009-11-17 11:51 ` David Miller
2009-11-17 13:32 ` Ben Hutchings
2009-11-17 14:13 ` David Miller
[not found] ` <20091117103554.03971b2f-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2009-11-17 20:59 ` Stephen Rothwell
[not found] ` <20091118075917.9ac0248c.sfr-3FnU+UHB4dNDw9hX6IcOSA@public.gmane.org>
2009-11-19 6:53 ` David Miller
2009-11-19 7:05 ` Stephen Rothwell
2009-11-10 11:42 ` linux-next: manual merge of the net tree with the i2c tree Jean Delvare
2009-11-10 13:22 ` Ben Hutchings
2009-11-10 15:02 ` Jean Delvare
2009-11-10 15:10 ` Ben Hutchings
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=20091029154317.651904b9@hyperion.delvare \
--to=khali@linux-fr.org \
--cc=bhutchings@solarflare.com \
--cc=davem@davemloft.net \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=mika.kuoppala@nokia.com \
--cc=netdev@vger.kernel.org \
--cc=sfr@canb.auug.org.au \
/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;
as well as URLs for NNTP newsgroup(s).