Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Mon, 5 Feb 2001 07:59:50 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Mon, 5 Feb 2001 07:59:40 -0500 Received: from colorfullife.com ([216.156.138.34]:43269 "EHLO colorfullife.com") by vger.kernel.org with ESMTP id ; Mon, 5 Feb 2001 07:59:29 -0500 Message-ID: <3A7EA3B0.2D7CFA19@colorfullife.com> Date: Mon, 05 Feb 2001 13:59:28 +0100 From: Manfred Spraul X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.2.16-22 i586) X-Accept-Language: en MIME-Version: 1.0 To: christophe barbe CC: linux-kernel@vger.kernel.org Subject: Re: IRQ and sleep_on In-Reply-To: <20010205131154.I31876@pc8.inup.com> <20010205133837.A485@pc8.inup.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org christophe barbe wrote: > > I've missed the thread "avoiding bad sleeps" last week. I've had a similar problem > and I would like to discuss the solution I've used to avoid it. > > I want to wake up a sleeping process from an IRQ handler. In the process, if I use > a interruptible_sleep_on(), I need first to restore flags (otherwise the process > will sleep forever). > > restore_flags(flags); > // <<== here IRQ handler possibly call wake_up() > interruptible_sleep_on(&my_queue); > > [...] > I've written a modified version of interruptible_sleep_on which takes an > additionnal argument : flags to be restored. That's possible, but it will crash on Sparc: you cannot restore the interrupt flag saved in one function in another function. The solution is very simple: do not call restore_flags() before interruptible_sleep_on(), the schedule internally reenables interrupts. >>>>>>>>>> for(;;) { cli(); if(condition) { sti(); break; } interruptible_sleep_on(); sti(); /* required! */ } >>>>>>>>> But if you are writing new code, then DO NOT USE sleep_on(), use add_wait_queue(), and a spinlock instead of cli(). Look at wait_event_irq in from the 2.4 kernel as an example. -- Manfred - 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/