From patchwork Mon Jan 20 15:08:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eli Britstein X-Patchwork-Id: 1226034 X-Patchwork-Delegate: i.maximets@samsung.com 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=mellanox.com 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 481Zq60ly9z9sRk for ; Tue, 21 Jan 2020 02:10:26 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 95EA9226FC; Mon, 20 Jan 2020 15:10:24 +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 Os56-3pZABg0; Mon, 20 Jan 2020 15:10:17 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id DA3E8226D0; Mon, 20 Jan 2020 15:09:12 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 97725C1D8F; Mon, 20 Jan 2020 15:09:12 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 64D5BC1D88 for ; Mon, 20 Jan 2020 15:08:58 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 52E44857E2 for ; Mon, 20 Jan 2020 15:08:58 +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 00u2LhFL4FO8 for ; Mon, 20 Jan 2020 15:08:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by fraxinus.osuosl.org (Postfix) with ESMTP id 1278785755 for ; Mon, 20 Jan 2020 15:08:49 +0000 (UTC) Received: from Internal Mail-Server by MTLPINE1 (envelope-from elibr@mellanox.com) with ESMTPS (AES256-SHA encrypted); 20 Jan 2020 17:08:44 +0200 Received: from dev-r-vrt-215.mtr.labs.mlnx. (dev-r-vrt-215.mtr.labs.mlnx [10.212.215.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 00KF8hV0013116; Mon, 20 Jan 2020 17:08:44 +0200 From: Eli Britstein To: dev@openvswitch.org, Ilya Maximets Date: Mon, 20 Jan 2020 15:08:15 +0000 Message-Id: <20200120150830.16262-11-elibr@mellanox.com> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20200120150830.16262-1-elibr@mellanox.com> References: <20200120150830.16262-1-elibr@mellanox.com> Cc: Simon Horman , Eli Britstein , Ameer Mahagneh Subject: [ovs-dev] [PATCH 10/25] dpif-netdev: Make mark allocation public API 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: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Ophir Munk Refactor mark allocation to offload layer, with API to be used by upper layers (dpif-netdev), as a pre-step towards allocating marks by offload layer. Co-authored-by: Eli Britstein Signed-off-by: Ophir Munk Reviewed-by: Roni Bar Yanai Signed-off-by: Eli Britstein --- lib/dpif-netdev.c | 33 +++------------------------------ lib/netdev-offload.c | 33 +++++++++++++++++++++++++++++++++ lib/netdev-offload.h | 4 ++++ 3 files changed, 40 insertions(+), 30 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 8e6b14d35..bd937f300 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -2146,9 +2146,6 @@ dp_netdev_pmd_find_dpcls(struct dp_netdev_pmd_thread *pmd, return cls; } -#define MAX_FLOW_MARK (UINT32_MAX - 1) -#define INVALID_FLOW_MARK (UINT32_MAX) - struct megaflow_to_mark_data { const struct cmap_node node; ovs_u128 mega_ufid; @@ -2158,7 +2155,6 @@ struct megaflow_to_mark_data { struct flow_mark { struct cmap megaflow_to_mark; struct cmap mark_to_flow; - struct id_pool *pool; }; static struct flow_mark flow_mark = { @@ -2166,29 +2162,6 @@ static struct flow_mark flow_mark = { .mark_to_flow = CMAP_INITIALIZER, }; -static uint32_t -flow_mark_alloc(void) -{ - uint32_t mark; - - if (!flow_mark.pool) { - /* Haven't initiated yet, do it here */ - flow_mark.pool = id_pool_create(0, MAX_FLOW_MARK); - } - - if (id_pool_alloc_id(flow_mark.pool, &mark)) { - return mark; - } - - return INVALID_FLOW_MARK; -} - -static void -flow_mark_free(uint32_t mark) -{ - id_pool_free_id(flow_mark.pool, mark); -} - /* associate megaflow with a mark, which is a 1:1 mapping */ static void megaflow_to_mark_associate(const ovs_u128 *mega_ufid, uint32_t mark) @@ -2300,7 +2273,7 @@ mark_to_flow_disassociate(struct dp_netdev_pmd_thread *pmd, netdev_close(port); } - flow_mark_free(mark); + netdev_offload_flow_mark_free(mark); VLOG_DBG("Freed flow mark %u\n", mark); megaflow_to_mark_disassociate(&flow->mega_ufid); @@ -2429,7 +2402,7 @@ dp_netdev_flow_offload_put(struct dp_flow_offload_item *offload) return 0; } - mark = flow_mark_alloc(); + mark = netdev_offload_flow_mark_alloc(); if (mark == INVALID_FLOW_MARK) { VLOG_ERR("Failed to allocate flow mark!\n"); } @@ -2462,7 +2435,7 @@ dp_netdev_flow_offload_put(struct dp_flow_offload_item *offload) err_free: if (!modification) { - flow_mark_free(mark); + netdev_offload_flow_mark_free(mark); } else { mark_to_flow_disassociate(pmd, flow); } diff --git a/lib/netdev-offload.c b/lib/netdev-offload.c index 1612fe6b8..008c46d50 100644 --- a/lib/netdev-offload.c +++ b/lib/netdev-offload.c @@ -33,6 +33,7 @@ #include "openvswitch/dynamic-string.h" #include "fatal-signal.h" #include "hash.h" +#include "id-pool.h" #include "openvswitch/list.h" #include "netdev-offload-provider.h" #include "netdev-provider.h" @@ -59,6 +60,8 @@ VLOG_DEFINE_THIS_MODULE(netdev_offload); static bool netdev_flow_api_enabled = false; +static struct id_pool *mark_pool = NULL; +static struct ovs_mutex mark_pool_mutex = OVS_MUTEX_INITIALIZER; /* Protects 'netdev_flow_apis'. */ static struct ovs_mutex netdev_flow_api_provider_mutex = OVS_MUTEX_INITIALIZER; @@ -279,6 +282,36 @@ netdev_flow_del(struct netdev *netdev, const ovs_u128 *ufid, : EOPNOTSUPP; } +#define MAX_FLOW_MARK (UINT32_MAX - 1) + +uint32_t +netdev_offload_flow_mark_alloc(void) +{ + uint32_t mark; + + ovs_mutex_lock(&mark_pool_mutex); + if (!mark_pool) { + /* Haven't initiated yet, do it here */ + mark_pool = id_pool_create(0, MAX_FLOW_MARK); + } + + if (id_pool_alloc_id(mark_pool, &mark)) { + ovs_mutex_unlock(&mark_pool_mutex); + return mark; + } + + ovs_mutex_unlock(&mark_pool_mutex); + return INVALID_FLOW_MARK; +} + +void +netdev_offload_flow_mark_free(uint32_t mark) +{ + ovs_mutex_lock(&mark_pool_mutex); + id_pool_free_id(mark_pool, mark); + ovs_mutex_unlock(&mark_pool_mutex); +} + int netdev_init_flow_api(struct netdev *netdev) { diff --git a/lib/netdev-offload.h b/lib/netdev-offload.h index 66ab75f82..b5488d00e 100644 --- a/lib/netdev-offload.h +++ b/lib/netdev-offload.h @@ -75,6 +75,8 @@ struct offload_info { uint32_t flow_mark; }; +#define INVALID_FLOW_MARK (UINT32_MAX) + int netdev_flow_flush(struct netdev *); int netdev_flow_dump_create(struct netdev *, struct netdev_flow_dump **dump); int netdev_flow_dump_destroy(struct netdev_flow_dump *); @@ -119,6 +121,8 @@ int netdev_ports_flow_get(const char *dpif_type, struct match *match, struct dpif_flow_stats *stats, struct dpif_flow_attrs *attrs, struct ofpbuf *buf); +uint32_t netdev_offload_flow_mark_alloc(void); +void netdev_offload_flow_mark_free(uint32_t mark); #ifdef __cplusplus }