Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3141155lqo; Wed, 15 May 2024 00:23:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUTkebzbxe8QaOcxXoLSEAGMyIMf6YHJe8tgX5GhuLLFae8cn69zB/XqvK5fsaA3ZwlHsHnu/VD4FQUn6/g2n1H4gCCeU/wHk4jBQpG6g== X-Google-Smtp-Source: AGHT+IFLvVJOR0KE6ThUB+XoEY1Ue3qb5JPm4zlZUccA3F8mkGakYps8IHkCtOgb5EEdhAm4oYy2 X-Received: by 2002:a05:6122:31a1:b0:4df:1d07:5ffa with SMTP id 71dfb90a1353d-4df88283d2fmr13567472e0c.3.1715757830415; Wed, 15 May 2024 00:23:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715757830; cv=pass; d=google.com; s=arc-20160816; b=UrBAc11RQsP4jIWa6j+6JUzswDWZl8Ox5V0rKHUy2i86Oh8D5u3mtrAiZsQiKTgkM4 zB6xTLvmsKlCcOcl+DQ2oXC/8rcGbnDm98hpwyEs4BzEmxLP7vPnWMRZIPBDXmGgjmnI GdskzO/Rh7vFNzFwQEYTojShR6C5hy6BIGqU75wD6CZJ65f4rZqUAzs4wjv/NVVtJ4XJ VHpGYlL3dIOdwCeL64WsP4tuQr5OGhZldPU4u6rq5rqREWZZl05c3ts9A6YsGkicCbhP Zj+vz2Mmq1z4ES5OWf9VceCfBj40IBrnULIFy0TrUiobvCb1564n6guEk9Dyd6f7fvoh agvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=vInc6tO6gm1EBIF0gkzHCYRIhFoOvwprPtnR3toXSdo=; fh=+m1BffB8bC2M8IQ0Qhc3XAKmMfZrsBBwXGgFYK7UNEM=; b=gOp2KLBH5gC44qBzlJjVSsxSYMD1YiUPKRGLP+KP55u6gdWAShcJumm6ICML/wsHaK XV0Y/0HijcCjevFsywpkyQtqGFOnC+42dY8qx/xpwYVk96eE03OgE8NEUgN7o/nv07DD nHVmOhmOCkZjAjSFlTIlZXnMtZexjlXjUtcrs32N6nP6NYhDSV+tr6aaYoQkBEZ/sRDO yZR3f5KReW4FMwL4b1arag6rh5Tk+Znji22MDqzqnhgXQHZinjwP5+7JWLb25r8QqByO ThKpf9kugU4dVMTuafI6ux0rYdEUqFaepPHDNi//oqLMOmETOcsNKveaPi13W3hsfPBd qtIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=F7cveteS; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-179575-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179575-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id af79cd13be357-792bf33b051si1298992685a.466.2024.05.15.00.23.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 00:23:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179575-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@fastly.com header.s=google header.b=F7cveteS; arc=pass (i=1 spf=pass spfdomain=fastly.com dkim=pass dkdomain=fastly.com dmarc=pass fromdomain=fastly.com); spf=pass (google.com: domain of linux-kernel+bounces-179575-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179575-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=fastly.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 146681C21D56 for ; Wed, 15 May 2024 07:23:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3543044C81; Wed, 15 May 2024 07:19:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b="F7cveteS" Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2215A42061 for ; Wed, 15 May 2024 07:19:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715757579; cv=none; b=kUlU/sp+dlvw7h7m0xM2I36t2fAibEijNMlem+cl5Eo6QhyMnwS7aj8QKefS4rczTO+wcGk9ay+TR4TCz25ee16TxXxFbiOwwZEAilA6I0k1tr3HbsPPQrcEkxIsCGVHR1P/viX542e6f6pBysSKPE7oweoPTZkWn+XSYzLVltQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715757579; c=relaxed/simple; bh=mS08T4zIxogbYBvEKUHiOAoYLAIbH6I61MwGI+XhY1I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aiC3Injg50K2w3uq4gkPkZBeWHr9FdG+xanNlQR8k8vmSiORQtdnq6/C9E1cVrlegr2AKTNdJeM3Xa+tHyi5PVaW4azYQD/L9/7CDVROnqhB5ZYKZ8IbTvz1mjCVJTf75l89rZ12DMYeqWJa48ehifZRILihSibKbCK97A/jKvs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com; spf=pass smtp.mailfrom=fastly.com; dkim=pass (1024-bit key) header.d=fastly.com header.i=@fastly.com header.b=F7cveteS; arc=none smtp.client-ip=209.85.210.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=fastly.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastly.com Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-6f054c567e2so4037667a34.2 for ; Wed, 15 May 2024 00:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastly.com; s=google; t=1715757576; x=1716362376; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=vInc6tO6gm1EBIF0gkzHCYRIhFoOvwprPtnR3toXSdo=; b=F7cveteSjC8s+OVdJoS1d+mrxpZuzNI9m11PWbt/z407Fa9sJl6adckzZqXkdfysko GMpLRo/WLEwx2QTYfcg+z2Q8S/ik6Wa+ukun89XysrhnSckGrh1rYWwIevQvu+4YmZH+ IzzZx7L+OJSFh1gFPPnjO5/BWcjjnUEZk+oyw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715757576; x=1716362376; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vInc6tO6gm1EBIF0gkzHCYRIhFoOvwprPtnR3toXSdo=; b=bRUndoNJV3Ey6kAwE9f4WjvSWRO7VXXQSFoNc92XU1NfD/dR6+5RkpZ9zVoLFSQFCc 6sZn9netgzwsR6fFCEsikdI99ja1yMvS9RO+Bya5QUEee+DpJ652VXeIhReV8D57zVzn BN2vibauBOMzayM96jXM6n0046/WzJg+JPulJtJNk5VvkgXe2GNXXmVhstnsKan9f1px P2tMqTdxyJXpweBDhyV3zmC14Biyc30gowLzyeHGx4gz+xTYHV2SDbj6oXHhHU4eFNaT 4Z3eHZqZtY99kEIUyT1CmyY7DmYvAnx6fz+KGvfibArsrqiHKfv4GQ5w97MkKG49LhR3 N1yQ== X-Gm-Message-State: AOJu0YyiLE+EhoDjzHjUEG2Hrmetj50Tgp9u/0iRyPB8RGhsETKpet66 YNUNbkq/gWRK+hDr2H/LnoMZ03rqAJ0hMsrg0TVlE3pNdVDRQQSx12kAJPkqvr0= X-Received: by 2002:a05:6830:1515:b0:6f0:e78d:7019 with SMTP id 46e09a7af769-6f0e9112427mr18418109a34.16.1715757576061; Wed, 15 May 2024 00:19:36 -0700 (PDT) Received: from LQ3V64L9R2 ([2601:3c7:4200:9500:c97:2507:4743:1383]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5b2b155b94csm1390433eaf.27.2024.05.15.00.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 00:19:35 -0700 (PDT) Date: Wed, 15 May 2024 02:19:33 -0500 From: Joe Damato To: Tariq Toukan Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, zyjzyj2000@gmail.com, nalramli@fastly.com, Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , "open list:MELLANOX MLX5 core VPI driver" , Tariq Toukan Subject: Re: [PATCH net-next v2 1/1] net/mlx5e: Add per queue netdev-genl stats Message-ID: Mail-Followup-To: Joe Damato , Tariq Toukan , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, zyjzyj2000@gmail.com, nalramli@fastly.com, Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran , "open list:MELLANOX MLX5 core VPI driver" , Tariq Toukan References: <20240510041705.96453-1-jdamato@fastly.com> <20240510041705.96453-2-jdamato@fastly.com> <230701b9-c52a-4b59-9969-4cd5a5d697f4@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <230701b9-c52a-4b59-9969-4cd5a5d697f4@gmail.com> On Tue, May 14, 2024 at 09:44:37PM +0300, Tariq Toukan wrote: > > > On 10/05/2024 7:17, Joe Damato wrote: > > Add functions to support the netdev-genl per queue stats API. > > > > ./cli.py --spec netlink/specs/netdev.yaml \ > > --dump qstats-get --json '{"scope": "queue"}' > > > > ...snip > > > > {'ifindex': 7, > > 'queue-id': 62, > > 'queue-type': 'rx', > > 'rx-alloc-fail': 0, > > 'rx-bytes': 105965251, > > 'rx-packets': 179790}, > > {'ifindex': 7, > > 'queue-id': 0, > > 'queue-type': 'tx', > > 'tx-bytes': 9402665, > > 'tx-packets': 17551}, > > > > ...snip > > > > Also tested with the script tools/testing/selftests/drivers/net/stats.py > > in several scenarios to ensure stats tallying was correct: > > > > - on boot (default queue counts) > > - adjusting queue count up or down (ethtool -L eth0 combined ...) > > - adding mqprio TCs > > > > Signed-off-by: Joe Damato > > --- > > .../net/ethernet/mellanox/mlx5/core/en_main.c | 144 ++++++++++++++++++ > > 1 file changed, 144 insertions(+) > > > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c > > index ffe8919494d5..4a675d8b31b5 100644 > > --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c > > +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c > > @@ -39,6 +39,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -5282,6 +5283,148 @@ static bool mlx5e_tunnel_any_tx_proto_supported(struct mlx5_core_dev *mdev) > > return (mlx5_vxlan_allowed(mdev->vxlan) || mlx5_geneve_tx_allowed(mdev)); > > } > > +static void mlx5e_get_queue_stats_rx(struct net_device *dev, int i, > > + struct netdev_queue_stats_rx *stats) > > +{ > > + struct mlx5e_priv *priv = netdev_priv(dev); > > + > > + if (mlx5e_is_uplink_rep(priv)) > > + return; > > + > > + struct mlx5e_channel_stats *channel_stats = priv->channel_stats[i]; > > + struct mlx5e_rq_stats *xskrq_stats = &channel_stats->xskrq; > > + struct mlx5e_rq_stats *rq_stats = &channel_stats->rq; > > + > > Don't we allow variable declaration only at the beginning of a block? > Is this style accepted in the networking subsystem? > > > + stats->packets = rq_stats->packets + xskrq_stats->packets; > > + stats->bytes = rq_stats->bytes + xskrq_stats->bytes; > > + stats->alloc_fail = rq_stats->buff_alloc_err + > > + xskrq_stats->buff_alloc_err; > > +} > > + > > +static void mlx5e_get_queue_stats_tx(struct net_device *dev, int i, > > + struct netdev_queue_stats_tx *stats) > > +{ > > + struct mlx5e_priv *priv = netdev_priv(dev); > > + struct net_device *netdev = priv->netdev; > > + struct mlx5e_txqsq *sq; > > + int j; > > + > > + if (mlx5e_is_uplink_rep(priv)) > > + return; > > + > > + for (j = 0; j < netdev->num_tx_queues; j++) { > > + sq = priv->txq2sq[j]; > > No sq instance in case interface is down. This seems easily fixable by checking: priv->channels.num > 0 > This should be a simple arithmetic calculation. I'm not sure why I can't use txq2sq? Please see below for my explanation about why I think txq2sq might be all I need. > Need to expose the proper functions for this calculation, and use it here > and in the sq create flows. I re-read the code several times and my apologies, but I am probably still missing something. I don't think a calculation function is necessary (see below), but if one is really needed, I'd probably add something like: static inline int tc_to_txq_ix(struct mlx5e_channel *c, struct mlx5e_params *params, int tc) { return c->ix + tc * params->num_channels; } And call it from mlx5e_open_sqs. But, I don't understand why any calculation is needed in mlx5e_get_queue_stats_tx. Please see below for explanation. > > Here it seems that you need a very involved user, so he passes the correct > index i of the SQ that he's interested in.. > > > + if (sq->ch_ix == i) { > > So you're looking for the first SQ on channel i? > But there might be multiple SQs on channel i... > Also, this SQ might be already included in the base stats. > In addition, this i might be too large for a channel index (num_tx_queues > can be 8 * num_channels) > > The logic here (of mapping from i in num_tx_queues to SQ stats) needs > careful definition. I read your comments a few times and read the mlx5 source and I am probably still missing something obvious here; my apologies. In net/core/netdev-genl.c, calls to the driver's get_queue_stats_tx appear to pass [0, netdev->real_num_tx_queues) as i. I think this means i is a txq_ix in mlx5, because mlx5 sets netdev->real_num_tx_queues in mlx5e_update_tx_netdev_queues, as: nch * ntc + qos_queues which when expanded is priv->channels.params.num_channels * mlx5e_get_dcb_num_tc + qos_queues So, net/core/netdev-genl.c will be using 0 up to that expression as i when calling mlx5e_get_queue_stats_tx. In mlx5: - mlx5e_activate_priv_channels calls mlx5e_build_txq_maps which generates priv->txq2sq[txq_ix] = sq for every mlx5e_get_dcb_num_tc of every priv->channels.num. This seems to happen every time mlx5e_activate_priv_channels is called, which I think means that priv->txq2sq is always up to date and will give the right sq for a given txq_ix (assuming the device isn't down). Putting all of this together, I think that mlx5e_get_queue_stats_tx might need to be something like: mutex_lock(&priv->state_lock); if (priv->channels.num > 0) { sq = priv->txq2sq[i]; stats->packets = sq->stats->packets; stats->bytes = sq->stats->bytes; } mutex_unlock(&priv->state_lock); Is this still incorrect somehow? If so, could you explain a bit more about why a calculation is needed? It seems like txq2sq would provide the mapping from txq_ix's (which is what mlx5e_get_queue_stats_tx gets as 'i') and an sq, which seems like all I would need? Sorry if I am still not following here. > > + stats->packets = sq->stats->packets; > > + stats->bytes = sq->stats->bytes; > > + return; > > + } > > + } > > +} > > + > > +static void mlx5e_get_base_stats(struct net_device *dev, > > + struct netdev_queue_stats_rx *rx, > > + struct netdev_queue_stats_tx *tx) > > +{ > > + struct mlx5e_priv *priv = netdev_priv(dev); > > + int i, j; > > + > > + if (!mlx5e_is_uplink_rep(priv)) { > > + rx->packets = 0; > > + rx->bytes = 0; > > + rx->alloc_fail = 0; > > + > > + /* compute stats for deactivated RX queues > > + * > > + * if priv->channels.num == 0 the device is down, so compute > > + * stats for every queue. > > + * > > + * otherwise, compute only the queues which have been deactivated. > > + */ > > + if (priv->channels.num == 0) > > + i = 0; > > + else > > + i = priv->channels.params.num_channels; > > + > > + for (; i < priv->stats_nch; i++) { > > + struct mlx5e_channel_stats *channel_stats = priv->channel_stats[i]; > > + struct mlx5e_rq_stats *xskrq_stats = &channel_stats->xskrq; > > + struct mlx5e_rq_stats *rq_stats = &channel_stats->rq; > > + > > + rx->packets += rq_stats->packets + xskrq_stats->packets; > > + rx->bytes += rq_stats->bytes + xskrq_stats->bytes; > > + rx->alloc_fail += rq_stats->buff_alloc_err + > > + xskrq_stats->buff_alloc_err; > > Isn't this equivalent to mlx5e_get_queue_stats_rx(i) ? > > > + } > > + > > + if (priv->rx_ptp_opened) { > > + struct mlx5e_rq_stats *rq_stats = &priv->ptp_stats.rq; > > + > > + rx->packets += rq_stats->packets; > > + rx->bytes += rq_stats->bytes; > > + } > > + } > > + > > + tx->packets = 0; > > + tx->bytes = 0; > > + > > + /* three TX cases to handle: > > + * > > + * case 1: priv->channels.num == 0, get the stats for every TC > > + * on every queue. > > + * > > + * case 2: priv->channel.num > 0, so get the stats for every TC on > > + * every deactivated queue. > > + * > > + * case 3: the number of TCs has changed, so get the stats for the > > + * inactive TCs on active TX queues (handled in the second loop > > + * below). > > + */ > > + if (priv->channels.num == 0) > > + i = 0; > > + else > > + i = priv->channels.params.num_channels; > > + > > All reads/writes to priv->channels must be under the priv->state_lock. > > > + for (; i < priv->stats_nch; i++) { > > + struct mlx5e_channel_stats *channel_stats = priv->channel_stats[i]; > > + > > + for (j = 0; j < priv->max_opened_tc; j++) { > > + struct mlx5e_sq_stats *sq_stats = &channel_stats->sq[j]; > > + > > + tx->packets += sq_stats->packets; > > + tx->bytes += sq_stats->bytes; > > + } > > + } > > + > > + /* Handle case 3 described above. */ > > + for (i = 0; i < priv->channels.params.num_channels; i++) { > > + struct mlx5e_channel_stats *channel_stats = priv->channel_stats[i]; > > + u8 dcb_num_tc = mlx5e_get_dcb_num_tc(&priv->channels.params); > > + > > + for (j = dcb_num_tc; j < priv->max_opened_tc; j++) { > > + struct mlx5e_sq_stats *sq_stats = &channel_stats->sq[j]; > > + > > + tx->packets += sq_stats->packets; > > + tx->bytes += sq_stats->bytes; > > + } > > + } > > + > > + if (priv->tx_ptp_opened) { > > + for (j = 0; j < priv->max_opened_tc; j++) { > > + struct mlx5e_sq_stats *sq_stats = &priv->ptp_stats.sq[j]; > > + > > + tx->packets += sq_stats->packets; > > + tx->bytes += sq_stats->bytes; > > + } > > + } > > +} > > + > > +static const struct netdev_stat_ops mlx5e_stat_ops = { > > + .get_queue_stats_rx = mlx5e_get_queue_stats_rx, > > + .get_queue_stats_tx = mlx5e_get_queue_stats_tx, > > + .get_base_stats = mlx5e_get_base_stats, > > +}; > > + > > static void mlx5e_build_nic_netdev(struct net_device *netdev) > > { > > struct mlx5e_priv *priv = netdev_priv(netdev); > > @@ -5299,6 +5442,7 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev) > > netdev->watchdog_timeo = 15 * HZ; > > + netdev->stat_ops = &mlx5e_stat_ops; > > netdev->ethtool_ops = &mlx5e_ethtool_ops; > > netdev->vlan_features |= NETIF_F_SG;