From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-eopbgr20043.outbound.protection.outlook.com [40.107.2.43]) by dpdk.org (Postfix) with ESMTP id 9657F4CC3 for ; Sun, 21 Oct 2018 11:20:56 +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=I6qjfcC95IIZRNiBQpzQHrfhmUsZcKg4c81NAkr7sOQ=; b=Zn0HNR3QnAGd/oi6U/8rk+HWZJvrVGvsG0/Y1HVUPdQg17Q4/mG+kYPHJWCUBMQTwZukAuBr3gA/c4pWnM6Mk4yiXj7CMiFGzK9zvhJH3i/QT/gbz8AmzhqrmKZdCqmPnbA31VG0VteAcgNYqVEk+2hummEqjATjJHeeKCKY5UQ= Received: from DB7PR05MB4426.eurprd05.prod.outlook.com (52.134.109.15) by DB7PR05MB4891.eurprd05.prod.outlook.com (20.176.235.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1250.25; Sun, 21 Oct 2018 09:20:55 +0000 Received: from DB7PR05MB4426.eurprd05.prod.outlook.com ([fe80::80e:e6b:baf2:d973]) by DB7PR05MB4426.eurprd05.prod.outlook.com ([fe80::80e:e6b:baf2:d973%3]) with mapi id 15.20.1250.028; Sun, 21 Oct 2018 09:20:55 +0000 From: Shahaf Shuler To: Slava Ovsiienko , Yongseok Koh CC: "dev@dpdk.org" Thread-Topic: [PATCH v3 6/6] net/mlx5: flow counters Verbs interface functions update Thread-Index: AQHUZ790TN95TVzV3E+0GAHE+uxGYaUpa5dA Date: Sun, 21 Oct 2018 09:20:55 +0000 Message-ID: References: <1539784438-29242-1-git-send-email-viacheslavo@mellanox.com> <1539962470-10950-1-git-send-email-viacheslavo@mellanox.com> <1539962470-10950-7-git-send-email-viacheslavo@mellanox.com> In-Reply-To: <1539962470-10950-7-git-send-email-viacheslavo@mellanox.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=shahafs@mellanox.com; x-originating-ip: [31.154.10.105] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB7PR05MB4891; 6:jZX/JquLJJYQnRrPtpJzjVcysFrz8a3oBOuvt3s0KhksRzyGfW2xO+dnBny708/DjMgvYxC68t4JPh9m9OJKEd2i4smYQa1U5U0mhmbTVBES7P3Tam+pE6QtLY2rdU9JA1+pFv6G7EGPnn+biWtgb0FnDYODG5pzr53U+/fCwEO0bLWA6MH0xTWTbBgt+RAlVtvAKHI3XlTBG0NjxM6P1KFQbJe4cQp3OE40Z5RC/jqQYdbrGqwLFQgYwWOgJ3DBIVNVliV+gUNRfmmFjM50pwJItzMDq8ZsSrsyGArrwDEr59OelqCkYg6YoxgV4flFlxb2EmHClpqQPrdA/wE1K+JBi639CECETpWDQPtQeTtUSHipKbYzxEeNmWVRV87sKPz1yW5liSlr9eA30BDlEINRijrsmTK9FPLFBWMNB572AojQ0ScfDsdZ/BxiHqVIracWsg1NevJ0Qp9uST7AcA==; 5:8xDg6Kg5V+UvlqCZNjJR2DrqL9CF2mtPn6ldmwHlu0FFEDKfIS+NtAvwzwsg/4ZUom8h7vTGf4m4TKLWSjihBZPkMFw4U9cqfU2ZAQ+r7QDxVyW9EyciiPTEDgeRYDSB9WSi3wYJ+NeOg/Qa9AAe96uvMYEGw3rpm3bolrOQ28o=; 7:Kc6lhE5jb8vW/hNif7IZ8yMWOPAA/GA3swo+xXbx+HNBAeU/cavfG/NvA9ieV0kIWd+g+cpeOQIayqXBbgfQ6WbVnEv+EICcB+D3VV0tU10yU+6q+NrUPi8mUTeCWMNrpq+kT6ZRRf4pDdAlDI1za+GjCCGwjzjk12pQ9QfM4Hxu1xq6IkV57Ozto0TqYjMFVekqyyBCDJ2v+CaRvtbp7EYjQeTW4/9fXXSEKGFUuaEcLdQ6vvAGnH0gKkaVLkmj x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 5663517f-943c-4f96-eb49-08d637368115 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:DB7PR05MB4891; x-ms-traffictypediagnostic: DB7PR05MB4891: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(17755550239193); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(3231355)(944501410)(52105095)(6055026)(148016)(149066)(150057)(6041310)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:DB7PR05MB4891; BCL:0; PCL:0; RULEID:; SRVR:DB7PR05MB4891; x-forefront-prvs: 083289FD26 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(366004)(136003)(396003)(376002)(39860400002)(346002)(199004)(189003)(33656002)(68736007)(74316002)(476003)(305945005)(81166006)(486006)(81156014)(2906002)(316002)(15650500001)(7736002)(97736004)(71200400001)(71190400001)(14454004)(6246003)(478600001)(6116002)(3846002)(5250100002)(2900100001)(14444005)(7696005)(5024004)(5660300001)(26005)(9686003)(76176011)(66066001)(86362001)(186003)(25786009)(102836004)(55016002)(256004)(53936002)(4326008)(6636002)(99286004)(446003)(110136005)(106356001)(229853002)(8936002)(6506007)(8676002)(11346002)(6436002)(105586002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR05MB4891; H:DB7PR05MB4426.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: m7Y6qj/hldUl6jZ2D+xwl61gDWzCxiFTBTPt7MEHncjgqmbq6lK7YsVkDzZcMVHZ/Nw3SaV2VrKzOKfipDPeP8wfSMrWeMHyxslvJuPhK2S0C4SL8XFFuxVdS8oiPi9fiblh9ubXr3jU742g+h/KsdHe+OJVvoLfQY9SPmzv87mPZcfNP3QJPeLGcWc83Mx5zNTnju796M0AICki6viBFhlobPniFbpA/KlVQutULxZcAHsw+6gcGbbzMuja8k1Iox1v6Tuvu0yJYWYr6c3YASVrTebptOUagQUeOprR/Ht6IoRo+figjDFIbTnD/FLs2Shvf7vdZcfY1W1kSBHMkmtbi2vg37NI9upkPo7TVDI= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5663517f-943c-4f96-eb49-08d637368115 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Oct 2018 09:20:55.1561 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR05MB4891 Subject: Re: [dpdk-dev] [PATCH v3 6/6] net/mlx5: flow counters Verbs interface functions update 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: Sun, 21 Oct 2018 09:20:57 -0000 Friday, October 19, 2018 6:21 PM, Slava Ovsiienko: > Subject: [PATCH v3 6/6] net/mlx5: flow counters Verbs interface functions > update How about: "net/mlx5: support new flow counter API"=20 >=20 > This part of patchset updates the functions performing the Verbs library = calls > in order to support different versions of library. > The functions: > - flow_verbs_counter_new() > - flow_verbs_counter_release() > - flow_verbs_counter_query() > now have the several compilations branches, depending on the counter > support found in the system at compile time. >=20 > The flow_verbs_counter_create() function is introduced as helper for > flow_verbs_counter_new(), actually this helper create the counters with > Verbs. >=20 > Signed-off-by: Viacheslav Ovsiienko > --- > drivers/net/mlx5/mlx5_flow.h | 6 ++ > drivers/net/mlx5/mlx5_flow_verbs.c | 129 > ++++++++++++++++++++++++++++--------- > 2 files changed, 104 insertions(+), 31 deletions(-) >=20 > diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h > index 69f55cf..44c7515 100644 > --- a/drivers/net/mlx5/mlx5_flow.h > +++ b/drivers/net/mlx5/mlx5_flow.h > @@ -224,7 +224,13 @@ 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. */ > +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) > struct ibv_counter_set *cs; /**< Holds the counters for the rule. */ > +#elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) > + struct ibv_counters *cs; /**< Holds the counters for the rule. */ > +#else > + void *cs; Why you need this else?=20 > +#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_flow_verbs.c > index f720c35..b657933 100644 > --- a/drivers/net/mlx5/mlx5_flow_verbs.c > +++ b/drivers/net/mlx5/mlx5_flow_verbs.c > @@ -33,6 +33,59 @@ > #include "mlx5_glue.h" > #include "mlx5_flow.h" >=20 > + > +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ > + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) As I already commented on the previous version. Ifdef are always inside the= function body, and not before the function declaration.=20 If no support for counters the function should return errno.=20 > +/** > + * Create Verbs flow counter with Verbs library. > + * > + * @param[in] dev > + * Pointer to the Ethernet device structure. > + * @param[in, out] counter > + * PMD flow counter object, contains the counter id, > + * handle of created Verbs flow counter is returned in cs field. The struct maybe will change in the future, but the doc isn't. better to sa= y "mlx5 flow counter object"=20 > + * > + * @return > + * counter->cs contains a handle of created Verbs counter, > + * NULL if error occurred and rte_errno is set. How can you return NULL if the function returns void?=20 It seems this function needs to return an integer.=20 > + */ > +static void > +flow_verbs_counter_create(struct rte_eth_dev *dev, > + struct mlx5_flow_counter *counter) { #if > +defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) > + struct priv *priv =3D dev->data->dev_private; > + struct ibv_counter_set_init_attr init =3D { > + .counter_set_id =3D counter->id}; > + > + counter->cs =3D mlx5_glue->create_counter_set(priv->ctx, &init); #elif > +defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) > + struct priv *priv =3D dev->data->dev_private; > + struct ibv_counters_init_attr init =3D {0}; > + struct ibv_counter_attach_attr attach =3D {0}; > + int ret; > + > + counter->cs =3D mlx5_glue->create_counters(priv->ctx, &init); > + if (!counter->cs) > + return; > + attach.counter_desc =3D IBV_COUNTER_PACKETS; > + attach.index =3D 0; > + ret =3D mlx5_glue->attach_counters(counter->cs, &attach, NULL); > + if (!ret) { > + attach.counter_desc =3D IBV_COUNTER_BYTES; > + attach.index =3D 1; > + ret =3D mlx5_glue->attach_counters > + (counter->cs, &attach, NULL); > + } > + if (ret) { > + claim_zero(mlx5_glue->destroy_counters(counter->cs)); > + counter->cs =3D NULL; > + rte_errno =3D ret; > + } > +#endif > +} > +#endif > + > /** > * Get a flow counter. > * > @@ -49,6 +102,8 @@ > static struct mlx5_flow_counter * > flow_verbs_counter_new(struct rte_eth_dev *dev, uint32_t shared, > uint32_t id) { > +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ > + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) No explicit need for this ifdef, the flow_verbs_counter_create will return = error if the counters are not supported. This is a duplicate check.=20 > struct priv *priv =3D dev->data->dev_private; > struct mlx5_flow_counter *cnt; >=20 > @@ -60,37 +115,32 @@ > cnt->ref_cnt++; > return cnt; > } > -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42 > - > - struct mlx5_flow_counter tmpl =3D { > - .shared =3D shared, > - .id =3D id, > - .cs =3D mlx5_glue->create_counter_set > - (priv->ctx, > - &(struct ibv_counter_set_init_attr){ > - .counter_set_id =3D id, > - }), > - .hits =3D 0, > - .bytes =3D 0, > - .ref_cnt =3D 1, > - }; > - > - if (!tmpl.cs) { > - rte_errno =3D errno; > - return NULL; > - } > 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 > + cnt->id =3D id; > + cnt->shared =3D shared; > + cnt->ref_cnt =3D 1; > + cnt->hits =3D 0; > + cnt->bytes =3D 0; > + /* Create counter with Verbs. */ > + flow_verbs_counter_create(dev, cnt); > + if (cnt->cs) { > + LIST_INSERT_HEAD(&priv->flow_counters, cnt, next); > + return cnt; > + } > + /* Some error occurred in Verbs library, rte_errno is set. */ > + rte_free(cnt); > + return NULL; > +#else > + (void)dev; > + (void)shared; > + (void)id; > rte_errno =3D ENOTSUP; > return NULL; > +#endif > } >=20 > /** > @@ -103,7 +153,11 @@ > flow_verbs_counter_release(struct mlx5_flow_counter *counter) { > if (--counter->ref_cnt =3D=3D 0) { > +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) > claim_zero(mlx5_glue->destroy_counter_set(counter->cs)); > +#elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) > + claim_zero(mlx5_glue->destroy_counters(counter->cs)); > +#endif > LIST_REMOVE(counter, next); > rte_free(counter); > } > @@ -117,14 +171,15 @@ > */ > static int > flow_verbs_counter_query(struct rte_eth_dev *dev __rte_unused, > - struct rte_flow *flow __rte_unused, > - void *data __rte_unused, > + struct rte_flow *flow, void *data, > struct rte_flow_error *error) > { > -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42 > +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ > + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) > if (flow->actions & MLX5_FLOW_ACTION_COUNT) { > struct rte_flow_query_count *qc =3D data; > uint64_t counters[2] =3D {0, 0}; > +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) > struct ibv_query_counter_set_attr query_cs_attr =3D { > .cs =3D flow->counter->cs, > .query_flags =3D IBV_COUNTER_SET_FORCE_UPDATE, > @@ -135,7 +190,12 @@ > }; > int err =3D mlx5_glue->query_counter_set(&query_cs_attr, > &query_out); > - > +#elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) > + int err =3D mlx5_glue->query_counters( > + flow->counter->cs, counters, > + RTE_DIM(counters), > + > IBV_READ_COUNTERS_ATTR_PREFER_CACHED); > +#endif > if (err) > return rte_flow_error_set > (error, err, > @@ -157,6 +217,8 @@ > NULL, > "flow does not have counter"); > #else > + (void)flow; > + (void)data; > return rte_flow_error_set(error, ENOTSUP, > RTE_FLOW_ERROR_TYPE_UNSPECIFIED, > NULL, > @@ -993,7 +1055,8 @@ > { > const struct rte_flow_action_count *count =3D action->conf; > struct rte_flow *flow =3D dev_flow->flow; -#ifdef > HAVE_IBV_DEVICE_COUNTERS_SET_V42 > +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ > + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) > unsigned int size =3D sizeof(struct ibv_flow_spec_counter_action); > struct ibv_flow_spec_counter_action counter =3D { > .type =3D IBV_FLOW_SPEC_ACTION_COUNT, > @@ -1012,9 +1075,12 @@ > " context."); > } > *action_flags |=3D MLX5_FLOW_ACTION_COUNT; -#ifdef > HAVE_IBV_DEVICE_COUNTERS_SET_V42 > +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) > counter.counter_set_handle =3D flow->counter->cs->handle; > flow_verbs_spec_add(dev_flow, &counter, size); > +#elif defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) > + counter.counters =3D flow->counter->cs; > + flow_verbs_spec_add(dev_flow, &counter, size); > #endif > return 0; > } > @@ -1277,7 +1343,8 @@ > detected_actions |=3D MLX5_FLOW_ACTION_RSS; > break; > case RTE_FLOW_ACTION_TYPE_COUNT: > -#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_V42 > +#if defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) || \ > + defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45) > size +=3D sizeof(struct ibv_flow_spec_counter_action); > #endif > detected_actions |=3D MLX5_FLOW_ACTION_COUNT; > -- > 1.8.3.1