From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 32213A0562; Mon, 30 Mar 2020 07:53:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 36C3D2BAE; Mon, 30 Mar 2020 07:53:43 +0200 (CEST) Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10050.outbound.protection.outlook.com [40.107.1.50]) by dpdk.org (Postfix) with ESMTP id 7CEF32B8B; Mon, 30 Mar 2020 07:53:41 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gl7gYAt9tpIGYMGXFOB1FCvX3BK3eOmgXzQ4apBSi7mbTRyZ+L1KDizmXm+MwUtbFSeYOrw+1vnwcrNvqdwwYblyXm5RcwX7HZ7j1QZjsKteuAFbZpIRQkrt/pe66C7IoTk81BqHcHWUImAOLPdWE2mhjlLCJRYg2qxlgJd7TIVm4Sm6vuixVTiLDL1PVAzD49Fp0oXq6PqwfYRy1QtC52pNl4bibCasu4n2vRkxqvcyjJHXTxu+eznv1Ct0n3lAWDmhvoHGniKf0Hd4egP7Cwg7VbVBZXavsHBhwxK69KJnvSpLcXNrxwjO4TakN3mEMLiTHNzgp7aztOTbFeAs6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TlfKklPCDmj5Uwteoe3l90Q0QGVHbsZEenbHcFxRwJc=; b=TU9H0vV2SFrzTrChV4P6pyraQNonaedd70yOt5YyvWPfeOzsVYU66n1zr2jxzEOjK970HiW2Qm6XQUGEEAUf8lVXLFB9sajctUQLBAmndtfSvNTyj45F6IqHDMkR8lQRTskvV3eFRTlbIAD/B2XFpuVbkj5UagqWxI0dtrfTqfG2ElJD6ZTI1ZCI6gdz7/oqXDn5xtrfYdfcNnld48MNA0HTEd/OPPCq0DFa3WAhN9WbTbMrThxYW8IS71RgznyoKPW9xizwp+dBOGKEAm+2Gnj8tTz26cJsKNO2tNIahserZHIWk0P54nQvvnO/Gqxmmi71Sh/P1rw/d2nDa+e7Bg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=mellanox.com; dmarc=pass action=none header.from=mellanox.com; dkim=pass header.d=mellanox.com; arc=none 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=TlfKklPCDmj5Uwteoe3l90Q0QGVHbsZEenbHcFxRwJc=; b=qbyBj2vhHwMO/3GITY5z5DOfVtDYtzgRUHRFDxZS5B+yMk/F+CjGdcwpfRrAkxPIEJu0dbYPz29+FnX8Zn73BOU4Tb+b6qTayLwBJOJHQ9YBZk/Ww/X4wfpThpwKOD+No1Ya7rF/+PpUGCeMEIgnVw8nSM4fYhlij6927Fcv8Wo= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.188.154) by AM4PR05MB3362.eurprd05.prod.outlook.com (10.171.187.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2856.20; Mon, 30 Mar 2020 05:53:40 +0000 Received: from AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::da5:7919:35c1:894]) by AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::da5:7919:35c1:894%6]) with mapi id 15.20.2856.019; Mon, 30 Mar 2020 05:53:40 +0000 From: Slava Ovsiienko To: "Jiawei(Jonny) Wang" , Matan Azrad , "Jiawei(Jonny) Wang" CC: Raslan Darawsheh , "dev@dpdk.org" , "stable@dpdk.org" Thread-Topic: [PATCH] net/mlx5: fix imissed counter overflow issue Thread-Index: AQHWBj+fUwauwZRee0Okflw1BHauRahgomRw Date: Mon, 30 Mar 2020 05:53:40 +0000 Message-ID: References: <20200330030210.21595-1-jiaweiw@mellanox.com> In-Reply-To: <20200330030210.21595-1-jiaweiw@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=viacheslavo@mellanox.com; x-originating-ip: [95.164.10.10] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 1a98d12b-fb98-406b-297e-08d7d46eb2ae x-ms-traffictypediagnostic: AM4PR05MB3362:|AM4PR05MB3362: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtFwd x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4303; x-forefront-prvs: 0358535363 x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM4PR05MB3265.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(10009020)(4636009)(376002)(346002)(39860400002)(136003)(366004)(396003)(7696005)(186003)(81166006)(9686003)(8676002)(2906002)(71200400001)(86362001)(6636002)(6506007)(53546011)(110136005)(66556008)(66446008)(66476007)(64756008)(316002)(5660300002)(478600001)(76116006)(4326008)(54906003)(66946007)(450100002)(55016002)(81156014)(8936002)(52536014)(33656002)(26005); DIR:OUT; SFP:1101; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 6KF/QP/yMJxxMwZHwqV55SG4PmqeheRVvDZhUL87/0pwZMsEqURUJDSAaEbvwrerDC3rG44qJqCpr6lHvbHQi3vqcrbnaKp90J9qiIC/y8B8CcPF3JvfGKXV8YjrkdFeXcsTNohySegIpiimFvhAZPCw1SJRc96p8FaKTE4mWnOWSKmyw55sq4C0awT2se6ZicvQ4vmNLDlkTeCtkpmWixgPkgHt5OFXurNGKHahT6PkRd+ZuYnKhBod4QzZ4o0rK8V1DnVbYn12MfUKoX5bz4V3gk0DE1acGFrBJxZtE9tY0oIsoMfMnhqv6BDjq3TFq441wjg+Nd1++gLk9kpk3vG+bD+Pfts1tmbJhcdWZ83BPRqkuzaUIpdqybll5p+xNpa/nSzxL/dlp/xkGTeDk9Nfx6HXuXVPNB0DrD+BisTwoSKThSl1+6cz1HAhS2wB x-ms-exchange-antispam-messagedata: wpK9Ue+tKRJwmKKX0ZO349nEilYSmB5cqzN7UKiBUXE8/xzojmhmFiSM3ZT/9D0WKXeVxwkA+QLhnY/ZPWQ2vMro1IrMUchdGAo4OecAMw5FkxmMmq8FcwzNMpbi6zElQHwdrGAwKhGAnelIyv0gJw== 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: 1a98d12b-fb98-406b-297e-08d7d46eb2ae X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Mar 2020 05:53:40.4174 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 2KNPO5LJZ3PhH/9AXPHev7sTHpbuHAzlGml0IOa7dB/nkPW2xZfVymS8bR7nYktXOjfxtwO2mT04Ug25YwkHr42vFHGfFveOU8hL117oDrI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM4PR05MB3362 Subject: Re: [dpdk-dev] [PATCH] net/mlx5: fix imissed counter overflow issue 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" > -----Original Message----- > From: Jiawei Wang > Sent: Monday, March 30, 2020 6:02 > To: Slava Ovsiienko ; Matan Azrad > ; Jiawei(Jonny) Wang > Cc: Raslan Darawsheh ; dev@dpdk.org; > stable@dpdk.org > Subject: [PATCH] net/mlx5: fix imissed counter overflow issue >=20 > The Hw counters is defined as 32bit unsigned value and read from the sysf= s. > Firstly read the base value while application start, then fetch the new v= alue > while do query and minus the base value. > If the new value is less than base value, will result in the a negative v= alue and > convert to the big value as unsigned 64bit. >=20 > PMD add xstats field to store the last successfully read counter, use it = if failed > to read hw counter from sysfs. > PMD also record the last output value to handle the wrap around case, if > overflow happened, increase the wrap count by 1 and save into the higher > 32bit, and update the new value into lower 32bit, finally return the 64bi= t > counter value. >=20 > Fixes: ce9494d76c4 ("net/mlx5: report imissed statistics") > Cc: stable@dpdk.org >=20 > Signed-off-by: Jiawei Wang Acked-by: Viacheslav Ovsiienko > --- > drivers/net/mlx5/mlx5.h | 3 ++ > drivers/net/mlx5/mlx5_stats.c | 57 ++++++++++++++++++++++++++++++----- > 2 files changed, 52 insertions(+), 8 deletions(-) >=20 > diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index > d7c519bae0..c01fae8c8e 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -112,12 +112,15 @@ struct mlx5_xstats_ctrl { > /* Index in the device counters table. */ > uint16_t dev_table_idx[MLX5_MAX_XSTATS]; > uint64_t base[MLX5_MAX_XSTATS]; > + uint64_t xstats[MLX5_MAX_XSTATS]; > + uint64_t hw_stats[MLX5_MAX_XSTATS]; > struct mlx5_counter_ctrl info[MLX5_MAX_XSTATS]; }; >=20 > struct mlx5_stats_ctrl { > /* Base for imissed counter. */ > uint64_t imissed_base; > + uint64_t imissed; > }; >=20 > /* Flow list . */ > diff --git a/drivers/net/mlx5/mlx5_stats.c b/drivers/net/mlx5/mlx5_stats.= c > index 7603502967..5bc6fa6aa1 100644 > --- a/drivers/net/mlx5/mlx5_stats.c > +++ b/drivers/net/mlx5/mlx5_stats.c > @@ -139,7 +139,7 @@ static const struct mlx5_counter_ctrl > mlx5_counters_init[] =3D { >=20 > static const unsigned int xstats_n =3D RTE_DIM(mlx5_counters_init); >=20 > -static inline void > +static inline int > mlx5_read_ib_stat(struct mlx5_priv *priv, const char *ctr_name, uint64_t > *stat) { > FILE *file; > @@ -155,10 +155,11 @@ mlx5_read_ib_stat(struct mlx5_priv *priv, const > char *ctr_name, uint64_t *stat) >=20 > fclose(file); > if (n =3D=3D 1) > - return; > + return 0; > } > } > *stat =3D 0; > + return 1; > } >=20 > /** > @@ -197,8 +198,14 @@ mlx5_read_dev_counters(struct rte_eth_dev *dev, > uint64_t *stats) > } > for (i =3D 0; i !=3D xstats_ctrl->mlx5_stats_n; ++i) { > if (xstats_ctrl->info[i].ib) { > - mlx5_read_ib_stat(priv, xstats_ctrl->info[i].ctr_name, > - &stats[i]); > + ret =3D mlx5_read_ib_stat(priv, > + xstats_ctrl->info[i].ctr_name, > + &stats[i]); > + /* return last xstats counter if fail to read. */ > + if (ret =3D=3D 0) > + xstats_ctrl->xstats[i] =3D stats[i]; > + else > + stats[i] =3D xstats_ctrl->xstats[i]; > } else { > stats[i] =3D (uint64_t) > et_stats->data[xstats_ctrl->dev_table_idx[i]]; > @@ -304,6 +311,7 @@ mlx5_stats_init(struct rte_eth_dev *dev) > unsigned int idx =3D xstats_ctrl->mlx5_stats_n++; >=20 > xstats_ctrl->info[idx] =3D mlx5_counters_init[i]; > + xstats_ctrl->hw_stats[idx] =3D 0; > } > } > MLX5_ASSERT(xstats_ctrl->mlx5_stats_n <=3D MLX5_MAX_XSTATS); @@ > -314,6 +322,7 @@ mlx5_stats_init(struct rte_eth_dev *dev) > DRV_LOG(ERR, "port %u cannot read device counters: %s", > dev->data->port_id, strerror(rte_errno)); > mlx5_read_ib_stat(priv, "out_of_buffer", &stats_ctrl->imissed_base); > + stats_ctrl->imissed =3D 0; > free: > rte_free(strings); > } > @@ -356,7 +365,23 @@ mlx5_xstats_get(struct rte_eth_dev *dev, struct > rte_eth_xstat *stats, > return ret; > for (i =3D 0; i !=3D mlx5_stats_n; ++i) { > stats[i].id =3D i; > - stats[i].value =3D (counters[i] - xstats_ctrl->base[i]); > + if (xstats_ctrl->info[i].ib) { > + uint64_t wrap_n; > + uint64_t hw_stat =3D xstats_ctrl->hw_stats[i]; > + > + stats[i].value =3D (counters[i] - > + xstats_ctrl->base[i]) & > + (uint64_t)UINT32_MAX; > + wrap_n =3D hw_stat >> 32; > + if (stats[i].value < > + (hw_stat & > (uint64_t)UINT32_MAX)) > + wrap_n++; > + stats[i].value |=3D (wrap_n) << 32; > + xstats_ctrl->hw_stats[i] =3D stats[i].value; > + } else { > + stats[i].value =3D > + (counters[i] - xstats_ctrl->base[i]); > + } > } > } > return mlx5_stats_n; > @@ -378,9 +403,12 @@ int > mlx5_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { > struct mlx5_priv *priv =3D dev->data->dev_private; > + struct mlx5_stats_ctrl *stats_ctrl =3D &priv->stats_ctrl; > struct rte_eth_stats tmp; > unsigned int i; > unsigned int idx; > + uint64_t wrap_n; > + int ret; >=20 > memset(&tmp, 0, sizeof(tmp)); > /* Add software counters. */ > @@ -423,8 +451,18 @@ mlx5_stats_get(struct rte_eth_dev *dev, struct > rte_eth_stats *stats) #endif > tmp.oerrors +=3D txq->stats.oerrors; > } > - mlx5_read_ib_stat(priv, "out_of_buffer", &tmp.imissed); > - tmp.imissed -=3D priv->stats_ctrl.imissed_base; > + ret =3D mlx5_read_ib_stat(priv, "out_of_buffer", &tmp.imissed); > + if (ret =3D=3D 0) { > + tmp.imissed =3D (tmp.imissed - stats_ctrl->imissed_base) & > + (uint64_t)UINT32_MAX; > + wrap_n =3D stats_ctrl->imissed >> 32; > + if (tmp.imissed < (stats_ctrl->imissed & > (uint64_t)UINT32_MAX)) > + wrap_n++; > + tmp.imissed |=3D (wrap_n) << 32; > + stats_ctrl->imissed =3D tmp.imissed; > + } else { > + tmp.imissed =3D stats_ctrl->imissed; > + } > #ifndef MLX5_PMD_SOFT_COUNTERS > /* FIXME: retrieve and add hardware counters. */ #endif @@ -461,6 > +499,7 @@ mlx5_stats_reset(struct rte_eth_dev *dev) > sizeof(struct mlx5_txq_stats)); > } > mlx5_read_ib_stat(priv, "out_of_buffer", &stats_ctrl->imissed_base); > + stats_ctrl->imissed =3D 0; > #ifndef MLX5_PMD_SOFT_COUNTERS > /* FIXME: reset hardware counters. */ > #endif > @@ -503,8 +542,10 @@ mlx5_xstats_reset(struct rte_eth_dev *dev) > dev->data->port_id, strerror(rte_errno)); > return ret; > } > - for (i =3D 0; i !=3D n; ++i) > + for (i =3D 0; i !=3D n; ++i) { > xstats_ctrl->base[i] =3D counters[i]; > + xstats_ctrl->hw_stats[i] =3D 0; > + } >=20 > return 0; > } > -- > 2.21.0