fn measure_tsc_offset(
    core: usize,
    rdtsc: fn() -> u64,
    tsc_frequency: u64,
    reference_moments: Vec<TscMoment>,
    num_samples: usize,
    stdev_limit: f64
) -> Result<i128, TscCalibrationError>
Expand description

Measure the TSC offset for core from core 0 where reference_moments were gathered.

This function first pins itself to core, then generates num_samples TscMoments for this core, and then measures the TSC offset between those moments and all reference_moments. Any moments that are outside of stddev_limit standard deviations from the median offset are discarded, because they may represent an interrupt that occurred while a TscMoment was generated. The remaining offsets are averaged and returned as nanoseconds.

§Arguments

  • core - Core that this function should run on.
  • rdtsc - Function for reading the TSC value, usually just runs RDTSC instruction.
  • tsc_frequency - TSC frequency measured from core 0.
  • reference_moments - TscMoments gathered from core 0.
  • num_samples - Number of TscMoments to generate on this thread for measuring the offset.
  • stdev_limit - Number of standard deviations outside of which offsets are discarded.