user2392631
user2392631

Reputation: 507

what is hrtick_clear(rq); in linux scheduler?

while going through linux kernel code inside __scheduler() function I saw hrtick_clear(rq). Can anyone explain what is this and why it is used? it seems something related to timer, but unable to proceed further.

Upvotes: 3

Views: 1100

Answers (1)

myaut
myaut

Reputation: 11514

Classic OS design involves system timer - an entity that ticks at fixed intervals. During each tick, scheduler is called and if process/thread should be switched. But system timer frequency is pretty low (i.e. 1000 HZ, which means once in 1 ms), and if process have only 100us of its timeslice left, it will get extra time (under certain circumstances), while other processes are starve.

However, modern CPUs provide more precision hardware timers like HPET on Intel, which are provided by hrtimers subsystem. They can be enabled for be used in scheduler by CONFIG_SCHED_HRTICK option.

But if you already called __schedule() (i.e. on path of system call), you do not need to call it second time from hrtimer, because you already scheduling, so before doing so, hrtick_clear disables that hrtimer.

Upvotes: 5

Related Questions