Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use monotonic/steady clock by default if available #2044

Closed
hololqq opened this issue Jun 21, 2021 · 4 comments · Fixed by #2088
Closed

Use monotonic/steady clock by default if available #2044

hololqq opened this issue Jun 21, 2021 · 4 comments · Fixed by #2088
Assignees
Labels
[build] Area: Changes in build files Type: Maintenance Work required to maintain or clean up the code
Milestone

Comments

@hololqq
Copy link

hololqq commented Jun 21, 2021

Hi,

I'm new to use the haivision srt project and have a question.

Out product uses v1.4.1 to achieve SRT transmit, but we found a bug that SRT will drop packet when system time is changed via NTP/manual. I checked the code and I though the related code is gettimeofday(), which use the system time as SRT start time.

Today I found the release logs of the 1.4.2&1.4.3, and some logs related to this function. So I imagined there's an issue indicated this bug and had been resolved in the following releases. Is this right? If so, please give me a reply.

Thanks for your time:)

@hololqq hololqq added the Type: Question Questions or things that require clarification label Jun 21, 2021
@maxsharabayko
Copy link
Collaborator

maxsharabayko commented Jun 21, 2021

Hi @hololqq
SRT v1.4.2 adds two options for SRT to use monotonic time source:

  1. C++11 std::chrono::steady_clock can be enabled with -DENABLE_STDCXX_SYNC=ON CMake build option.
  2. POSIX clock_gettime with monotonic time source can be enabled with -DENABLE_MONOTONIC_CLOCK.

If you can use C++11 compliant compiler, consider using the first option.

@maxsharabayko maxsharabayko added the [API] Area: Changes in SRT library API label Jun 21, 2021
@hololqq
Copy link
Author

hololqq commented Jun 22, 2021

Hi @hololqq
SRT v1.4.2 adds two options for SRT to use monotonic time source:

  1. C++11 std::chrono::steady_clock can be enabled with -DENABLE_STDCXX_SYNC=ON CMake build option.
  2. POSIX clock_gettime with monotonic time source can be enabled with -DENABLE_MONOTONIC_CLOCK.

If you can use C++11 compliant compiler, consider using the first option.

Thanks. I'll test it today.

@gizahNL
Copy link

gizahNL commented Jun 25, 2021

Hi @hololqq
SRT v1.4.2 adds two options for SRT to use monotonic time source:

  1. C++11 std::chrono::steady_clock can be enabled with -DENABLE_STDCXX_SYNC=ON CMake build option.
  2. POSIX clock_gettime with monotonic time source can be enabled with -DENABLE_MONOTONIC_CLOCK.

If you can use C++11 compliant compiler, consider using the first option.

What is the rationale for not having these turned on by default? It would seem to me that monotonic clock source is a strict requirement for a networking protocol doing time based recovery.

@maxsharabayko
Copy link
Collaborator

@gizahNL

What is the rationale for not having these turned on by default?

The end goal is to fully transition to a monotonic clock. There are/were several things to consider before transitioning.

  1. Compatibility with old versions of SRT using wallclock. This has been confirmed. ✔️
  2. Define what should be the new defaults.

As shared above, there are two ways to enable a monotonic clock:

  1. C++11 std::chrono::steady_clock can be enabled with -DENABLE_STDCXX_SYNC=ON CMake build option.
  2. POSIX clock_gettime with monotonic time source can be enabled with -DENABLE_MONOTONIC_CLOCK.

Without those options, the current defaults are:

  • On MacOS SRT uses mach_absolute_time(..) by default, which is monotonic, except the timer is not incremented while the device is asleep.
  • On Windows QueryPerformanceCounter(..) is used by default, though together with gettimeofday() port in pthreads4win. Not 100% accurate monotonic clock.
  • On Linux gettimeofday(..) is used by default. Wall clock.

The New Defaults to Apply

There are two options here.

  1. The easiest way is to enable C++11 build of SRT by default, providing STL steady clock. However, it may impact some integrations, forcing them to explicitly disable C++11 in SRT. Also, in some experiments, we observed STL steady clock to provide system clock, which is weird and requires further study.

  2. Another option is to enable C++11 by default only for Windows builds, and enable -DENABLE_MONOTONIC_CLOCK for Linux builds. If a Linux system does not support CLOCK_MONOTONIC, it is the user who should specify -DENABLE_MONOTONIC_CLOCK=OFF.

@maxsharabayko maxsharabayko self-assigned this Jul 12, 2021
@maxsharabayko maxsharabayko changed the title Has the bug of dropping packet when changing system time fixed at 1.4.2&newer versions? Use monotonic/steady clock by default if available Aug 9, 2021
@maxsharabayko maxsharabayko added [build] Area: Changes in build files Type: Maintenance Work required to maintain or clean up the code and removed Type: Question Questions or things that require clarification [API] Area: Changes in SRT library API labels Aug 9, 2021
@maxsharabayko maxsharabayko added this to the v1.4.4 milestone Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[build] Area: Changes in build files Type: Maintenance Work required to maintain or clean up the code
Projects
None yet
3 participants