sched_getscheduler(pid) 中的每个 return int 值对应什么调度策略? [C]

What scheduling policy does each return int value from sched_getscheduler(pid) correspond to? [C]

当我使用以下代码将调度策略设置为 Deadline 时:

struct sched_attr attr = {
          .size = sizeof(attr),
          .sched_policy = SCHED_DEADLINE,
          .sched_runtime = 30000000,
          .sched_period = 100000000,
          .sched_deadline = 100000000
      };

  pid_t pid = getpid();
    printf("pid=(%d)\n",pid);

  if (sched_setattr(pid, &attr, 0)){
    printf("[ERROR] sched_setattr()\n");
    perror("[ERROR] sched_setattr()\n");
  }

  // Check scheduler policy is set correctly
  printf("Scheduler Policy is %d.\n", sched_getscheduler(pid));

上述代码运行结果如下:

pid=(XXXXXX)

Scheduler Policy is 6.

有人可以解释 sched_getscheduler(pid) 中的哪个 return int 值对应于哪个调度程序策略吗?

例如:根据上述代码,我认为 6 对应于 SCHED_DEADLINE 政策。

您可以自己在自己的系统上轻松找到类似的东西,例如:

$ grep -r SCHED_DEADLINE /usr/include/ 
/usr/include/linux/sched.h:
#define SCHED_DEADLINE      6
$ grep define.SCHED_ /usr/include/linux/sched.h 
#define SCHED_NORMAL        0
#define SCHED_FIFO      1
#define SCHED_RR        2
#define SCHED_BATCH     3
#define SCHED_IDLE      5
#define SCHED_DEADLINE      6