From: fs.rajat@gmail.com (Rajat Sharma)
To: kernelnewbies@lists.kernelnewbies.org
Subject: spin_lock and scheduler confusion
Date: Sat, 8 Jan 2011 16:28:43 +0530 [thread overview]
Message-ID: <AANLkTimc6smGtBO5sB05nsO-7cz5R+sXAjn3nOihDi=T@mail.gmail.com> (raw)
In-Reply-To: <D69C90565D53114396BF743585AF5A09122E61E913@VSHINMSMBX01.vshodc.lntinfotech.com>
Hi Dave,
> > spin_lock_irqsave();
> > schedule();
> > spin_lock_irqrestore();
>
> You're not supposed to call schedule with interrupts disbled.
>
> If you follow the code though schedule, you'll see that it calls
> schedule_debug, which in turns checks to see if its being called from
> an atomic context and if it is, it will cause the
>
> BUG: scheduling while atomic:
Please refer to my first mail in this thread, I have already mentioned
about scheduling while atomic in my first mail:
> however if you have debugging options turned on like CONFIG_DEBUG_SPINLOCK, you may likely get kernel warning for 'scheduling > in atomic context'.
And also its just a warning print with stack dump but not the panic()
or BUG(), so system is still responsive. Its anyways not a good
practice, but what I was trying to highlight is what can happen if we
call schedule() function while holding spin_lock_irqsave. To kill the
curiosity, I tried out following module:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/spinlock.h>
#include <linux/sched.h>
MODULE_LICENSE("GPL");
static DEFINE_SPINLOCK(sleepy_lock);
static int __init sleepy_init(void)
{
unsigned long flags;
printk("SLEEPTEST: loading sleepytest\n");
spin_lock_irqsave(&sleepy_lock, flags);
schedule();
spin_unlock_irqrestore(&sleepy_lock, flags);
return 0;
}
static void __exit sleepy_exit(void)
{
printk("SLEEPTEST: unloading sleepytest\n");
}
module_init(sleepy_init);
module_exit(sleepy_exit);
And on my system, module silently prints messages without any atomic
schedule warning:
[ 6850.499940] SLEEPTEST: loading sleepytest
[ 6871.822539] SLEEPTEST: unloading sleepytest
I am not sure what config option turns on __schedule_bug(), but I
didn't see this message on my system:
CONFIG_SCHED_DEBUG=y
# CONFIG_DEBUG_SPINLOCK is not set
# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
Please try this module and let us know if you can hit schedule_bug().
Rajat
On Fri, Jan 7, 2011 at 11:16 PM, Viral Mehta
<Viral.Mehta@lntinfotech.com> wrote:
> Hi,
> ________________________________________
> From: Dave Hylands [dhylands at gmail.com]
> Subject: Re: spin_lock and scheduler confusion
>
>>> I guess timeslice expire case is not as same as preemption. Or may be I am
>>> terribly wrong.
>>
>>You shouldn't be holding ?a spinlock for periods of time approaching
>>the length of a timeslice. The timer interrupt is what determines the
>>end of a timeslice. No timer interrupt, no end of a timeslice.
>>Preemption is also triggered by the timer interrupt, or by releasing a
>>resource that a higher priority task is waiting for.
>
> thanks,
> it is much clear now.
>
>>Dave Hylands
>
> Thanks,
> Viral
>
> http://groups.google.com/group/fundamental-discussion?hl=en
>
> The contents of this e-mail and any attachment(s) may contain confidential or privileged information for the intended recipient(s). Unintended recipients are prohibited from taking action on the basis of information in this e-mail and ?using or disseminating the information, ?and must notify the sender and delete it from their system. L&T Infotech will not accept responsibility or liability for the accuracy or completeness of, or the presence of any virus or disabling code in this e-mail"
>
> ______________________________________________________________________
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
prev parent reply other threads:[~2011-01-08 10:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <D69C90565D53114396BF743585AF5A09122E61E90F@VSHINMSMBX01.vshodc.lntinfotech.com>
2011-01-05 22:23 ` spin_lock and scheduler confusion Viral Mehta
2011-01-07 3:51 ` Alexandre Courbot
2011-01-07 3:56 ` Mulyadi Santosa
2011-01-07 5:28 ` Dave Hylands
2011-01-07 6:27 ` Tayade, Nilesh
2011-01-07 7:02 ` Tirtha Ghosh
2011-01-07 7:35 ` Rajat Sharma
2011-01-07 7:49 ` nilesh
2011-01-07 8:03 ` anish singh
2011-01-07 9:31 ` nilesh
2011-01-07 13:58 ` Rajat Sharma
2011-01-07 15:49 ` Dave Hylands
2011-01-07 15:51 ` Dave Hylands
2011-01-07 17:46 ` Viral Mehta
2011-01-08 10:58 ` Rajat Sharma [this message]
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='AANLkTimc6smGtBO5sB05nsO-7cz5R+sXAjn3nOihDi=T@mail.gmail.com' \
--to=fs.rajat@gmail.com \
--cc=kernelnewbies@lists.kernelnewbies.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;
as well as URLs for NNTP newsgroup(s).