Somdip Dey
Somdip Dey

Reputation: 3386

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

When I use the following code to set the scheduling policy to 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));

The result of the aformentioned code is as follows:

pid=(XXXXXX)

Scheduler Policy is 6.

Can someone explain which return int value from sched_getscheduler(pid) corresponds to which scheduler policy?

For example: From the aforementioned code I believe 6 corresponds to SCHED_DEADLINE policy.

Upvotes: 0

Views: 761

Answers (1)

Ctx
Ctx

Reputation: 18420

You can find out things like this easily yourself on your system like for example that:

$ 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

Upvotes: 2

Related Questions