What does it mean to say that the "Linux kernel is proactive"?

I read that the Linux kernel is proactive, which is different from most Unix kernels. So what does this mean for the core to be proactive?

Some analogues or examples would be better than a purely theoretical explanation.

ADD 1 - 11:00 AM 12/07/2018

Priority is just one multitasking paradigm. There are also such as Cooperative Multi-tasking . By comparing them, a better understanding can be achieved.

+25
source share
8 answers

Imagine a simple look at proactive multitasking. We have two user tasks, both of which work all the time without using I / O or making kernel calls. These two tasks should not do anything special to work in a multi-tasking operating system. The kernel, usually based on a timer interrupt, simply decides that the time for one task pauses to start another. The task in question is completely unaware that something has happened.

However, most tasks make random kernel requests through system calls. When this happens, the same user context exists, but the CPU executes kernel code on behalf of this task.

Older Linux kernels would never have exceeded the task while it was busy running kernel code. (Note that I / O is always voluntarily rescheduled. I am talking about the case when the kernel code has some intensive work with the processor, for example, sorting a list.)

If the system allows you to perform this task when running the kernel code, then we have the so-called “proactive kernel”. Such a system is immune to unpredictable delays that can occur during system calls, so it may be better suited for embedded or real-time tasks.

For example, if there are two tasks on a particular processor, and one takes a system call, which takes 5 ms, and the other an application for an MP3 player, which must deliver an audio channel every 2 ms, you can hear the audio stutter.

The argument against the premise is that all the kernel code that can be called in the context of the task must be able to survive overcoming - for example, there is a lot of bad device driver code, which could be better if it can always complete before allow the execution of another task on this processor. (In multiprocessor systems, the rule, and not the exception these days, all kernel code must be re-enabled, so this argument is not so important today.) In addition, if the same goal can be solved by improving system calls with poor latency, perhaps no prerequisite needed.

A compromise is CONFIG_PREEMPT_VOLUNTARY, which allows you to switch the task at specific points within the kernel, but not everywhere. If there are a small number of places where kernel code can get bogged down, this is a cheap way to reduce latency, while maintaining control complexity.

+15
source

Prior to the Linux kernel version 2.5.4, the Linux kernel was not proactive, which means that a process running in kernel mode cannot be removed from the processor until it leaves the processor itself, or it begins to wait for any operation to complete input output.

Typically, a user-mode process can enter kernel mode using system calls. Previously, when the kernel was not proactive, a process with a lower priority could transfer a process of a higher priority, denying it access to the processor, repeatedly calling system calls and remaining in kernel mode. Even if the lower priority has expired, it will continue to work until it finishes its work in the kernel or is canceled by force. If a higher priority process awaiting start is a text editor in which the user types or the MP3 player is ready to replenish his sound buffer, the result is low interactivity. Thus, an unacceptable core at that time was a major flaw.

+24
source

In traditional unix kernels, there was only one lock that was supported by the thread while the kernel code was running. Therefore, no other kernel code can interrupt this thread.

This simplified the design of the kernel because you knew that while one thread was using the resources of the kernel, no other thread was. Therefore, different threads can not spoil each other.

On uniprocessor systems, this does not cause too many problems.

However, in multiprocessor systems, you may have a situation where several threads on different processors or cores still want to run kernel code at the same time. This means that depending on the type of workload you may have many processors, but they all spend most of the time waiting for each other.

On Linux 2.6, kernel resources were divided into much smaller units, protected by separate locks, and kernel code was checked to ensure that locks were only saved when the corresponding resources were used. Therefore, now different processors should wait for each other only if they want to access the same resource (for example, hardware resources).

+6
source

Prevention allows the kernel to give IMPRESSION concurrency: you only have one processor (say ten years ago), but you feel that all your processes are running at the same time. This is because the kernel unloads (i.e., takes out execution from) the execution from one process to pass it to the next (possibly according to their priority).

EDIT Non-preventive kernels expect processes to return a hand (i.e., during system calls), so if your process calculates a lot of data and does not call the yield function, other processes will not be able to make their calls. Such systems are said to be cooperative because they require process collaboration to ensure fair lead times.

EDIT 2 The main goal of preemption is to improve the responsiveness of the system between several tasks, so it’s good for end users, whereas, on the other hand, servers want to achieve maximum throughput, so they are not needed: (from the Linux kernel configuration)

+5
source

This means that the operating system scheduler can pause running processes so that the processor can process another process whenever it wants; the usual way to do this is to give every process that expects the processor to be a "quantum" of processor time to start. After it has expired, the scheduler returns the control (and the current process cannot avoid it) to give another quantum a different process.

This method is often compared to collaborative multitasking, which processes support the processor for as long as they need, without interruption, and to launch other applications, they must explicitly call the "exit" function; Naturally, in order to avoid the feeling of a system getting stuck, well-managed applications will often provide a processor. However, if there is an error in the application (for example, an endless loop without calls to exit), the whole system will freeze, as the processor is completely saved by the faulty program.

Almost all the latest desktop OSs use proactive multitasking, which, even if it is more expensive in terms of resources, is generally more stable (more difficult when an application with a sigle error hangs the entire system, since the OS is always in control). On the other hand, when resources are tight and the application is expected to behave well, collaborative multitasking is used. Windows 3 was a collaborative multi-tasking OS; a more recent example would be RockBox, an open source replacement for PMP firmware.

+3
source

The linux kernel is monolithic and provides short computation time for the entire running process in sequence. This means that processes (for example, programs) do not start at the same time, but they are provided with a regular response to execute their logic. The main problem is that some logic may take longer to shut down and prevent the kernel from giving time for the next process. This leads to a "lag" of the system.

The preemtive kernel has the ability to switch context . This means that it can stop the “freezing” process, even if it is not finished yet, and give the computing time to the next process as expected. The “hanging” process will continue to be executed when its time has come without a problem.

In practice, this means that the kernel has the ability to perform tasks in real time, which is especially interesting for recording and editing sound.

ubuntu studio districution includes a proactive kernel as well as free software designed for audio and video.

+2
source

I think it has become proactive since 2.6. preventive means, when the new process is ready to start, the processor will be assigned to the new process, it does not need the working process to be cooperative and abandon the processor.

0
source

The Linux kernel is proactive, meaning the kernel supports preemption.

For example, there are two processes: P1 (higher priority) and P2 (lower priority), which perform read system calls, and they work in kernel mode. Assume that P2 is running and is in kernel mode, and it is planned to start P2.

If kernel pre-use is available, then continuity can occur at the kernel level. I P2 can be unloaded, but sleep and P1 can continue to work.

If kernel priority is unavailable because P2 is in kernel mode, the system just waits for P2 to finish, and then

0
source

Source: https://habr.com/ru/post/921082/


All Articles