Linux operating system kernel preemptible patch basic principle-Linux general technology-Linux programming and kernel information, the following is a detailed description. When the CPU runs in the kernel, it cannot be preemptible everywhere. There are some gaps in the kernel. In this case, it is safe to preemptible, the basic principle of kernel preemption patch is to regard SMP parallel code segments as areas where kernel preemption can be performed.
2.4 The kernel precisely refined the kernel thread synchronization mechanism under multiple CPUs, and made a detailed representation of non-parallel instruction blocks using the spinlock and rwlock. The implementation of this patch can be justified. The specific method is to add a preempt_count variable in the task structure of the process as the kernel preemptible lock. It locks and unlocks along with the spinlock and rwlock. When preempt_count is 0, kernel scheduling can be performed. The entry of the kernel scheduler is preempt_schedule (), which marks the current process as TASK_PREEMPTED and then calls schedule (). In the TASK_PREEMPTED status, schedule () does not delete the process from the running queue.
The following shows the main code for Kernel preemptible patches: