Camera timestamp slow drift

Board: Nvidia Jetson Xavier NX
L4T version: 32.5.1

Hello, I am getting the timestamps from my frames using the argus api like so :
(getTscOffsetNs() reads and return the value from /sys/devices/system/clocksource/clocksource0/offset_ns)

  // Get frame meta.
  IArgusCaptureMetadata *iArgusCaptureMetadata =
      interface_cast<IArgusCaptureMetadata>(frame);

  CaptureMetadata *metadata = iArgusCaptureMetadata->getMetadata();

  const Ext::ISensorTimestampTsc *iSensorTimestampTsc =
      interface_cast<const Ext::ISensorTimestampTsc>(metadata);

  // Get frame SOF timestamp.
  uint64_t frame_sof_timestamp = iSensorTimestampTsc->getSensorSofTimestampTsc();

  // Substract offset between system monotonic clock and VI HW timestamp system counter.
  uint64_t sensor_timestamp_ns = frame_sof_timestamp - getTscOffsetNs();

  // Get timestamp from monotonic clock.
  timespec t;
  clock_gettime(CLOCK_MONOTONIC, &t);
  uint64_t monotonic_raw_ns = t.tv_sec * 1e9l + t.tv_nsec;

  // Compute frame age.
  uint64_t captured_ago_ns = monotonic_raw_ns - sensor_timestamp_ns;

  GST_DEBUG("Frame age:   %20f ms\n", captured_ago_ns * 1e-6);

The code above will log the age of the frame in ms. Typically the log looks like this (~39 ms):

But after some time (~1h) the time will slowly creep up (~41ms):

It continues to go up slowly.

If I stop one camera then the delay goes away in other cameras.

I have tried to run sudo jetson_clocks but the issue persists.

How to solve this issue ? Thanks !

Do you boost the clocks like below to try.

sudo nvpmodel -m 0
sudo jetson_clocks
sudo su
echo 1 > /sys/kernel/debug/bpmp/debug/clk/vi/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/isp/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/nvcsi/mrq_rate_locked
echo 1 > /sys/kernel/debug/bpmp/debug/clk/emc/mrq_rate_locked
cat /sys/kernel/debug/bpmp/debug/clk/vi/max_rate |tee /sys/kernel/debug/bpmp/debug/clk/vi/rate
cat /sys/kernel/debug/bpmp/debug/clk/isp/max_rate | tee  /sys/kernel/debug/bpmp/debug/clk/isp/rate
cat /sys/kernel/debug/bpmp/debug/clk/nvcsi/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/nvcsi/rate
cat /sys/kernel/debug/bpmp/debug/clk/emc/max_rate | tee /sys/kernel/debug/bpmp/debug/clk/emc/rate

Hey @ShaneCCC and thanks for your answer.

it seems that once the drift has started the above commands do not solve the issue. After 22h the drift gets very significant :

Could it be that /sys/devices/system/clocksource/clocksource0/offset_ns needs to be updated ?

Also, when I get the timestamp from v4l-ctl with:

v4l2-ctl --device=/dev/video0 --stream-mmap --stream-to=/tmp/frame0.raw --stream-count=1 --set-ctrl bypass_mode=0 --verbose 2>&1

I get a similar frame age: 724.645 162 ms

Problem solved!
I should have used

  clock_gettime(CLOCK_MONOTONIC_RAW, &t);

and not

  clock_gettime(CLOCK_MONOTONIC, &t);

This jetson was synced via PTP, and CLOCK_MONOTONIC_RAW will actually drift with PTP adjustments.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.