From: "Rafał Miłecki" <zajec5@gmail.com>
To: "David S . Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
"Rafał Miłecki" <rafal@milecki.pl>
Subject: [PATCH] net-sysfs: expose IRQ number
Date: Mon, 29 Apr 2019 08:01:07 +0200 [thread overview]
Message-ID: <20190429060107.10245-1-zajec5@gmail.com> (raw)
From: Rafał Miłecki <rafal@milecki.pl>
Knowing IRQ number makes e.g. reading /proc/interrupts much simpler.
It's more reliable than guessing device name used by a driver when
calling request_irq().
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
I found a script parsing /proc/interrupts for a given interface name. It wasn't
working for me as it assumed request_irq() was called with a device name. It's
not a case for all drivers.
I also found some other people looking for a proper solution for that:
https://unix.stackexchange.com/questions/275075/programmatically-determine-the-irqs-associated-with-a-network-interface
https://stackoverflow.com/questions/7516984/retrieving-irq-number-of-a-nic
Let me know if this solution makes sense. I can say it works for me ;)
---
Documentation/ABI/testing/sysfs-class-net | 7 +++++++
net/core/net-sysfs.c | 16 ++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-class-net b/Documentation/ABI/testing/sysfs-class-net
index 664a8f6a634f..33440fe77ca7 100644
--- a/Documentation/ABI/testing/sysfs-class-net
+++ b/Documentation/ABI/testing/sysfs-class-net
@@ -301,3 +301,10 @@ Contact: netdev@vger.kernel.org
Description:
32-bit unsigned integer counting the number of times the link has
been down
+
+What: /sys/class/net/<iface>/irq
+Date: April 2019
+KernelVersion: 5.2
+Contact: netdev@vger.kernel.org
+Description:
+ IRQ number used by device
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index e4fd68389d6f..a3eb7c3f1f37 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -512,6 +512,21 @@ static ssize_t phys_switch_id_show(struct device *dev,
}
static DEVICE_ATTR_RO(phys_switch_id);
+static ssize_t irq_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ const struct net_device *netdev = to_net_dev(dev);
+ ssize_t ret;
+
+ if (!rtnl_trylock())
+ return restart_syscall();
+ ret = sprintf(buf, "%d\n", netdev->irq);
+ rtnl_unlock();
+
+ return ret;
+}
+static DEVICE_ATTR_RO(irq);
+
static struct attribute *net_class_attrs[] __ro_after_init = {
&dev_attr_netdev_group.attr,
&dev_attr_type.attr,
@@ -542,6 +557,7 @@ static struct attribute *net_class_attrs[] __ro_after_init = {
&dev_attr_proto_down.attr,
&dev_attr_carrier_up_count.attr,
&dev_attr_carrier_down_count.attr,
+ &dev_attr_irq.attr,
NULL,
};
ATTRIBUTE_GROUPS(net_class);
--
2.21.0
next reply other threads:[~2019-04-29 6:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-29 6:01 Rafał Miłecki [this message]
2019-04-29 16:15 ` [PATCH] net-sysfs: expose IRQ number Willem de Bruijn
2019-04-29 16:20 ` Stephen Hemminger
2019-04-29 16:45 ` Rafał Miłecki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190429060107.10245-1-zajec5@gmail.com \
--to=zajec5@gmail.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rafal@milecki.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).