我们需要能够使用中断从用户空间唤醒进程。
为此,我们将执行以下操作:
·一个用户空间程序与ioctl()一起进入内核空间并调用wait-que-head。
此时用户空间线程块。
当中断发生时,它调用另一个ioctl()到内核空间并唤醒内核进程。
·此时,用户空间程序不再阻塞,继续执行。
这是使用以下伪代码实现的:
static DECLARE_WAIT_QUEUE_HEAD(int0_wait);
static u32 int0_wait_flag = 0 ;
*/ inside the Kernel ioctl function */
case WAIT_INT_0:
wait_event_inetrruptible(int0_wait, int0_wait_flag !=0); /* blocked here */
int0_wait_flag = 0;
printk("Returning from IOCTL kernel â¦\n");
break;
/* interrupt handler */
Irqreturn_t irq_handler(int irq, void *dev)
{
Int0_eait_flag = 1;
wake_up_interruptible(&int0_wait);
return IRQ_HANDLED;
}
/* a user space test program */
Int_function()
{
ioctl(â¦, WAIT_INT_0, â¦); /* call the kernel for blocking */
/* comes here when IRQ arrives */
/* continue with run the rest of codeâ¦. */
当我们这样做时,我们几乎总是会在内核中发现一个错误:
[..]调用跟踪:
[..]错误:原子时调度:testercpp/2000/0x00000200
__