Hi,
I'd do time accounting during task switches. For example, imagine something like this at the start of the task switch:
Code:
used += get_time() - time_of_last_task_switch;
time_of_last_task_switch = now;
current_task->used_time[current_task->priority_group] += used;
this_cpu->used_time[current_task->priority_group] += used;
Of course this works better if "get_time()" is fast and precise (e.g. use the TSC or maybe HPET's main counter if you can). It still works if "get_time()" is returning "ticks_since_boot" (with 10ms between ticks or something) though.
From that you can find out how much time each CPU has spent running high priority tasks, medium priority tasks, low priority tasks, etc. You could monitor these values and calculate averages and draw pretty graphs of CPU load; or figure out how much CPU time each task has consumed.
For your "activity light", maybe you could do something like this:
Code:
for each CPU {
last_total += cpu->used_time[HIGH_PRIORITY] + cpu->used_time[MEDIUM_PRIORITY];
}
for(;;) {
sleep(1);
total = 0;
for each CPU {
total += cpu->used_time[HIGH_PRIORITY] + cpu->used_time[MEDIUM_PRIORITY];
}
used = total - last_total;
last_total = total;
if(used / number_of_cpus >= 0.5) turn_light_on();
else turn_light_off();
}
If the light is on, then CPUs are spending at least 50% of their time running medium priority or high priority tasks...
Cheers,
Brendan