From: Thomas Gleixner <tglx@linutronix.de>
To: Craig Gallek <kraigatgoog@gmail.com>
Cc: David Decotigny <decot@google.com>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH RESEND] genirq: Machine-parsable version of /proc/interrupts
Date: Fri, 2 Sep 2016 16:59:09 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.20.1609021626430.5647@nanos> (raw)
In-Reply-To: <1469543126-158620-1-git-send-email-kraigatgoog@gmail.com>
On Tue, 26 Jul 2016, Craig Gallek wrote:
> /*
> * Core internal functions to deal with irq descriptors
> @@ -92,6 +93,7 @@ struct irq_desc {
> int parent_irq;
> struct module *owner;
> const char *name;
> + struct kobject kobj;
Lacks a docbook comment.
> @@ -121,6 +122,145 @@ EXPORT_SYMBOL_GPL(nr_irqs);
> static DEFINE_MUTEX(sparse_irq_lock);
> static DECLARE_BITMAP(allocated_irqs, IRQ_BITMAP_BITS);
>
> +struct kobject *irq_kobj;
That wants to be static. Aside of that the variable name
sucks. irq_kobj_base or such would be self explaining.
> +#define IRQ_ATTR_RO(_name) \
> +static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
All these show() functions want to be conditional on CONFIG_SYSFS
> +static ssize_t per_cpu_count_show(struct kobject *kobj,
> + struct kobj_attribute *attr, char *buf)
> +{
> + struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
> + int i;
> + unsigned long flags;
> + ssize_t ret = 0;
Can you please order the variables as we do everywhere else?
+ struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
+ unsigned long flags;
+ ssize_t ret = 0;
+ int i;
Hmm?
> +
> + raw_spin_lock_irqsave(&desc->lock, flags);
Why would we need locking for this? The count is unsigned int, so you can
access it lockless.
> + for_each_online_cpu(i) {
> + unsigned int c = kstat_irqs_cpu(desc->irq_data.irq, i);
Missing new line between variable declaration and code.
> + if (!ret)
> + ret = sprintf(buf, "%u", c);
> + else
> + ret += scnprintf(buf+ret, PAGE_SIZE-ret, ",%u", c);
'buf + ret', PAGE_SIZE - ret,
Please.
> + }
> + raw_spin_unlock_irqrestore(&desc->lock, flags);
> +
> + if (ret)
This conditional is pointless. There is always at least one cpu online
otherwise you would not be executing this function ....
> + ret += scnprintf(buf+ret, PAGE_SIZE-ret, "\n");
And the whole thing can be simplified to:
int cpu, irq = desc->irq_data.irq;
ssize_t ret = 0;
char *p = "";
for_each_online_cpu(cpu) {
unsigned int c = kstat_irqs_cpu(irq, cpu);
ret += scnprintf(buf + ret , PAGE_SIZE - ret, "%s%u", p, c);
p = ",";
}
ret += scnprintf(buf + ret , PAGE_SIZE - ret, "\n");
return ret;
Hmm?
> +IRQ_ATTR_RO(per_cpu_count);
> +
> +static ssize_t chip_name_show(struct kobject *kobj,
> + struct kobj_attribute *attr, char *buf)
> +{
> + struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
> + unsigned long flags;
> + ssize_t ret = 0;
> +
> + raw_spin_lock_irqsave(&desc->lock, flags);
raw_spin_lock_irq() because this is always called from non interrupt
disabled code. No need for flags.
> + if (desc->irq_data.chip->name)
chip can be NULL .....
> + ret = scnprintf(buf, PAGE_SIZE, "%s\n",
> + desc->irq_data.chip->name);
If you break the line of the conditional statement, please add
a pair of curly braces.
> +static ssize_t actions_show(struct kobject *kobj,
> + struct kobj_attribute *attr, char *buf)
> +{
> + struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
> + struct irqaction *action;
> + unsigned long flags;
> + ssize_t ret = 0;
> +
> + raw_spin_lock_irqsave(&desc->lock, flags);
> + for (action = desc->action; action != NULL; action = action->next) {
> + if (!ret)
> + ret = scnprintf(buf, PAGE_SIZE, "%s", action->name);
> + else
> + ret += scnprintf(buf+ret, PAGE_SIZE-ret, ",%s",
> + action->name);
> + }
> + raw_spin_unlock_irqrestore(&desc->lock, flags);
> +
> + if (ret)
> + ret += scnprintf(buf+ret, PAGE_SIZE-ret, "\n");
Can be deuglified as well.
> @@ -261,6 +410,12 @@ static int alloc_descs(unsigned int start, unsigned int cnt, int node,
> goto err;
> mutex_lock(&sparse_irq_lock);
> irq_insert_desc(start + i, desc);
> + if (irq_kobj) {
> + if (kobject_add(&desc->kobj, irq_kobj, "%d", start + i))
> + printk(KERN_WARNING
> + "Fail to add kobject for irq %d\n",
> + start + i);
pr_warn please
> + }
Please split that out into a a helper function. irq_sysfs_add() or such so
you avoid that mess in the code and you can reuse that for the init stuff.
> +static void irq_kobj_release(struct kobject *kobj)
> +{
> + struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
> +
> + /*
> + * This irq_desc is statically allocated. Simply zero its kobject
> + * rather than kfree it.
> + */
> + memset(&desc->kobj, 0, sizeof(desc->kobj));
This will nicely explode when the irq descriptor is handed out again before
this function is called.
There is no point to make this work for !SPARSE_IRQ. Just ignore it.
> +static int __init irq_sysfs_init(void)
Again: CONFIG_SYSFS ....
> +{
> + int i;
> +
> + irq_kobj = kobject_create_and_add("irq", kernel_kobj);
> + if (!irq_kobj)
> + return -ENOMEM;
> +
> + irq_lock_sparse();
> + for (i = 0; i < nr_irqs; ++i) {
for_each_irq_desc() ....
> + struct irq_desc *desc = irq_to_desc(i);
> +
> + if (!desc)
> + continue;
> +
> + if (kobject_add(&desc->kobj, irq_kobj, "%d", i))
> + printk(KERN_WARNING
> + "Fail to add kobject for irq %d\n", i);
So you managed to copy the same thing 3 times ....
Thanks,
tglx
next prev parent reply other threads:[~2016-09-02 15:01 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-26 14:25 [PATCH RESEND] genirq: Machine-parsable version of /proc/interrupts Craig Gallek
2016-08-10 15:26 ` Craig Gallek
2016-09-02 13:52 ` Thomas Gleixner
2016-09-02 14:59 ` Thomas Gleixner [this message]
2016-09-06 20:55 ` Craig Gallek
2016-09-09 6:15 ` Thomas Gleixner
2016-09-08 17:34 ` [PATCH v2] " Craig Gallek
2016-09-08 17:57 ` Randy Dunlap
2016-09-08 20:25 ` [PATCH v3] " Craig Gallek
2016-09-08 22:00 ` Randy Dunlap
2016-09-08 22:15 ` Craig Gallek
2016-09-09 12:39 ` Thomas Gleixner
2016-09-09 16:28 ` [PATCH v4] " Craig Gallek
2016-09-09 23:19 ` Thomas Gleixner
2016-09-12 14:12 ` [PATCH v5] " Craig Gallek
2016-09-13 14:50 ` Thomas Gleixner
2016-09-13 16:14 ` [PATCH v6] " Craig Gallek
2016-09-14 13:34 ` [tip:irq/core] genirq: Expose interrupt information through sysfs tip-bot for Craig Gallek
2016-09-14 13:36 ` [PATCH v6] genirq: Machine-parsable version of /proc/interrupts Thomas Gleixner
2016-09-14 13:59 ` Craig Gallek
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=alpine.DEB.2.20.1609021626430.5647@nanos \
--to=tglx@linutronix.de \
--cc=decot@google.com \
--cc=kraigatgoog@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/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).