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 <[email protected]> wrote:

> ** **
>
> ** **
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *Prajosh Premdas
> *Sent:* Wednesday, November 02, 2011 2:02 AM
> *To:* [email protected]
> *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
_______________________________________________
Kernelnewbies mailing list
[email protected]
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

Reply via email to