From patchwork Fri Aug 28 17:03:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Gray X-Patchwork-Id: 1353410 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=fraxinus.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SVPmQ65C; dkim-atps=neutral Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BdQsQ24zJz9sTC for ; Sat, 29 Aug 2020 03:03:22 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 5B1C48721A; Fri, 28 Aug 2020 17:03:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1KnIEcR-B8ND; Fri, 28 Aug 2020 17:03:19 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id CF4FC8720E; Fri, 28 Aug 2020 17:03:19 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A313AC016F; Fri, 28 Aug 2020 17:03:19 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4CFA2C0051 for ; Fri, 28 Aug 2020 17:03:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 48A7B22253 for ; Fri, 28 Aug 2020 17:03:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Cm1CpAHqLbC9 for ; Fri, 28 Aug 2020 17:03:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by silver.osuosl.org (Postfix) with ESMTPS id 1FA0D20449 for ; Fri, 28 Aug 2020 17:03:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598634195; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OZl49i51M10B1/1T0FtYv5wmAOPW72de6iXs+kOBod0=; b=SVPmQ65CxuoWZqClR2NNPeS7Y7cjQ8A7Vh14Kx3DoStG+Wknzk/eVyg1tBJbQQgwATJah+ v7FqLJPUcO+22JRbRBQldcJ/EzhD/4GdbXKApV8eCoDibvvMMevXZr7t2eC6ayaSzL8v66 nQ4pKIR/bYNGgu0dry1wHR2QYtaKgik= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-325-WBOW3VHJPUmYM-8r4JmnJA-1; Fri, 28 Aug 2020 13:03:13 -0400 X-MC-Unique: WBOW3VHJPUmYM-8r4JmnJA-1 Received: by mail-wm1-f71.google.com with SMTP id p184so20039wmp.7 for ; Fri, 28 Aug 2020 10:03:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OZl49i51M10B1/1T0FtYv5wmAOPW72de6iXs+kOBod0=; b=h2HnUCChNZEfP09yfyqcv9OfbEOa5x471itApOlnGycAkxHAd0UqIPoWxjr/gDn8pn T9L+AcmycFqM4vZlgrAI3OZKwMHHjJST4sGAKHmi0dRncodUa0HQ1MxgEN4ACnd03xdF srKteWtyte+ijwTEP5SIgTduTh7RwlO5TIWBDV6u/RsuIO2ZBaj2qA2YrXXaJVQcBd6l g2yILvu/6wE2XW+wPQK5rHpy+8oOVlGxq4Z6Cuu4fuEj1ILSFsHqCn2YNX7T+xs3PugQ 8CSzgr44bZGfZ0nOk40hjeH/TssPvPtiuqRLkrFbgPhqsohadCsZs9wB6jSlgpDbAkiB 7JKA== X-Gm-Message-State: AOAM531lONrUsxC2t5ZeUsF6obXyMrYYIxxVvSQ+EfLKDNDvZyVssAqF rROZGUR15qme127802FQD9BBw6v3L5tyhwoaRi0KgO3EsU59ozAXRbqVBy9zjK/LMM047iBz/Ub 6bIZ8xCdzdZ5XeUg9Sw== X-Received: by 2002:a1c:3d44:: with SMTP id k65mr74972wma.132.1598634191743; Fri, 28 Aug 2020 10:03:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJphRW2c+6+cyLu/uoNzGuJBEff9Qv+ESt0g5VENga2gsORRtPpuI8yXEhmfKLlMIK6JjAMg== X-Received: by 2002:a1c:3d44:: with SMTP id k65mr74954wma.132.1598634191565; Fri, 28 Aug 2020 10:03:11 -0700 (PDT) Received: from magray.users.ipa.redhat.com ([64.43.20.39]) by smtp.gmail.com with ESMTPSA id 126sm58393wme.42.2020.08.28.10.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Aug 2020 10:03:10 -0700 (PDT) From: Mark Gray To: ovs-dev@openvswitch.org Date: Fri, 28 Aug 2020 18:03:03 +0100 Message-Id: <20200828170305.43583-1-mark.d.gray@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200721232741.1497121-1-aconole@redhat.com> References: <20200721232741.1497121-1-aconole@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mark.d.gray@redhat.com X-Mimecast-Spam-Score: 0.0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v4 1/3] id-pool: Add interface to check if id has been allocated X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Signed-off-by: Mark Gray --- lib/id-pool.c | 10 ++++++++++ lib/id-pool.h | 1 + 2 files changed, 11 insertions(+) diff --git a/lib/id-pool.c b/lib/id-pool.c index 69910ad08..2b085db64 100644 --- a/lib/id-pool.c +++ b/lib/id-pool.c @@ -93,6 +93,16 @@ id_pool_find(struct id_pool *pool, uint32_t id) return NULL; } +bool +id_pool_check(struct id_pool *pool, uint32_t id) +{ + if (!id_pool_find(pool, id)) { + return false; + } + + return true; +} + void id_pool_add(struct id_pool *pool, uint32_t id) { diff --git a/lib/id-pool.h b/lib/id-pool.h index 8721f8793..6b642e4ff 100644 --- a/lib/id-pool.h +++ b/lib/id-pool.h @@ -29,6 +29,7 @@ void id_pool_destroy(struct id_pool *); bool id_pool_alloc_id(struct id_pool *, uint32_t *id); void id_pool_free_id(struct id_pool *, uint32_t id); void id_pool_add(struct id_pool *, uint32_t id); +bool id_pool_check(struct id_pool *, uint32_t id); /* * ID pool. From patchwork Fri Aug 28 17:03:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Gray X-Patchwork-Id: 1353411 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=e/U8nE8d; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BdQsX4gFKz9sTC for ; Sat, 29 Aug 2020 03:03:28 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id A064F8877C; Fri, 28 Aug 2020 17:03:26 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bwHsocLQacfu; Fri, 28 Aug 2020 17:03:24 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id B8FA78870C; Fri, 28 Aug 2020 17:03:24 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 97CA5C016F; Fri, 28 Aug 2020 17:03:24 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9047FC016F for ; Fri, 28 Aug 2020 17:03:23 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 7375C8872C for ; Fri, 28 Aug 2020 17:03:23 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id L8+ztMyoqToz for ; Fri, 28 Aug 2020 17:03:19 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by hemlock.osuosl.org (Postfix) with ESMTPS id 6338A8870C for ; Fri, 28 Aug 2020 17:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598634198; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mHUA9dH2+LpCKveTHFdV4G39bDMvpG1Q2+rrpzjZKvU=; b=e/U8nE8dHqFQD5VA8Sg0vn5pfZ5wW2MWo+7LYTt61OJsDtyiOHpH88N2uKQlovVL60toql nnGidQYVqzmZGGrUTWAdtmtlPv9MJ3eRWUkzbHRcOicwt0KzmdEdO5IAwTUlMF8FTYCNVB EophIbsYjNwMXsfZGgjuaWKElPCIVLs= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-227-XPpmBgpHO4y_Wx2SDGHcjg-1; Fri, 28 Aug 2020 13:03:15 -0400 X-MC-Unique: XPpmBgpHO4y_Wx2SDGHcjg-1 Received: by mail-wm1-f70.google.com with SMTP id z1so15364wmf.9 for ; Fri, 28 Aug 2020 10:03:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mHUA9dH2+LpCKveTHFdV4G39bDMvpG1Q2+rrpzjZKvU=; b=LjpTdGnX8rhV9a7pnoG0nxbWQ0gItNFv0VHfGuo3P8kSsGd5BmwehFcv57TC++eaq9 XOMeyc4UrHbRYeOA8LyMk5GRVEaDxnq8Bpq9gk93yA3b1EJ/U7DN4kKG0I5UhNAZmcKq 4tqLUKuXUzpk7CSxyaBoSRLODymBTNIwY+tQt+IkV5s+7WKfoXT3Hel0yo65kKW1U7zl z9ivQCQpc1O92WG3lNSw46wXkPbcBuogtyi6/gIemiL4eVuDrHPn2U+IzhbwOxQtRuDq SJF1nRY7Tw30LHfd9uGZuDu+dmDl4r53HV5Aq8fDA2g0RL6SBbczY99m1boyrW3cI5xl 888A== X-Gm-Message-State: AOAM532FTuzbyf9DJBlflqsIs1S9JsDcVSJTiA6+8RVwUfOCTZeCaRQw HN8V7Yh4KgsgUca8e6C9o+yAT8bFl/uRe2HpNNw8UWWRExP0VRvGmc0GAwoOGEX8heC8QRhy2QS C4pyyazR6rTBi9dmCeA== X-Received: by 2002:a5d:570a:: with SMTP id a10mr2537729wrv.301.1598634193958; Fri, 28 Aug 2020 10:03:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVGaZ6u8rpU/Xhc2UgtJ+wyHJNKWi15pfGwP11DleuabDB8LqPMFtRVxooD9SaaAK+IQ69wA== X-Received: by 2002:a5d:570a:: with SMTP id a10mr2537689wrv.301.1598634193558; Fri, 28 Aug 2020 10:03:13 -0700 (PDT) Received: from magray.users.ipa.redhat.com ([64.43.20.39]) by smtp.gmail.com with ESMTPSA id 126sm58393wme.42.2020.08.28.10.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Aug 2020 10:03:12 -0700 (PDT) From: Mark Gray To: ovs-dev@openvswitch.org Date: Fri, 28 Aug 2020 18:03:04 +0100 Message-Id: <20200828170305.43583-2-mark.d.gray@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200828170305.43583-1-mark.d.gray@redhat.com> References: <20200721232741.1497121-1-aconole@redhat.com> <20200828170305.43583-1-mark.d.gray@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mark.d.gray@redhat.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: redhat.com Cc: Flavio Leitner , Matteo Croce , David Ahern Subject: [ovs-dev] [PATCH v4 2/3] dpif-netlink: distribute polling to discreet handlers X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Aaron Conole Currently, the channel handlers are polled globally. On some systems, this causes a thundering herd issue where multiple handler threads become active, only to do no work and immediately sleep. The approach here is to push the netlink socket channels to discreet handler threads to process, rather than polling on every thread. This will eliminate the need to wake multiple threads. To check: ip netns add left ip netns add right ip link add center-left type veth peer name left0 netns left ip link add center-right type veth peer name right0 netns right ip link set center-left up ip link set center-right up ip -n left ip link set left0 up ip -n left ip addr add 172.31.110.10/24 dev left0 ip -n right ip link set right0 up ip -n right ip addr add 172.31.110.11/24 dev right0 ovs-vsctl add-br br0 ovs-vsctl add-port br0 center-right ovs-vsctl add-port br0 center-left # in one terminal perf record -e sched:sched_wakeup,irq:softirq_entry -ag # in a separate terminal ip netns exec left arping -I left0 -c 1 172.31.110.11 # in the perf terminal after exiting perf script Look for the number of 'handler' threads which were made active. Suggested-by: Ben Pfaff Co-authored-by: Mark Gray Reported-by: David Ahern Reported-at: https://mail.openvswitch.org/pipermail/ovs-dev/2019-December/365857.html Cc: Matteo Croce Cc: Flavio Leitner Fixes: 69c51582f ("dpif-netlink: don't allocate per thread netlink sockets") Signed-off-by: Aaron Conole Signed-off-by: Mark Gray --- v2: Oops - forgot to commit my whitespace cleanups. v3: one port latency results as per Matteo's comments Stock: min/avg/max/mdev = 21.5/36.5/96.5/1.0 us With Patch: min/avg/max/mdev = 5.3/9.7/98.4/0.5 us v4: Oops - first email did not send lib/dpif-netlink.c | 311 ++++++++++++++++++++++++++------------------- 1 file changed, 182 insertions(+), 129 deletions(-) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 7da4fb54d..d928d7aa1 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -37,6 +37,7 @@ #include "dpif-provider.h" #include "fat-rwlock.h" #include "flow.h" +#include "id-pool.h" #include "netdev-linux.h" #include "netdev-offload.h" #include "netdev-provider.h" @@ -160,6 +161,8 @@ static void dpif_netlink_flow_to_dpif_flow(struct dpif_flow *, /* One of the dpif channels between the kernel and userspace. */ struct dpif_channel { + struct hmap_node hmap_node; + uint32_t port_idx; struct nl_sock *sock; /* Netlink socket. */ long long int last_poll; /* Last time this channel was polled. */ }; @@ -183,6 +186,8 @@ struct dpif_handler { int n_events; /* Num events returned by epoll_wait(). */ int event_offset; /* Offset into 'epoll_events'. */ + struct hmap channels; /* map of channels for each port. */ + #ifdef _WIN32 /* Pool of sockets. */ struct dpif_windows_vport_sock *vport_sock_pool; @@ -201,9 +206,8 @@ struct dpif_netlink { struct fat_rwlock upcall_lock; struct dpif_handler *handlers; uint32_t n_handlers; /* Num of upcall handlers. */ - struct dpif_channel *channels; /* Array of channels for each port. */ - int uc_array_size; /* Size of 'handler->channels' and */ - /* 'handler->epoll_events'. */ + + struct id_pool *port_ids; /* Set of added port ids */ /* Change notification. */ struct nl_sock *port_notifier; /* vport multicast group subscriber. */ @@ -287,6 +291,53 @@ close_nl_sock(struct nl_sock *sock) #endif } +static size_t +dpif_handler_channels_count(const struct dpif_handler *handler) +{ + return hmap_count(&handler->channels); +} + +static struct dpif_channel * +dpif_handler_channel_get(struct dpif_handler *handler, uint32_t idx) +{ + struct dpif_channel *channel; + + HMAP_FOR_EACH_WITH_HASH (channel, hmap_node, hash_int(idx, 0), + &handler->channels) { + if (channel->port_idx == idx) { + return channel; + } + } + + return NULL; +} + +static void +dpif_handler_channel_add(struct dpif_handler *handler, uint32_t idx, + struct nl_sock *sock) +{ + struct dpif_channel *channel = xmalloc(sizeof *channel); + + channel->port_idx = idx; + channel->sock = sock; + channel->last_poll = LLONG_MIN; + + hmap_insert(&handler->channels, &channel->hmap_node, hash_int(idx,0)); +} + +static void +dpif_handler_channel_del(struct dpif_handler *handler, uint32_t port_idx) +{ + struct dpif_channel *channel = dpif_handler_channel_get(handler, port_idx); + + hmap_remove(&(handler->channels), &(channel->hmap_node)); + + free(channel); +} + + + + static struct dpif_netlink * dpif_netlink_cast(const struct dpif *dpif) { @@ -385,6 +436,11 @@ open_dpif(const struct dpif_netlink_dp *dp, struct dpif **dpifp) dpif->dp_ifindex = dp->dp_ifindex; dpif->user_features = dp->user_features; + dpif->port_ids = id_pool_create(0, MAX_PORTS); + if (!dpif->port_ids) { + return ENOMEM; + } + *dpifp = &dpif->dpif; return 0; @@ -452,161 +508,144 @@ static bool vport_get_pid(struct dpif_netlink *dpif, uint32_t port_idx, uint32_t *upcall_pid) { - /* Since the nl_sock can only be assigned in either all - * or none "dpif" channels, the following check - * would suffice. */ - if (!dpif->channels[port_idx].sock) { + size_t i; + ovs_assert(!WINDOWS || dpif->n_handlers <= 1); + + if (!id_pool_check(dpif->port_ids, port_idx)) { return false; } - ovs_assert(!WINDOWS || dpif->n_handlers <= 1); - *upcall_pid = nl_sock_pid(dpif->channels[port_idx].sock); + /* The 'port_idx' should only be valid for a single handler. */ + for (i = 0; i < dpif->n_handlers; i++) { + struct dpif_channel *channel = + dpif_handler_channel_get(&dpif->handlers[i], port_idx); + + if (channel) { + *upcall_pid = nl_sock_pid(channel->sock); + return true; + } + } - return true; + return false; } static int vport_add_channel(struct dpif_netlink *dpif, odp_port_t port_no, struct nl_sock *sock) { - struct epoll_event event; uint32_t port_idx = odp_to_u32(port_no); + struct dpif_handler *handler; + struct epoll_event event; size_t i; - int error; - if (dpif->handlers == NULL) { + if (dpif->handlers == NULL || + id_pool_check(dpif->port_ids, port_idx)) { close_nl_sock(sock); - return 0; + return EINVAL; } - /* We assume that the datapath densely chooses port numbers, which can - * therefore be used as an index into 'channels' and 'epoll_events' of - * 'dpif'. */ - if (port_idx >= dpif->uc_array_size) { - uint32_t new_size = port_idx + 1; - - if (new_size > MAX_PORTS) { + if (port_idx >= MAX_PORTS) { VLOG_WARN_RL(&error_rl, "%s: datapath port %"PRIu32" too big", dpif_name(&dpif->dpif), port_no); return EFBIG; - } - - dpif->channels = xrealloc(dpif->channels, - new_size * sizeof *dpif->channels); + } - for (i = dpif->uc_array_size; i < new_size; i++) { - dpif->channels[i].sock = NULL; - } + handler = &dpif->handlers[0]; - for (i = 0; i < dpif->n_handlers; i++) { - struct dpif_handler *handler = &dpif->handlers[i]; + for (i = 0; i < dpif->n_handlers; i++) { + if (dpif_handler_channels_count(&dpif->handlers[i]) < + dpif_handler_channels_count(handler)) + handler = &dpif->handlers[i]; + } - handler->epoll_events = xrealloc(handler->epoll_events, - new_size * sizeof *handler->epoll_events); + dpif_handler_channel_add(handler, port_idx, sock); - } - dpif->uc_array_size = new_size; - } + handler->epoll_events = xrealloc(handler->epoll_events, + dpif_handler_channels_count(handler) * + sizeof *handler->epoll_events); memset(&event, 0, sizeof event); event.events = EPOLLIN | EPOLLEXCLUSIVE; event.data.u32 = port_idx; - for (i = 0; i < dpif->n_handlers; i++) { - struct dpif_handler *handler = &dpif->handlers[i]; - #ifndef _WIN32 - if (epoll_ctl(handler->epoll_fd, EPOLL_CTL_ADD, nl_sock_fd(sock), - &event) < 0) { - error = errno; - goto error; - } -#endif - } - dpif->channels[port_idx].sock = sock; - dpif->channels[port_idx].last_poll = LLONG_MIN; - - return 0; - -error: -#ifndef _WIN32 - while (i--) { - epoll_ctl(dpif->handlers[i].epoll_fd, EPOLL_CTL_DEL, - nl_sock_fd(sock), NULL); + if (epoll_ctl(handler->epoll_fd, EPOLL_CTL_ADD, nl_sock_fd(sock), + &event) < 0) { + dpif_handler_channel_del(handler, port_idx); + id_pool_free_id(dpif->port_ids, port_idx); + return errno; } #endif - dpif->channels[port_idx].sock = NULL; - return error; + id_pool_add(dpif->port_ids, port_idx); + return 0; } static void vport_del_channels(struct dpif_netlink *dpif, odp_port_t port_no) { uint32_t port_idx = odp_to_u32(port_no); + struct dpif_handler *handler = NULL; + struct dpif_channel *channel = NULL; size_t i; - if (!dpif->handlers || port_idx >= dpif->uc_array_size - || !dpif->channels[port_idx].sock) { + if (!dpif->handlers) { return; } for (i = 0; i < dpif->n_handlers; i++) { - struct dpif_handler *handler = &dpif->handlers[i]; + handler = &dpif->handlers[i]; + channel = dpif_handler_channel_get(handler, port_idx); + + if (channel) { #ifndef _WIN32 - epoll_ctl(handler->epoll_fd, EPOLL_CTL_DEL, - nl_sock_fd(dpif->channels[port_idx].sock), NULL); + epoll_ctl(handler->epoll_fd, EPOLL_CTL_DEL, + nl_sock_fd(channel->sock), NULL); + nl_sock_destroy(channel->sock); #endif - handler->event_offset = handler->n_events = 0; + dpif_handler_channel_del(handler, port_idx); + id_pool_free_id(dpif->port_ids, port_idx); + handler->event_offset = handler->n_events = 0; + break; + } } -#ifndef _WIN32 - nl_sock_destroy(dpif->channels[port_idx].sock); -#endif - dpif->channels[port_idx].sock = NULL; } static void destroy_all_channels(struct dpif_netlink *dpif) OVS_REQ_WRLOCK(dpif->upcall_lock) { - unsigned int i; + size_t i; if (!dpif->handlers) { return; } - for (i = 0; i < dpif->uc_array_size; i++ ) { - struct dpif_netlink_vport vport_request; - uint32_t upcall_pids = 0; - - if (!dpif->channels[i].sock) { - continue; - } - - /* Turn off upcalls. */ - dpif_netlink_vport_init(&vport_request); - vport_request.cmd = OVS_VPORT_CMD_SET; - vport_request.dp_ifindex = dpif->dp_ifindex; - vport_request.port_no = u32_to_odp(i); - vport_request.n_upcall_pids = 1; - vport_request.upcall_pids = &upcall_pids; - dpif_netlink_vport_transact(&vport_request, NULL, NULL); - - vport_del_channels(dpif, u32_to_odp(i)); - } - for (i = 0; i < dpif->n_handlers; i++) { struct dpif_handler *handler = &dpif->handlers[i]; + struct dpif_channel *channel, *next; + + HMAP_FOR_EACH_SAFE (channel, next, hmap_node, &handler->channels) { + struct dpif_netlink_vport vport_request; + uint32_t upcall_pids = 0; + /* Turn off upcalls. */ + dpif_netlink_vport_init(&vport_request); + vport_request.cmd = OVS_VPORT_CMD_SET; + vport_request.dp_ifindex = dpif->dp_ifindex; + vport_request.port_no = u32_to_odp(channel->port_idx); + vport_request.n_upcall_pids = 1; + vport_request.upcall_pids = &upcall_pids; + dpif_netlink_vport_transact(&vport_request, NULL, NULL); + + vport_del_channels(dpif, u32_to_odp(channel->port_idx)); + } dpif_netlink_handler_uninit(handler); free(handler->epoll_events); } - free(dpif->channels); - free(dpif->handlers); + dpif->handlers = NULL; - dpif->channels = NULL; dpif->n_handlers = 0; - dpif->uc_array_size = 0; } static void @@ -618,9 +657,11 @@ dpif_netlink_close(struct dpif *dpif_) fat_rwlock_wrlock(&dpif->upcall_lock); destroy_all_channels(dpif); + id_pool_destroy(dpif->port_ids); fat_rwlock_unlock(&dpif->upcall_lock); fat_rwlock_destroy(&dpif->upcall_lock); + free(dpif); } @@ -1084,23 +1125,40 @@ dpif_netlink_port_get_pid__(const struct dpif_netlink *dpif, odp_port_t port_no) OVS_REQ_RDLOCK(dpif->upcall_lock) { + struct dpif_channel *min_channel = NULL, *found_channel = NULL; uint32_t port_idx = odp_to_u32(port_no); uint32_t pid = 0; + size_t i; + + /* The ODPP_NONE "reserved" port number uses the "ovs-system"'s + * channel, since it is not heavily loaded. */ + uint32_t idx = port_no == ODPP_NONE ? 0 : port_idx; + + if (!id_pool_check(dpif->port_ids, port_idx)) { + return 0; + } + + if (dpif->handlers) { + for (i = 0; i < dpif->n_handlers; i++) { + if (dpif_handler_channel_get(&dpif->handlers[i], idx)) { + found_channel = dpif_handler_channel_get(&dpif->handlers[i], + idx); + break; + } - if (dpif->handlers && dpif->uc_array_size > 0) { - /* The ODPP_NONE "reserved" port number uses the "ovs-system"'s - * channel, since it is not heavily loaded. */ - uint32_t idx = port_idx >= dpif->uc_array_size ? 0 : port_idx; - - /* Needs to check in case the socket pointer is changed in between - * the holding of upcall_lock. A known case happens when the main - * thread deletes the vport while the handler thread is handling - * the upcall from that port. */ - if (dpif->channels[idx].sock) { - pid = nl_sock_pid(dpif->channels[idx].sock); + if (dpif_handler_channel_get(&dpif->handlers[i], 0)) { + min_channel = dpif_handler_channel_get(&dpif->handlers[i], + 0); + } } } + if (found_channel) { + pid = nl_sock_pid(found_channel->sock); + } else if (min_channel) { + pid = nl_sock_pid(min_channel->sock); + } + return pid; } @@ -2342,12 +2400,14 @@ dpif_netlink_operate(struct dpif *dpif_, struct dpif_op **ops, size_t n_ops, static void dpif_netlink_handler_uninit(struct dpif_handler *handler) { + hmap_destroy(&handler->channels); vport_delete_sock_pool(handler); } static int dpif_netlink_handler_init(struct dpif_handler *handler) { + hmap_init(&handler->channels); return vport_create_sock_pool(handler); } #else @@ -2355,6 +2415,7 @@ dpif_netlink_handler_init(struct dpif_handler *handler) static int dpif_netlink_handler_init(struct dpif_handler *handler) { + hmap_init(&handler->channels); handler->epoll_fd = epoll_create(10); return handler->epoll_fd < 0 ? errno : 0; } @@ -2362,6 +2423,7 @@ dpif_netlink_handler_init(struct dpif_handler *handler) static void dpif_netlink_handler_uninit(struct dpif_handler *handler) { + hmap_destroy(&handler->channels); close(handler->epoll_fd); } #endif @@ -2374,9 +2436,7 @@ static int dpif_netlink_refresh_channels(struct dpif_netlink *dpif, uint32_t n_handlers) OVS_REQ_WRLOCK(dpif->upcall_lock) { - unsigned long int *keep_channels; struct dpif_netlink_vport vport; - size_t keep_channels_nbits; struct nl_dump dump; uint64_t reply_stub[NL_DUMP_BUFSIZE / 8]; struct ofpbuf buf; @@ -2416,9 +2476,6 @@ dpif_netlink_refresh_channels(struct dpif_netlink *dpif, uint32_t n_handlers) handler->event_offset = handler->n_events = 0; } - keep_channels_nbits = dpif->uc_array_size; - keep_channels = bitmap_allocate(keep_channels_nbits); - ofpbuf_use_stub(&buf, reply_stub, sizeof reply_stub); dpif_netlink_port_dump_start__(dpif, &dump); while (!dpif_netlink_port_dump_next__(dpif, &dump, &vport, &buf)) { @@ -2426,8 +2483,7 @@ dpif_netlink_refresh_channels(struct dpif_netlink *dpif, uint32_t n_handlers) uint32_t upcall_pid; int error; - if (port_no >= dpif->uc_array_size - || !vport_get_pid(dpif, port_no, &upcall_pid)) { + if (!vport_get_pid(dpif, port_no, &upcall_pid)) { struct nl_sock *sock; error = create_nl_sock(dpif, &sock); @@ -2475,9 +2531,6 @@ dpif_netlink_refresh_channels(struct dpif_netlink *dpif, uint32_t n_handlers) } } - if (port_no < keep_channels_nbits) { - bitmap_set1(keep_channels, port_no); - } continue; error: @@ -2486,14 +2539,6 @@ dpif_netlink_refresh_channels(struct dpif_netlink *dpif, uint32_t n_handlers) nl_dump_done(&dump); ofpbuf_uninit(&buf); - /* Discard any saved channels that we didn't reuse. */ - for (i = 0; i < keep_channels_nbits; i++) { - if (!bitmap_is_set(keep_channels, i)) { - vport_del_channels(dpif, u32_to_odp(i)); - } - } - free(keep_channels); - return retval; } @@ -2714,6 +2759,8 @@ dpif_netlink_recv__(struct dpif_netlink *dpif, uint32_t handler_id, OVS_REQ_RDLOCK(dpif->upcall_lock) { struct dpif_handler *handler; + size_t n_channels; + int read_tries = 0; if (!dpif->handlers || handler_id >= dpif->n_handlers) { @@ -2721,14 +2768,15 @@ dpif_netlink_recv__(struct dpif_netlink *dpif, uint32_t handler_id, } handler = &dpif->handlers[handler_id]; - if (handler->event_offset >= handler->n_events) { + n_channels = dpif_handler_channels_count(handler); + if (handler->event_offset >= handler->n_events && n_channels) { int retval; handler->event_offset = handler->n_events = 0; do { retval = epoll_wait(handler->epoll_fd, handler->epoll_events, - dpif->uc_array_size, 0); + n_channels, 0); } while (retval < 0 && errno == EINTR); if (retval < 0) { @@ -2741,7 +2789,10 @@ dpif_netlink_recv__(struct dpif_netlink *dpif, uint32_t handler_id, while (handler->event_offset < handler->n_events) { int idx = handler->epoll_events[handler->event_offset].data.u32; - struct dpif_channel *ch = &dpif->channels[idx]; + struct dpif_channel *ch = dpif_handler_channel_get(handler, idx); + if (!ch) { + return EAGAIN; + } handler->event_offset++; @@ -2845,12 +2896,14 @@ dpif_netlink_recv_purge__(struct dpif_netlink *dpif) if (dpif->handlers) { size_t i; - if (!dpif->channels[0].sock) { - return; - } - for (i = 0; i < dpif->uc_array_size; i++ ) { + for (i = 0; i < dpif->n_handlers; i++) { + struct dpif_handler *handler = &dpif->handlers[i]; + struct dpif_channel *channel; + + HMAP_FOR_EACH (channel, hmap_node, &handler->channels) { + nl_sock_drain(channel->sock); + } - nl_sock_drain(dpif->channels[i].sock); } } } From patchwork Fri Aug 28 17:03:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Gray X-Patchwork-Id: 1353412 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=CLBF2Drm; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BdQsc6ZzBz9sTC for ; Sat, 29 Aug 2020 03:03:32 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 9416E23730; Fri, 28 Aug 2020 17:03:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QtrusdTamppg; Fri, 28 Aug 2020 17:03:27 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 6B96623492; Fri, 28 Aug 2020 17:03:27 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 52723C016F; Fri, 28 Aug 2020 17:03:27 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1E2AAC0051 for ; Fri, 28 Aug 2020 17:03:26 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id F233422DE3 for ; Fri, 28 Aug 2020 17:03:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kUQAkDFc4Am6 for ; Fri, 28 Aug 2020 17:03:22 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by silver.osuosl.org (Postfix) with ESMTPS id D3F3A23265 for ; Fri, 28 Aug 2020 17:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598634200; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UAXl6mpx8n7s/R/yRb5rW7yfUwqts5Bw0zpk2Q8/7mE=; b=CLBF2DrmWSgnSBfcg3FZiV0GF+rn+FNnn0ZEQsOiXmaXE1TaZ1UgYh4MMsIb5asHhkPON+ MBf/g31zgKnuI4Lwh9hyG69shHxexLtKTsycIGRyYOoR3WQ+Qjfa584E+5kstalW7nZRue Z6k2XK64kJgM8pHEDMqFIAoaJhguI34= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-573-oEEL2YHpNqyy54-RwUt0XA-1; Fri, 28 Aug 2020 13:03:18 -0400 X-MC-Unique: oEEL2YHpNqyy54-RwUt0XA-1 Received: by mail-wm1-f71.google.com with SMTP id c198so24354wme.5 for ; Fri, 28 Aug 2020 10:03:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UAXl6mpx8n7s/R/yRb5rW7yfUwqts5Bw0zpk2Q8/7mE=; b=UDGiPEFdmTNs2ISHpp7BrpCw8YJj8zijeSnAh0yRGyLdRx5F0VAY+azKA+YbAI1ysJ Ty/+/Fj5Gw6A3eDx0bHLr0alGFg5ZpTMneTf/nRsM5PZK9XFqe3a6ekDNyI7KCKX/Cz+ goYxeSIo5mo6IMR0kUFih3nMtPiiB3xyKr+GAr/D3CUQlGcaJmamQe/9Iz2YkmfJd2Xi EM90JqCWjq7sKgfwDlvwZLnfJyRTx+gF5wGFTdiOFKKxakLBaSiu/9y2Iyj/kqhYsF40 KWh82f4GsJod2akG4wbOr9UVEd9HYr6KHSAlzaxdL3RZ8fqGSiI0NhbaCKkKqQrsVakN 02Xw== X-Gm-Message-State: AOAM5318uzWe0ByYzQdZpeN2nNHIiIv0ZiiX0ZY2Mn6p/MNf/OXQ3VBe WC05JgRs8mrO/EaNnhBD69edScR+P6/a8FM6mjA9GqERL8qqcmASuowRUrk0cTPk/MwUpojO+xa QuhGhAAkf0Q9M+zBhYg== X-Received: by 2002:a1c:7e02:: with SMTP id z2mr80495wmc.138.1598634197218; Fri, 28 Aug 2020 10:03:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfZklgpX6AVmMyiIxNDddwhtS6sCgHcYXI45qf/Pk8xIiNplkFGkDNQQLqSFSYlIdVA75XVA== X-Received: by 2002:a1c:7e02:: with SMTP id z2mr80478wmc.138.1598634197070; Fri, 28 Aug 2020 10:03:17 -0700 (PDT) Received: from magray.users.ipa.redhat.com ([64.43.20.39]) by smtp.gmail.com with ESMTPSA id 126sm58393wme.42.2020.08.28.10.03.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Aug 2020 10:03:16 -0700 (PDT) From: Mark Gray To: ovs-dev@openvswitch.org Date: Fri, 28 Aug 2020 18:03:05 +0100 Message-Id: <20200828170305.43583-3-mark.d.gray@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200828170305.43583-1-mark.d.gray@redhat.com> References: <20200721232741.1497121-1-aconole@redhat.com> <20200828170305.43583-1-mark.d.gray@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mark.d.gray@redhat.com X-Mimecast-Spam-Score: 0.0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v4 3/3] AUTHORS: Update email address X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Signed-off-by: Mark Gray Acked-by: Flavio Leitner --- AUTHORS.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 4d8eaa3bd..cb26e0197 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -255,7 +255,7 @@ Madhu Challa challa@noironetworks.com Manohar K C manukc@gmail.com Marcin Mirecki mmirecki@redhat.com Mario Cabrera mario.cabrera@hpe.com -Mark D. Gray mark.d.gray@intel.com +Mark D. Gray mark.d.gray@redhat.com Mark Hamilton Mark Kavanagh mark.b.kavanagh81@gmail.com Mark Maglana mmaglana@gmail.com