Getting current TSC hardware timestamp in user space

Hi,

we’re attempting to measure the latency between a stereo camera’s Start Of Frame and various other components down the pipeline.

We’re comparing against the getSensorSofTimestampTsc and getSensorSofTimestampTsc2 values provided by Jetson Linux API Reference: Argus::Ext::ISensorTimestampTsc Class Reference | NVIDIA Docs

We’ve seen How to get the clock source offset_ns on Jetpack 6 but don’t want to go via other clocks as we’ve noted they’re unstable similar to Clock source not stable - #5 by alexcekay-aut

Is the following code the best option for getting the current TSC timestamp on the latest JetPack 6 or is there an API for it?

uint64_t getTscNow()
{
  unsigned long cycles, frequency;

  asm volatile("mrs %0, cntfrq_el0" : "=r"(frequency));
  asm volatile("mrs %0, cntvct_el0" : "=r"(cycles));

  return (cycles * 100 / (frequency / 10000)) * 1000;
}

Thanks in advance!

hello janne.husberg1,

FYI, starting from JP-6.0, the Generic Timestamp Engine (GTE) driver has been marked as deprecated and replaced by the Hardware Timestamp Engine (HTE) from the upstream kernel.

you may see-also Topic 303499 for reference.