Skip to contentSkip to conversation

PM / wakeirq: Add wakeup name to dedicated wake irqs

PATCH Superseded Tony Lindgren 4 participants 12 messages Feb 9, 2018 – Feb 23, 2018

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM / wakeirq: Add wakeup name to dedicated wake irqs

This makes it easy to grep :wakeup /proc/interrupts.

Cc Brian Norris <[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Ulf Hansson <[email protected]>
---
 drivers/base/power/power.h   |  1 +
 drivers/base/power/wakeirq.c | 18 +++++++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
drivers/base/power/power.h +1 -0
@@ -31,6 +31,7 @@ struct wake_irq {
 	struct device *dev;
 	unsigned int status;
 	int irq;
+	char *name;
 };
 
 extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
drivers/base/power/wakeirq.c +15 -3
@@ -112,6 +112,7 @@ void dev_pm_clear_wake_irq(struct device *dev)
 		free_irq(wirq->irq, wirq);
 		wirq->status &= ~WAKE_IRQ_DEDICATED_MASK;
 	}
+	kfree(wirq->name);
 	kfree(wirq);
 }
 EXPORT_SYMBOL_GPL(dev_pm_clear_wake_irq);
@@ -175,7 +176,8 @@ static irqreturn_t handle_threaded_wake_irq(int irq, void *_wirq)
 int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
 {
 	struct wake_irq *wirq;
-	int err;
+	int err, namelen;
+	const char *postfix = ":wakeup";
 
 	if (irq < 0)
 		return -EINVAL;
@@ -184,6 +186,14 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
 	if (!wirq)
 		return -ENOMEM;
 
+	namelen = strlen(dev_name(dev)) + strlen(postfix) + 1;
+	wirq->name = kzalloc(namelen, GFP_KERNEL);
+	if (!wirq->name) {
+		err = -ENOMEM;
+		goto err_free;
+	}
+
+	snprintf(wirq->name, namelen, "%s%s", dev_name(dev), postfix);
 	wirq->dev = dev;
 	wirq->irq = irq;
 	irq_set_status_flags(irq, IRQ_NOAUTOEN);
@@ -196,9 +206,9 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
 	 * so we use a threaded irq.
 	 */
 	err = request_threaded_irq(irq, NULL, handle_threaded_wake_irq,
-				   IRQF_ONESHOT, dev_name(dev), wirq);
+				   IRQF_ONESHOT, wirq->name, wirq);
 	if (err)
-		goto err_free;
+		goto err_free_name;
 
 	err = dev_pm_attach_wake_irq(dev, irq, wirq);
 	if (err)
@@ -210,6 +220,8 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
 
 err_free_irq:
 	free_irq(irq, wirq);
+err_free_name:
+	kfree(wirq->name);
 err_free:
 	kfree(wirq);
 
Signature · 1 line
2.16.1
#1 lore raw
Quoted 73 lines · CET Tony Lindgren

This makes it easy to grep :wakeup /proc/interrupts.

Cc Brian Norris <[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Ulf Hansson <[email protected]>
---
 drivers/base/power/power.h   |  1 +
 drivers/base/power/wakeirq.c | 18 +++++++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
drivers/base/power/power.h +1 -0
@@ -31,6 +31,7 @@ struct wake_irq {
 	struct device *dev;
 	unsigned int status;
 	int irq;
+	char *name;
 };
 
 extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
drivers/base/power/wakeirq.c +13 -3
@@ -112,6 +112,7 @@ void dev_pm_clear_wake_irq(struct device *dev)
 		free_irq(wirq->irq, wirq);
 		wirq->status &= ~WAKE_IRQ_DEDICATED_MASK;
 	}
+	kfree(wirq->name);
 	kfree(wirq);
 }
 EXPORT_SYMBOL_GPL(dev_pm_clear_wake_irq);
@@ -175,7 +176,8 @@ static irqreturn_t handle_threaded_wake_irq(int irq, void *_wirq)
 int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
 {
 	struct wake_irq *wirq;
-	int err;
+	int err, namelen;
+	const char *postfix = ":wakeup";
 
 	if (irq < 0)
 		return -EINVAL;
@@ -184,6 +186,14 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
 	if (!wirq)
 		return -ENOMEM;
 
+	namelen = strlen(dev_name(dev)) + strlen(postfix) + 1;
+	wirq->name = kzalloc(namelen, GFP_KERNEL);
+	if (!wirq->name) {
+		err = -ENOMEM;
+		goto err_free;
+	}
+
+	snprintf(wirq->name, namelen, "%s%s", dev_name(dev), postfix);
 	wirq->dev = dev;
 	wirq->irq = irq;
 	irq_set_status_flags(irq, IRQ_NOAUTOEN);
@@ -196,9 +206,9 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
 	 * so we use a threaded irq.
 	 */
 	err = request_threaded_irq(irq, NULL, handle_threaded_wake_irq,
-				   IRQF_ONESHOT, dev_name(dev), wirq);
+				   IRQF_ONESHOT, wirq->name, wirq);
 	if (err)
-		goto err_free;
+		goto err_free_name;
 
 	err = dev_pm_attach_wake_irq(dev, irq, wirq);
 	if (err)

drivers/base/power/wakeirq.c int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq) · line 227

Quoted 8 lines
drivers/base/power/wakeirq.c +2 -0
@@ -210,6 +220,8 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
 
 err_free_irq:
 	free_irq(irq, wirq);
+err_free_name:
+	kfree(wirq->name);
 err_free:
 	kfree(wirq);
 

I'll queue this up for 4.17 if there are no objections.

Thanks,
Rafael

#2 lore raw
In reply to Tony Lindgren
Quoted 1 line · Tony Lindgren

This makes it easy to grep :wakeup /proc/interrupts.

I used to have another patch (not published) to provide this information via /sys/kernel/irq.

OK, here we are:

Review

Quoted 2 lines
(quoted diff) +2 -0
+       namelen = strlen(dev_name(dev)) + strlen(postfix) + 1;
+       wirq->name = kzalloc(namelen, GFP_KERNEL);

kasprintf()

Signature · 2 lines
With Best Regards,
Andy Shevchenko

From ef35d3fd789a32d85212b2bcb82f754ae244cd58 Mon Sep 17 00:00:00 2001
From: Andy Shevchenko <[email protected]>
Date: Fri, 12 May 2017 20:19:32 +0300
Subject: [PATCH] genirq: Add wakeup sysfs node to show IRQ wakeup state

Surprisingly there is no simple way to see if the IRQ line in question is wakeup source or not.

Note that wakeup might be an OOB (out-of-band) source like GPIO line which makes things slightly more complicated.

Add a sysfs node to cover this case.

---
 Documentation/ABI/testing/sysfs-kernel-irq |  7 +++++++
 kernel/irq/irqdesc.c                       | 17 +++++++++++++++++
 2 files changed, 24 insertions(+)
Documentation/ABI/testing/sysfs-kernel-irq +7 -0
index eb074b100986..10ad998f9411 100644
@@ -51,3 +51,10 @@ Date:		September 2016
 KernelVersion:	4.9
 Contact:	Craig Gallek <[email protected]>
 Description:	The type of the interrupt.  Either the string 'level' or 'edge'.
+
+What:		/sys/kernel/irq/<irq>/wakeup
+Date:		Jan 2018
+KernelVersion:	4.16
+Contact:	Andy Shevchenko <[email protected]>
+Description:	The wakeup state of the interrupt. Either the string
+		'enabled' or 'disabled'.
kernel/irq/irqdesc.c +17 -0
index 49b54e9979cc..d9ded088d336 100644
@@ -210,6 +210,22 @@ static ssize_t type_show(struct kobject *kobj,
 }
 IRQ_ATTR_RO(type);
 
+static ssize_t wakeup_show(struct kobject *kobj,
+			   struct kobj_attribute *attr, char *buf)
+{
+	struct irq_desc *desc = container_of(kobj, struct irq_desc, kobj);
+	ssize_t ret = 0;
+
+	raw_spin_lock_irq(&desc->lock);
+	ret = sprintf(buf, "%s\n",
+		      irqd_is_wakeup_set(&desc->irq_data) ? "enabled" : "disabled");
+	raw_spin_unlock_irq(&desc->lock);
+
+	return ret;
+
+}
+IRQ_ATTR_RO(wakeup);
+
 static ssize_t name_show(struct kobject *kobj,
 			 struct kobj_attribute *attr, char *buf)
 {
@@ -253,6 +269,7 @@ static struct attribute *irq_attrs[] = {
 	&chip_name_attr.attr,
 	&hwirq_attr.attr,
 	&type_attr.attr,
+	&wakeup_attr.attr,
 	&name_attr.attr,
 	&actions_attr.attr,
 	NULL
Signature · 1 line
2.15.1
#3 lore raw
Quoted 6 lines · Andy Shevchenko
Quoted 1 line · Tony Lindgren

This makes it easy to grep :wakeup /proc/interrupts.

I used to have another patch (not published) to provide this information via /sys/kernel/irq.

Quoted 7 lines

OK, here we are:

Review

Quoted 2 lines
(quoted diff) +2 -0
+       namelen = strlen(dev_name(dev)) + strlen(postfix) + 1;
+       wirq->name = kzalloc(namelen, GFP_KERNEL);

kasprintf()

It's a bit hard to comment patches sent as attachments, but I'll try anyway. :-)

IMO it is somewhat excessive to put the entire sprintf() under a raw spinlock and it's not even necessary.

The value can change any time after you've dropped the lock and in particular before the function returns, so why bother with locking? desc will not go away from under you at that point anyway.

#4 lore raw
Quoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Andy Shevchenko
Quoted 1 line · Tony Lindgren

This makes it easy to grep :wakeup /proc/interrupts.

I used to have another patch (not published) to provide this information via /sys/kernel/irq.

OK, here we are:

It's a bit hard to comment patches sent as attachments, but I'll try anyway. :-)

Sorry, I was thinking that Tony may test it first to see if it does what he wants.
Of course I would send normally in case it's an expected approach.

Quoted 2 lines

IMO it is somewhat excessive to put the entire sprintf() under a raw spinlock and it's not even necessary.

It's a copy'n'paste of from the rest of functions there.

Quoted 3 lines

The value can change any time after you've dropped the lock and in particular before the function returns, so why bother with locking? desc will not go away from under you at that point anyway.

IIRC descriptor's content might be changed, or descriptor itself might be gone (potential crash).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Andy Shevchenko
Quoted 1 line · Tony Lindgren

This makes it easy to grep :wakeup /proc/interrupts.

I used to have another patch (not published) to provide this information via /sys/kernel/irq.

OK, here we are:

It's a bit hard to comment patches sent as attachments, but I'll try anyway. :-)

Quoted 8 lines

Sorry, I was thinking that Tony may test it first to see if it does what he wants.
Of course I would send normally in case it's an expected approach.

Quoted 2 lines

IMO it is somewhat excessive to put the entire sprintf() under a raw spinlock and it's not even necessary.

It's a copy'n'paste of from the rest of functions there.

Fair enough. :-)

Quoted 6 lines
Quoted 3 lines

The value can change any time after you've dropped the lock and in particular before the function returns, so why bother with locking? desc will not go away from under you at that point anyway.

IIRC descriptor's content might be changed, or descriptor itself might be gone (potential crash).

No, desc cannot go away at this point AFAICS due to the kernfs refcounting. And the lock is *inside* of the desc object anyway, so it doesn't help really against that.

The contents may change, but so what?

Effectively, you read an int and reading an int is atomic. It may change after that, but the lock doesn't prevent it from changing. It only prevents the change from being applied to it before you drop the lock, but why do you care?

#6 lore raw
Quoted 17 lines · Rafael J. Wysocki
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Rafael J. Wysocki

On Wed, Feb 14, 2018 at 12:23 PM, Andy Shevchenko
<[email protected]> wrote:

IMO it is somewhat excessive to put the entire sprintf() under a raw spinlock and it's not even necessary.

It's a copy'n'paste of from the rest of functions there.

Fair enough. :-)

Quoted 4 lines
Quoted 3 lines

The value can change any time after you've dropped the lock and in particular before the function returns, so why bother with locking? desc will not go away from under you at that point anyway.

Quoted 6 lines
Quoted 2 lines

IIRC descriptor's content might be changed, or descriptor itself might be gone (potential crash).

No, desc cannot go away at this point AFAICS due to the kernfs refcounting. And the lock is *inside* of the desc object anyway, so it doesn't help really against that.

Oh, indeed.

Quoted 6 lines

The contents may change, but so what?

Effectively, you read an int and reading an int is atomic. It may change after that, but the lock doesn't prevent it from changing. It only prevents the change from being applied to it before you drop the lock, but why do you care?

So, with explanations above, perhaps we can produce the patch to remove those locks from the rest?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 29 lines · CET Andy Shevchenko
Quoted 17 lines · Rafael J. Wysocki
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Rafael J. Wysocki

On Wed, Feb 14, 2018 at 12:23 PM, Andy Shevchenko
<[email protected]> wrote:

IMO it is somewhat excessive to put the entire sprintf() under a raw spinlock and it's not even necessary.

It's a copy'n'paste of from the rest of functions there.

Fair enough. :-)

Quoted 4 lines
Quoted 3 lines

The value can change any time after you've dropped the lock and in particular before the function returns, so why bother with locking? desc will not go away from under you at that point anyway.

Quoted 6 lines
Quoted 2 lines

IIRC descriptor's content might be changed, or descriptor itself might be gone (potential crash).

No, desc cannot go away at this point AFAICS due to the kernfs refcounting. And the lock is *inside* of the desc object anyway, so it doesn't help really against that.

Oh, indeed.

Quoted 2 lines

The contents may change, but so what?

Quoted 7 lines
Quoted 4 lines

Effectively, you read an int and reading an int is atomic. It may change after that, but the lock doesn't prevent it from changing. It only prevents the change from being applied to it before you drop the lock, but why do you care?

So, with explanations above, perhaps we can produce the patch to remove those locks from the rest?

Well, I guess so.

I'm not the maintainer of that code, however. :-)

#8 lore raw
In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

Sorry, I was thinking that Tony may test it first to see if it does what he wants.

Well using dev_name() for the wakeirq name might still conflict with the device IO interrupt. But yeah I'll give it a try.

Regards,

Tony

#9 lore raw
In reply to Andy Shevchenko
Quoted 4 lines · Andy Shevchenko

Subject: [PATCH] genirq: Add wakeup sysfs node to show IRQ wakeup state

Surprisingly there is no simple way to see if the IRQ line in question is wakeup source or not.

Finally got around trying this one. Yeah it's nice and it seems that this is how we could also allow add support for showing the time when the wakeirq triggered and was actually seen by the irq subsystem. I think that's what people have been after for a while :)

It seems we should do both /sys/kernel/irq/*/wakeup and also have a name for the dedicated wakeirqs. I'll send out my kasprintf updated patch shortly.

Regards,

Tony

#10 lore raw
In reply to Tony Lindgren
Quoted 46 lines · Tony Lindgren

This makes it easy to grep :wakeup /proc/interrupts.

Cc Brian Norris <[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Ulf Hansson <[email protected]>
---
 drivers/base/power/power.h   |  1 +
 drivers/base/power/wakeirq.c | 18 +++++++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)
drivers/base/power/power.h +1 -0
@@ -31,6 +31,7 @@ struct wake_irq {
        struct device *dev;
        unsigned int status;
        int irq;
+       char *name;
 };
 
 extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
drivers/base/power/wakeirq.c +3 -1
@@ -112,6 +112,7 @@ void dev_pm_clear_wake_irq(struct device *dev)
                free_irq(wirq->irq, wirq);
                wirq->status &= ~WAKE_IRQ_DEDICATED_MASK;
        }
+       kfree(wirq->name);
        kfree(wirq);
 }
 EXPORT_SYMBOL_GPL(dev_pm_clear_wake_irq);
@@ -175,7 +176,8 @@ static irqreturn_t handle_threaded_wake_irq(int irq, void *_wirq)
 int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
 {
        struct wake_irq *wirq;
-       int err;
+       int err, namelen;
+       const char *postfix = ":wakeup";
 
        if (irq < 0)
                return -EINVAL;
@@ -184,6 +186,14 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
        if (!wirq)

drivers/base/power/wakeirq.c int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq) · line 196

Quoted 10 lines
drivers/base/power/wakeirq.c +8 -0
                return -ENOMEM;
 
+       namelen = strlen(dev_name(dev)) + strlen(postfix) + 1;
+       wirq->name = kzalloc(namelen, GFP_KERNEL);
+       if (!wirq->name) {
+               err = -ENOMEM;
+               goto err_free;
+       }
+
+       snprintf(wirq->name, namelen, "%s%s", dev_name(dev), postfix);

As Andy said you can do

wirq->name = kasprintf(GFP_KERNEL, "%s:wakeup", dev_name(dev));

if (!wirq->name) {
        err = -ENOMEM;
        goto err_free;
}

here and it will allocate the buffer for you.

#11 lore raw
Quoted 38 lines · Rafael J. Wysocki
Quoted 24 lines · Tony Lindgren

This makes it easy to grep :wakeup /proc/interrupts.

drivers/base/power/wakeirq.c +3 -1
@@ -112,6 +112,7 @@ void dev_pm_clear_wake_irq(struct device *dev)
                free_irq(wirq->irq, wirq);
                wirq->status &= ~WAKE_IRQ_DEDICATED_MASK;
        }
+       kfree(wirq->name);
        kfree(wirq);
 }
 EXPORT_SYMBOL_GPL(dev_pm_clear_wake_irq);
@@ -175,7 +176,8 @@ static irqreturn_t handle_threaded_wake_irq(int irq, void *_wirq)
 int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
 {
        struct wake_irq *wirq;
-       int err;
+       int err, namelen;
+       const char *postfix = ":wakeup";
 
        if (irq < 0)
                return -EINVAL;
@@ -184,6 +186,14 @@ int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq)
        if (!wirq)

drivers/base/power/wakeirq.c int dev_pm_set_dedicated_wake_irq(struct device *dev, int irq) · line 196

Quoted 10 lines
drivers/base/power/wakeirq.c +8 -0
                return -ENOMEM;
 
+       namelen = strlen(dev_name(dev)) + strlen(postfix) + 1;
+       wirq->name = kzalloc(namelen, GFP_KERNEL);
+       if (!wirq->name) {
+               err = -ENOMEM;
+               goto err_free;
+       }
+
+       snprintf(wirq->name, namelen, "%s%s", dev_name(dev), postfix);

As Andy said you can do

Quoted 7 lines

wirq->name = kasprintf(GFP_KERNEL, "%s:wakeup", dev_name(dev));

if (!wirq->name) {
        err = -ENOMEM;
        goto err_free;
}

here and it will allocate the buffer for you.

Yeah great, will update and repost next week. I'll also give Andy's patch a try, sounds like we may want to do both though.

Regards,

Tony