2021-11-16 12:34:58

by Srinivas Kandagatla

[permalink] [raw]
Subject: [PATCH] genirq/irqdesc: Add state node to show if IRQ is enabled

While debugging some issues with SoundWire WakeUp interrupt,
I did not find a way to figure out if the interrupt is really enabled
or disabled.

So I have added an new state entry in the sysfs to dump the current
interrupt state.

Signed-off-by: Srinivas Kandagatla <[email protected]>
---

While debugging I found this patch very useful, specially in SoundWire Wakeup
usecase where we dynamically enable Low Power Wakeup interrupt.

Sending this out, hoping that it will be useful for others as well.

--srini


Documentation/ABI/testing/sysfs-kernel-irq | 7 +++++++
kernel/irq/irqdesc.c | 16 ++++++++++++++++
2 files changed, 23 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-kernel-irq b/Documentation/ABI/testing/sysfs-kernel-irq
index 8910d0c4bcd8..d858ed133ba2 100644
--- a/Documentation/ABI/testing/sysfs-kernel-irq
+++ b/Documentation/ABI/testing/sysfs-kernel-irq
@@ -58,3 +58,10 @@ KernelVersion: 4.17
Contact: Andy Shevchenko <[email protected]>
Description: The wakeup state of the interrupt. Either the string
'enabled' or 'disabled'.
+
+What: /sys/kernel/irq/<irq>/state
+Date: November 2021
+KernelVersion: 5.16
+Contact: Srinivas Kandagatla <[email protected]>
+Description: The state of the interrupt. Either the string
+ 'enabled' or 'disabled'.
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 2267e6527db3..60c69978ea45 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -265,6 +265,21 @@ static ssize_t actions_show(struct kobject *kobj,
}
IRQ_ATTR_RO(actions);

+static ssize_t state_show(struct kobject *kobj,
+ struct kobj_attribute *attr, char *buf)
+{
+ struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
+ ssize_t ret;
+
+ raw_spin_lock_irq(&desc->lock);
+ ret = sprintf(buf, "%s\n",
+ irqd_irq_disabled(&desc->irq_data) ? "disabled" : "enabled");
+ raw_spin_unlock_irq(&desc->lock);
+
+ return ret;
+}
+IRQ_ATTR_RO(state);
+
static struct attribute *irq_attrs[] = {
&per_cpu_count_attr.attr,
&chip_name_attr.attr,
@@ -273,6 +288,7 @@ static struct attribute *irq_attrs[] = {
&wakeup_attr.attr,
&name_attr.attr,
&actions_attr.attr,
+ &state_attr.attr,
NULL
};
ATTRIBUTE_GROUPS(irq);
--
2.21.0



2021-11-16 12:47:43

by Srinivas Kandagatla

[permalink] [raw]
Subject: Re: [PATCH] genirq/irqdesc: Add state node to show if IRQ is enabled



On 16/11/2021 12:34, Srinivas Kandagatla wrote:
> While debugging some issues with SoundWire WakeUp interrupt,
> I did not find a way to figure out if the interrupt is really enabled
> or disabled.
>
> So I have added an new state entry in the sysfs to dump the current
> interrupt state.
>
> Signed-off-by: Srinivas Kandagatla <[email protected]>
> ---
>
> While debugging I found this patch very useful, specially in SoundWire Wakeup
> usecase where we dynamically enable Low Power Wakeup interrupt.
>
> Sending this out, hoping that it will be useful for others as well.
>
> --srini


Please ignore this patch! It will not work for every case.

--srini


>
>
> Documentation/ABI/testing/sysfs-kernel-irq | 7 +++++++
> kernel/irq/irqdesc.c | 16 ++++++++++++++++
> 2 files changed, 23 insertions(+)
>
> diff --git a/Documentation/ABI/testing/sysfs-kernel-irq b/Documentation/ABI/testing/sysfs-kernel-irq
> index 8910d0c4bcd8..d858ed133ba2 100644
> --- a/Documentation/ABI/testing/sysfs-kernel-irq
> +++ b/Documentation/ABI/testing/sysfs-kernel-irq
> @@ -58,3 +58,10 @@ KernelVersion: 4.17
> Contact: Andy Shevchenko <[email protected]>
> Description: The wakeup state of the interrupt. Either the string
> 'enabled' or 'disabled'.
> +
> +What: /sys/kernel/irq/<irq>/state
> +Date: November 2021
> +KernelVersion: 5.16
> +Contact: Srinivas Kandagatla <[email protected]>
> +Description: The state of the interrupt. Either the string
> + 'enabled' or 'disabled'.
> diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
> index 2267e6527db3..60c69978ea45 100644
> --- a/kernel/irq/irqdesc.c
> +++ b/kernel/irq/irqdesc.c
> @@ -265,6 +265,21 @@ static ssize_t actions_show(struct kobject *kobj,
> }
> IRQ_ATTR_RO(actions);
>
> +static ssize_t state_show(struct kobject *kobj,
> + struct kobj_attribute *attr, char *buf)
> +{
> + struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
> + ssize_t ret;
> +
> + raw_spin_lock_irq(&desc->lock);
> + ret = sprintf(buf, "%s\n",
> + irqd_irq_disabled(&desc->irq_data) ? "disabled" : "enabled");
> + raw_spin_unlock_irq(&desc->lock);
> +
> + return ret;
> +}
> +IRQ_ATTR_RO(state);
> +
> static struct attribute *irq_attrs[] = {
> &per_cpu_count_attr.attr,
> &chip_name_attr.attr,
> @@ -273,6 +288,7 @@ static struct attribute *irq_attrs[] = {
> &wakeup_attr.attr,
> &name_attr.attr,
> &actions_attr.attr,
> + &state_attr.attr,
> NULL
> };
> ATTRIBUTE_GROUPS(irq);
>

2021-11-24 19:16:37

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH] genirq/irqdesc: Add state node to show if IRQ is enabled

On Tue, Nov 16 2021 at 12:34, Srinivas Kandagatla wrote:
> While debugging some issues with SoundWire WakeUp interrupt,
> I did not find a way to figure out if the interrupt is really enabled
> or disabled.

You can find this information along with more details when you enable
CONFIG_GENERIC_IRQ_DEBUGFS. Dig into /sys/kernel/debug/irq/

Thanks,

tglx