3

My project is a long time daemon service and need to busy check some conditions and take actions as soon as possible.

I want to use std::steady_clock to account the responsing time of my service and the busy/free duty proportion.

Everytime the service runs about in 20~100 microseconds, while the designing requirement is less than 160us. So I'm afraid that it would waste too much time to call steady_clock::now() frequently.

My question:

  1. Does steady_clock::now() make a syscall potentially? Would it result my program to be blocked irregularly for a long time(exceed 1ms)?
  2. Is there any better alternative method?
8
  • 1
    This is likely to depend on specifics of kernel and library version, as well as hardware architecture. Commented Apr 23, 2024 at 16:45
  • 2
    If you want to know what's actually going on, then 1) read the source code. 2) use a profiler. 3) use a debugger. But, if I were to guess, I'd guess that on linux the gettimeofday or similar syscall would be called using the vdso, so would stay entirely in userspace - but that's just a guess. Commented Apr 23, 2024 at 16:45
  • 2
    Looks like it can: github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/src/c++11/… Commented Apr 23, 2024 at 16:53
  • "need to busy check some conditions and take actions" - why use a busy loop and not a condition variable? Commented Apr 23, 2024 at 17:03
  • 1
    @leon yeah, having a "long time daemon service" is sure to be great when it's cooking your CPU at 100% all the time... well, it's not my project. Commented Apr 23, 2024 at 23:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.