From: David Brownell <david-b@pacbell.net>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Linux Kernel list <linux-kernel@vger.kernel.org>,
Florian Fainelli <florian.fainelli@telecomint.eu>,
Haavard Skinnemoen <hskinnemoen@atmel.com>,
Ingo Molnar <mingo@elte.hu>,
Nick Piggin <nickpiggin@yahoo.com.au>
Subject: Re: [patch 2.6.24-rc2 1/3] generic gpio -- gpio_chip support
Date: Wed, 14 Nov 2007 23:02:01 -0800 [thread overview]
Message-ID: <200711142302.02498.david-b@pacbell.net> (raw)
In-Reply-To: <alpine.LFD.0.9999.0711141228210.3265@localhost.localdomain>
On Wednesday 14 November 2007, Thomas Gleixner wrote:
> On Mon, 12 Nov 2007, David Brownell wrote:
> > > I'm still trying to understand what you've observed here. Is it the case
> > > that a single gpio operation went from 6.4 up to 11.2 usecs?
> >
> > That was a single bitbanged I2C bit transfer, with embedded udelay()s.
> > I believe that was four gpio operations, as summarized at the end of
> > that email above. Enabling preempt + debug increased the cost of
> > each GPIO call from whatever it was (reasonable) by 1.2 usecs.
>
> This raw lock change is just pampering over the design problem of the
> gpio lib:
>
> There is no need to check for every single access to a GPIO pin,
> whether the pin has a valid number and the chip, which provides access
> to the pin, is still registered.
As Haavard had noted. The "requested" flag is actually serving
as a longterm bit-level lock, which -- assuming well-behaved
callers, and no debug instrumentation -- obviates any need to
grab a spinlock in hot paths.
> Each driver, which wants to access a pin, needs to make sure that
>
> - the pin is available
> - the pin is associated to this driver
> - the chip reference count is incremented
>
> _before_ it starts to do anything with the pin. Once this is done the
> access to the pin is completely lock free except for the protection of
> the chip hardware itself.
That's what the gpio_request() call does, although it's using
something isomorphic to a refcount, not an actual refcount.
The key observation here is that we already *have* a bit which
is serving as a per-gpio lock. It's just never been viewed as
a lock before. :)
> The protection of the chip list can be converted to a mutex and
> does not need to be a spinlock at all.
No, we still need to use a spinlock to protect table changes.
The reason for that is briefly:
- gpio_request()/gpio_free() have so far been optional. Most
platforms implement them as NOPs, not all drivers use them.
(Having gpiolib in place should help change that ...)
- gpio_direction_input()/gpio_direction_output() implicitly
request the pins, if they weren't already requested.
- Those input/output direction-setting calls may be called
in IRQ contexts, which means (on non-RT kernels) no mutex.
So we're actually in good shape; just take out a bit of code
(or turn it into debugging instrumentation) and I don't think
anyone will complain about the locking any more.
- Dave
next prev parent reply other threads:[~2007-11-15 7:18 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-09 19:36 [patch 2.6.24-rc2 1/3] generic gpio -- gpio_chip support David Brownell
2007-11-12 21:36 ` Andrew Morton
2007-11-12 22:32 ` David Brownell
2007-11-12 23:28 ` Andrew Morton
2007-11-13 1:26 ` David Brownell
2007-11-13 9:34 ` Ingo Molnar
2007-11-13 19:22 ` David Brownell
2007-11-13 12:25 ` Nick Piggin
2007-11-14 8:20 ` David Brownell
2007-11-13 21:18 ` Nick Piggin
2007-11-15 6:28 ` David Brownell
2007-11-14 18:51 ` Nick Piggin
2007-11-15 8:17 ` David Brownell
2007-11-14 19:19 ` Nick Piggin
2007-11-14 19:21 ` Nick Piggin
2007-11-13 20:46 ` Andrew Morton
2007-11-14 6:52 ` David Brownell
2007-11-13 19:45 ` Nick Piggin
2007-11-14 8:37 ` David Brownell
2007-11-13 21:08 ` Nick Piggin
2007-11-15 6:23 ` David Brownell
2007-11-14 9:54 ` Haavard Skinnemoen
2007-11-15 6:50 ` David Brownell
2007-11-15 8:43 ` Haavard Skinnemoen
2007-11-14 9:59 ` Ingo Molnar
2007-11-14 12:14 ` Thomas Gleixner
2007-11-15 7:02 ` David Brownell [this message]
2007-11-15 7:32 ` Thomas Gleixner
2007-11-15 8:20 ` David Brownell
2007-11-15 8:51 ` Haavard Skinnemoen
2007-11-15 18:55 ` David Brownell
2007-11-15 7:17 ` David Brownell
2007-11-15 7:35 ` Thomas Gleixner
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=200711142302.02498.david-b@pacbell.net \
--to=david-b@pacbell.net \
--cc=akpm@linux-foundation.org \
--cc=florian.fainelli@telecomint.eu \
--cc=hskinnemoen@atmel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=nickpiggin@yahoo.com.au \
--cc=tglx@linutronix.de \
/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