// JP opened flex table

Click to See Complete Forum and Search --> : WaitForSingleObject question-problem..


tylerktp
May 21st, 2004, 11:54 AM
Hello everyone!

I want to calculate the elapsed time of a WaitForSingleObject function.
As i read on a previous thread, someone suggested
QueryPerformanceCounter() (QPC).
I have used this function with success a lot times in the past , but this time I have a problem.
Please take a look at the following piece of code:


LARGE_INTEGER timeStart;
LARGE_INTEGER timeStop;
LARGE_INTEGER Frequency;
LONGLONG Diff1;

for (i=0:i<1000;i++) {

QueryPerformanceFrequency(&Frequency);

QueryPerformanceCounter(&liStart);

......
......

WaitForSingleObject(hEventSRB, INFINITE);

QueryPerformanceCounter(&liStop);

Diff1 = timeStop.QuadPart - timeStart.QuadPart;

SlowFunction();

}

The problem is that if the SlowFunction follows I take completely wrong values in Diff1. I mean that Diff1 has a value far from the expected. If I remove the SlowFunction, everything seems correct.

Is there something wrong with the above? Is there any other way to calculate the ellapsed time of WaitForSingleObject with high precision?

Thank you very much for your time.
regards,
tyler

kuphryn
May 21st, 2004, 12:45 PM
How are you checking Diff1? Are you using breakpoint or output?

Kuphryn

tylerktp
May 22nd, 2004, 02:55 AM
Thank you for your reply.

I am using output of Diff1 in a List Control.

kuphryn
May 24th, 2004, 08:45 PM
Diff1 is created on the stack. Where does the program update the list control with the latest Diff1 value?

Kuphryn

Andreas Masur
May 25th, 2004, 03:33 AM
Originally posted by tylerktp
The problem is that if the SlowFunction follows I take completely wrong values in Diff1. I mean that Diff1 has a value far from the expected. If I remove the SlowFunction, everything seems correct.

Well...besides that you should simply take a look with your debugger...check the 'SlowFunction()' whether you are corrupting your memory, e.g. writing over the boundaries of an array...

tylerktp
May 25th, 2004, 07:53 AM
Originally posted by kuphryn
Diff1 is created on the stack. Where does the program update the list control with the latest Diff1 value?

List control is being updated just before the "SlowFunction()". I tried not to use this list control and report the values of Dif1 direct to a file, and unfortunately I took the same results..


Originally posted by Andreas Masur
Well...besides that you should simply take a look with your debugger...check the 'SlowFunction()' whether you are corrupting your memory, e.g. writing over the boundaries of an array...


Well, I checked the "SlowFunction()" again and moreover I replaced it with a simple dummy "for" loop, just to simulate the delay. I took the same reults.. As the event that I am waiting to be signaled with WaitSingleObject (therefore the time I want to measure) is an access to a CDROM drive through an ASPI command ( SendASPI32Command() ) I wonder if something is going wrong there.. but this is maybe beyond the scope of this thread.
It seems like the timer stops counting before the event been signaled, because Dif1 has smaller values when SlowFunction() or a delay loop exists....

Andreas Masur
May 25th, 2004, 10:48 AM
Originally posted by tylerktp
It seems like the timer stops counting before the event been signaled, because Dif1 has smaller values when SlowFunction() or a delay loop exists....
Well...that is basically not possible since we are talking about a hardware counter here... :cool:

tylerktp
May 25th, 2004, 11:36 AM
Originally posted by Andreas Masur
Well...that is basically not possible since we are talking about a hardware counter here...

This is true, that's why I wrote some assemply code, setting the timer directly via port 40h, in order to avoid QPC function, with no luck.. the same results.. I wrote also another assembly routine getting time from system RTC (RDTSC command), but always the same strange behaviour... :confused:
any ideas??

Andreas Masur
May 25th, 2004, 11:49 AM
Well...in this case, I do not have any ideas right from the top of my head. Can you simulate this behaviour with a small test application you could post here?

So that others can check it as well?

tylerktp
May 26th, 2004, 04:49 AM
It is a little bit difficult to simulate all the actions needed to access a cdrom drive, because there are a lot of functions and structs needed to do these operations which I had to post here, but this is a lot of code.. I will try to make a small applet doing someting like that, and I will keep you informed ;)
Thank you very much for your help and time!

Best regards,
tyler

//JP added flex table