c - 为什么tasklet_action()函数中会调用BUG?
问题描述
static void tasklet_action(struct softirq_action *a)
{
// ...
while (list) {
struct tasklet_struct *t = list;
list = list->next;
if (tasklet_trylock(t)) {
if (!atomic_read(&t->count)) {
if (!test_and_clear_bit(TASKLET_STATE_SCHED,
&t->state))
BUG();
// ...
}
}
我的理解是,如果已经安排了一个 tasklet,那么这段代码会抛出一个BUG()
. 这是否意味着同一个tasklet不能同时运行,也不能被调度?
解决方案
这只是对 tasklet 有保证的属性的健全性检查。您可以在以下注释中include/linux/interrupt.h
查看 tasklet 的属性:
Properties:
* If tasklet_schedule() is called, then tasklet is guaranteed
to be executed on some cpu at least once after this.
* If the tasklet is already scheduled, but its execution is still not
started, it will be executed only once.
* If this tasklet is already running on another CPU (or schedule is called
from tasklet itself), it is rescheduled for later.
* Tasklet is strictly serialized wrt itself, but not
wrt another tasklets. If client needs some intertask synchronization,
he makes it with spinlocks.
根据定义,tasklet 保证在调度后至少运行一次。这段代码:
if (!atomic_read(&t->count)) {
if (!test_and_clear_bit(TASKLET_STATE_SCHED,
&t->state))
BUG();
确保此属性成立,否则存在错误,并BUG()
用于停止执行并导致运行时恐慌。
这是上述代码的注释版本,以使其更清晰:
// If the tasklet never ran (t->count == 0)
if (!atomic_read(&t->count)) {
// And the tasklet is not scheduled for running (bit TASKLET_STATE_SCHED of t->state is 0)
if (!test_and_clear_bit(TASKLET_STATE_SCHED,
&t->state))
// There's something wrong, this should never happen!
BUG();
换句话说,你不能有一个带有t->count == 0
and的 tasklet t->state & (1<<TASKLET_STATE_SCHED) == 0
。如果发生这种情况,则存在错误。
推荐阅读
- reactjs - 如何从组件中检索状态
- angularjs - 通过 Jasmine Karma 运行测试用例时控制器未注册错误
- qml - 如何将样式模块添加到
- vb.net - 带有 webview-element 的用户表单不加载,程序冻结
- batch-file - 变量未存储正确的字符串
- database-design - 将 SQL 模式建模到 DynamoDB
- c# - 从 C# 中的其他表单更新 datagridview
- matlab - Matlab:如何将文件加载为结构数组
- windows - 我如何使用 Crypto API 来叹息 TLS 1.2 的哈希值
- javascript - 必应地图中未触发方向错误事件