什么是可重入内核 [英] what is a reentrant kernel

查看:252
本文介绍了什么是可重入内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是可重入内核?

推荐答案

更简单的答案:

内核重入

如果内核不是可重入的,则只能在用户模式下挂起该进程.尽管可以在内核模式下将其挂起,但这仍然会阻止在所有其他进程上执行内核模式.这样做的原因是所有内核线程共享相同的内存.如果执行会在它们之间任意跳转,则可能会发生损坏.

If the kernel is not re-entrant, a process can only be suspended while it is in user mode. Although it could be suspended in kernel mode, that would still block kernel mode execution on all other processes. The reason for this is that all kernel threads share the same memory. If execution would jump between them arbitrarily, corruption might occur.

可重入内核使进程(或更确切地说,其相应的内核线程)在内核模式下可以释放CPU.它们不会阻止其他进程也进入内核模式.典型的用例是IO等待.该进程想要读取文件.为此,它调用内核函数.在内核功能内部,磁盘控制器被要求提供数据.获取数据将花费一些时间,并且在此期间功能被阻止. 对于可重入的内核,调度程序会将CPU分配给另一个进程(内核线程),直到磁盘控制器的中断表明数据可用并且可以恢复我们的线程为止.该过程仍然可以访问IO(需要内核功能),例如用户输入.系统保持响应状态,并减少了由于IO等待而导致的CPU时间浪费.

A re-entrant kernel enables processes (or, to be more precise, their corresponding kernel threads) to give away the CPU while in kernel mode. They do not hinder other processes from also entering kernel mode. A typical use case is IO wait. The process wants to read a file. It calls a kernel function for this. Inside the kernel function, the disk controller is asked for the data. Getting the data will take some time and the function is blocked during that time. With a re-entrant kernel, the scheduler will assign the CPU to another process (kernel thread) until an interrupt from the disk controller indicates that the data is available and our thread can be resumed. This process can still access IO (which needs kernel functions), like user input. The system stays responsive and CPU time waste due to IO wait is reduced.

这对于当今的桌面操作系统几乎是标准的.

This is pretty much standard for today's desktop operating systems.

内核抢占

内核抢占对系统的整体吞吐量没有帮助.相反,它寻求更好的响应能力.

Kernel pre-emption does not help in the overall throughput of the system. Instead, it seeks for better responsiveness.

这里的想法是通常内核功能仅由硬件原因中断:外部中断或IO等待情况,它们会自动将控制权交给调度程序.抢占式内核也会中断和挂起内核功能,就像它会中断用户模式下的进程一样.该系统响应更快,例如处理.即使在内核内部完成繁重的工作后,唤醒鼠标的操作也会被唤醒.

The idea here is that normally kernel functions are only interrupted by hardware causes: Either external interrupts, or IO wait cases, where it voluntarily gives away control to the scheduler. A pre-emptive kernel instead also interrupts and suspends kernel functions just like it would interrupt processes in user mode. The system is more responsive, as processes e.g. handling mouse input, are woken up even while heavy work is done inside the kernel.

内核级别的抢占使内核开发人员更难:内核功能不能仅通过自愿中断或中断处理程序(在某种程度上是受控环境)而挂起,也不能通过调度程序挂起.必须注意例如避免死锁:一个线程锁定资源A但需要资源B被另一个锁定资源B的线程中断,然后又需要资源A.

Pre-emption on kernel level makes things harder for the kernel developer: The kernel function cannot be suspended only voluntarily or by interrupt handlers (which are somewhat a controlled environment), but also by any other process due to the scheduler. Care has to be taken to e.g. avoid deadlocks: A thread locks resource A but needing resource B is interrupted by another thread which locks resource B, but then needs resource A.

解释一下先发制人的优势.我很高兴做出任何改正.

Take my explanation of pre-emption with a grain of salt. I'm happy for any corrections.

这篇关于什么是可重入内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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