realtime

 

 

 

 


Proccess 的 class

 

ps -L -o comm,pid,tid,class

COMMAND           PID   TID CLS
bash              965   965 TS
ps               8711  8711 TS

By default programs run with Time Sharing (TS policy) on Linux.

Find RR class

ps x -L -o comm,pid,tid,class,rtprio,ni | grep RR

watchdog        11817 11817 RR       1   -

 


Scheduled

 

Each thread has an associated scheduling policy(ps 見到的 class)

sched_priority = 0 # It is not used in scheduling decisions (ps 見到的 rtprio)

SCHED_OTHER

Default Linux time-sharing scheduling

Thread under real-time policies always have priority over SCHED_OTHER

only static priority "sched_priority = 0"

The dynamic priority is based on the nice value (ps 的 ni)

SCHED_IDLE

The thread to run is chosen based on a dynamic priority that is determined only inside this list.

The dynamic priority is based on the nice value and is increased for each time quantum the thread is ready to run

sched_priority = 0

SCHED_BATCH

Scheduling very low priority jobs

sched_priority = 0

Real-Time Policies

sched_priority: 1 (low) ~ 99

 - SCHED_FIFO

needs the task to explicitly yield the processor

 - SCHED_RR

It is a simple enhancement of SCHED_FIFO

each thread is allowed to run only for a maximum time quantum (round-robin)

 * real-time threads always have higher priority than normal threads

 


chrt

 

chrt - show & manipulate the real-time attributes of a process

# -m, --max              # Show minimum and maximum valid priorities

chrt -m

SCHED_OTHER min/max priority    : 0/0
SCHED_FIFO min/max priority     : 1/99
SCHED_RR min/max priority       : 1/99
SCHED_BATCH min/max priority    : 0/0
SCHED_IDLE min/max priority     : 0/0
SCHED_DEADLINE min/max priority : 0/0

# -p, --pid                # Show policy & priority of pid

chrt -p 11817

pid 11817's current scheduling policy: SCHED_RR
pid 11817's current scheduling priority: 1

set policy & priorities

  • -b, --batch            # Set scheduling policy to SCHED_BATCH
  • -f, --fifo                # Set scheduling policy to SCHED_FIFO
  • -i, --idle                # Set scheduling policy to SCHED_IDLE
  • -o, --other            # Set policy scheduling policy to SCHED_OTHER
  • -r, --rr( Default )   # Set scheduling policy to SCHED_RR. 

Example

# setting SCHED_RR require root permissions

chrt -r -p [1..99] {pid}

 


 

Creative Commons license icon Creative Commons license icon