exact timing ? (residual bus simulation)

hi!
first of all, thanks for your help in the past - you helped me a lot (as a read-only-guy) :)

im trying do some exact timing.
A clock of 1ms, but as exact as possible.
At the moment, i got it pretty exact (~10µs jitter on my sys, measured with kithara realtime suit, that i want to replace)
I do this with the query performance counter.
The jitter should be no problem, the problem is the CPU usage.
Something around 33%!!!! (loop...) ^^

last week i read about the <chrono> lib.
This lib is from c++11 standard. Unfortunately my Embarcadero RAD Studio XE7 doesnt support c++11 and im not able to update it in the near future.

now my question:

does anyone have any experience with chrono?
how exact can i do timings with it and how is the cpu performance?
is it necessary to update to c++11 or can i donwnload <chrono> anywhere?

other option:
is there a possibility to wait for less than 1ms without burning cpu?

thanks for your help!!!

faddl


ps: yes i know, win7 is no rt-sys. but i dont need hard rt, so it might work.
as we had some issues with kithara in the near past i want to replace it.
Last edited on
AFAIK, there's no subsystem in Win32 that has the precision you're looking for. The best I've found that didn't involve looping on QueryPerformanceCounter() (and thus burning CPU) was to use a multimedia timer to wake a thread up. This does have 1 ms accuracy, but the jitter is awful. Sometimes it would easily miss two or three notifications in a row, and nearly none of them arrived within 100 us of the perfect time.
first of all thanks for your answers! :)

@helios: unfortunately true, this jitter is way too much..^^

@golden lizard: thanks for this info.
i also found this libs two weeks ago but i aimed on not to use extern libs.
now i have to change my mind as i just waste so much time trying to do it on my own... :P

on my XE7 boost 1.55 is already pre-installed. so lets try this! :)
the biggest problem here is, that i have to do any kind of loop.
so i need something to sleep my pc for less than 1 msec (100us would be enough).
does anyone know how to do that?...
The problem is precisely that nothing on Windows supports such short sleep intervals. It's an issue with the way the scheduler is designed. There's no way to work around it short of writing your own driver that takes full control of a whole CPU core.
it seems youre right. i can do pretty exact timing with QPC with about 80% less than 3µs jitter (what is amazingly good, didnt expect that) measured with kithara rt-suite.
the only problem is, that im burning the cpu.
i just started with programming but i think im learning pretty fast.
hope i will get a driver working... challenge accepted.

if you still have some information for me that might help me, please let me know :)

faddl
i just started with programming but i think im learning pretty fast.
hope i will get a driver working... challenge accepted.
Writing a kernel driver is not really something a programming newbie should undertake. Especially not one that tries to override the scheduler.

I've just been told of an ntdll function: NtDelayExecution(). Its parameter is a sleep interval in 100 ns units (i.e. 1 = 100 us, 2 = 200 us, etc.). See https://undocumented.ntinternals.net/ under UserMode/NTDLL/NT Objects/Thread/NtDelayExecution
No word on its actual precision or accuracy, though. I would not expect it to be much different.
first of all thanks a lot for your help!
NtDelayExecution seems to be the only solution to go below 1ms without burning a whole core - and it works!
its still no perfect solution - but at least it is one :D

if someone else needs it too:
-the minimum time quantum that is possible is 0.5ms, so 500µs.
-you have to set the parameter in 100ns units
- intervall time is negative!

when something else comes to your mind, please let me know :)
i will test it now for a while and tell you what happened.

faddl
im going to implement my selfmade-timer this week.
but actually i just cannot believe, that there is no win7 (kernel) timer for 1ms tick. systems are so fast this time, windows aswell. if anywone has an idea how to get some 1ms timer, please please let me know.

thanks!

faddl
I'll forward a small snippet of the discussion I had with a coworker on this matter. Perhaps it'll help:

Me: I imagine the hardware should have ways to produce interrupts at very short intervals. I suppose, since oscillators nowadays are never slower than 1 GHz.
Him: I think it does, and there are some products that try to provide high resolution timers. But everything does it kernel-side, and interfacing with HAL.sys. [My emphasis.]
I think, if you work at it, you can command the CPU to keep a constant clock rate and then use the rdtsc assembly command to get the current clock cycle and division by the hertz of the machine is back to grillionths of a second or whatever. The trick is getting the cpu power saver features to stop monkeying with the clock speed. I can't remember how we did that, and its probably obsolete now anyway (3 or 4 generations of CPU back).


first of all: thanks for your help!
i just fixed it directly in my program - for sure not "the perfect solution" but it works.
the timer is way more accurate than the rest of my program.
The timer, written with NtDelayExecution and the qpc, jitters around +-3µs (>90% of values), 97% less than 10µs jitter.
As the Program Code itself takes between 100-750µs, jitter is like nothing :D

i also thought about an trigger with an interrupt, but didnt want to use extern hardware and didnt know where to get the osci from the intern hardware.

ps: yes, i know this execution difference should not be. i didnt do it but might change next few months.

feel hugged for your help - ty :)

faddl
Topic archived. No new replies allowed.