The Linux/SMP Scheduler

The Linux/SMP Scheduler

The Linux scheduler must be slightly modified in order to support the symmetric multiprocessor (SMP) architecture. Actually, each processor runs the schedule( ) function on its own, but processors must exchange information in order to boost system performance.

When the scheduler computes the goodness of a runnable process, it should consider whether that process was previously running on the same CPU or on another one. A process that was running on the same CPU is always preferred, since the hardware cache of the CPU could still include useful data. This rule helps in reducing the number of cache misses.

Let us suppose, however, that CPU 1 is running a process when a second, higher-priority process that was last running on CPU 2 becomes runnable. Now the kernel is faced with an interesting dilemma: should it immediately execute the higher-priority process on CPU 1, or should it defer that process's execution until CPU 2 becomes available? In the former case, hardware caches contents are discarded; in the latter case, parallelism of the SMP architecture may not be fully exploited when CPU 2 is running the idle process (swapper).

In order to achieve good system performance, Linux/SMP adopts an empirical rule to solve the dilemma. The adopted choice is always a compromise, and the trade-off mainly depends on the size of the hardware caches integrated into each CPU: the larger the CPU cache is, the more convenient it is to keep a process bound on that CPU.

Linux/SMP scheduler data structures

An aligned_data table includes one data structure for each processor, which is used mainly to obtain the descriptors of current processes quickly. Each element is filled by every invocation of the schedule( ) function and has the following structure:

struct schedule_data { 
    struct task_struct * curr; 
    unsigned long last_schedule; 
}; 

The curr field points to the descriptor of the process running on the corresponding CPU, while last_schedule specifies when schedule( ) selected curr as the running process.

Several SMP-related fields are included in the process descriptor. In particular, the avg_slice field keeps track of the average quantum duration of the process, and the processor field stores the logical identifier of the last CPU that executed it.

The cacheflush_time variable contains a rough estimate of the minimal number of CPU cycles it takes to entirely overwrite the hardware cache content. It is initialized by the smp_tune_scheduling( ) function to:

 

Intel Pentium processors have a hardware cache of 8 KB, so their cacheflush_time is initialized to a few hundred CPU cycles, that is, a few microseconds. Recent Intel processors have larger hardware caches, and therefore the minimal cache flush time could range from 50 to 100 microseconds.

As we shall see later, if cacheflush_time is greater than the average time slice of some currently running process, no process preemption is performed because it is convenient in this case to bind processes to the processors that last executed them.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
~/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp/tools/pc/image_tool ~/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp Traceback (most recent call last): File "/home/lkuser/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp/tools/pc/image_tool/oem/oem_quick_build.py", line 9, in <module> oem_main.main(['', 'build', 'oem/quick_build_config.json']) File "/home/lkuser/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp/tools/pc/image_tool/oem/oem_main.py", line 115, in main build(cfg_file=argv[2]) File "/home/lkuser/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp/tools/pc/image_tool/oem/oem_main.py", line 16, in build from oem_build import OemAreaBuilder, OemImageBuilder File "/home/lkuser/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp/tools/pc/image_tool/oem/tool/oem_build.py", line 15, in <module> from common.area_tool import PublicKey, AreaTool File "/home/lkuser/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp/tools/pc/image_tool/common/area_tool.py", line 9, in <module> import security as sec File "/home/lkuser/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp/tools/pc/image_tool/common/security.py", line 351, in <module> from Crypto.PublicKey import RSA ModuleNotFoundError: No module named 'Crypto' ~/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp cp /home/lkuser/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp/tools/pc/image_tool/image/oem/boot_image.bin /home/lkuser/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp/pub/hi3519dv500_emmc_image_glibc/boot_image.bin; cp: cannot stat '/home/lkuser/SDK/Hi3519DV500_SDK_V2.0.0.2/smp/a55_linux/source/bsp/tools/pc/image_tool/image/oem/boot_image.bin': No such file or directory make: *** [Makefile:505: gslboot_build] Error 1
最新发布
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值