Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Regardless of the timing mechanism you use, it boils down to a combination of change in your task's run status, when the kernel scheduler is invoked (usually 100 or 1000 times per second), and cpu contention with other processes.</p> <p>The mechanism I've found that achieves the "best" timing on Linux (Windows as well) is to do the following:</p> <ol> <li>Place the process on a <a href="http://www.linuxjournal.com/article/6900" rel="nofollow noreferrer">Shielded CPU</a></li> <li>Have the process initially sleep for 1ms. If on a shielded CPU, your process <em>should</em> wake right on the OS scheduler's tick boundary</li> <li>Use either the RDTSC directly or CLOCK_MONOTONIC to capture the current time. Use this as the zero time for calculating the absolute wakeup times for all future periods. This will help minimize drift over time. It can't be eliminated completely since hardware timekeeping fluctuates over time (thermal issues and the like) but it's a pretty good start.</li> <li>Create a sleep function that sleeps 1ms short of the target absolute wakeup time (as that's the most accurate the OS scheduler can be) then burn the CPU in a tight loop continually checking the RDTSC/CLOCK_REALTIME value.</li> </ol> <p>It takes some work but you can get pretty good results using this approach. A related question you may want to take a look at can be found <a href="https://stackoverflow.com/questions/2904887/sub-millisecond-precision-timing-in-c-or-c/2905082#2905082">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload