* Kernel semaphores
@ 2004-09-14 5:25 James Roper
0 siblings, 0 replies; 3+ messages in thread
From: James Roper @ 2004-09-14 5:25 UTC (permalink / raw)
To: linux-kernel
Hi,
I'm very new to kernel development. I'm implementing a mechanism in the CIFS
VFS client to ensure that the maximum number of outstanding requests is not
exceeded. To do this I'm using a semaphore. It works for a while, but
eventually (while doing some torture tests that send/receive many > 10MB
files simultaneously by multiple threads) my computer freezes. The logs show
the message "bad: scheduling while atomic!" followed by a trace. I'm
guessing this is where the problem is. So my question is, if my semaphore is
causing that error, what possible things could be triggering it? Could it be
an interrupt while waiting to acquire the semaphore? I'm using the
down_interruptible() to acquire and up() to release.
Thanks,
James
^ permalink raw reply [flat|nested] 3+ messages in thread
[parent not found: <mailman.1095139743.24686.linux-kernel2news@redhat.com>]
* Re: Kernel semaphores
[not found] <mailman.1095139743.24686.linux-kernel2news@redhat.com>
@ 2004-09-14 16:05 ` Pete Zaitcev
2004-09-14 17:03 ` Richard B. Johnson
0 siblings, 1 reply; 3+ messages in thread
From: Pete Zaitcev @ 2004-09-14 16:05 UTC (permalink / raw)
To: James Roper, linux-kernel
On Tue, 14 Sep 2004 15:25:24 +1000
James Roper <u3205097@anu.edu.au> wrote:
> [] So my question is, if my semaphore is
> causing that error, what possible things could be triggering it? Could it be
> an interrupt while waiting to acquire the semaphore? I'm using the
> down_interruptible() to acquire and up() to release.
You have to use spinlocks to provide a mutual exclusion to interrupts.
However, a process on CPU cannot sleep while holding a spinlock. So,
sometimes it's needed to create a derivative locking scheme, based
on spinlocks. A common trick is to combine semaphores and spinlocks.
I cannot be more specific without knowing your code.
-- Pete
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Kernel semaphores
2004-09-14 16:05 ` Pete Zaitcev
@ 2004-09-14 17:03 ` Richard B. Johnson
0 siblings, 0 replies; 3+ messages in thread
From: Richard B. Johnson @ 2004-09-14 17:03 UTC (permalink / raw)
To: James Roper; +Cc: Linux kernel
On Tue, 14 Sep 2004 15:25:24 +1000
James Roper <u3205097@anu.edu.au> wrote:
>
> [] So my question is, if my semaphore is
> causing that error, what possible things could be triggering it?
> Could it be an interrupt while waiting to acquire the semaphore?
> I'm using the down_interruptible() to acquire and up() to release.
>
You use downXXX() and upXXX() to serialize user-access to your
driver in the usual APIs like read() and write().
You need to use spin-locks to protect critical sections
from being changed by interrupts. You need to do this
even if you are using downXXX() and upXXX(). Basically
downXXX() will cause a semaphore-contender to sleep. You
can't do this in an interrupt.
Any code in an ISR or on the timer-queue must never
execute downXXX(). It is possible, under extremely
strange circumstances to execute upXXX() from an
interrupt because it doesn't sleep, only releases
the lock (if the resource is locked). You don't
design anything to do this, though. It can be used
as a work-around to release a resource that was acquired
by a task that hung or died.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-09-14 17:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-14 5:25 Kernel semaphores James Roper
[not found] <mailman.1095139743.24686.linux-kernel2news@redhat.com>
2004-09-14 16:05 ` Pete Zaitcev
2004-09-14 17:03 ` Richard B. Johnson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®