I am trying to understand the working of the Linux CFS scheduler using kernel version 4.19.2.

As mentioned in the documentation, it does not use timeslices in the traditional way but uses the concept of virtual runtime. The update to this vruntime for every process is made in the file kernel/sched/fair.c

The exact line for the update is

    curr->vruntime += calc_delta_fair(delta_exec, curr);
   //curr is the currently scheduled task, the function cal_delta_fair() 
   returns a value depending on the duration the task ran and its priority 
   ensuring fairness.

The variable vruntime is u64, defined in the kernel types as unsigned integer of 64B. To understand how the vruntime varies for a process, I wrote a system call to get it's value out, which turned out to be negative as well as positive at times. How? What does a negative value for vruntime signify?


The datatype of vruntime is an UNSIGHNED 64 bit integer. If you are reading negative numbers, then i think you need to cast the variable to the right type in your system call implementation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.