From: Emmanuel Michon <emmanuel_michon@realmagic.fr>
To: linux-kernel@vger.kernel.org
Subject: spinlocking between user context / tasklet / tophalf question
Date: 26 Apr 2002 10:52:33 +0200 [thread overview]
Message-ID: <7wwuuu4zam.fsf@avalon.france.sdesigns.com> (raw)
Hi,
I read various documents about spinlocks, including Linux device
drivers by A.Rubini 2nd edition, Unreliable guide to locking by P.R.Russel,
and the source code of mainly network device drivers.
I'm trying to achieve correct SMP synchronization on the Sigma Designs
EM84xx; this one involves an extra small hardware interrupt (let's call it tophalf),
only one tasklet scheduled at end of tophalf, and usual kernel side code of
ioctl() I call usercontext.
tophalf and tasklet are potentially writing the same data X
tasklet and usercontext are potentially writing the same data Y
So, my first guess was to use two spinlocks, X_lock and Y_lock,
with
tophalf()
{
spin_lock(&X_lock);
write X
spin_unlock(&X_lock);
}
tasklet()
{
unsigned long flags;
spin_lock_irqsave(&X_lock,flags);
write X
spin_lock(&Y_lock);
write X, write Y
spin_unlock(&Y_lock);
write X
spin_unlock_irqrestore(&X_lock,flags);
}
ioctl()
{
spin_lock_bh(&Y_lock);
write Y ... maybe copy_from_user/copy_to_user
spin_unlock_bh(&Y_lock);
}
So far I get really hardcore freezes and I'm trying to handle this with kgdb
1. Should I use spin_lock(&Y_lock); or spin_lock_bh(&Y_lock); in the tasklet body?
2. What is the reality behind: ``things which sleep'', is it really a problem
to use copy_from_user/copy_to_user holding a spinlock?
3. Previous version used one semaphore to serialize usercontext access
down_interruptible(&sem)/up(&sem)
and handle tasklet concurrency with:
down_trylock(&sem)/up(&sem)
That allowed to catch signals (^C) with the usual -ERESTARTSYS stuff. As
far as I understand, spinlocks allow the serialization but no way to interrupt
a dead system call --- should I keep the semaphore only for this purpose?
Sincerely yours,
--
Emmanuel Michon
Chef de projet
REALmagic France SAS
Mobile: 0614372733 GPGkeyID: D2997E42
next reply other threads:[~2002-04-26 8:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-26 8:52 Emmanuel Michon [this message]
2002-04-26 16:33 ` george anzinger
2002-04-27 19:13 ` Alan Cox
2002-04-26 19:19 ` Robert Love
2002-04-27 22:52 ` Daniel Phillips
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7wwuuu4zam.fsf@avalon.france.sdesigns.com \
--to=emmanuel_michon@realmagic.fr \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®