From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70043.outbound.protection.outlook.com [40.107.7.43]) by dpdk.org (Postfix) with ESMTP id 94F045F3C for ; Wed, 3 Oct 2018 17:29:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=76Xq+4uG5a09bz1rSG3rI1EjF3S1Eg7va0+WWyj0C7g=; b=wyLbVZz74XeDVOovDDFcMMrAJoYH2D5r98iJCaoR4vGTtnus9g3G3y1wZUNewjnQYq1bh+dqG0nWur+jx6RVTGkCTKPJ0Oeo4AJ5BMJpcYfbhBRcIvraw/3nnIXnHGNdI3oHcYvVX0HwWUFYj3m8vrLXvxl6E7nkwcC+mdXX2Jg= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.186.150) by AM4PR05MB1682.eurprd05.prod.outlook.com (10.165.245.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1185.24; Wed, 3 Oct 2018 15:29:12 +0000 Received: from AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::81a1:b719:2345:50e5]) by AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::81a1:b719:2345:50e5%5]) with mapi id 15.20.1185.024; Wed, 3 Oct 2018 15:29:12 +0000 From: Slava Ovsiienko To: "dev@dpdk.org" CC: Shahaf Shuler , Slava Ovsiienko Thread-Topic: [PATCH] net/mlx5: flow counters support on the Linux-rdma v19 base Thread-Index: AQHUWy3VsSyyKvf92EGKk7upuWJoBQ== Date: Wed, 3 Oct 2018 15:29:12 +0000 Message-ID: <1538580540-2224-1-git-send-email-viacheslavo@mellanox.com> References: <1534772079-6514-1-git-send-email-viacheslavo@mellanox.com> In-Reply-To: <1534772079-6514-1-git-send-email-viacheslavo@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM4PR0101CA0063.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::31) To AM4PR05MB3265.eurprd05.prod.outlook.com (2603:10a6:205:4::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=viacheslavo@mellanox.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [37.142.13.130] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM4PR05MB1682; 6:ujv8VA+km8cZyIgnKxacXxKXwIBXVpHMb/pFzJMDtcAyxcgxEpuNR1C6rWQcXE/SDpt8lq6uSb3hZk79iB/0cAjcPe5IViizJ5VCebhkkmQWg/Y79k+vh2Ln59p1n9KwT++jlk57fO2BxlbnCWK7NX95J2QYzZeiql4aZ1jA2X1QLS2HJ2UkQ25bOOHW/N31M1puJjjSwtLhKEXXzib55X/3KqQ0CSvUBGJxyqmzUjTTfdD+fnH0kyuaUFhkAVF2wz1EgtqraSN0Fk7fDqx1GAw3Gg73e9PENo6u5pLwRWgJ8qGUhajMb9WPIaPfGk8jzAmOFYcGDJRTKDzO49SchUhUI1qemS0Iavtk7Lv2KDfDg3BpsIQsBIoKy7TlfJT/asQOaiOIWhfB8mzMa27nJi28ezaIgA8PETAWbPPexME9kwG3RE3D88rD/2aZB9zw4ATXsYQotZOHdBZsosAJUw==; 5:7DV4F+abEOwXeFSjJZr1ub8VAaxn2G7T6T2AFudZqteRgvgZMUe6Ezl+WVgTaruzycFem+3+0eJHY/9u56fBI4j1mDTqDAgiEeH8PSkKrIvutsskxyd4e/d9Ilr+/VXlZqdY9AgLPcPxYX/2woa5n00HUJQM2uzttkjWBwqAaSU=; 7:BL9AR0aeSbnAZdtXKbAWgKEtIxaLcte6x/wz5sAbBYz+wrkTutTh6YmkuKcOtef4Y6Z26az9Jmzyd0h7DCrmsSKc6VOWP3sYXPV5nMxxbmJnygUhfMWRtwQtnola/2nB6Zq/tr19n9zIg6+v8+OrUjSwNmNlsVuwESd1OCWrzdmMMRgja/tvGrDXxA240+uBvejybiJJ74rxjWvrU4s/Kmx8LjAfkZH3TqiW3jd2s2oXvTLE+JzKKjliaPg01E8C x-ms-office365-filtering-correlation-id: 89a55c6d-9463-43a4-9203-08d62944f837 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM4PR05MB1682; x-ms-traffictypediagnostic: AM4PR05MB1682: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(3231355)(944501410)(52105095)(10201501046)(93006095)(93001095)(6055026)(149066)(150057)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM4PR05MB1682; BCL:0; PCL:0; RULEID:; SRVR:AM4PR05MB1682; x-forefront-prvs: 0814A2C7A3 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(366004)(346002)(376002)(136003)(39860400002)(189003)(199004)(2616005)(6916009)(446003)(476003)(11346002)(102836004)(316002)(71200400001)(71190400001)(186003)(14454004)(1857600001)(26005)(36756003)(25786009)(86362001)(486006)(5660300001)(4326008)(6486002)(6512007)(53936002)(5640700003)(6436002)(107886003)(76176011)(54906003)(81156014)(305945005)(8676002)(386003)(1730700003)(7736002)(6506007)(8936002)(81166006)(256004)(52116002)(3846002)(106356001)(5024004)(2900100001)(105586002)(97736004)(478600001)(68736007)(2501003)(2906002)(5250100002)(2351001)(66066001)(14444005)(99286004)(4744004)(6116002)(309714004); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB1682; H:AM4PR05MB3265.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: mdO07FiK0zpM1wVW6K819ImyOD09ovhnXyvvXefsQkSAYRS6NFgYy2Srjd5tYt3U5j/1ZVEm7QOmQK+pKF202zOiro1G4YIsgBaKB2yqwpUJfk1uFw/YdFN5zTPcH6jogT5Imdt03h//qjQi1SAjyhiCJyO5uV6nQ+wtnvQbEBcyah7eRtBhgJRvD94jAxbkCGAPSR7Qc9g9SYwL8MdMf2iuOUVYOCn2fw6FmWeD6hfODN9v3YXYuOf12aSuoa0AehQYhjj43+K7PXfWHrqN7ubc2JgHSrTgIkVwKI4kajlgqhLNAkZkmk19dr5Bmv8mTvse9Eqrx0irTjqtn95enbLzOq+g1FE8PzkI30jvgnA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89a55c6d-9463-43a4-9203-08d62944f837 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Oct 2018 15:29:12.1192 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB1682 Subject: [dpdk-dev] [PATCH] net/mlx5: flow counters support on the Linux-rdma v19 base X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Oct 2018 15:29:13 -0000 Mellanox mlx5 PMD supports Flow Counters via Verbs library. The current implementation is based on the Mellanox proprietary Verbs library included in MLNX OFED packages. The Flow Counter support is recently added into linux-rdma release (v19), so the mlx5 PMD update is needed to provide Counter feature on the base of linux-rdma. mlx5 PMD can be compiled with MLNX OFED or linux-rdma v19+ and provide flow counters for both. Signed-off-by: Viacheslav Ovsiienko --- drivers/net/mlx5/Makefile | 10 ++++++++ drivers/net/mlx5/mlx5.c | 6 +++++ drivers/net/mlx5/mlx5_flow.c | 9 ++++++- drivers/net/mlx5/mlx5_flow.h | 4 +++ drivers/net/mlx5/mlx5_flow_verbs.c | 52 ++++++++++++++++++++++++++++++----= ---- drivers/net/mlx5/mlx5_glue.c | 41 ++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_glue.h | 16 ++++++++++++ 7 files changed, 127 insertions(+), 11 deletions(-) diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile index ca1de9f..e3d2156 100644 --- a/drivers/net/mlx5/Makefile +++ b/drivers/net/mlx5/Makefile @@ -162,6 +162,16 @@ mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config= -h.sh type 'struct ibv_counter_set_init_attr' \ $(AUTOCONF_OUTPUT) $Q sh -- '$<' '$@' \ + HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT \ + infiniband/verbs.h \ + type 'struct ibv_counters_init_attr' \ + $(AUTOCONF_OUTPUT) + $Q sh -- '$<' '$@' \ + HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 \ + infiniband/verbs.h \ + type 'struct ibv_counters_init_attr' \ + $(AUTOCONF_OUTPUT) + $Q sh -- '$<' '$@' \ HAVE_RDMA_NL_NLDEV \ rdma/rdma_netlink.h \ enum RDMA_NL_NLDEV \ diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 4be6a1c..81f6ba1 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -739,8 +739,10 @@ unsigned int mprq_min_stride_num_n =3D 0; unsigned int mprq_max_stride_num_n =3D 0; #ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT +#ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 struct ibv_counter_set_description cs_desc =3D { .counter_type =3D 0 }; #endif +#endif struct ether_addr mac; char name[RTE_ETH_NAME_MAX_LEN]; int own_domain_id =3D 0; @@ -1009,11 +1011,15 @@ DRV_LOG(DEBUG, "checksum offloading is %ssupported", (config.hw_csum ? "" : "not ")); #ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT +#ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 config.flow_counter_en =3D !!attr.max_counter_sets; mlx5_glue->describe_counter_set(ctx, 0, &cs_desc); DRV_LOG(DEBUG, "counter type =3D %d, num of cs =3D %ld, attributes =3D %d= ", cs_desc.counter_type, cs_desc.num_of_cs, cs_desc.attributes); +#else + config.flow_counter_en =3D 1; +#endif #endif config.ind_table_max_size =3D attr.rss_caps.max_rwq_indirection_table_size; diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 8007bf1..652580c 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -2306,6 +2306,13 @@ struct rte_flow * if (flow->actions & MLX5_ACTION_COUNT) { struct rte_flow_query_count *qc =3D data; uint64_t counters[2] =3D {0, 0}; +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 + int err =3D mlx5_glue->query_counter_set( + flow->counter->cs, + counters, + RTE_DIM(counters), + IBV_READ_COUNTERS_ATTR_PREFER_CACHED); +#else struct ibv_query_counter_set_attr query_cs_attr =3D { .cs =3D flow->counter->cs, .query_flags =3D IBV_COUNTER_SET_FORCE_UPDATE, @@ -2316,7 +2323,7 @@ struct rte_flow * }; int err =3D mlx5_glue->query_counter_set(&query_cs_attr, &query_out); - +#endif if (err) return rte_flow_error_set (error, err, diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 10d700a..a3b82dd 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -222,7 +222,11 @@ struct mlx5_flow_counter { uint32_t shared:1; /**< Share counter ID with other flow rules. */ uint32_t ref_cnt:31; /**< Reference counter. */ uint32_t id; /**< Counter ID. */ +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 + struct ibv_counters *cs; /**< Holds the counters for the rule. */ +#else struct ibv_counter_set *cs; /**< Holds the counters for the rule. */ +#endif uint64_t hits; /**< Number of packets matched by the rule. */ uint64_t bytes; /**< Number of bytes matched by the rule. */ }; diff --git a/drivers/net/mlx5/mlx5_flow_verbs.c b/drivers/net/mlx5/mlx5_flo= w_verbs.c index 05ab5fd..1c8bdba 100644 --- a/drivers/net/mlx5/mlx5_flow_verbs.c +++ b/drivers/net/mlx5/mlx5_flow_verbs.c @@ -48,27 +48,32 @@ static struct mlx5_flow_counter * flow_verbs_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t = id) { +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT struct priv *priv =3D dev->data->dev_private; struct mlx5_flow_counter *cnt; =20 - LIST_FOREACH(cnt, &priv->flow_counters, next) { - if (!cnt->shared || cnt->shared !=3D shared) - continue; - if (cnt->id !=3D id) - continue; - cnt->ref_cnt++; - return cnt; + if (shared) { + LIST_FOREACH(cnt, &priv->flow_counters, next) + if (cnt->shared && cnt->id =3D=3D id) { + cnt->ref_cnt++; + return cnt; + } } -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT =20 struct mlx5_flow_counter tmpl =3D { .shared =3D shared, .id =3D id, +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 + .cs =3D mlx5_glue->create_counter_set + (priv->ctx, + &(struct ibv_counters_init_attr){0}), +#else .cs =3D mlx5_glue->create_counter_set (priv->ctx, &(struct ibv_counter_set_init_attr){ .counter_set_id =3D id, }), +#endif .hits =3D 0, .bytes =3D 0, }; @@ -77,17 +82,40 @@ rte_errno =3D errno; return NULL; } + +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 + struct ibv_counter_attach_attr attach_attr =3D {0}; + int ret; + + attach_attr.counter_desc =3D IBV_COUNTER_PACKETS; + attach_attr.index =3D 0; + ret =3D ibv_attach_counters_point_flow(tmpl.cs, &attach_attr, NULL); + if (!ret) { + attach_attr.counter_desc =3D IBV_COUNTER_BYTES; + attach_attr.index =3D 1; + ret =3D ibv_attach_counters_point_flow(tmpl.cs, + &attach_attr, + NULL); + } + if (ret) { + claim_zero(mlx5_glue->destroy_counter_set(tmpl.cs)); + rte_errno =3D ret; + return NULL; + } +#endif cnt =3D rte_calloc(__func__, 1, sizeof(*cnt), 0); if (!cnt) { + claim_zero(mlx5_glue->destroy_counter_set(tmpl.cs)); rte_errno =3D ENOMEM; return NULL; } *cnt =3D tmpl; LIST_INSERT_HEAD(&priv->flow_counters, cnt, next); return cnt; -#endif +#else rte_errno =3D ENOTSUP; return NULL; +#endif } =20 /** @@ -947,7 +975,7 @@ flow->counter =3D flow_verbs_counter_new(dev, count->shared, count->id); if (!flow->counter) - return rte_flow_error_set(error, ENOTSUP, + return rte_flow_error_set(error, rte_errno, RTE_FLOW_ERROR_TYPE_ACTION, action, "cannot get counter" @@ -955,7 +983,11 @@ } *action_flags |=3D MLX5_ACTION_COUNT; #ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 + counter.counters =3D flow->counter->cs; +#else counter.counter_set_handle =3D flow->counter->cs->handle; +#endif flow_verbs_spec_add(dev_flow, &counter, size); #endif return 0; diff --git a/drivers/net/mlx5/mlx5_glue.c b/drivers/net/mlx5/mlx5_glue.c index 48590df..785234c 100644 --- a/drivers/net/mlx5/mlx5_glue.c +++ b/drivers/net/mlx5/mlx5_glue.c @@ -211,6 +211,39 @@ return ibv_dereg_mr(mr); } =20 +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 +static struct ibv_counters * +mlx5_glue_create_counters(struct ibv_context *context, + struct ibv_counters_init_attr *init_attr) +{ + return ibv_create_counters(context, init_attr); +} + +static int +mlx5_glue_destroy_counters(struct ibv_counters *counters) +{ + return ibv_destroy_counters(counters); +} + +static int +mlx5_glue_attach_counters(struct ibv_counters *counters, + struct ibv_counter_attach_attr *attr, + struct ibv_flow *flow) +{ + return ibv_attach_counters_point_flow(counters, attr, flow); +} + +static int +mlx5_glue_query_counters(struct ibv_counters *counters, + uint64_t *counters_value, + uint32_t ncounters, + uint32_t flags) +{ + return ibv_read_counters(counters, counters_value, ncounters, flags); +} +#endif + +#ifndef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 static struct ibv_counter_set * mlx5_glue_create_counter_set(struct ibv_context *context, struct ibv_counter_set_init_attr *init_attr) @@ -262,6 +295,7 @@ return ibv_query_counter_set(query_attr, cs_data); #endif } +#endif =20 static void mlx5_glue_ack_async_event(struct ibv_async_event *event) @@ -420,10 +454,17 @@ .modify_qp =3D mlx5_glue_modify_qp, .reg_mr =3D mlx5_glue_reg_mr, .dereg_mr =3D mlx5_glue_dereg_mr, +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 + .create_counter_set =3D mlx5_glue_create_counters, + .destroy_counter_set =3D mlx5_glue_destroy_counters, + .attach_counter_set =3D mlx5_glue_attach_counters, + .query_counter_set =3D mlx5_glue_query_counters, +#else .create_counter_set =3D mlx5_glue_create_counter_set, .destroy_counter_set =3D mlx5_glue_destroy_counter_set, .describe_counter_set =3D mlx5_glue_describe_counter_set, .query_counter_set =3D mlx5_glue_query_counter_set, +#endif .ack_async_event =3D mlx5_glue_ack_async_event, .get_async_event =3D mlx5_glue_get_async_event, .port_state_str =3D mlx5_glue_port_state_str, diff --git a/drivers/net/mlx5/mlx5_glue.h b/drivers/net/mlx5/mlx5_glue.h index f6e4e38..504d487 100644 --- a/drivers/net/mlx5/mlx5_glue.h +++ b/drivers/net/mlx5/mlx5_glue.h @@ -96,6 +96,21 @@ struct mlx5_glue { struct ibv_mr *(*reg_mr)(struct ibv_pd *pd, void *addr, size_t length, int access); int (*dereg_mr)(struct ibv_mr *mr); +#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT_V45 + struct ibv_counters *(*create_counter_set) + (struct ibv_context *context, + struct ibv_counters_init_attr *init_attr); + int (*destroy_counter_set)(struct ibv_counters *cs); + int (*attach_counter_set) + (struct ibv_counters *cs, + struct ibv_counter_attach_attr *attr, + struct ibv_flow *flow); + int (*query_counter_set) + (struct ibv_counters *cs, + uint64_t *counters_value, + uint32_t ncounters, + uint32_t flags); +#else struct ibv_counter_set *(*create_counter_set) (struct ibv_context *context, struct ibv_counter_set_init_attr *init_attr); @@ -106,6 +121,7 @@ struct mlx5_glue { struct ibv_counter_set_description *cs_desc); int (*query_counter_set)(struct ibv_query_counter_set_attr *query_attr, struct ibv_counter_set_data *cs_data); +#endif void (*ack_async_event)(struct ibv_async_event *event); int (*get_async_event)(struct ibv_context *context, struct ibv_async_event *event); --=20 1.8.3.1