From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D0EE18E37A for ; Tue, 20 Aug 2024 20:02:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724184175; cv=none; b=YIpZw/PYZFbc0+6XMvBUzFFd7P2cwiv6sct0VjNs/5SCaCnmZkhwTMHtgkUj4FcNOBurHqNh/J/7fYb4UunssMquPhKpo1AgfwIPEkeXnmr7IC171G3E5XzuciG74TCyHB39CqDwbXdGqlSeLbD2IphlY/jCber5kwU0IsmxDPU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724184175; c=relaxed/simple; bh=GNtqUA7xiKx52NKreqjOI2Wa3/fykoaR+q4UKI0lZUc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=c3q+yu/oAh1it3J0ncgtkZXDW5rU12omCCMElVnOb1wwjCbRn8j+unSh0QDpIpAOv1w0FImdZvWQ8GBfwuez902ngnvFQbC55Mm2nim0RpPdHwKAv98FNRsRtHJh0WEi7/5He84xnQ9H3j1Qea38USCl+J07owaNHGxHSVDOxFA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=X3JANH2n; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="X3JANH2n" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1724184170; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=x+Xnac8NFnrgWa0w+0I5z9TRviIwR6516HIJjJX2blg=; b=X3JANH2niWLsnw+n9r57hQETNGwH4SMKfpkCKDR9GwL/wwRNW1n+SmZTS5AFKhSQFWJkqb VozSK/e6POx05Q1RdVGjqjIZK0fcqa7bYCwmlebB0pV8MmBtE81PwTb5NoeOQCB8TS7Hox D8LgaGNzJHek9Gr9WqghmJlApUBgQhg= Date: Tue, 20 Aug 2024 16:02:45 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH net-next v4 2/2] net: xilinx: axienet: Add statistics support To: "Pandey, Radhey Shyam" , Andrew Lunn , "netdev@vger.kernel.org" Cc: "Simek, Michal" , "linux-kernel@vger.kernel.org" , Russell King , "David S . Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , Simon Horman , "linux-arm-kernel@lists.infradead.org" , "Katakam, Harini" References: <20240820175343.760389-1-sean.anderson@linux.dev> <20240820175343.760389-3-sean.anderson@linux.dev> Content-Language: en-US X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Sean Anderson In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 8/20/24 15:04, Pandey, Radhey Shyam wrote: >> -----Original Message----- >> From: Sean Anderson >> Sent: Tuesday, August 20, 2024 11:24 PM >> To: Andrew Lunn ; Pandey, Radhey Shyam >> ; netdev@vger.kernel.org >> Cc: Simek, Michal ; linux-kernel@vger.kernel.org; >> Russell King ; David S . Miller >> ; Jakub Kicinski ; Paolo Abeni >> ; Eric Dumazet ; Simon >> Horman ; linux-arm-kernel@lists.infradead.org; Sean >> Anderson >> Subject: [PATCH net-next v4 2/2] net: xilinx: axienet: Add statistics support >> >> Add support for reading the statistics counters, if they are enabled. >> The counters may be 64-bit, but we can't detect this statically as >> there's no ability bit for it and the counters are read-only. Therefore, >> we assume the counters are 32-bits by default. To ensure we don't miss > > Any reason why we can't have DT property to detect if stats counter > are configured as 32-bit /64bit? The IP export CONFIG.Statistics_Width > and device tree generator can read this IP block property and populate > stats width property. Mainly simplicity: - We need the functions to work with 32-bit counters anyway - We can always treat 64-bit counters are 32-bit counters - The reset issue below necessitates keeping track of a "base" anyway. And for my devicetrees (generated with 2022.2) all I get is xlnx,stats = <0x1>; regardless of whether I select 32- or 64-bit counters. So this wouldn't be something we could reuse from existing devictrees. >> an overflow, we read all counters at 13-second intervals. This should be >> often enough to ensure the bytes counters don't wrap at 2.5 Gbit/s. >> >> Another complication is that the counters may be reset when the device >> is reset (depending on configuration). To ensure the counters persist >> across link up/down (including suspend/resume), we maintain our own >> versions along with the last counter value we saw. Because we might wait > > Is that a standard convention to retain/persist counter values across > link up/down? IEEE 802.3 section 30.2.1 says | All counters defined in this specification are assumed to be | wrap-around counters. Wrap-around counters are those that | automatically go from their maximum value (or final value) to zero and | continue to operate. These unsigned counters do not provide for any | explicit means to return them to their minimum (zero), i.e., reset. And get_eth_mac_stats implements these counters for Linux. So I would say that resetting the counters on link up/down would be non-conformant. Other drivers also preserve stats across link up/down. For example, MACB/GEM doesn't reset it stats either. And keeping the stats is also more friendly for users and monitoring tools. --- If you happen to have an ear with the RTL designers, I would say that saturating, clear-on-read counters would be much easier to work with in software. --Sean >> up to 100 ms for the reset to complete, we use a mutex to protect >> writing hw_stats. We can't sleep in ndo_get_stats64, so we use a seqlock >> to protect readers. >> >> We don't bother disabling the refresh work when we detect 64-bit >> counters. This is because the reset issue requires us to read >> hw_stat_base and reset_in_progress anyway, which would still require the >> seqcount. And I don't think skipping the task is worth the extra >> bookkeeping. >> >> We can't use the byte counters for either get_stats64 or >> get_eth_mac_stats. This is because the byte counters include everything >> in the frame (destination address to FCS, inclusive). But >> rtnl_link_stats64 wants bytes excluding the FCS, and >> ethtool_eth_mac_stats wants to exclude the L2 overhead (addresses and >> length/type). It might be possible to calculate the byte values Linux >> expects based on the frame counters, but I think it is simpler to use >> the existing software counters. >> >> get_ethtool_stats is implemented for nonstandard statistics. This >> includes the aforementioned byte counters, VLAN and PFC frame >> counters, and user-defined (e.g. with custom RTL) counters. >> >> Signed-off-by: Sean Anderson --Sean