2

I am reading "Linux Kernel Development" and I don't understand weight value of process. In linux kernel, each process has a nice value, and then mapping nice value to weight.

  • I think weight is "the proportion of processor time". it mean process'runtime allocated is: its weight/(total weight of all process)* (processor time). if result of above formula is 10%, but actual the runtime of process lower than 10%, it is priority. Right?
  • I'm confused about how cfs check it. Does cfs check periodly (e.g. 1 milisecond) and update runtime of process, compare the proportion of actual runtime/process'runtime allocated with the chosen minimum and run it ? By the way, can you list some function used?
1

check the function set_load_weight in linux kernel source. Here, the actual load of a scheduling entity(task/group of tasks) is calculated. This routine gets called from different places(e.g fork, or when you set a new nice value from user space, etc).

if (update_load && p->sched_class == &fair_sched_class) {
    reweight_task(p, prio);
} else {
    load->weight = scale_load(sched_prio_to_weight[prio]);
    load->inv_weight = sched_prio_to_wmult[prio];
}

sched_prio_to_weight contains the weight according to priority.

The structure that saves the weight information for a task is struct load_weight. This structure is used by cfs to get the load of an entity and update the runtime(vruntime) of a task in the routine update_curr. cfs selects next task to run in pick_next_task. Below is the code snippet.

for_each_class(class) {
        p = class->pick_next_task(rq, prev, rf);
        if (p) {
            if (unlikely(p == RETRY_TASK))
                goto again;
            return p;
        }
    }

Here, it traverses each scheduling class and checks for a task to run.

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.