小编fei*_*iny的帖子

为什么禁用中断会禁用内核抢占以及自旋锁如何禁用抢占

我最近正在阅读Linux内核开发,我有一些与禁用抢占相关的问题.

  1. 在第7章的"中断控制"部分,它说:

    此外,禁用中断还会禁用内核抢占.

    我还从书中读到,在以下情况下可能会发生内核抢占:

    当中断处理程序退出时,返回内核空间之前.
    当内核代码再次成为可抢占状态时.
    如果内核中的任务显式调用schedule()
    如果内核中的任务阻塞(导致调用schedule())

    但我无法将禁用中断与这些情况联系起来.

  2. 据我所知,自旋锁将使用preempt_disable()函数禁用抢占.

    帖子究竟什么是"自旋锁"? 说:

    在单核心机器上,自旋锁只是"禁用中断"或"引发IRQL",这完全阻止了线程调度.

    preempt_disable()是否通过禁用中断来禁用抢占?

linux interrupt linux-kernel preemption spinlock

11
推荐指数
1
解决办法
1万
查看次数

操作员删除时不清楚的事情

我是C++的新手,我有一些不清楚的地方:

#include <iostream>
using namespace std;

double* foo(void)
{
    double* b = new double[100];
    return b;
}

int main()
{
    double* a = foo();

    delete [] a;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这段代码有问题吗?我的意思是我使用operator delete的方式是否正确?我指向foo函数中指向已分配内存的指针b指向外部foo,我可以通过delete [] a释放内存吗?我不知道编译器如何计算执行delete []时要释放的字节数.谢谢

c++ delete-operator

4
推荐指数
1
解决办法
142
查看次数

当中断处理程序被另一个中断中断时,中断上下文如何"恢复"?

我读了一些相关的帖子:

(1)来自Robert Love:http://permalink.gmane.org/gmane.linux.kernel.kernelnewbies/1791

You cannot sleep in an interrupt handler because interrupts do not have a backing 
process context, and thus there is nothing to reschedule back into. In other 
words, interrupt handlers are not associated with a task, so there is nothing to 
"put to sleep" and (more importantly) "nothing to wake up". They must run 
atomically.
Run Code Online (Sandbox Code Playgroud)

(2)哪个上下文是softirq和tasklet?

If sleep is allowed, then the linux cannot schedule them and finally cause a 
kernel panic with …
Run Code Online (Sandbox Code Playgroud)

linux interrupt linux-kernel

3
推荐指数
1
解决办法
1304
查看次数