idleTime = 0; t0 = timer_value(); for (;;) { // kernel main loop t1 = timer_value(); leave_kernel(); t2 = timer_value(); if (idle) idleTime += (t2 - t1); idlePercent = ((unsigned long long)idleTime * 100) / (t2 - t0); // reset: idleTime = 0; t0 = timer_value(); }