@@ -5250,6 +5250,14 @@ dpif_netdev_set_config(struct dpif *dpif, const struct smap *other_config)
return 0;
}
+static bool
+dpif_netdev_number_handlers_required(struct dpif *dpif_ OVS_UNUSED,
+ uint32_t *n_handlers)
+{
+ *n_handlers = 0;
+ return true;
+}
+
/* Parses affinity list and returns result in 'core_ids'. */
static int
parse_affinity_list(const char *affinity_list, unsigned *core_ids, int n_rxq)
@@ -9985,7 +9993,7 @@ const struct dpif_class dpif_netdev_class = {
dpif_netdev_offload_stats_get,
NULL, /* recv_set */
NULL, /* handlers_set */
- NULL, /* number_handlers_required */
+ dpif_netdev_number_handlers_required,
dpif_netdev_set_config,
dpif_netdev_queue_to_priority,
NULL, /* recv */
@@ -584,7 +584,7 @@ static void
udpif_start_threads(struct udpif *udpif, uint32_t n_handlers_,
uint32_t n_revalidators_)
{
- if (udpif && n_handlers_ && n_revalidators_) {
+ if (udpif && n_revalidators_) {
/* Creating a thread can take a significant amount of time on some
* systems, even hundred of milliseconds, so quiesce around it. */
ovsrcu_quiesce_start();
@@ -592,14 +592,19 @@ udpif_start_threads(struct udpif *udpif, uint32_t n_handlers_,
udpif->n_handlers = n_handlers_;
udpif->n_revalidators = n_revalidators_;
- udpif->handlers = xzalloc(udpif->n_handlers * sizeof *udpif->handlers);
- for (size_t i = 0; i < udpif->n_handlers; i++) {
- struct handler *handler = &udpif->handlers[i];
+ if (udpif->n_handlers) {
+ udpif->handlers = xzalloc(udpif->n_handlers
+ * sizeof *udpif->handlers);
+ for (size_t i = 0; i < udpif->n_handlers; i++) {
+ struct handler *handler = &udpif->handlers[i];
- handler->udpif = udpif;
- handler->handler_id = i;
- handler->thread = ovs_thread_create(
- "handler", udpif_upcall_handler, handler);
+ handler->udpif = udpif;
+ handler->handler_id = i;
+ handler->thread = ovs_thread_create(
+ "handler", udpif_upcall_handler, handler);
+ }
+ } else {
+ udpif->handlers = NULL;
}
atomic_init(&udpif->enable_ufid, udpif->backer->rt_support.ufid);
@@ -662,7 +667,9 @@ udpif_set_threads(struct udpif *udpif, uint32_t n_handlers_,
if (dpif_number_handlers_required(udpif->dpif, &n_handlers_requested)) {
forced = true;
if (!n_revalidators_) {
- n_revalidators_requested = n_handlers_requested / 4 + 1;
+ n_revalidators_requested = (n_handlers_requested
+ ? n_handlers_requested
+ : MAX(count_cpu_cores(), 2)) / 4 + 1;
} else {
n_revalidators_requested = n_revalidators_;
}
Avoid unnecessary thread creation as no upcalls are generated, resulting in idle threads waiting for process termination. This optimization significantly reduces memory usage, cutting it by half on a 128 CPU/thread system during testing, with the number of threads reduced from 95 to 0. Signed-off-by: Eelco Chaudron <echaudro@redhat.com> --- v2: Sending this as a separate patch. lib/dpif-netdev.c | 10 +++++++++- ofproto/ofproto-dpif-upcall.c | 25 ++++++++++++++++--------- 2 files changed, 25 insertions(+), 10 deletions(-)