mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 14:25:26 +00:00
util: Add high resolution sleep support.
This commit introduces xnanosleep() for the threads needing high resolution sleep timeouts. usleep() that provides microsecond granularity is deprecated and threads wanting sub-second(ms,us,ns) granularity can use this implementation. Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org> Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
committed by
Ben Pfaff
parent
a89e91c6ab
commit
ca3cc1aad4
@@ -514,6 +514,25 @@ msec_to_timespec(long long int ms, struct timespec *ts)
|
||||
ts->tv_nsec = (ms % 1000) * 1000 * 1000;
|
||||
}
|
||||
|
||||
void
|
||||
nsec_to_timespec(long long int nsec, struct timespec *ts)
|
||||
{
|
||||
if (!nsec) {
|
||||
ts->tv_sec = ts->tv_nsec = 0;
|
||||
return;
|
||||
}
|
||||
ts->tv_sec = nsec / (1000 * 1000 * 1000);
|
||||
|
||||
nsec = nsec % (1000 * 1000 * 1000);
|
||||
/* This is to handle dates before epoch. */
|
||||
if (OVS_UNLIKELY(nsec < 0)) {
|
||||
nsec += 1000 * 1000 * 1000;
|
||||
ts->tv_sec--;
|
||||
}
|
||||
|
||||
ts->tv_nsec = nsec;
|
||||
}
|
||||
|
||||
static void
|
||||
timewarp_work(void)
|
||||
{
|
||||
|
Reference in New Issue
Block a user