I've been wondering how much thought/measurements went into choosing 
floating-point vs integers for tracking/managing time in VPP?

Intuitively I worry that the floating-point operations are more costly than 
integer and I worry about the overhead of vlib doing conversions (including 
divisions) all the time from the integer CPU clock value.

Also I worry about precision. I just did a back of the napkin calculations for 
a 4GHz CPU, and it will start losing precision after 26 days uptime (2^53 / 4e9 
/ 3600 / 24 == 26.06...). So after 1 year uptime the precision is reduced to 
7ns and that value then doubles (halves the precision) each year after.

For now I am using clib_cpu_time_now() and local u64 values to calculate 
periodic timer stuff within my packet processing routine. I wonder how much 
more expensive using vlib and the inherent divisions for converting to f64s 
here would be?

Thanks,
Chris.

Dave Barach via Lists.Fd.Io <[email protected]> writes:

Vlib_time_now(...) works reasonably hard to return the same time on all worker 
threads:

  /*
   * Note when we let go of the barrier.
   * Workers can use this to derive a reasonably accurate
   * time offset. See vlib_time_now(...)
   */
  vm->time_last_barrier_release = vlib_time_now (vm);


always_inline f64
vlib_time_now (vlib_main_t * vm)
{
  return clib_time_now (&vm->clib_time) + vm->time_offset;
}

      /*
       * Recompute the offset from thread-0 time.
       * Note that vlib_time_now adds vm->time_offset, so
       * clear it first. Save the resulting idea of "now", to
       * see how well we're doing. See show_clock_command_fn(...)
       */
      {
        f64 now;
        vm->time_offset = 0.0;
        now = vlib_time_now (vm);
        vm->time_offset = vlib_global_main.time_last_barrier_release - now;
        vm->time_last_barrier_release = vlib_time_now (vm);
      }

See also the "show clock" command.

There should be no need to re-solve this problem yourself.

Thanks...

-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Prashant Upadhyaya
Sent: Tuesday, May 28, 2019 7:48 AM
To: [email protected]
Subject: [vpp-dev] Regarding vlib_time_now

Hi,

I suppose vlib_time_now can return different times on different workers.
If I want to have some global notion of time between workers (and possibly main 
thread), what would be the best way, please suggest.

I thought of passing the vm of main thread for the above usecase, from workers, 
while calling vlib_time_now but that seems like a spectacularly bad idea as the 
code inside  modifies some variables related to time inside the vm (and 
therefore looks like one must pass the correct vm from the correct thread)

Is it ok to use a combination of os_cpu_clock_frequency() and clib_cpu_time_now 
?

Regards
-Prashant
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#13159): https://lists.fd.io/g/vpp-dev/message/13159
Mute This Topic: https://lists.fd.io/mt/31820577/1826170
Group Owner: [email protected]
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Attachment: signature.asc
Description: PGP signature

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#13161): https://lists.fd.io/g/vpp-dev/message/13161
Mute This Topic: https://lists.fd.io/mt/31821738/21656
Group Owner: [email protected]
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to