diff mbox series

[ovs-dev,v3,2/2] handlers: Add additional handler threads for inactive cores

Message ID 20220527063739.512492-2-msantana@redhat.com
State Superseded
Headers show
Series [ovs-dev,v3,1/2] handlers: Fix handlers mapping | expand

Checks

Context Check Description
ovsrobot/apply-robot warning apply and check: warning
ovsrobot/github-robot-_Build_and_Test fail github build: failed
ovsrobot/intel-ovs-compilation fail test: fail

Commit Message

Michael Santana May 27, 2022, 6:37 a.m. UTC
Signed-off-by: Michael Santana <msantana@redhat.com>
---
 lib/dpif-netlink.c | 14 ++++++++++++
 lib/ovs-thread.c   | 53 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/ovs-thread.h   |  4 ++++
 3 files changed, 71 insertions(+)

Comments

0-day Robot May 27, 2022, 7 a.m. UTC | #1
Bleep bloop.  Greetings Michael Santana, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
ERROR: Inappropriate spacing around cast
#69 FILE: lib/ovs-thread.c:695:
    uint32_t limit = sqrt((float)num);

WARNING: Line lacks whitespace around operator
WARNING: Line lacks whitespace around operator
#70 FILE: lib/ovs-thread.c:696:
    for (i = 3; i <= limit; i+=2) {

WARNING: Line lacks whitespace around operator
WARNING: Line lacks whitespace around operator
#100 FILE: lib/ovs-thread.c:726:
    for (i = num; i < limit; i+=2) {

Lines checked: 130, Warnings: 4, Errors: 1


Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot
diff mbox series

Patch

diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 77a97beac..556596a13 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -2759,9 +2759,23 @@  static bool
 dpif_netlink_number_handlers_required(struct dpif *dpif_, uint32_t *n_handlers)
 {
     struct dpif_netlink *dpif = dpif_netlink_cast(dpif_);
+    uint32_t total_cores, next_prime_num;
 
     if (dpif_netlink_upcall_per_cpu(dpif)) {
         *n_handlers = count_cpu_cores();
+        total_cores = count_total_cores();
+
+        /*
+         * If we have isolated cores, add additional handler threads to
+         * service inactive cores in the unlikely event that traffic goes
+         * through inactive cores
+         */
+        if (*n_handlers < total_cores) {
+            next_prime_num = next_prime(*n_handlers +1, 10000000);
+            *n_handlers = next_prime_num >= total_cores ?
+                                                total_cores : next_prime_num;
+        }
+
         return true;
     }
 
diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index 2172b3d3f..a685d022f 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -18,6 +18,7 @@ 
 #include "ovs-thread.h"
 #include <errno.h>
 #include <poll.h>
+#include <math.h>
 #ifndef _WIN32
 #include <signal.h>
 #endif
@@ -679,6 +680,58 @@  count_total_cores(void) {
     return n_cores > 0 ? n_cores : 0;
 }
 
+/*
+ * Returns 1 if num is a prime number,
+ * Otherwise return 0
+ */
+uint32_t
+is_prime(uint32_t num)
+{
+    if ((num % 2) == 0) {
+        return num == 2;
+    }
+
+    uint32_t i;
+    uint32_t limit = sqrt((float)num);
+    for (i = 3; i <= limit; i+=2) {
+        if (num % i == 0) {
+            return 0;
+        }
+    }
+
+    return 1;
+}
+
+/*
+ * Returns num if num is a prime number. Otherwise returns the next
+ * prime greater than num. Search is limited by the limit variable.
+ *
+ * Returns 0 if num >= limit, or if no prime has been found between
+ * num and limit
+ */
+uint32_t
+next_prime(uint32_t num, uint32_t limit)
+{
+    if (num < 2) {
+        return 2;
+    }
+    if (num == 2) {
+        return 3;
+    }
+    if (num % 2 == 0) {
+        num++;
+    }
+
+    uint32_t i;
+    for (i = num; i < limit; i+=2) {
+        if (is_prime(i)) {
+            return i;
+        }
+    }
+
+    return 0;
+}
+
 /* Returns 'true' if current thread is PMD thread. */
 bool
 thread_is_pmd(void)
diff --git a/lib/ovs-thread.h b/lib/ovs-thread.h
index aac5e19c9..634dcae05 100644
--- a/lib/ovs-thread.h
+++ b/lib/ovs-thread.h
@@ -523,6 +523,10 @@  bool may_fork(void);
 
 int count_cpu_cores(void);
 int count_total_cores(void);
+
+uint32_t is_prime(uint32_t num);
+uint32_t next_prime(uint32_t num, uint32_t limit);
+
 bool thread_is_pmd(void);
 
 #endif /* ovs-thread.h */