Linux system scheduler (4) -- use the chrt command to query and modify the process scheduler

The user 3147702 2022-09-23 09:32:12 阅读数:215


1. Introduction

In the last article, we covered the evolution of the linux scheduler:

linux process scheduler (below) -- scheduler evolution

In the last article, we know that after Linux version 2.6.23, Linux actually maintains a set of schedulers to achieve different scheduling needs, they are divided into four layers:

  1. DL scheduler: adopt sched_deadline strategy;
  2. RT scheduler: adopts sched_rr and sched_fifo strategies;
  3. CFS scheduler: uses sched_normal and sched_batch strategies;
  4. IDEL scheduler: adopts the sched_idle strategy.

So, how can we get our processes to be scheduled by different layers of schedulers?Then you need to use the very useful tool provided by linux -- chrt to achieve this. In this article, we will introduce the use of this command.

2. Introduction of chrt command


chrt command is a low-level application instruction provided by linux. It can set some attributes of the process at runtime, and can also change the scheduling policy and scheduling priority.

It is used in the following ways:

$ chrt [options] -p [priority] pid

It seems to be very simple to use. The easiest way to use chrt is to query. In this scenario, you don't need to pass options and priority:

You can see that the priority of the process is 0, and the scheduling policy is SCHED_OTHER, which is the default policy, which is scheduled by the CFS scheduler based on the SCHED_NORMAL policy.

3. chrt help

Through the chrt --help command, you can see the description of all parameters:

Actually, this set of instructions is pretty clear.

4. chrt options

There are five options for chrt options, which correspond to the five strategies of the four-layer scheduler introduced in the previous article:

  1. SCHED_DEADLINE: The strategy used by the DL scheduler for system use only, the user cannot choose;
  2. SCHED_FIFO: use the RT scheduler's sched_fifo strategy, first-in, first-out task queue;
  3. SCHED_RR: Use the sched_rr strategy of the RT scheduler to implement the scheduling algorithm with a polling mechanism;
  4. SCHED_OTHER: use the CFS scheduler's sched_other strategy, using the default time_sharing scheduling algorithm;
  5. SCHED_BATCH: Use the sched_batch strategy of the CFS scheduler to submit tasks and execute them in batches using the batch algorithm;
  6. SCHED_IDLE: Use the sched_idle policy of the IDLE scheduler.

5. chrt's priority

Through the chrt -m command, you can view the user-selectable priority range under different chrt scheduling policies:

priority is a nice value that can affect the scheduling priority to a certain extent, although only two schedulers, SCHED_FIFO and SCHED_RR, allow us to specify, because the RT scheduler is implemented using the traditional O(1) scheduling algorithmBased on time slice scheduling policy.

copyright:author[The user 3147702],Please bring the original link to reprint, thank you.