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 86740A057B; Tue, 31 Mar 2020 16:33:08 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6A61F1BFC1; Tue, 31 Mar 2020 16:33:08 +0200 (CEST) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2062.outbound.protection.outlook.com [40.107.22.62]) by dpdk.org (Postfix) with ESMTP id 29B202BCE; Tue, 31 Mar 2020 16:33:07 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Io2wsVbEG1MmqqlsEZIymxD/oaGKuYcjl6f7BJC/JHKyt+YB2zbFXBw+6I/O98Mz07TmfWEocVDSsUYZaSr35Prodaxu7L8EzBgKJJ35pJ8oQJB4ombCHxhCM4roqXiE86X4I98zlKNeuMk1GPv0uyqfDQx3lEy0c3C/SNextIIouOcF2v+XnVRA0Aox5EdQFcgOipskaCXHAhtQ7/aMFdM5TfAO6aRfvNcIXhaMVmZaO7EpQ8kRQgbw/3JoedTsK7mkLMQLV7kI6kVHB7GI7ynThIp6f/m82g3GLfncmL4luocpwC4L8qLKbrqXJKDygM7c+73ZR1PDj1l/kqSImw== 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=Uz9yLTvvYoOf1fwh20V+igy8F3iCZG3AE6g7d9lmSSU=; b=ASUrqV3VBau7YPSgBfQfGBZ9wXQ6451Ip7hyCAsLcgMA6ZL81/O1C/OTQtCWItHrPHm/6aWdw5EynNFQwCiGwEm81KTjpwvnhmV/QBr/bU8y7haGXKCmsdyZaCNYgt0OYzUJ3+LRB+PzR02ZaA339jOVWT1M6j3prr8HMFWGux+8k1m0zbDId0k4ixr+ec6V+9kijwigSo5f9Mv8B5gUxarFFpMt44EjLKMDfGeTxv8A8KPncXNILBf3bk/kkywsYyE+0zpxPPOwGcc+moBBxfm3G+9deiQ+DJILi7EG1GKKbLlgvgBZfWisxtcswmtlT3LkzytNvg5Kz6MwCaNHrQ== 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=Uz9yLTvvYoOf1fwh20V+igy8F3iCZG3AE6g7d9lmSSU=; b=kaEYyxe3ivhgNPUXXhMwoIJt8S2CVthTN0K+diOlUsmIxc2xw+aAjm2UYKMOCIMJxnCK8FSbvqZ/0aloOpkgdNqQErR84twM9ZUGFhfiLJaY4Gfd+AfrlOKtFT29izqqzlv+BkPehp85a8HutK6VtkTsfZAaRg2e1kK0PAot7fc= Received: from AM0PR05MB6707.eurprd05.prod.outlook.com (10.186.174.145) by AM0PR05MB6660.eurprd05.prod.outlook.com (10.186.172.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2856.20; Tue, 31 Mar 2020 14:33:06 +0000 Received: from AM0PR05MB6707.eurprd05.prod.outlook.com ([fe80::adbd:45ca:54:bba9]) by AM0PR05MB6707.eurprd05.prod.outlook.com ([fe80::adbd:45ca:54:bba9%7]) with mapi id 15.20.2856.019; Tue, 31 Mar 2020 14:33:06 +0000 From: Raslan Darawsheh To: "Jiawei(Jonny) Wang" , Slava Ovsiienko , Matan Azrad , "Jiawei(Jonny) Wang" CC: "dev@dpdk.org" , "stable@dpdk.org" Thread-Topic: [PATCH] net/mlx5: fix imissed counter overflow issue Thread-Index: AQHWBj+fxsXcSCUyDkq5RQZdQ+6wl6hixgRw Date: Tue, 31 Mar 2020 14:33:06 +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=rasland@mellanox.com; x-originating-ip: [188.161.229.130] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: f25e4430-69e1-4521-0f62-08d7d5806d5b x-ms-traffictypediagnostic: AM0PR05MB6660:|AM0PR05MB6660: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1468; x-forefront-prvs: 0359162B6D x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM0PR05MB6707.eurprd05.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(10009020)(4636009)(396003)(366004)(136003)(376002)(346002)(39860400002)(86362001)(76116006)(81166006)(8676002)(8936002)(478600001)(6506007)(7696005)(2906002)(9686003)(52536014)(26005)(81156014)(53546011)(110136005)(55016002)(64756008)(66946007)(66446008)(5660300002)(450100002)(316002)(33656002)(66556008)(186003)(71200400001)(66476007)(54906003)(6636002)(4326008); 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: f6XNeTTsDrxe50WTZ72skxt7I9MB/AG3o3veaktDMJY0pJrHcw0GT3TQCuEuocCReriOLkE2Gyl2zSG+T3qqRBJ775AgPQLgboIjkb3zZ1q8m0JporeuZaSVacmJkiIgyBV7nO/EG+2Iit0n+AeZBhh9x/kzRKw62m7z2+IjMrf7W9aphsKr/lZ+iEgGQa18/fKHqIlCgzzbqm9rKi40ent/96IsHLm5Q1LOCNP3ucg5Un/NdL39H1USUqVCc7pTqtFEQ7/nlWCCBFTznr/WYcMewZniIJRhQ99e5OD/KFwQVJF0IuDA74NZpGKYnNEw+WqzJD0cp0vjfqXvhHILIm+JWwkBQqd9fCTDckYc/k/MdUzfALxFdXCrrX4vYfiw4Xz5pStoHy3hu13WuWBTag2Julmeq5kY/QjGWIyssxv8bh1eoCnWhwa6V3R+xvx7 x-ms-exchange-antispam-messagedata: 1aAYiiQReTMdUq8BTNV6RvHl4K+nBzlMSslUOSiElzftvaMS4f641yWSXvHQ0qirdC5bAw5cIWfJ26ofl9OPw90TqSs4IwQ7Z7gaPqHJFWV1DHQ6Yng9s6Qhpiu8RDM9ATthRACObuJShautYWKbBw== 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: f25e4430-69e1-4521-0f62-08d7d5806d5b X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Mar 2020 14:33:06.1905 (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: uQ/bUxoX6Ynwvd5cXK8MCpb176a4ea0Wa6z2F5QotcQDafeZ1RGCyEKyc1+rhTOiHWzXMy7iwtk2eh0iURzd5g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR05MB6660 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" Hi, > -----Original Message----- > From: Jiawei Wang > Sent: Monday, March 30, 2020 6:02 AM > 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 sysfs. Firstly read the base value while application start, > then fetch the new value while do query and minus the base value. > If the new value is less than base value, will result in the a > negative value 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 64bit counter value. >=20 > Fixes: ce9494d76c4 ("net/mlx5: report imissed statistics") > Cc: stable@dpdk.org >=20 > Signed-off-by: Jiawei Wang > --- > 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 Patch applied to next-net-mlx, Kindest regards, Raslan Darawsheh