Sign in to follow this  
emmai

using winio.dll to read 8253 timer

Recommended Posts

I'd like to get accurate timer by using read 8253 directly,I'm now using winio.dll to do this,the code is like this: if (InitializeWinIo()) { // Under Windows NT/2000/XP, after calling InitializeWinIo, // you can call _inp/_outp instead of using GetPortVal/SetPortVal DWORD dwCount = 0; DWORD dwBegin = GetTick(); LARGE_INTEGER liQ,liC1,liC2; DWORD dw1 = GetTickCount(); QueryPerformanceFrequency(&liQ); QueryPerformanceCounter(&liC1); DWORD dwOldProcessP = GetPriorityClass(GetCurrentProcess()); DWORD dwOldThreadP = GetThreadPriority(GetCurrentThread()); SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); do { //printf("%d\n",dwBegin); DWORD dwTick = GetTick(); dwCount += dwBegin > dwTick ? dwBegin - dwTick : 65535 + dwBegin - dwTick; dwBegin = dwTick; QueryPerformanceCounter(&liC2); }while((liC2.QuadPart - liC1.QuadPart) / (double)liQ.QuadPart < 1.000000); SetThreadPriority(GetCurrentThread(), dwOldThreadP); SetPriorityClass(GetCurrentProcess(), dwOldProcessP); printf("QueryPerformanceCounter : %f\n",(liC2.QuadPart - liC1.QuadPart) / (double)liQ.QuadPart); printf("8253 Tick : %d\n",dwCount); DWORD dw2 = GetTickCount(); printf("GetTickCount : %d\n",dw2 - dw1); ShutdownWinIo(); } this is a test program,I loop one second,and count the 8253 ticks,that result should be ~1193177. it works on many machines,but on my machine,the result is ~2386362,twice the right value! can anyone help me?

Share this post


Link to post
Share on other sites
Be aware that depending on what mode they're set up in, some timers count by twos instead of ones. Check the count mode selection?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this