* Calling wait_event_interruptible_timeout() in I2C wait functions
@ 2009-02-03 19:37 Timur Tabi
2009-02-04 20:00 ` Mike Ditto
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Timur Tabi @ 2009-02-03 19:37 UTC (permalink / raw)
To: linuxppc-dev, linux-i2c-u79uwXL29TY76Z2rM5mHXA; +Cc: Mark Brown
In i2c-mpc.c, the i2c_wait() function has this:
} else {
/* Interrupt mode */
result = wait_event_interruptible_timeout(i2c->queue,
(i2c->interrupt & CSR_MIF), timeout * HZ);
if (unlikely(result < 0)) {
pr_debug("I2C: wait interrupted\n");
writeccr(i2c, 0);
} else if (unlikely(!(i2c->interrupt & CSR_MIF))) {
That is, the driver calls wait_event_interruptible_timeout() to wait for
a response from the I2C controller after a read or write operation.
However, it appears that this is not common behavior for I2C driver. In
fact, only these six drivers ever call wait_event_interruptible_timeout():
i2c-cpm.c
i2c-ibm_iic.c
i2c-mpc.c
i2c-taos-evm.c
i2c-iop3xx.c
i2c-mv64xxx.c
Although one would think that calling wait_event_interruptible_timeout()
is a good idea, it fails in one situation: when the abrupt termination
of a process causes an I2C operation to occur. That is, you press ^C in
your application, and the driver issues a final I2C operation to shut
down the device. In this situation, wait_event_interruptible_timeout()
returns -ERESTARTSYS, which is then passed up through
i2c_smbus_write_byte_data().
So my question is, is i2c-mpc.c wrong in using
wait_event_interruptible_timeout()?
--
Timur Tabi
Linux kernel developer at Freescale
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: Calling wait_event_interruptible_timeout() in I2C wait functions
2009-02-03 19:37 Calling wait_event_interruptible_timeout() in I2C wait functions Timur Tabi
@ 2009-02-04 20:00 ` Mike Ditto
[not found] ` <49889CFA.7070308-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
[not found] ` <4989F3F4.7070207@consentry.com>
2 siblings, 0 replies; 5+ messages in thread
From: Mike Ditto @ 2009-02-04 20:00 UTC (permalink / raw)
To: linuxppc-dev, linux-i2c, Timur Tabi
Timur Tabi wrote:
> However, it appears that this is not common behavior for I2C driver. In
> fact, only these six drivers ever call wait_event_interruptible_timeout():
>
> i2c-cpm.c
I don't know about the others, but in i2c-cpm.c the use of interruptible
wait seems incorrect. Maybe it could be made correct, but as is, it
does not correctly clean up the hardware state or return a useful
value when interrupted by a signal. It's not clear what to do, anyway -
it's hard to know which messages of the interrupted transaction have
actually taken effect in the hardware. I think it's better to use
uninterruptible wait here and just live with the delayed signal
handling (one second delay in the unlikely worst case for i2c-cpm).
In general, I think it's best to consider I2C I/O to be uninterruptible,
like disk I/O. The only reason to make it interruptible is to make
sure you don't end up with an unkillable process due to an I/O error,
and that is adequately handled by a timeout (and re-initialization of
the I2C interface in that case).
-=] Mike [=-
^ permalink raw reply [flat|nested] 5+ messages in thread[parent not found: <49889CFA.7070308-KZfg59tc24xl57MIdRCFDg@public.gmane.org>]
* Re: Calling wait_event_interruptible_timeout() in I2C wait functions
[not found] ` <49889CFA.7070308-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
@ 2009-02-04 20:00 ` Mike Ditto
0 siblings, 0 replies; 5+ messages in thread
From: Mike Ditto @ 2009-02-04 20:00 UTC (permalink / raw)
To: linuxppc-dev-mnsaURCQ41sdnm+yROfE0A,
linux-i2c-u79uwXL29TY76Z2rM5mHXA, Timur Tabi
Timur Tabi wrote:
> However, it appears that this is not common behavior for I2C driver. In
> fact, only these six drivers ever call wait_event_interruptible_timeout():
>
> i2c-cpm.c
I don't know about the others, but in i2c-cpm.c the use of interruptible
wait seems incorrect. Maybe it could be made correct, but as is, it
does not correctly clean up the hardware state or return a useful
value when interrupted by a signal. It's not clear what to do, anyway -
it's hard to know which messages of the interrupted transaction have
actually taken effect in the hardware. I think it's better to use
uninterruptible wait here and just live with the delayed signal
handling (one second delay in the unlikely worst case for i2c-cpm).
In general, I think it's best to consider I2C I/O to be uninterruptible,
like disk I/O. The only reason to make it interruptible is to make
sure you don't end up with an unkillable process due to an I/O error,
and that is adequately handled by a timeout (and re-initialization of
the I2C interface in that case).
-=] Mike [=-
^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <4989F3F4.7070207@consentry.com>]
end of thread, other threads:[~2009-02-05 15:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-03 19:37 Calling wait_event_interruptible_timeout() in I2C wait functions Timur Tabi
2009-02-04 20:00 ` Mike Ditto
[not found] ` <49889CFA.7070308-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2009-02-04 20:00 ` Mike Ditto
[not found] ` <4989F3F4.7070207@consentry.com>
[not found] ` <4989F3F4.7070207-Vjf7OWgA3BLqlBn2x/YWAg@public.gmane.org>
2009-02-05 11:51 ` Mark Brown
[not found] ` <20090205115100.GD422-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2009-02-05 15:18 ` Timur Tabi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox