Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3866176yba; Mon, 29 Apr 2019 09:46:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwS0H3EQ8o37p99D8JSN3bFo3/FuYJyGVQlBxq4QHS8PWIoOzKbUcxT45eNWO6pypFaoG6k X-Received: by 2002:aa7:8096:: with SMTP id v22mr64083855pff.94.1556556413494; Mon, 29 Apr 2019 09:46:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556556413; cv=none; d=google.com; s=arc-20160816; b=w5AhPu1nQcPHw4NliOh1k79skJRaTt97V7WoRtw5qeg/o651vich5yjHkhbzt3EQhO /qipe+Jako/hNE3AAzjQqSztuvnLg8q1a0mjw65cpD5SMKkNig1xdFKqwLDXiAuxGT97 L0YkW/VANL+dT8XyagksMNttU8cZmgIzb0d6NqXNOxbqFf1bVZQzKiRjTNOPRc/h7vO1 wC00iErKb5ACwbQ2ligxl1Djal1RHu2dIT4UBetVrEkVs1YftqETb0h0JxS2pnNNZ2XM lmINP130ht9gkDMBfjh60cWiKxNlXeC8aQ7Q2ds9wW/vPrz+qD9s399ly4ZqdzG2EWRe 79mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=g1Yba+QgALlemKiNnIFJPcJGdSg5qg6+Ws/obYqZr2s=; b=0BRNee8918hL2POW+8okVqynOCxK3/m4oparPwZy18ppbFayVGqr7Bq0GzO7zuutCZ HwOisN0L4fIeWi/8/NqUNpmhL1IhwY9tYVegF+O13lsx9yfsYtihtbv4uOJW0X4TvrJc HITrj3HD+/jKXVxLXcUSHAFrsacYGQZrXwDSgpmFrDlp1+m4hS5JY1bu2+AHqUhFuN/i 5pBrI6Zww6FemUZau1LnfpRenukc94B3gvvCLX39aZkttMOFYl2rNW3+wTIoOjZhURlw nt+X0oOcx+fQAUXXee/pUMI0w2AaPbRU14QDtQDb5oOdN33H/RaqFJXZ12LTz9Daghag ++Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vG2Jaxvr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a22si34103949pfc.217.2019.04.29.09.46.38; Mon, 29 Apr 2019 09:46:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vG2Jaxvr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728841AbfD2Qpl (ORCPT + 99 others); Mon, 29 Apr 2019 12:45:41 -0400 Received: from mail-yw1-f66.google.com ([209.85.161.66]:33551 "EHLO mail-yw1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728629AbfD2Qpk (ORCPT ); Mon, 29 Apr 2019 12:45:40 -0400 Received: by mail-yw1-f66.google.com with SMTP id q11so3954003ywb.0; Mon, 29 Apr 2019 09:45:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=g1Yba+QgALlemKiNnIFJPcJGdSg5qg6+Ws/obYqZr2s=; b=vG2JaxvrLJn69v0XTXrXGlmN7IJahwJEOOqEOu+kB3/39GuWdeiYXPiHPidkJII8At 7RoI+VAoMqr1UNqDPAzhaUIEMu74at7sr1iZ3DAUjdDa6hQ5yiocFV6yGmZWdcrRqc7u +YWqYlKEua2bWFGRJBHOPzynYB0unnK+aSDzHsE7zgA/vxKIlJ/3ofJNX6I43nFto35L OQfDM3zmImtw3raJOjTCZZ7cayzEOCpLyr3z2xopByyrjVJ9J9R8QH4SBrKvJQkgP+IC O4nZP7P8TzzQLNDS08vMLbh+sIZEBE4HfgWr3bjtxHV7WCJFV2u/Mc6MrVPBrMc1sRFx gl6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=g1Yba+QgALlemKiNnIFJPcJGdSg5qg6+Ws/obYqZr2s=; b=CXjkWAO6v0P+9YFK2iJuNe3m+KwMZktaCbP6tcP4TDO1LbXg8UgChboUEoCeVbMFR+ 8FrVAs9WByH0+X5RwGgG+Rau/Xv9b5zNuuuFJAvEFK7Cc44KuOubRuFsM6JMXLHw4+dA hLdlZSeLu/RlNgkXb2FVHSJPd0dbDSh3rBBvNg8k5C7yjq9rhuCoVLpqzcXGJQkuVgRQ 4iAQoAA2pomPqyyNFVzoq4kseBehVUrUaMGYtAO+rWOvneTNCf/qGa0gmbaklt0NYRK3 nXsgnshUE35NSBcGe/XKpvEldwYVToBjNzbvsH3Wp1eoTKJDcG/UI+gXdSAmPVc6DCqk CdJg== X-Gm-Message-State: APjAAAVj8Coiy+9x0n8YzwSiUlpCpVkmpC5R1Exx4hhVNOzdPw4+qiOj SjM+8zMgAwJF9MMlTvlUreRpLr2SEFg7QkXXwv01/r8AAf8= X-Received: by 2002:a81:b653:: with SMTP id h19mr41969960ywk.253.1556556339615; Mon, 29 Apr 2019 09:45:39 -0700 (PDT) MIME-Version: 1.0 References: <20190429060107.10245-1-zajec5@gmail.com> <20190429092027.6013677d@hermes.lan> In-Reply-To: <20190429092027.6013677d@hermes.lan> From: =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= Date: Mon, 29 Apr 2019 18:45:28 +0200 Message-ID: Subject: Re: [PATCH] net-sysfs: expose IRQ number To: Stephen Hemminger Cc: "David S . Miller" , Network Development , Linux Kernel Mailing List , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 29 Apr 2019 at 18:20, Stephen Hemminger wrote: > On Mon, 29 Apr 2019 08:01:07 +0200 > Rafa=C5=82 Mi=C5=82ecki wrote: > > > From: Rafa=C5=82 Mi=C5=82ecki > > > > 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=C5=82 Mi=C5=82ecki > > --- > > I found a script parsing /proc/interrupts for a given interface name. I= t wasn't > > working for me as it assumed request_irq() was called with a device nam= e. 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-determ= ine-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//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 *a= ttr, > > + char *buf) > > +{ > > + const struct net_device *netdev =3D to_net_dev(dev); > > + ssize_t ret; > > + > > + if (!rtnl_trylock()) > > + return restart_syscall(); > > + ret =3D sprintf(buf, "%d\n", netdev->irq); > > + rtnl_unlock(); > > + > > + return ret; > > +} > > +static DEVICE_ATTR_RO(irq); > > + > > static struct attribute *net_class_attrs[] __ro_after_init =3D { > > &dev_attr_netdev_group.attr, > > &dev_attr_type.attr, > > @@ -542,6 +557,7 @@ static struct attribute *net_class_attrs[] __ro_aft= er_init =3D { > > &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); > > Can't you find this on the PCI side already? > $ ls /sys/class/net/eno1/device/msi_irqs/ > 37 38 39 40 41 I'm dealing with bgmac supported ethernet device on bcma bus (not PCI). I could make bcma bus provide IRQ numbers, but I thought something at net subsystem level will be more generic. I'm going to review Willem's solution/idea for now. --=20 Rafa=C5=82