* spin_lock behavior
@ 2011-11-02 9:01 Prajosh Premdas
2011-11-03 22:04 ` Daniel Baluta
2011-11-03 22:11 ` Jeff Haran
0 siblings, 2 replies; 5+ messages in thread
From: Prajosh Premdas @ 2011-11-02 9:01 UTC (permalink / raw)
To: kernelnewbies
Hi
I wrote a sample module which looked like this and i expected the module to
hang as i have used 2 spin_lock simultaneously. But i find the print after
the second spin_lock being printed and the module works perfectly fine. Can
any body please help me in understanding this? I got this problem from a
driver i wrote and had a typo "spin_lock" instead of "spin_unlock" the
driver worked fine and i caught the mistake only during a review
*#include <linux/module.h>*
*#include <linux/spinlock.h>*
*
*
*struct sp_q {*
*spinlock_t spinlock;*
*uint8_t data;*
*};*
*
*
*static int __init sp_lck_init(void)*
*{*
*
*
* struct sp_q test;*
* *
* /* Spin lock Init */*
*
*
* spin_lock_init(&test.spinlock);*
* *
* printk("<1>Test start\n");*
* *
* spin_lock(&test.spinlock);*
* test.data = 0; *
* spin_lock(&test.spinlock); *
* *
* printk("<1>How come???\n");*
* return 0;*
*
*
*}*
*
*
*static void __exit sp_lck_exit(void)*
*{*
*
*
*}*
*
*
*module_init(sp_lck_init);*
*module_exit(sp_lck_exit);*
*MODULE_LICENSE("GPL");*
--
Regards,
Prajosh Premdas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111102/b922f1a2/attachment.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* spin_lock behavior
@ 2011-11-02 13:53 Prajosh Premdas
0 siblings, 0 replies; 5+ messages in thread
From: Prajosh Premdas @ 2011-11-02 13:53 UTC (permalink / raw)
To: kernelnewbies
Hi
I wrote a sample module which looked like this and i expected the module to
hang as i have used 2 spin_lock simultaneously. But i find the print after
the second spin_lock being printed and the module works perfectly fine. Can
any body please help me in understanding this? I got this problem from a
driver i wrote and had a typo "spin_lock" instead of "spin_unlock" the
driver worked fine and i caught the mistake only during a review
*#include <linux/module.h>*
*#include <linux/spinlock.h>*
*
*
*struct sp_q {*
*spinlock_t spinlock;*
*uint8_t data;*
*};*
*
*
*static int __init sp_lck_init(void)*
*{*
*
*
* struct sp_q test;*
* *
* /* Spin lock Init */*
*
*
* spin_lock_init(&test.spinlock);*
* *
* printk("<1>Test start\n");*
* *
* spin_lock(&test.spinlock);*
* test.data = 0; *
* spin_lock(&test.spinlock); *
* *
* printk("<1>How come???\n");*
* return 0;*
*
*
*}*
*
*
*static void __exit sp_lck_exit(void)*
*{*
*
*
*}*
*
*
*module_init(sp_lck_init);*
*module_exit(sp_lck_exit);*
*MODULE_LICENSE("GPL");*
--
Regards,
Prajosh Premdas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111102/60a34bbd/attachment.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* spin_lock behavior
2011-11-02 9:01 Prajosh Premdas
@ 2011-11-03 22:04 ` Daniel Baluta
2011-11-03 22:11 ` Jeff Haran
1 sibling, 0 replies; 5+ messages in thread
From: Daniel Baluta @ 2011-11-03 22:04 UTC (permalink / raw)
To: kernelnewbies
Hello,
> I wrote a sample module which looked like this and i expected the module to
> hang as i have used 2 spin_lock simultaneously. But i find the print after
> the second spin_lock being printed and the module works perfectly fine. Can
> any body please help me in understanding this? I got this problem from a
> driver i wrote and had a typo "spin_lock" instead of "spin_unlock" the
> driver worked fine and i caught the mistake only during a review
Are you running your tests on an UP with preemption disabled?
thanks,
Daniel.
^ permalink raw reply [flat|nested] 5+ messages in thread
* spin_lock behavior
2011-11-02 9:01 Prajosh Premdas
2011-11-03 22:04 ` Daniel Baluta
@ 2011-11-03 22:11 ` Jeff Haran
2011-11-04 6:33 ` Prajosh Premdas
1 sibling, 1 reply; 5+ messages in thread
From: Jeff Haran @ 2011-11-03 22:11 UTC (permalink / raw)
To: kernelnewbies
From: kernelnewbies-bounces@kernelnewbies.org
[mailto:kernelnewbies-bounces at kernelnewbies.org] On Behalf Of Prajosh
Premdas
Sent: Wednesday, November 02, 2011 2:02 AM
To: kernelnewbies at kernelnewbies.org
Subject: spin_lock behavior
Hi
I wrote a sample module which looked like this and i expected the module
to hang as i have used 2 spin_lock simultaneously. But i find the print
after the second spin_lock being printed and the module works perfectly
fine. Can any body please help me in understanding this? I got this
problem from a driver i wrote and had a typo "spin_lock" instead of
"spin_unlock" the driver worked fine and i caught the mistake only
during a review
#include <linux/module.h>
#include <linux/spinlock.h>
struct sp_q {
spinlock_t spinlock;
uint8_t data;
};
static int __init sp_lck_init(void)
{
struct sp_q test;
/* Spin lock Init */
spin_lock_init(&test.spinlock);
printk("<1>Test start\n");
spin_lock(&test.spinlock);
test.data = 0;
spin_lock(&test.spinlock);
printk("<1>How come???\n");
return 0;
}
static void __exit sp_lck_exit(void)
{
}
module_init(sp_lck_init);
module_exit(sp_lck_exit);
MODULE_LICENSE("GPL");
--
Regards,
Prajosh Premdas
On single processor systems, spin_lock() doesn't actually spin on
anything.
The term spin_lock() is a bit of a misnomer in my opinion as it implies
that some sort of spinning will go on if the lock has already been
taken.
It really means, sort of, "disable preemption, then serialize access on
this variable among other threads on other CPUs, and I promise not to
try to take this lock in any top or bottom half context on this CPU."
Of course, that would make for an unwieldy function name, so its call
spin_lock().
Jeff Haran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111103/290676ef/attachment-0001.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* spin_lock behavior
2011-11-03 22:11 ` Jeff Haran
@ 2011-11-04 6:33 ` Prajosh Premdas
0 siblings, 0 replies; 5+ messages in thread
From: Prajosh Premdas @ 2011-11-04 6:33 UTC (permalink / raw)
To: kernelnewbies
Hi
I am running with preemption on.
Jeff, but when i tried this on x86 machine my kernel just froze. How is
that happening?
On Fri, Nov 4, 2011 at 3:41 AM, Jeff Haran <jharan@bytemobile.com> wrote:
> ** **
>
> ** **
>
> *From:* kernelnewbies-bounces at kernelnewbies.org [mailto:
> kernelnewbies-bounces at kernelnewbies.org] *On Behalf Of *Prajosh Premdas
> *Sent:* Wednesday, November 02, 2011 2:02 AM
> *To:* kernelnewbies at kernelnewbies.org
> *Subject:* spin_lock behavior****
>
> ** **
>
> Hi ****
>
> ** **
>
> I wrote a sample module which looked like this and i expected the module
> to hang as i have used 2 spin_lock simultaneously. But i find the print
> after the second spin_lock being printed and the module works perfectly
> fine. Can any body please help me in understanding this? I got this problem
> from a driver i wrote and had a typo "spin_lock" instead of "spin_unlock"
> the driver worked fine and i caught the mistake only during a review ****
>
> ** **
>
> *#include <linux/module.h>*****
>
> *#include <linux/spinlock.h>*****
>
> ** **
>
> *struct sp_q {*****
>
> *spinlock_t spinlock;*****
>
> *uint8_t data;*****
>
> *};*****
>
> ** **
>
> *static int __init sp_lck_init(void)*****
>
> *{*****
>
> ** **
>
> * struct sp_q test;*****
>
> * *****
>
> * /* Spin lock Init */*****
>
> ** **
>
> * spin_lock_init(&test.spinlock);*****
>
> * *****
>
> * printk("<1>Test start\n");*****
>
> * *****
>
> * spin_lock(&test.spinlock);*****
>
> * test.data = 0; *****
>
> * spin_lock(&test.spinlock); *****
>
> * *****
>
> * printk("<1>How come???\n");*****
>
> * return 0;*****
>
> ** **
>
> *}*****
>
> ** **
>
> *static void __exit sp_lck_exit(void)*****
>
> *{*****
>
> ** **
>
> *}*****
>
> ** **
>
> *module_init(sp_lck_init);*****
>
> *module_exit(sp_lck_exit);*****
>
> *MODULE_LICENSE("GPL");*****
>
> ** **
>
> --
> Regards,
>
> Prajosh Premdas****
>
> ** **
>
> On single processor systems, spin_lock() doesn?t actually spin on anything.
> ****
>
> ** **
>
> The term spin_lock() is a bit of a misnomer in my opinion as it implies
> that some sort of spinning will go on if the lock has already been taken.*
> ***
>
> ** **
>
> It really means, sort of, ?disable preemption, then serialize access on
> this variable among other threads on other CPUs, and I promise not to try
> to take this lock in any top or bottom half context on this CPU.?****
>
> ** **
>
> Of course, that would make for an unwieldy function name, so its call
> spin_lock().****
>
> ** **
>
> Jeff Haran****
>
> ** **
>
--
Regards,
Prajosh Premdas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20111104/9aa540cb/attachment-0001.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-11-04 6:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-02 13:53 spin_lock behavior Prajosh Premdas
-- strict thread matches above, loose matches on Subject: below --
2011-11-02 9:01 Prajosh Premdas
2011-11-03 22:04 ` Daniel Baluta
2011-11-03 22:11 ` Jeff Haran
2011-11-04 6:33 ` Prajosh Premdas
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).