当前位置:网站首页>中断中为何不能使用信号量,中断上下文为何不能睡眠
中断中为何不能使用信号量,中断上下文为何不能睡眠
2022-06-22 08:11:00 【土豆西瓜大芝麻】
不论是书上还是网上,对这块的解释,总是很凌乱, 让人不好理清。 大部分开发者可能也只知其然,不知所以然。在网上找到一篇对此解释言简意赅,一看就懂的文章,故分享过来。
1、中断中为何不能使用信号量?
答: 信号量会导致睡眠。
2、中断上下为何不能睡眠?
(以下为转载: http://blog.chinaunix.net/uid-7332782-id-3213376.html)
中断发生以后,CPU跳到内核设置好的中断处理代码中去,由这部分内核代码来处理中断。这个处理过程中的上下文就是中断上下文。
为什么可能导致睡眠的函数都不能在中断上下文中使用呢? 首先睡眠的含义是将进程置于“睡眠”状态,在这个状态的进程不能被调度执行。然后,在一定的时机,这个进程可能会被重新置为“运行”状态,从而可能被调度执行。 可见,“睡眠”与“运行”是针对进程而言的,代表进程的task_struct结构记录着进程的状态。内核中的“调度器”通过task_struct对进程进行调度。
但是,中断上下文却不是一个进程,它并不存在task_struct,所以它是不可调度的。所以,在中断上下文就不能睡眠。
那么,中断上下文为什么不存在对应的task_struct结构呢?
中断的产生是很频繁的(至少每毫秒(看配置,可能10毫秒或其他值)会产生一个时钟中断),并且中断处理过程会很快。如果为中断上下文维护一个对应的task_struct结构,那么这个结构频繁地分配、回收、并且影响调度器的管理,这样会对整个系统的吞吐量有所影响。
但是在某些追求实时性的嵌入式linux中,中断也可能被赋予task_struct结构。这是为了避免大量中断不断的嵌套,导致一段时间内CPU总是运行在中断上下文,使得某些优先级非常高的进程得不到运行。这种做法能够提高系统的实时性,但是代价是吞吐量的降低。
边栏推荐
- . Net core technology stack website Collection
- 【Oracle 数据库】奶妈式教程 day14 转换函数
- Postgresql源码(56)可扩展类型分析ExpandedObject/ExpandedRecord
- Mt4/mql4 getting started to mastering EA tutorial lesson 5 - common functions of MQL language (V) - common functions of account information
- Mt4/mql4 getting started to proficient in foreign exchange EA automatic trading tutorial - identify the emergence of the new K line
- LR 2022 ultra detailed installation tutorial "latest"
- Mt4/mql4 getting started to mastering EA tutorial lesson 3 - common functions of MQL language (III) - common functions of K-line value taking
- Stored procedures and functions of MySQL
- MySQL queries data within one hour
- (8)顺序栈和链栈
猜你喜欢

Maptalks: basic operation and wms/wmts map service loading

QT combox的使用示例

并发三大特性2-有序性

【Oracle 数据库】奶妈式教程 day14 转换函数
关于菲涅尔现象
![[普通物理]波的能量与干涉](/img/fe/066aa9e8ed776b8f069b59b7123367.png)
[普通物理]波的能量与干涉

多点闹钟实例

【Oracle 數據庫】奶媽式教程 day13 日期函數

The solution to the problem of the first screen picture loading flicker

Mt4/mql4 getting started to mastering EA tutorial lesson 5 - common functions of MQL language (V) - common functions of account information
随机推荐
并发三大特性1-可见性
0 basic self-study STM32 (wildfire) -- what is a register?
【Oracle 数据库】奶妈式教程 day14 转换函数
Mt4/mql4 getting started to mastering EA tutorial lesson 5 - common functions of MQL language (V) - common functions of account information
矩阵运算
(9) Sequential queue and stack queue
【Oracle 数据库】奶妈式教程 day13 日期函数
Thoughts on the construction of data analysis platform for small and medium-sized enterprises (I)
QT 自定义组合控件(类提升功能)
Master data management system
How to handle root password forgetting in MySQL
【Oracle 數據庫】奶媽式教程 day13 日期函數
QT error prompt 1:invalid use of incomplete type '***‘
Mt4-mql4 language EA automatic transaction programming introduction to proficiency
成为一名卓越云架构师要具备的五项技能
Expérience électrique en mode - - expérience 2 circuit d'amplification de source commune JFET
先锋期货安全么?期货开户都是哪些流程?期货手续费怎么降低?
[普通物理]波的能量与干涉
力扣(LeetCode)172. 阶乘后的零(2022.06.21)
C语言双向链表实现图书管理系统 可读写文件