@@ -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;
}
@@ -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)
@@ -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 */
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(+)