This commit introduces xnanosleep() for the threads needing high resolution sleep timeouts.
Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodire...@intel.com> --- lib/timeval.c | 2 +- lib/timeval.h | 1 + lib/util.c | 19 +++++++++++++++++++ lib/util.h | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/timeval.c b/lib/timeval.c index dd63f03..8190b41 100644 --- a/lib/timeval.c +++ b/lib/timeval.c @@ -474,7 +474,7 @@ xclock_gettime(clock_t id, struct timespec *ts) } } -static void +void msec_to_timespec(long long int ms, struct timespec *ts) { ts->tv_sec = ms / 1000; diff --git a/lib/timeval.h b/lib/timeval.h index 7957dad..110745c 100644 --- a/lib/timeval.h +++ b/lib/timeval.h @@ -69,6 +69,7 @@ size_t strftime_msec(char *s, size_t max, const char *format, const struct tm_msec *); void xgettimeofday(struct timeval *); void xclock_gettime(clock_t, struct timespec *); +void msec_to_timespec(long long int , struct timespec *); int get_cpu_usage(void); diff --git a/lib/util.c b/lib/util.c index 36e3731..4ad7eea 100644 --- a/lib/util.c +++ b/lib/util.c @@ -2197,6 +2197,25 @@ xsleep(unsigned int seconds) ovsrcu_quiesce_end(); } +/* High resolution sleep. */ +void +xnanosleep(uint64_t ms) +{ + ovsrcu_quiesce_start(); +#ifdef __linux__ + int retval; + struct timespec ts_sleep; + msec_to_timespec(ms, &ts_sleep); + + int error = 0; + do { + retval = nanosleep(&ts_sleep, NULL); + error = retval < 0 ? errno : 0; + } while (error == EINTR); +#endif + ovsrcu_quiesce_end(); +} + /* Determine whether standard output is a tty or not. This is useful to decide * whether to use color output or not when --color option for utilities is set * to `auto`. diff --git a/lib/util.h b/lib/util.h index 764e0a0..0449fa1 100644 --- a/lib/util.h +++ b/lib/util.h @@ -489,6 +489,7 @@ ovs_u128_and(const ovs_u128 a, const ovs_u128 b) } void xsleep(unsigned int seconds); +void xnanosleep(uint64_t ms); bool is_stdout_a_tty(void); -- 2.4.11 _______________________________________________ dev mailing list d...@openvswitch.org https://mail.openvswitch.org/mailman/listinfo/ovs-dev