Spinlocks & schedule_timeout

buyitian buyit at live.cn
Thu Jan 9 00:09:01 EST 2014


I can understand that you are doing this only for test and study purpose, rather than use this in real scenario.

It is safe to sleep after you get a spinlock, although it is not reasonable to use spinlock if you need to sleep.
Let's say you have two threads:a and b. a is running on CPU 0 and b is running on CPU 1, and both of them are requiring spinlock x, suppose thread a gets x first, and it sleeps for 5 seconds, then the thread b which is running on CPU 1 have to wait for at least 5 seconds for the spinlock x, which is meaningless waiting. The task schedule on both CPU 0 and 1 are normal, CPU 0 can schedule because thread a falls to sleep although it has spinlock; CPU 1 can schedule on my ARM platform also because thread b will enable schedule on CPU 1 before polling spinlock.


在 2013年12月25日,18:15,"SaNtosh kuLkarni" <santosh.yesoptus at gmail.com> 写道:

Hi,

I wanted to verify/clarify if using schedule_timeout after acquiring a spinlock is safe?. So basically you have a situation where you are working on a critical code and you acquire a spin lock and you end up using a schedule_timeout after say setting the current task to Interruptible state 'cause you are waiting for some user space code to fill in some buffer from which you want to read.
So my doubt is simple, is it safe to acquire a spinlock and use schedule_timeout.
I assume the task is put in the run queue and will "ALWAYS" be scheduled back after the specified delay in schedule_timeout.

-- 
Regards,
Santosh
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140109/34f3c30b/attachment.html 
-------------- next part --------------
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


More information about the Kernelnewbies mailing list