summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Traynor <ktraynor@redhat.com>2023-01-11 09:35:00 +0000
committerIlya Maximets <i.maximets@ovn.org>2023-01-12 12:21:20 +0100
commitf4c884135139f0d9e309bcd58244191145c5abba (patch)
treeccd96d153aa30ecb5826e831fbac41c1e8fc1e85
parent4de6b009cfec1e4aac57283f5cab129718939292 (diff)
downloadopenvswitch-f4c884135139f0d9e309bcd58244191145c5abba.tar.gz
util: Add non quiesce xnanosleep.
xnanosleep forces the thread into quiesce state in anticipation that it will be sleeping for a considerable time and that the thread may need to quiesce before the sleep is finished. In some cases, a very short sleep may be requested and in that case the overhead of going to into quiesce state may be unnecessary. To allow for those cases add a xnanosleep_no_quiesce() variant. Suggested-by: Ilya Maximets <i.maximets@ovn.org> Reviewed-by: David Marchand <david.marchand@redhat.com> Signed-off-by: Kevin Traynor <ktraynor@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
-rw-r--r--lib/util.c21
-rw-r--r--lib/util.h1
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/util.c b/lib/util.c
index 1195c7982..7576eb06e 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -2371,11 +2371,9 @@ xsleep(unsigned int seconds)
ovsrcu_quiesce_end();
}
-/* High resolution sleep. */
-void
-xnanosleep(uint64_t nanoseconds)
+static void
+xnanosleep__(uint64_t nanoseconds)
{
- ovsrcu_quiesce_start();
#ifndef _WIN32
int retval;
struct timespec ts_sleep;
@@ -2403,9 +2401,24 @@ xnanosleep(uint64_t nanoseconds)
ovs_lasterror_to_string());
}
#endif
+}
+
+/* High resolution sleep with thread quiesce. */
+void
+xnanosleep(uint64_t nanoseconds)
+{
+ ovsrcu_quiesce_start();
+ xnanosleep__(nanoseconds);
ovsrcu_quiesce_end();
}
+/* High resolution sleep without thread quiesce. */
+void
+xnanosleep_no_quiesce(uint64_t nanoseconds)
+{
+ xnanosleep__(nanoseconds);
+}
+
/* 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 9ff84b3dc..f35f33021 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -593,6 +593,7 @@ ovs_u128_is_superset(ovs_u128 super, ovs_u128 sub)
void xsleep(unsigned int seconds);
void xnanosleep(uint64_t nanoseconds);
+void xnanosleep_no_quiesce(uint64_t nanoseconds);
bool is_stdout_a_tty(void);