lkml.org 
[lkml]   [2000]   [Oct]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Interrupt/Sleep deadlock

On Thu, 28 Sep 2000, Ivan Passos wrote:
>
> In order to get the configuration of a board, I have to send, from
> userspace, an ioctl to the driver and wait for the board to complete its
> action. The way this is implemented is as follows:
> - In the ioctl, the driver sends a command to the board and then goes to
> sleep (interruptible_sleep_on(&info->config_wait));
> - The board receives the command, handles it and answers back with an
> interrupt;
> - The driver's interrupt handler schedules a bottom-half action.
> - The bottom-half calls wake_up_interuptible(&info->config_wait).
> - The ioctl returns and the userspace application has the board
> configuration.
>
> Now, the problem: the board is so fast that it interrupts back _before_
> the driver goes to sleep, i.e.:
> - Driver sends command to board;
> - Driver goes to sl... interrupt back from board!!
> - Interrupt handler schedules bottom-half.
> - Bottom-half calls wake_up.
> - Ioctl continues, and _then_ goes to sleep. System locked.
>
> I can't disable interrupts before going to sleep, because the event that
> wakes me up is an interrupt. However, if I don't protect it from the
> interrupts, the system locks ...
>
> Is there any other way in Linux to implement this?!?!?!

This e-mail is to thank everybody who answered, and to let you know that
the solution I'm using is the one suggested by Nigel Gamble
<nigel@mvista.com>:

"You could use a semaphore for this. Initialize it to 0, then call
down() from the ioctl, and up() from the interrupt handler. If the
up() happens before the down(), the down() won't go to sleep."

Initializing it to 0 means:

cfg_sem = MUTEX_LOCKED;

It's the simplest to understand, and it works great!!

Does anybody see a problem with this implementation??

Thanks again!!

Later,
Ivan

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:39    [from the cache]
©2003-2011 Jasper Spaans