Linux I2C development
 help / color / mirror / Atom feed
* Re: I2C from interrupt context?
       [not found] ` <m3bpws8ln3.fsf-fiqtE+24Nu0B9AHHLWeGtNQXobZC6xk2@public.gmane.org>
@ 2008-11-06 23:47   ` David Miller
       [not found]     ` <20081106.154754.02648408.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2008-11-06 23:47 UTC (permalink / raw)
  To: khc-9GfyWEdoJtJmR6Xm/wNWPw
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, khali-PUYAD+kWke1g9hUCZPvPmw,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA

From: Krzysztof Halasa <khc-9GfyWEdoJtJmR6Xm/wNWPw@public.gmane.org>
Date: Fri, 07 Nov 2008 00:44:48 +0100

[ Fixed i2c list address, it's now hosted at vger ]

> I'm updating my EEPROM console logger and have encountered a problem
> - the logger (as any console) can be called with hardware interrupts
> disabled and/or from interrupt context. It needs to write to I^2C
> (using ARM (Xscale) GPIO) and possibly SMBUS-only EEPROM chip. Is it
> at all supposed to be possible?

Not really.  The I2C operations need to be able to sleep and that's
not allowed in interrupt context.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: I2C from interrupt context?
       [not found]     ` <20081106.154754.02648408.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
@ 2008-11-07  9:11       ` Jean Delvare
       [not found]         ` <20081107101118.286f3713-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Jean Delvare @ 2008-11-07  9:11 UTC (permalink / raw)
  To: David Miller
  Cc: Krzysztof Halasa, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA

On Thu, 06 Nov 2008 15:47:54 -0800 (PST), David Miller wrote:
> From: Krzysztof Halasa <khc-9GfyWEdoJtJmR6Xm/wNWPw@public.gmane.org>
> Date: Fri, 07 Nov 2008 00:44:48 +0100
> 
> [ Fixed i2c list address, it's now hosted at vger ]
> 
> > I'm updating my EEPROM console logger and have encountered a problem
> > - the logger (as any console) can be called with hardware interrupts
> > disabled and/or from interrupt context. It needs to write to I^2C
> > (using ARM (Xscale) GPIO) and possibly SMBUS-only EEPROM chip. Is it
> > at all supposed to be possible?
> 
> Not really.  The I2C operations need to be able to sleep and that's
> not allowed in interrupt context.

That's not totally correct. Since kernel 2.6.25, i2c_transfer()
supports being called in contexts where it cannot sleep. Of course, for
it to work, the underlying i2c adapter driver must also not sleep. As I
recall, only the i2c-pxa driver was explicitly modified to support this
at the moment (see member use_pio of struct pxa_i2c) but other drivers
could be modified in a similar way (and some i2c adapter drivers may be
naturally non-sleeping - everything based on i2c-algo-bit is likely to
fall into this category.)

The situation is far from perfect though. For one thing, I seem to
recall that Andrew Morton didn't like the approach taken in
i2c_transfer(). For another, i2c_smbus_xfer() was not yet modified so
at this point only I2C-level transactions can be non-sleeping,
SMBus-level transactions can't. But all this could be fixed by anyone
who cares about these specific issues.

-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: I2C from interrupt context?
       [not found]         ` <20081107101118.286f3713-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
@ 2008-11-07 16:05           ` Krzysztof Halasa
       [not found]             ` <m3bpwrbjxs.fsf-fiqtE+24Nu0B9AHHLWeGtNQXobZC6xk2@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Halasa @ 2008-11-07 16:05 UTC (permalink / raw)
  To: Jean Delvare
  Cc: David Miller, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA

Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> writes:

> The situation is far from perfect though. For one thing, I seem to
> recall that Andrew Morton didn't like the approach taken in
> i2c_transfer(). For another, i2c_smbus_xfer() was not yet modified so
> at this point only I2C-level transactions can be non-sleeping,
> SMBus-level transactions can't. But all this could be fixed by anyone
> who cares about these specific issues.

Thanks, I'll look at it.
-- 
Krzysztof Halasa

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: I2C from interrupt context?
       [not found]             ` <m3bpwrbjxs.fsf-fiqtE+24Nu0B9AHHLWeGtNQXobZC6xk2@public.gmane.org>
@ 2008-11-11  7:57               ` Andrew Morton
  0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2008-11-11  7:57 UTC (permalink / raw)
  To: Krzysztof Halasa
  Cc: Jean Delvare, David Miller, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA

On Fri, 07 Nov 2008 17:05:35 +0100 Krzysztof Halasa <khc-9GfyWEdoJtJmR6Xm/wNWPw@public.gmane.org> wrote:

> Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> writes:
> 
> > The situation is far from perfect though. For one thing, I seem to
> > recall that Andrew Morton didn't like the approach taken in
> > i2c_transfer(). For another, i2c_smbus_xfer() was not yet modified so
> > at this point only I2C-level transactions can be non-sleeping,
> > SMBus-level transactions can't. But all this could be fixed by anyone
> > who cares about these specific issues.
> 
> Thanks, I'll look at it.

The problem (well: bug) is that in_atomic() returns false inside a
spinlock when CONFIG_PREEMPT=n.  The code as it stands can sleep
inside a spinlock, which is deadlockable if a scheduled-to task
tries to take the same spinlock.

There is no means like this by which a piece of code can determine
whether it can call schedule().  The pattern which we use in many many
places (most especially GFP_KERNEL/GFP_ATOMIC) is to pass a flag down
to callees telling them in some manner which context they were called from.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-11-11  7:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <m3bpws8ln3.fsf@maximus.localdomain>
     [not found] ` <m3bpws8ln3.fsf-fiqtE+24Nu0B9AHHLWeGtNQXobZC6xk2@public.gmane.org>
2008-11-06 23:47   ` I2C from interrupt context? David Miller
     [not found]     ` <20081106.154754.02648408.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2008-11-07  9:11       ` Jean Delvare
     [not found]         ` <20081107101118.286f3713-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2008-11-07 16:05           ` Krzysztof Halasa
     [not found]             ` <m3bpwrbjxs.fsf-fiqtE+24Nu0B9AHHLWeGtNQXobZC6xk2@public.gmane.org>
2008-11-11  7:57               ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox