diff mbox series

[1/2] power: supply: bq27xxx_battery: Notify about all battery changes

Message ID 20200525141200.17199-1-krzk@kernel.org (mailing list archive)
State Not Applicable, archived
Headers show
Series [1/2] power: supply: bq27xxx_battery: Notify about all battery changes | expand

Commit Message

Krzysztof Kozlowski May 25, 2020, 2:11 p.m. UTC
All battery related data could be important for user-space.  For example
time-to-full could be shown to user on the screen or health could be
monitored for any issues.  Instead of comparing few selected old/new
values, just check if anything changed in the cache.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 drivers/power/supply/bq27xxx_battery.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Andrew Davis May 27, 2020, 1:24 a.m. UTC | #1
On 5/25/20 10:11 AM, Krzysztof Kozlowski wrote:
> All battery related data could be important for user-space.  For example
> time-to-full could be shown to user on the screen or health could be
> monitored for any issues.  Instead of comparing few selected old/new
> values, just check if anything changed in the cache.
> 


At least some value will change every time we poll the battery, are we
okay with having power_supply_changed() called every time?

Andrew


> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
> ---
>  drivers/power/supply/bq27xxx_battery.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
> index 942c92127b6d..33c26d42cd02 100644
> --- a/drivers/power/supply/bq27xxx_battery.c
> +++ b/drivers/power/supply/bq27xxx_battery.c
> @@ -1612,12 +1612,10 @@ void bq27xxx_battery_update(struct bq27xxx_device_info *di)
>  			di->charge_design_full = bq27xxx_battery_read_dcap(di);
>  	}
>  
> -	if ((di->cache.capacity != cache.capacity) ||
> -	    (di->cache.flags != cache.flags))
> +	if (memcmp(&di->cache, &cache, sizeof(cache)) != 0) {
>  		power_supply_changed(di->bat);
> -
> -	if (memcmp(&di->cache, &cache, sizeof(cache)) != 0)
>  		di->cache = cache;
> +	}
>  
>  	di->last_update = jiffies;
>  }
>
Krzysztof Kozlowski May 27, 2020, 7:22 a.m. UTC | #2
On Tue, May 26, 2020 at 09:24:39PM -0400, Andrew F. Davis wrote:
> On 5/25/20 10:11 AM, Krzysztof Kozlowski wrote:
> > All battery related data could be important for user-space.  For example
> > time-to-full could be shown to user on the screen or health could be
> > monitored for any issues.  Instead of comparing few selected old/new
> > values, just check if anything changed in the cache.
> > 
> 
> 
> At least some value will change every time we poll the battery, are we
> okay with having power_supply_changed() called every time?

Hi,

Let me give few arguments:
1. "Every time" means still once per poll interval or in case of many
   get_property() calls, once per 5 seconds. In first case, if users
   sets polling every 1 second, I expect he knows what he wants. I2C
   will be busy anyway so uevents should not matter that much.
   In second case, called through get_property(), once per 5 seconds is
   not that frequent.

2. Different drivers do it differently. Many chargers notify about
   everything. Most fuel gauges only on status or capacity change (although
   I am not sure if they measure more) but few FG send uevents about
   everything (max17042_battery, sbs-battery, s3c_adc_battery).

3. If drivers does not send notifications on changed properties of
   battery, then basically the user-space has to poll every time for all
   data which is not being a trigger.  The overhead for system would be
   the same, I guess.

Best regards,
Krzysztof


> Andrew
> 
> 
> > Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
> > ---
> >  drivers/power/supply/bq27xxx_battery.c | 6 ++----
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
> > index 942c92127b6d..33c26d42cd02 100644
> > --- a/drivers/power/supply/bq27xxx_battery.c
> > +++ b/drivers/power/supply/bq27xxx_battery.c
> > @@ -1612,12 +1612,10 @@ void bq27xxx_battery_update(struct bq27xxx_device_info *di)
> >  			di->charge_design_full = bq27xxx_battery_read_dcap(di);
> >  	}
> >  
> > -	if ((di->cache.capacity != cache.capacity) ||
> > -	    (di->cache.flags != cache.flags))
> > +	if (memcmp(&di->cache, &cache, sizeof(cache)) != 0) {
> >  		power_supply_changed(di->bat);
> > -
> > -	if (memcmp(&di->cache, &cache, sizeof(cache)) != 0)
> >  		di->cache = cache;
> > +	}
> >  
> >  	di->last_update = jiffies;
> >  }
> >
Krzysztof Kozlowski May 27, 2020, 7:30 a.m. UTC | #3
On Wed, May 27, 2020 at 09:22:24AM +0200, Krzysztof Kozlowski wrote:
> On Tue, May 26, 2020 at 09:24:39PM -0400, Andrew F. Davis wrote:
> > On 5/25/20 10:11 AM, Krzysztof Kozlowski wrote:
> > > All battery related data could be important for user-space.  For example
> > > time-to-full could be shown to user on the screen or health could be
> > > monitored for any issues.  Instead of comparing few selected old/new
> > > values, just check if anything changed in the cache.
> > > 
> > 
> > 
> > At least some value will change every time we poll the battery, are we
> > okay with having power_supply_changed() called every time?
> 
> Hi,
> 
> Let me give few arguments:
> 1. "Every time" means still once per poll interval or in case of many
>    get_property() calls, once per 5 seconds. In first case, if users
>    sets polling every 1 second, I expect he knows what he wants. I2C
>    will be busy anyway so uevents should not matter that much.
>    In second case, called through get_property(), once per 5 seconds is
>    not that frequent.
> 
> 2. Different drivers do it differently. Many chargers notify about
>    everything. Most fuel gauges only on status or capacity change (although
>    I am not sure if they measure more) but few FG send uevents about
>    everything (max17042_battery, sbs-battery, s3c_adc_battery).
> 
> 3. If drivers does not send notifications on changed properties of
>    battery, then basically the user-space has to poll every time for all
>    data which is not being a trigger.  The overhead for system would be
>    the same, I guess.
> 

And one more:
4. I actually needed for my project. I have a user-space which
   previously was polling the battery status but I converted it to udev
   events.  The voltage, current and temperature are important for me as
   well so I need all uevents.

Best regards,
Krzysztof
Pavel Machek June 16, 2020, 10:52 a.m. UTC | #4
On Tue 2020-05-26 21:24:39, Andrew F. Davis wrote:
> On 5/25/20 10:11 AM, Krzysztof Kozlowski wrote:
> > All battery related data could be important for user-space.  For example
> > time-to-full could be shown to user on the screen or health could be
> > monitored for any issues.  Instead of comparing few selected old/new
> > values, just check if anything changed in the cache.
> > 
> 
> 
> At least some value will change every time we poll the battery, are we
> okay with having power_supply_changed() called every time?

I believe that's very bad idea. AFAICT that would wake up userspace every
5 seconds, eating power in unexpected way, and without easy ability of opting
out. IOW a regression.

									Pavel
Krzysztof Kozlowski June 16, 2020, 11:57 a.m. UTC | #5
On Tue, Jun 16, 2020 at 12:52:24PM +0200, Pavel Machek wrote:
> On Tue 2020-05-26 21:24:39, Andrew F. Davis wrote:
> > On 5/25/20 10:11 AM, Krzysztof Kozlowski wrote:
> > > All battery related data could be important for user-space.  For example
> > > time-to-full could be shown to user on the screen or health could be
> > > monitored for any issues.  Instead of comparing few selected old/new
> > > values, just check if anything changed in the cache.
> > > 
> > 
> > 
> > At least some value will change every time we poll the battery, are we
> > okay with having power_supply_changed() called every time?
> 
> I believe that's very bad idea. AFAICT that would wake up userspace every
> 5 seconds, eating power in unexpected way, and without easy ability of opting
> out. IOW a regression.

It won't be 5 seconds but poll_interval which is 360 seconds by default.
It can be 5 seconds if user-space changes this time or if user-space
keeps asking for get_property. In first case: user-space kind of decided
about it... In second: user-space is already woken-up since it polls get
properties.

However I understand that this is quite intrusive change and maybe in
such case user-space should just keep polling (if it wants all data to
be provided every n-seconds).

Best regards,
Krzysztof
diff mbox series

Patch

diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
index 942c92127b6d..33c26d42cd02 100644
--- a/drivers/power/supply/bq27xxx_battery.c
+++ b/drivers/power/supply/bq27xxx_battery.c
@@ -1612,12 +1612,10 @@  void bq27xxx_battery_update(struct bq27xxx_device_info *di)
 			di->charge_design_full = bq27xxx_battery_read_dcap(di);
 	}
 
-	if ((di->cache.capacity != cache.capacity) ||
-	    (di->cache.flags != cache.flags))
+	if (memcmp(&di->cache, &cache, sizeof(cache)) != 0) {
 		power_supply_changed(di->bat);
-
-	if (memcmp(&di->cache, &cache, sizeof(cache)) != 0)
 		di->cache = cache;
+	}
 
 	di->last_update = jiffies;
 }