Commit 1b37ad8b authored by Thanassis Tsiodras's avatar Thanassis Tsiodras

Proper accounting of time: look at the stopwatch every ctx switch.

parent cb8d5d56
......@@ -41,10 +41,8 @@ typedef struct {
// to dump this over grmon; we need the symbol to be visible!
Tasks_CPU_usage cpuLoad[PRIO_MAX - PRIO_MIN + 1];
// Keep a note of when we started measuring CPU time.
// This will allow us in the end to divide the accumulatedTime against the total
// time taken; and get percentage of CPU impact from each task.
uint32_t startTimestampInMicroSec;
// Total time we've been running; used to get percentage of CPU impact from each task.
uint32_t totalTimeInMicroSec;
} Scheduler_accounting;
// The Book of Life.
......@@ -74,6 +72,10 @@ rtems_extension user_task_switch(rtems_tcb *current, rtems_tcb *new)
// We'll accumulate the execution since last time, and update the timestamp
// so we'll be able to accurately accumulate again the next time.
accounting.cpuLoad[new_task_index].lastTime = current_highres_time;
// Record total time passed since we started accounting.
accounting.totalTimeInMicroSec = current_highres_time;
}
void setup_RTEMS_scheduler_tracking()
......@@ -88,13 +90,11 @@ void setup_RTEMS_scheduler_tracking()
setup_high_accuracy_timer();
// We don't need to zero-init; the variable is in BSS, it's already done.
// accounting.totalTimeInMicroSec = 0;
for(i = 0; i < sizeof(accounting.cpuLoad)/sizeof(accounting.cpuLoad[0]); i++)
accounting.cpuLoad[i].lastTime = 0xFFFFFFFF; // Sentinel value.
// On your marks... get set...
accounting.startTimestampInMicroSec = get_highres_ticks_passed();
/// ...GO!
// On your marks... get set... GO!
rtems_extension_create(
rtems_build_name('C', 'T', 'X', 'T'),
&table,
......@@ -105,15 +105,8 @@ void report_CPU_Load()
{
size_t i;
uint64_t percentage;
uint32_t currentMicrosecond;
uint32_t totalMicrosecondsOfCPUused = 0;
// Compute total time since we started accounting.
currentMicrosecond = get_highres_ticks_passed();
// So, total microseconds since we started:
currentMicrosecond -= accounting.startTimestampInMicroSec;
printk("===================================\n");
for(i = 0; i < sizeof(accounting.cpuLoad)/sizeof(accounting.cpuLoad[0]); i++) {
// Is this a real task slot, or just filler space because of the spacing
......@@ -122,18 +115,18 @@ void report_CPU_Load()
// IT IS REAL.
// The accumulatedTime is stored in microseconds ; multiply by 100 and
// divide by total milliseconds passed in real-world time.
percentage = (100ULL*accounting.cpuLoad[i].accumulatedTime) / currentMicrosecond;
percentage = (100ULL*accounting.cpuLoad[i].accumulatedTime) / accounting.totalTimeInMicroSec;
printk("Task with priority %3u took %3u%% of CPU time (%9u / %u ms).\n",
i+PRIO_MIN,
(uint32_t) percentage,
(uint32_t) (accounting.cpuLoad[i].accumulatedTime / 1000ULL),
currentMicrosecond/1000U);
accounting.totalTimeInMicroSec/1000U);
totalMicrosecondsOfCPUused += accounting.cpuLoad[i].accumulatedTime;
}
}
percentage = (100ULL*totalMicrosecondsOfCPUused) / currentMicrosecond;
percentage = (100ULL*totalMicrosecondsOfCPUused) / accounting.totalTimeInMicroSec;
printk("Total CPU load of %3u%% time (%9u / %u ms).\n",
(uint32_t) percentage,
(uint32_t) (totalMicrosecondsOfCPUused / 1000ULL),
currentMicrosecond/1000U);
accounting.totalTimeInMicroSec/1000U);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment