c - How can I tell if every core on my machine uses the same timer? -
i'm trying write code determine if clock_gettime
used clock_monotonic_raw
give me results coming same hardware on different cores.
from understand possible each core produce independent results not always. given task of obtaining timings on cores precision of 40 nanoseconds.
the reason i'm not using clock_realtime
program absolutely must not affected ntp adjustments.
edit:
i have found unsynchronized_tsc function tries test whether tsc same on cores. attempting find if clock_monotonic_raw
based on tsc.
final edit:
it turns out clock_monotonic_raw
usable on multi-core systems , not rely on tsc on intel machines.
to measurements precisely; you'd need:
- code that's executed on cpus, reads cpu's time stamp counter , stores "an event" occurs
- some way create "an event" noticed @ same time cpus
- some way prevent timing problems caused irqs, task switches, etc.
various possibilities event include:
- polling memory location in loop, 1 cpu writes new value , other cpus stop polling when see new value
- using local apic broadcast ipi (inter-processor interrupt) cpus
for both of these methods there delays between cpus (especially larger numa systems) - write memory (cache) may visible on cpu made write immediately, , visible cpu on different physical chip (in different numa domain) later. avoid may need find average of initiating event on cpus. e.g. (for 2 cpus) 1 cpu initiates , both measure, other cpu initiates , both measure, results combined cancel out "event propagation latency".
to fix other timing problems (irqs, task switches, etc) i'd want doing these tests during boot nothing else can mess things up. otherwise either need prevent problems (ensure cpus running @ same speed, disable irqs, disable thread switches, stop pci device bus mastering, etc) or cope problems (e.g. run same test many times , see if similar results of time).
also note of above can ensure time stamp counters in sync @ time test done, , don't guarantee won't become out of sync after test done. ensure cpus remain in sync you'd need rely on cpu's "monotonic clock" guarantees (but older cpus don't make guarantee).
finally; if you're attempting in user-space (and not in kernel code); advice design code in way isn't fragile begin with. if tscs on different cpus guaranteed in sync @ times, can't prevent irq interrupting before or after reading tsc (and there's no way atomically , read tsc @ same time); , therefore if code requires such precisely synchronised timing code's design flawed.
Comments
Post a Comment