lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250304190504.3743-5-darinzon@amazon.com>
Date: Tue, 4 Mar 2025 21:05:03 +0200
From: David Arinzon <darinzon@...zon.com>
To: David Miller <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>,
	<netdev@...r.kernel.org>
CC: David Arinzon <darinzon@...zon.com>, Eric Dumazet <edumazet@...gle.com>,
	Paolo Abeni <pabeni@...hat.com>, Simon Horman <horms@...nel.org>, "Richard
 Cochran" <richardcochran@...il.com>, "Woodhouse, David" <dwmw@...zon.com>,
	"Machulsky, Zorik" <zorik@...zon.com>, "Matushevsky, Alexander"
	<matua@...zon.com>, Saeed Bshara <saeedb@...zon.com>, "Wilson, Matt"
	<msw@...zon.com>, "Liguori, Anthony" <aliguori@...zon.com>, "Bshara, Nafea"
	<nafea@...zon.com>, "Schmeilin, Evgeny" <evgenys@...zon.com>, "Belgazal,
 Netanel" <netanel@...zon.com>, "Saidi, Ali" <alisaidi@...zon.com>,
	"Herrenschmidt, Benjamin" <benh@...zon.com>, "Kiyanovski, Arthur"
	<akiyano@...zon.com>, "Dagan, Noam" <ndagan@...zon.com>, "Bernstein, Amit"
	<amitbern@...zon.com>, "Agroskin, Shay" <shayagr@...zon.com>, "Ostrovsky,
 Evgeny" <evostrov@...zon.com>, "Tabachnik, Ofir" <ofirt@...zon.com>,
	"Machnikowski, Maciek" <maciek@...hnikowski.net>, Rahul Rameshbabu
	<rrameshbabu@...dia.com>, Gal Pressman <gal@...dia.com>, Vadim Fedorenko
	<vadim.fedorenko@...ux.dev>
Subject: [PATCH v8 net-next 4/5] net: ena: PHC stats through sysfs

The patch allows retrieving PHC statistics
through sysfs.
In case the feature is not enabled (through `phc_enable`
sysfs entry), no output will be written.

Signed-off-by: David Arinzon <darinzon@...zon.com>
---
 drivers/net/ethernet/amazon/ena/ena_sysfs.c | 80 +++++++++++++++++++++
 1 file changed, 80 insertions(+)

diff --git a/drivers/net/ethernet/amazon/ena/ena_sysfs.c b/drivers/net/ethernet/amazon/ena/ena_sysfs.c
index d0ded92d..441085d2 100644
--- a/drivers/net/ethernet/amazon/ena/ena_sysfs.c
+++ b/drivers/net/ethernet/amazon/ena/ena_sysfs.c
@@ -65,6 +65,82 @@ static ssize_t ena_phc_enable_get(struct device *dev,
 static DEVICE_ATTR(phc_enable, S_IRUGO | S_IWUSR, ena_phc_enable_get,
 		   ena_phc_enable_set);
 
+/* Takes into account max u64 value, null and new line characters */
+#define ENA_PHC_STAT_MAX_LEN 22
+
+static ssize_t ena_phc_cnt_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct ena_adapter *adapter = dev_get_drvdata(dev);
+
+	if (!ena_phc_is_active(adapter))
+		return 0;
+
+	return snprintf(buf, ENA_PHC_STAT_MAX_LEN, "%llu\n",
+			adapter->ena_dev->phc.stats.phc_cnt);
+}
+
+static DEVICE_ATTR(phc_cnt, S_IRUGO, ena_phc_cnt_show, NULL);
+
+static ssize_t ena_phc_exp_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct ena_adapter *adapter = dev_get_drvdata(dev);
+
+	if (!ena_phc_is_active(adapter))
+		return 0;
+
+	return snprintf(buf, ENA_PHC_STAT_MAX_LEN, "%llu\n",
+			adapter->ena_dev->phc.stats.phc_exp);
+}
+
+static DEVICE_ATTR(phc_exp, S_IRUGO, ena_phc_exp_show, NULL);
+
+static ssize_t ena_phc_skp_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct ena_adapter *adapter = dev_get_drvdata(dev);
+
+	if (!ena_phc_is_active(adapter))
+		return 0;
+
+	return snprintf(buf, ENA_PHC_STAT_MAX_LEN, "%llu\n",
+			adapter->ena_dev->phc.stats.phc_skp);
+}
+
+static DEVICE_ATTR(phc_skp, S_IRUGO, ena_phc_skp_show, NULL);
+
+static ssize_t ena_phc_err_show(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct ena_adapter *adapter = dev_get_drvdata(dev);
+
+	if (!ena_phc_is_active(adapter))
+		return 0;
+
+	return snprintf(buf, ENA_PHC_STAT_MAX_LEN, "%llu\n",
+			adapter->ena_dev->phc.stats.phc_err);
+}
+
+static DEVICE_ATTR(phc_err, S_IRUGO, ena_phc_err_show, NULL);
+
+static struct attribute *phc_stats_attrs[] = {
+	&dev_attr_phc_cnt.attr,
+	&dev_attr_phc_exp.attr,
+	&dev_attr_phc_skp.attr,
+	&dev_attr_phc_err.attr,
+	NULL
+};
+
+static struct attribute_group phc_stats_group = {
+	.attrs = phc_stats_attrs,
+	.name = "phc_stats",
+};
+
 /******************************************************************************
  *****************************************************************************/
 int ena_sysfs_init(struct device *dev)
@@ -72,6 +148,9 @@ int ena_sysfs_init(struct device *dev)
 	if (device_create_file(dev, &dev_attr_phc_enable))
 		dev_err(dev, "Failed to create phc_enable sysfs entry");
 
+	if (device_add_group(dev, &phc_stats_group))
+		dev_err(dev, "Failed to create phc_stats sysfs group");
+
 	return 0;
 }
 
@@ -80,4 +159,5 @@ int ena_sysfs_init(struct device *dev)
 void ena_sysfs_terminate(struct device *dev)
 {
 	device_remove_file(dev, &dev_attr_phc_enable);
+	device_remove_group(dev, &phc_stats_group);
 }
-- 
2.47.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ