Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to count number of active users in kernel

We're using kernel version 2.4-20 and we need to count number of active users, in kernel mode. Objective is to change the scheduler, so we are in sched.c, modifying schedule() function.

What we do is to count the users in list_for_each macro.

list_for_each(tmp, &runqueue_head) {
    p = list_entry(tmp, struct task_struct, run_list);
    if (can_schedule(p, this_cpu)) {
        if (unique(p->uid)) add_new_user(p->uid);
        int weight = goodness(p, this_cpu, prev->active_mm);
        if (weight > c)
            c = weight, next = p;
    }
}

which is basically adding unique users to a list. However, we get random results. Is there a concrete way to solve this problem?

Thank you.

like image 789
Halil Kaskavalci Avatar asked May 16 '12 17:05

Halil Kaskavalci


1 Answers

You may want to try counting the users inside the for_each_task macro. This results in counting the users that have a task which is blocked due to I/O or any other reason. This should provide better results as you can't guarantee being able to count the users who run interactive processes if you use the run queue.

like image 122
Ayberk Avatar answered Nov 04 '22 19:11

Ayberk