When a touchpad's attention interrupt is triggered on a different
CPU than the GPIO controller interrupt multiple CPUs wake up the system
and can cause higher power consumption than necessary for operating
the touchpad.
Waking up the additional CPUs is especially unnecessary as the
irq_ack() callback for pinctrl-amd doesn't do anything.
To solve this save the affinity of the GPIO controller interrupt when
it's set up and assign that affinity to the GPIO line IRQ.
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Reported-by: Kieran Levin <[email protected]>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=218169
Signed-off-by: Mario Limonciello <[email protected]>
---
drivers/pinctrl/pinctrl-amd.c | 18 ++++++++++++++++++
drivers/pinctrl/pinctrl-amd.h | 1 +
2 files changed, 19 insertions(+)
diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index 7f66ec73199a..0f126caa8dfc 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -561,6 +561,21 @@ static int amd_gpio_irq_set_type(struct irq_data *d, unsigned int type)
return ret;
}
+static int amd_gpio_set_affinity(struct irq_data *data, const struct cpumask *dest,
+ bool force)
+{
+ struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
+ struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
+
+ /*
+ * The affinity is explicitly set to the GPIO controller as amd_irq_ack()
+ * doesn't do anything and pinning to a different CPU is a needless wakeup.
+ */
+ irq_data_update_effective_affinity(data, gpio_dev->base_affinity);
+
+ return 0;
+}
+
static void amd_irq_ack(struct irq_data *d)
{
/*
@@ -580,6 +595,7 @@ static const struct irq_chip amd_gpio_irqchip = {
.irq_set_wake = amd_gpio_irq_set_wake,
.irq_eoi = amd_gpio_irq_eoi,
.irq_set_type = amd_gpio_irq_set_type,
+ .irq_set_affinity = amd_gpio_set_affinity,
/*
* We need to set IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND so that a wake event
* also generates an IRQ. We need the IRQ so the irq_handler can clear
@@ -1163,6 +1179,8 @@ static int amd_gpio_probe(struct platform_device *pdev)
if (ret)
goto out2;
+ gpio_dev->base_affinity = irq_get_affinity_mask(gpio_dev->irq);
+
platform_set_drvdata(pdev, gpio_dev);
acpi_register_wakeup_handler(gpio_dev->irq, amd_gpio_check_wake, gpio_dev);
diff --git a/drivers/pinctrl/pinctrl-amd.h b/drivers/pinctrl/pinctrl-amd.h
index cf59089f2776..1a97c7570374 100644
--- a/drivers/pinctrl/pinctrl-amd.h
+++ b/drivers/pinctrl/pinctrl-amd.h
@@ -106,6 +106,7 @@ struct amd_gpio {
struct platform_device *pdev;
u32 *saved_regs;
int irq;
+ const struct cpumask *base_affinity;
};
/* KERNCZ configuration*/
--
2.43.0
On Sun, May 19, 2024 at 07:41:09AM -0500, Mario Limonciello wrote:
> When a touchpad's attention interrupt is triggered on a different
> CPU than the GPIO controller interrupt multiple CPUs wake up the system
> and can cause higher power consumption than necessary for operating
> the touchpad.
>
> Waking up the additional CPUs is especially unnecessary as the
> irq_ack() callback for pinctrl-amd doesn't do anything.
>
> To solve this save the affinity of the GPIO controller interrupt when
> it's set up and assign that affinity to the GPIO line IRQ.
I do not much care about AMD :-) case but I think this is quite a big hammer
with possible undesired effects. It will basically put _all_ GPIO IRQs on
the same CPU which may slow down other peripherals, like UART, with potential
of buffer overrun (on the high speed modes).
Ideally it should be done in a way that exact consumer may ask for this from
its driver. Yet, I have no idea how to achieve this, but it would be really
nice to have something in I?C HID to
set_the_same_affinity_as_parent/GPIO_irq()
..
> Cc: Andy Shevchenko <[email protected]>
> Cc: Hans de Goede <[email protected]>
You can move these (Cc lines) to be after ---, that they won't pollute
the commit message with the same effect made on email, i.e. Cc'ing to
the listed people.
--
With Best Regards,
Andy Shevchenko
On 5/20/2024 04:38, Andy Shevchenko wrote:
> On Sun, May 19, 2024 at 07:41:09AM -0500, Mario Limonciello wrote:
>> When a touchpad's attention interrupt is triggered on a different
>> CPU than the GPIO controller interrupt multiple CPUs wake up the system
>> and can cause higher power consumption than necessary for operating
>> the touchpad.
>>
>> Waking up the additional CPUs is especially unnecessary as the
>> irq_ack() callback for pinctrl-amd doesn't do anything.
>>
>> To solve this save the affinity of the GPIO controller interrupt when
>> it's set up and assign that affinity to the GPIO line IRQ.
>
> I do not much care about AMD :-) case but I think this is quite a big hammer
> with possible undesired effects. It will basically put _all_ GPIO IRQs on
> the same CPU which may slow down other peripherals, like UART, with potential
> of buffer overrun (on the high speed modes).
>
Yeah I see your point.
> Ideally it should be done in a way that exact consumer may ask for this from
> its driver. Yet, I have no idea how to achieve this, but it would be really
> nice to have something in I²C HID to
>
> set_the_same_affinity_as_parent/GPIO_irq()
>
You know I think this is only half of the problem. The interrupts need
to be aligned but so does the I2C traffic. This was something else that
Hans mentioned in the linked thread. It's a lot more complex to sync
everything up.
I'm tempted to have a helper that i2c-hid uses after everything is setup
to go and align the affinities rather than at probe.
> ...
>
>> Cc: Andy Shevchenko <[email protected]>
>> Cc: Hans de Goede <[email protected]>
>
> You can move these (Cc lines) to be after ---, that they won't pollute
> the commit message with the same effect made on email, i.e. Cc'ing to
> the listed people.
>
Right; thanks.