Busy idle loop when profiling

- the Intel architecture cycle counter (performance counter) does not
  count when the CPU is idle therefore we use busy loop instead of
  halting the cpu when there is nothing to schedule

- the downside is that handling interrupts may be accounted as idle
  time if a sample is taken before we get out of the nested trap and
  pick a new process
This commit is contained in:
Tomas Hruby
2010-09-23 10:49:52 +00:00
parent d2b56f60da
commit ef92583c3a
5 changed files with 31 additions and 1 deletions

View File

@@ -43,6 +43,7 @@
#include "vm.h"
#include "clock.h"
#include "spinlock.h"
#include "profile.h"
#include "arch_proto.h"
@@ -214,7 +215,18 @@ PRIVATE void idle(void)
/* start accounting for the idle time */
context_stop(proc_addr(KERNEL));
halt_cpu();
if (!sprofiling)
halt_cpu();
else {
volatile int * v;
v = get_cpulocal_var_ptr(idle_interrupted);
interrupts_enable();
while (!*v)
arch_pause();
interrupts_disable();
*v = 0;
}
/*
* end of accounting for the idle task does not happen here, the kernel
* is handling stuff for quite a while before it gets back here!