Linux Scheduler

Overview

Understanding Linux Scheduling Classes   
    SCHED_OTHER            - the default universal time-sharing scheduler policy used by most processes.
    SCHED_FIFO or SCHED_RR - intended for special time-critical applications that need precise control 
                             over the way in which runnable processes are selected for execution
    SCHED_BATCH            - intended for "batch" style execution of processes
Scheduling Algorithm
    SCHED_FIFO uses First In-First Out scheduling algorithm
    SCHED_RR uses Round Robin scheduling algorithm
    SCHED_OTHER uses Default Linux time-sharing scheduling algorithm
    SCHED_BATCH use Scheduling batch processes algorithm

What scheduling priorities are available    
$  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

Display and change priority of a RT process (  policy: SCHED_RR )

$  ps -elf | grep  ocssd.bin |  egrep 'PRI|smon'
F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
4 S grid      4742     1  1 -40   - - 281796 futex_ Mar16 ?       00:35:29 /u01/app/11204/grid/bin/ocssd.bin

To get/retrieve the real-time attributes of an existing task / PID, enter
$ chrt -p 4742
pid 4742's current scheduling policy: SCHED_RR
pid 4742's current scheduling priority: 99

Set policy to SCHED_RR scheduling with 20 priority:
# chrt -r -p 20 14742
# chrt -p 4742
pid 4742's current scheduling policy: SCHED_RR
pid 4742's current scheduling priority: 20

Display and change priority of a normal Linux  process ( policy: SCHED_OTHER )

$  ps -elf |  egrep 'PRI|smon'
F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
0 S oracle   25437     1  0  80   0 - 390185 semtim 13:15 ?       00:00:00 ora_smon_grac41
$ chrt -p 25437
pid 25437's current scheduling policy: SCHED_OTHER
pid 25437's current scheduling priority: 0

To set policy scheduling policy to SCHED_OTHER, Prio 0 enter:
# chrt -o -p 0 4742
# chrt -p 4742
pid 4742's current scheduling policy: SCHED_OTHER
pid 4742's current scheduling priority: 0

C-Code fragment to create a RT process ( priority -99 )

  • Note top shows this process priority as RT
PID  USER    PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+ COMMAND  
22660 root   RT   0 1501m 1.4g  504 S 100.4 33.5   0:24.07 mp_mem
C-code: 
struct sched_param sp = { .sched_priority = 99 };
int ret;
ret = sched_setscheduler(0, SCHED_RR, &sp);
if (ret == -1)
   {
   printf("-> Error setting priorty - please run program as root ! \n") ;
   exit(1);;
   }

Reference

http://www.cyberciti.biz/faq/howto-set-real-time-scheduling-priority-process/

Leave a Reply

Your email address will not be published. Required fields are marked *