I'm just wanted to implement some eye candy ui things and show a cpu activity (In a blinking dot).
How do I get the current state of my cpu? I don't really know what to search for.

Any hints?
Code: Select all
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;
Code: Select all
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();
}
That gave me an idea. You could turn off the light if you schedule idle thread, turn it on otherwise. On a normal desktop it will light about 2-3% of the time. If load increases, time grows, and blinking will be more rapid; on an overloaded machine it will light continously.Brendan wrote:If the light is on, then CPUs are spending at least 50% of their time running medium priority or high priority tasks...
I use my GetSystemTime syscall which returns number of (PIT, 1.193MHz) tics (8 bytes) since boot regardless of if this derives from PIT, HPET or something else. That means I record execution with sub-microsecond precision per thread. Since each core also has a null-thread, which accumulates time, I can compare the load between cores with good precision, and see how much the cores are loaded.Brendan wrote: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.
With only one CPU, I'm going to write a task that sleeps for 8.333 ms and then runs for 8.333 ms (then sleep, then run, etc). If the video mode is 60 frames per second (very likely) then the activity light will look like it's permanently on or permanently off.turdus wrote:That gave me an idea. You could turn off the light if you schedule idle thread, turn it on otherwise. On a normal desktop it will light about 2-3% of the time. If load increases, time grows, and blinking will be more rapid; on an overloaded machine it will light continously.Brendan wrote:If the light is on, then CPUs are spending at least 50% of their time running medium priority or high priority tasks...