diff mbox series

[ovs-dev,v5,1/2] util: Add non quiesce xnanosleep.

Message ID 20230111093501.409990-2-ktraynor@redhat.com
State Accepted
Commit f4c884135139f0d9e309bcd58244191145c5abba
Headers show
Series Add pmd sleeping. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Kevin Traynor Jan. 11, 2023, 9:35 a.m. UTC
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>
---
 lib/util.c | 21 +++++++++++++++++----
 lib/util.h |  1 +
 2 files changed, 18 insertions(+), 4 deletions(-)

Comments

David Marchand Jan. 11, 2023, 10:23 a.m. UTC | #1
On Wed, Jan 11, 2023 at 10:35 AM Kevin Traynor <ktraynor@redhat.com> wrote:
>
> 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>

Just to confirm.
Reviewed-by: David Marchand <david.marchand@redhat.com>
diff mbox series

Patch

diff --git a/lib/util.c b/lib/util.c
index 1195c7982..7576eb06e 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -2372,9 +2372,7 @@  xsleep(unsigned int seconds)
 }
 
-/* High resolution sleep. */
-void
-xnanosleep(uint64_t nanoseconds)
+static void
+xnanosleep__(uint64_t nanoseconds)
 {
-    ovsrcu_quiesce_start();
 #ifndef _WIN32
     int retval;
@@ -2404,7 +2402,22 @@  xnanosleep(uint64_t nanoseconds)
     }
 #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
diff --git a/lib/util.h b/lib/util.h
index 9ff84b3dc..f35f33021 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -594,4 +594,5 @@  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);