J
John Lafrowda
Dear all,
I have detected a very strange behaviour of the Windows scheduler concerning
its latency. This can be illustrated by the code segment at the end of this
mail.
The code should simply read the system time in milliseconds (using WinAPI's
GetTickCount) then sleep for a specified number of milliseconds and repeat
this loop for a given number of cycles. In the end, it presents the mean
value of the time needed per loop - which should be more or less the time
specified with the Sleep() command as the rest of the commands should take
much time.
On various PCs with different configurations (Intel and Athlon, different
boards, but all on WinXP) we find that the code is running as expected. When
setting SleepTime to 1 ms, 10 ms, and 100 ms, we receive messages that tell
us that the cycle time was 1 ms, 10 ms, and 100 ms, respectively. On other
PCs (also with XP), however, we get the following cycle times:
SleepTime = 1 ms --> CycleTime = 15 ms
SleepTime = 10 ms --> CycleTime = 15 ms
SleepTime = 100 ms --> CycleTime = 109 ms
The strange thing is, that on all PCs that were tested with this straneg
behaviour, the resulting times are exactly the same. Moreover, we found that
some PCs showed the wrong times but were ok after a they were rebooted.
For your own tests, you can compile the code below as a plain WinAPI or
console programme. In our case, Visual C++ 6.0 and Visual .net (2003)
produced the same results. BTW: Results were equal when using timers instead
of Sleep
Could anyone give me some information on what's going wrong here?
Regards,
John
------------------------------
#include <windows.h>
#include <stdio.h>
const int SleepTime = 100;
int main(){
int NewTime;
int OldTime;
int CycleTime = 0;
int Cycles = 100;
int i;
int SleepTime = 1;
char TextBuffer[256];
OldTime = GetTickCount();
Sleep(SleepTime);
for(i = 0; i < Cycles; i++){
NewTime = GetTickCount();
CycleTime += (NewTime-OldTime);
OldTime = NewTime;
Sleep(SleepTime);
}
sprintf(TextBuffer, "CycleTime: %d\n", CycleTime/Cycles);
MessageBox(NULL, TextBuffer, "TickTest", MB_OK);
return 0;
}
I have detected a very strange behaviour of the Windows scheduler concerning
its latency. This can be illustrated by the code segment at the end of this
mail.
The code should simply read the system time in milliseconds (using WinAPI's
GetTickCount) then sleep for a specified number of milliseconds and repeat
this loop for a given number of cycles. In the end, it presents the mean
value of the time needed per loop - which should be more or less the time
specified with the Sleep() command as the rest of the commands should take
much time.
On various PCs with different configurations (Intel and Athlon, different
boards, but all on WinXP) we find that the code is running as expected. When
setting SleepTime to 1 ms, 10 ms, and 100 ms, we receive messages that tell
us that the cycle time was 1 ms, 10 ms, and 100 ms, respectively. On other
PCs (also with XP), however, we get the following cycle times:
SleepTime = 1 ms --> CycleTime = 15 ms
SleepTime = 10 ms --> CycleTime = 15 ms
SleepTime = 100 ms --> CycleTime = 109 ms
The strange thing is, that on all PCs that were tested with this straneg
behaviour, the resulting times are exactly the same. Moreover, we found that
some PCs showed the wrong times but were ok after a they were rebooted.
For your own tests, you can compile the code below as a plain WinAPI or
console programme. In our case, Visual C++ 6.0 and Visual .net (2003)
produced the same results. BTW: Results were equal when using timers instead
of Sleep
Could anyone give me some information on what's going wrong here?
Regards,
John
------------------------------
#include <windows.h>
#include <stdio.h>
const int SleepTime = 100;
int main(){
int NewTime;
int OldTime;
int CycleTime = 0;
int Cycles = 100;
int i;
int SleepTime = 1;
char TextBuffer[256];
OldTime = GetTickCount();
Sleep(SleepTime);
for(i = 0; i < Cycles; i++){
NewTime = GetTickCount();
CycleTime += (NewTime-OldTime);
OldTime = NewTime;
Sleep(SleepTime);
}
sprintf(TextBuffer, "CycleTime: %d\n", CycleTime/Cycles);
MessageBox(NULL, TextBuffer, "TickTest", MB_OK);
return 0;
}