public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: David Brownell <david-b@pacbell.net>
Cc: Linux Kernel list <linux-kernel@vger.kernel.org>,
	Florian Fainelli <florian.fainelli@telecomint.eu>,
	Haavard Skinnemoen <hskinnemoen@atmel.com>
Subject: Re: [patch 2.6.24-rc2 1/3] generic gpio -- gpio_chip support
Date: Mon, 12 Nov 2007 13:36:38 -0800	[thread overview]
Message-ID: <20071112133638.ff671fa0.akpm@linux-foundation.org> (raw)
In-Reply-To: <200711091136.20051.david-b@pacbell.net>

On Fri, 9 Nov 2007 11:36:19 -0800 David Brownell <david-b@pacbell.net> wrote:

> Provide new implementation infrastructure that platforms may choose to use
> when implementing the GPIO programming interface.  Platforms can update their
> GPIO support to use this.  In many cases the incremental cost to access a
> non-inlined GPIO should be on the order of a dozen instructions, so it won't
> normally be a problem.  The upside is:
> 
>   * Providing two features which were "want to have (but OK to defer)" when
>     GPIO interfaces were first discussed in November 2006:
> 
>     -	A "struct gpio_chip" to plug in GPIOs that aren't directly supported
> 	by SOC platforms, but come from FPGAs or other multifunction devices
> 	using conventional device registers (like UCB-1x00 or SM501 GPIOs,
> 	and southbridges in PCs with more open specs than usual).
> 
>     -	Full support for message-based GPIO expanders, where registers are
> 	accessed through sleeping I/O calls.  Previous support for these
> 	"cansleep" calls was just stubs.  (One example: the widely used
> 	pcf8574 I2C chips, with 8 GPIOs each.)
> 
>   * Including a non-stub implementation of the gpio_{request,free}() calls,
>     making those calls much more useful.  The diagnostic labels are also
>     recorded given DEBUG_FS, so /sys/kernel/debug/gpio can show a snapshot
>     of all GPIOs known to this infrastructure.
> 
> The driver programming interfaces introduced in 2.6.21 do not change at all;
> this infrastructure is entirely below those covers.
> 
> This opens the door to an augmented programming interface, addressing GPIOs
> by chip and index.  That could be used as a performance tweak (lookup once
> then cache, avoiding locking and lookup overheads) or to support transient
> GPIOs not registered in the integer GPIO namespace (maybe a USB-to-GPIO
> adapter, or GPIOs coupled to some other type of add-on card).
> 
> ...
>
> +
> +/* gpio_lock protects the table of chips and to gpio_chip->requested.
> + * While any gpio is requested, its gpio_chip is not removable.  It's
> + * a raw spinlock to ensure safe access from hardirq contexts, and to
> + * shrink bitbang overhead:  per-bit preemption would be very wrong.
> + */
> +static raw_spinlock_t gpio_lock = __RAW_SPIN_LOCK_UNLOCKED;

Well that's weird.

For starters, this initialisation will confound lockdep: it should use
DEFINE_SPINLOCK.

And the rationale seems dubious.  All you're saving here is a couple of
accesses to task_struct at spin_unlock()-time.  If the current task has a
preemption pending then yes, we'll schedule away but that's a very rare
thing and that's just what we're supposed to do.

So please tell us more about this.  Perhaps there are performance problems
with the current core preemption machinery.

> +	local_irq_save(flags);
> +	__raw_spin_lock(&gpio_lock);
>
> ...
> +	__raw_spin_unlock(&gpio_lock);
> +	local_irq_restore(flags);
> +	return status;
> +}

And of course if this code is converted to conventional locking, the above
becomes spin_lock_irqsave()/spin_lock_irqrestore() in many places.

> +/* There's no value in inlining GPIO calls that may sleep.

There's no value in inlining anything, hardly ;)

> +postcore_initcall(gpiolib_debugfs_init);

postcore_initcall() is unusual, hence a comment describing why it was
employed would be a good thing to have.

  reply	other threads:[~2007-11-12 21:37 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 [this message]
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
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=20071112133638.ff671fa0.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=david-b@pacbell.net \
    --cc=florian.fainelli@telecomint.eu \
    --cc=hskinnemoen@atmel.com \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox