Weird timer bug
Posted: Mon Oct 24, 2011 8:12 am
Hello all,
I set PIT on IRQ0 @ 1mS intervals, and on every tick I increment one variable. That work perfect, I even measured time with external stopwatch, and it`s fine
The problem is when I want to measure time between some CPU activity. I set while loop @ 900M and increment some variable. Before I start to do this, I reed current number of ticks and store it in variable timerStart. Now after 900M while loop I read time again and it said that only ~1.5sec has passed, and in reality it`s about 10sec. First I thought that when CPU do it`s work I don`t get interrupt @ IRQ0, but no, if I check number of ticks later on, they are OK???
Here`s the code so u can see what I mean...
and here he do k++ for ~10sec, but says that only 1.5 has passed. And if I call printSysTime() it shows the REAL values...
I set PIT on IRQ0 @ 1mS intervals, and on every tick I increment one variable. That work perfect, I even measured time with external stopwatch, and it`s fine
The problem is when I want to measure time between some CPU activity. I set while loop @ 900M and increment some variable. Before I start to do this, I reed current number of ticks and store it in variable timerStart. Now after 900M while loop I read time again and it said that only ~1.5sec has passed, and in reality it`s about 10sec. First I thought that when CPU do it`s work I don`t get interrupt @ IRQ0, but no, if I check number of ticks later on, they are OK???
Here`s the code so u can see what I mean...
Code: Select all
struct CLOCK
{
int32u H;
int32u M;
int32u S;
int32u mS;
};
void printSysTime()
{
__asm__ __volatile__("cli");
itoa(time.H, out);
puts(out); putch(':');
itoa(time.M, out);
puts(out); putch(':');
itoa(time.S, out);
puts(out); putch('.');
itoa(time.mS, out);
puts(out);
__asm__ __volatile__("sti");
}
...
void startTimer()
{
__asm__ __volatile__("cli");
timerStart.H = time.H;
timerStart.M = time.M;
timerStart.S = time.S;
timerStart.mS = time.mS;
__asm__ __volatile__("sti");
puts("\nTimer started @: ");
printTime(&timerStart);
putch('\n');
}
struct CLOCK getTimer()
{
struct CLOCK current;
__asm__ __volatile__("cli");
current.H = time.H;
current.M = time.M;
current.S = time.S;
current.mS = time.mS;
__asm__ __volatile__("sti");
puts("\nTimer ended @: ");
printTime(¤t);
putch('\n');
//empty for now, i have some other logic to do here...
struct CLOCK ret;
return ret;
}
...
void someFunc()
{
startTimer();
int i = 900000000;
int k = 0;
while(i-- > 0)
{
k++;
}
getTimer();
}