All of lore.kernel.org
 help / color / mirror / Atom feed
* driver notification when switching between battery vs AC power?
@ 2021-03-05  8:07 Christoph Hellwig
  2021-03-05 15:18 ` Rafael J. Wysocki
  0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2021-03-05  8:07 UTC (permalink / raw)
  To: rjw; +Cc: linux-pm

Hi Rafael,

do we have infrastructure that notifies the driver when a system is
switching from batter to AC power?  There is a proposal to make the
Linux NVMe driver power management match the policy used by the
Windows driver more closely, which does this and we'd like to prototype
that to check what difference the policy makes.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: driver notification when switching between battery vs AC power?
  2021-03-05  8:07 driver notification when switching between battery vs AC power? Christoph Hellwig
@ 2021-03-05 15:18 ` Rafael J. Wysocki
  2021-03-07 13:53   ` Zhang Rui
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2021-03-05 15:18 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Rafael J. Wysocki, Linux PM, Zhang, Rui

Hi Christoph,

On Fri, Mar 5, 2021 at 9:07 AM Christoph Hellwig <hch@lst.de> wrote:
>
> Hi Rafael,
>
> do we have infrastructure that notifies the driver when a system is
> switching from batter to AC power?

On systems with ACPI that can be done through an ACPI notifier, see
amdgpu_acpi_event() for one example.

Adding Rui who's likely to be more familiar with this topic than I am.

> There is a proposal to make the
> Linux NVMe driver power management match the policy used by the
> Windows driver more closely, which does this and we'd like to prototype
> that to check what difference the policy makes.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: driver notification when switching between battery vs AC power?
  2021-03-05 15:18 ` Rafael J. Wysocki
@ 2021-03-07 13:53   ` Zhang Rui
  2021-03-08  7:50     ` Christoph Hellwig
  0 siblings, 1 reply; 7+ messages in thread
From: Zhang Rui @ 2021-03-07 13:53 UTC (permalink / raw)
  To: Rafael J. Wysocki, Christoph Hellwig; +Cc: Rafael J. Wysocki, Linux PM

On Fri, 2021-03-05 at 16:18 +0100, Rafael J. Wysocki wrote:
> Hi Christoph,
> 
> On Fri, Mar 5, 2021 at 9:07 AM Christoph Hellwig <hch@lst.de> wrote:
> > 
> > Hi Rafael,
> > 
> > do we have infrastructure that notifies the driver when a system is
> > switching from batter to AC power?
> 
> On systems with ACPI that can be done through an ACPI notifier, see
> amdgpu_acpi_event() for one example.
> 
> Adding Rui who's likely to be more familiar with this topic than I
> am.

Thanks for adding me in the loop.

Yes, an ACPI notifier callback should be sufficient for this purpose.

Usually, we get an ACPI notification upon AC plug/unplug, so what we
need in the NVMe driver is to get the notification and then get the
status of AC adapter. As ACPI AC driver always sends the AC events to
acpi notifier chain, what we need is 
a) define a notifier callback, and in the notifier callback
   1. ignore non-AC devices,
   2. get AC status, you can refer to acpi_ac_get_state()
b) register the notifier cb to ACPI notifier chain, by invoking
   register_acpi_notifier()

thanks,
rui
> 
> > There is a proposal to make the
> > Linux NVMe driver power management match the policy used by the
> > Windows driver more closely, which does this and we'd like to
> > prototype
> > that to check what difference the policy makes.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: driver notification when switching between battery vs AC power?
  2021-03-07 13:53   ` Zhang Rui
@ 2021-03-08  7:50     ` Christoph Hellwig
  2021-03-08 15:29       ` Rafael J. Wysocki
  0 siblings, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2021-03-08  7:50 UTC (permalink / raw)
  To: Zhang Rui
  Cc: Rafael J. Wysocki, Christoph Hellwig, Rafael J. Wysocki, Linux PM

On Sun, Mar 07, 2021 at 09:53:06PM +0800, Zhang Rui wrote:
> Thanks for adding me in the loop.
> 
> Yes, an ACPI notifier callback should be sufficient for this purpose.
> 
> Usually, we get an ACPI notification upon AC plug/unplug, so what we
> need in the NVMe driver is to get the notification and then get the
> status of AC adapter. As ACPI AC driver always sends the AC events to
> acpi notifier chain, what we need is 
> a) define a notifier callback, and in the notifier callback
>    1. ignore non-AC devices,
>    2. get AC status, you can refer to acpi_ac_get_state()
> b) register the notifier cb to ACPI notifier chain, by invoking
>    register_acpi_notifier()

Not my direct priority now, but would there be any objections to
wire up a power_source_notifier method in struct dev_pm_ops to
avoid boilerplate code and ACPI dependencies in drivers?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: driver notification when switching between battery vs AC power?
  2021-03-08  7:50     ` Christoph Hellwig
@ 2021-03-08 15:29       ` Rafael J. Wysocki
  2021-03-08 17:30         ` Rafael J. Wysocki
  2021-03-08 18:13         ` Sebastian Reichel
  0 siblings, 2 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2021-03-08 15:29 UTC (permalink / raw)
  To: Christoph Hellwig, Sebastian Reichel
  Cc: Zhang Rui, Rafael J. Wysocki, Rafael J. Wysocki, Linux PM

On Mon, Mar 8, 2021 at 8:50 AM Christoph Hellwig <hch@lst.de> wrote:
>
> On Sun, Mar 07, 2021 at 09:53:06PM +0800, Zhang Rui wrote:
> > Thanks for adding me in the loop.
> >
> > Yes, an ACPI notifier callback should be sufficient for this purpose.
> >
> > Usually, we get an ACPI notification upon AC plug/unplug, so what we
> > need in the NVMe driver is to get the notification and then get the
> > status of AC adapter. As ACPI AC driver always sends the AC events to
> > acpi notifier chain, what we need is
> > a) define a notifier callback, and in the notifier callback
> >    1. ignore non-AC devices,
> >    2. get AC status, you can refer to acpi_ac_get_state()
> > b) register the notifier cb to ACPI notifier chain, by invoking
> >    register_acpi_notifier()
>
> Not my direct priority now, but would there be any objections to
> wire up a power_source_notifier method in struct dev_pm_ops to
> avoid boilerplate code and ACPI dependencies in drivers?

That would work for me, unless there is something more generic than
the ACPI-based notification mechanism already in the power supply
framework.  Sebastian?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: driver notification when switching between battery vs AC power?
  2021-03-08 15:29       ` Rafael J. Wysocki
@ 2021-03-08 17:30         ` Rafael J. Wysocki
  2021-03-08 18:13         ` Sebastian Reichel
  1 sibling, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2021-03-08 17:30 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Sebastian Reichel, Zhang Rui, Rafael J. Wysocki,
	Rafael J. Wysocki, Linux PM

On Mon, Mar 8, 2021 at 4:29 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> On Mon, Mar 8, 2021 at 8:50 AM Christoph Hellwig <hch@lst.de> wrote:
> >
> > On Sun, Mar 07, 2021 at 09:53:06PM +0800, Zhang Rui wrote:
> > > Thanks for adding me in the loop.
> > >
> > > Yes, an ACPI notifier callback should be sufficient for this purpose.
> > >
> > > Usually, we get an ACPI notification upon AC plug/unplug, so what we
> > > need in the NVMe driver is to get the notification and then get the
> > > status of AC adapter. As ACPI AC driver always sends the AC events to
> > > acpi notifier chain, what we need is
> > > a) define a notifier callback, and in the notifier callback
> > >    1. ignore non-AC devices,
> > >    2. get AC status, you can refer to acpi_ac_get_state()
> > > b) register the notifier cb to ACPI notifier chain, by invoking
> > >    register_acpi_notifier()
> >
> > Not my direct priority now, but would there be any objections to
> > wire up a power_source_notifier method in struct dev_pm_ops to
> > avoid boilerplate code and ACPI dependencies in drivers?
>
> That would work for me,

Kind of on a second thought, the convention around dev_pm_ops is that
if the given callback is provided by the device's bus type, it will be
invoked from there and not directly from the driver, and the
bus-type-level callback is expected to decide whether or not to invoke
the driver one.

If that doesn't match the envisioned power_source_notifier handling,
dev_pm_ops may not be the most suitable location for it.  It may be
better to add something to struct device_driver directly.

> unless there is something more generic than
> the ACPI-based notification mechanism already in the power supply
> framework.  Sebastian?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: driver notification when switching between battery vs AC power?
  2021-03-08 15:29       ` Rafael J. Wysocki
  2021-03-08 17:30         ` Rafael J. Wysocki
@ 2021-03-08 18:13         ` Sebastian Reichel
  1 sibling, 0 replies; 7+ messages in thread
From: Sebastian Reichel @ 2021-03-08 18:13 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Christoph Hellwig, Zhang Rui, Rafael J. Wysocki, Linux PM

[-- Attachment #1: Type: text/plain, Size: 1958 bytes --]

Hi,

On Mon, Mar 08, 2021 at 04:29:31PM +0100, Rafael J. Wysocki wrote:
> On Mon, Mar 8, 2021 at 8:50 AM Christoph Hellwig <hch@lst.de> wrote:
> > On Sun, Mar 07, 2021 at 09:53:06PM +0800, Zhang Rui wrote:
> > > Thanks for adding me in the loop.
> > >
> > > Yes, an ACPI notifier callback should be sufficient for this purpose.
> > >
> > > Usually, we get an ACPI notification upon AC plug/unplug, so what we
> > > need in the NVMe driver is to get the notification and then get the
> > > status of AC adapter. As ACPI AC driver always sends the AC events to
> > > acpi notifier chain, what we need is
> > > a) define a notifier callback, and in the notifier callback
> > >    1. ignore non-AC devices,
> > >    2. get AC status, you can refer to acpi_ac_get_state()
> > > b) register the notifier cb to ACPI notifier chain, by invoking
> > >    register_acpi_notifier()
> >
> > Not my direct priority now, but would there be any objections to
> > wire up a power_source_notifier method in struct dev_pm_ops to
> > avoid boilerplate code and ACPI dependencies in drivers?
> 
> That would work for me, unless there is something more generic than
> the ACPI-based notification mechanism already in the power supply
> framework. Sebastian?

power-supply framework provides two things:

a) One can register into the power-supply notifier chain using
   power_supply_reg_notifier(). This should be triggered by AC
   plug/unplug (among other things) as long as the driver calls
   power_supply_changed() when online state changes. I took a
   quick glance and ACPI AC driver does not seem to call it at
   the moment. I think both calls to kobject_uevent() in the
   driver need to change into power_supply_changed() for this
   to work on ACPI based systems.

b) There is power_supply_is_system_supplied() to check if the
   system is supplied by a non-battery type device (which might
   also be USB-C).

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-03-08 18:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-05  8:07 driver notification when switching between battery vs AC power? Christoph Hellwig
2021-03-05 15:18 ` Rafael J. Wysocki
2021-03-07 13:53   ` Zhang Rui
2021-03-08  7:50     ` Christoph Hellwig
2021-03-08 15:29       ` Rafael J. Wysocki
2021-03-08 17:30         ` Rafael J. Wysocki
2021-03-08 18:13         ` Sebastian Reichel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.