Linux – what is hrtick_clear (rq); In the Linux scheduler?

what is hrtick_clear (rq); In the Linux scheduler?… here is a solution to the problem.

what is hrtick_clear (rq); In the Linux scheduler?

When I look at the Linux kernel code in the __scheduler() function, I see hrtick_clear(rq).
Can anyone explain what this is and why it is used?
It seems to be related to the timer, but it can’t go any further.

Solution

Classic operating system design involves a system timer – an entity that times at regular intervals. During each tick, the dispatcher is called, and whether the process/thread should be switched. BUT THE SYSTEM TIMER FREQUENCY IS VERY LOW (I.E. 1000 HZ, which means every 1 millisecond), and if a process only has 100us of time slices left, it will gain extra time (in some cases), while other processes are starvation.

However, modern CPUs offer more accurate hardware timers such as on Intel, by hrtimers provides subsystems. They can be enabled for use in the scheduler through the CONFIG_SCHED_HRTICK option.

But if you have already called __schedule() (i.e. on the path of the system call), you don’t need to call it a second time from hrtimer because you’re already dispatching, so hrtick_clear disable hrtimer before doing so.

Related Problems and Solutions