Linux: 为什么 FIFO 调度程序在 1 核 CPU 机器上没有按预期工作?
Linux: Why does the FIFO scheduler not work as expected on the 1 core CPU machine?
我正在学习 Linux 调度程序。首先,我想测试 FIFO 调度程序。这是我用来测试的代码:
#include <sched.h>
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Setting SCHED_FIFO and priority to %d\n",atoi(argv[1]));
struct sched_param param;
param.sched_priority = atoi(argv[1]);
sched_setscheduler(0, SCHED_FIFO, ¶m);
int n = 0;
while(1) {
n++;
if (!(n % 10000000)) {
printf("%s FIFO Prio %d running (n=%d)\n",argv[2], atoi(argv[1]),n);
}
}
}
I 运行 这个程序在 2 个终端上优先级为 1:./main 1
。因为我的CPU只有一个核心,我希望只有第一个终端可以运行因为先进先出的属性。但是,在实测情况下:两个终端都可以运行代码。
这是我的 CPU 信息,当我 运行 命令 lscpu
:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 6140 CPU @ 2.30GHz
Stepping: 4
CPU MHz: 2294.608
BogoMIPS: 4589.21
Virtualization: VT-x
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 4096K
请解释原因。
我正在学习 Linux 调度程序。首先,我想测试 FIFO 调度程序。这是我用来测试的代码:
#include <sched.h>
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Setting SCHED_FIFO and priority to %d\n",atoi(argv[1]));
struct sched_param param;
param.sched_priority = atoi(argv[1]);
sched_setscheduler(0, SCHED_FIFO, ¶m);
int n = 0;
while(1) {
n++;
if (!(n % 10000000)) {
printf("%s FIFO Prio %d running (n=%d)\n",argv[2], atoi(argv[1]),n);
}
}
}
I 运行 这个程序在 2 个终端上优先级为 1:./main 1
。因为我的CPU只有一个核心,我希望只有第一个终端可以运行因为先进先出的属性。但是,在实测情况下:两个终端都可以运行代码。
这是我的 CPU 信息,当我 运行 命令 lscpu
:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 6140 CPU @ 2.30GHz
Stepping: 4
CPU MHz: 2294.608
BogoMIPS: 4589.21
Virtualization: VT-x
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 4096K
请解释原因。