为什么拿着自旋锁不能入睡? [英] Why can't you sleep while holding spinlock?

查看:132
本文介绍了为什么拿着自旋锁不能入睡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在linux内核中,为什么在按住自旋锁的同时不能入睡?

In the linux kernel, why can't you sleep while holding a spinlock?

推荐答案

示例:您的驱动程序正在执行,并且刚刚拔出了一个控制对其设备的访问的锁.保持锁定状态时,设备将发出一个中断,这将导致您的中断处理程序运行.在访问设备之前,中断处理程序还必须获得锁.在中断处理程序中取出自旋锁是一件合法的事.这是自旋锁操作无法休眠的原因之一.但是,如果中断例程与最初取出锁的代码在同一处理器中执行,会发生什么情况?当中断处理程序旋转时,非中断代码将无法运行以释放锁定.该处理器将永远旋转.

Example: your driver is executing and has just taken out a lock that controls access to its device. While the lock is held, the device issues an interrupt, which causes your interrupt handler to run. The interrupt handler, before accessing the device, must also obtain the lock. Taking out a spinlock in an interrupt handler is a legitimate thing to do; that is one of the reasons that spinlock operations do not sleep. But what happens if the interrupt routine executes in the same processor as the code that took out the lock originally? While the interrupt handler is spinning, the noninterrupt code will not be able to run to release the lock. That processor will spin forever.

来源: http://www.makelinux.net/ldd3/chp-5-sect-5.shtml

这篇关于为什么拿着自旋锁不能入睡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆