Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

charging: Apply thresholds after full just once. JB#58372 #13

Closed
wants to merge 3 commits into from

Conversation

martyone
Copy link
Member

No description provided.

@monich
Copy link
Member

monich commented Jul 19, 2022

Regarding "more natural enumeration order" - of course it's more or less an arbitrary choice (unless it's a part of an ABI in which case the values must remain backward-compatible) but the original one looks more natural to me (non-zero if enabled, zero if disabled)

@martyone
Copy link
Member Author

My reasoning is that the default behavior is that charging is enabled once the cable is connected and there are three options how to disable it - either fully or based on the current charge level. So enable is the default (zero), while disable, apply-thresholds or apply-thresholds-after-full are three levels of disabling it, i.e., overriding the default behavior.

@martyone martyone changed the title [charging] Apply thresholds after full just once. JB#58372 Expose charging hysteresis control on DBus. JB#58372 Jul 20, 2022
@martyone martyone force-pushed the jb58372 branch 2 times, most recently from abd8369 to 9bd6235 Compare July 20, 2022 12:39
@monich
Copy link
Member

monich commented Jul 20, 2022

My reasoning is that the default behavior is that charging is enabled once the cable is connected and there are three options how to disable it - either fully or based on the current charge level. So enable is the default (zero), while disable, apply-thresholds or apply-thresholds-after-full are three levels of disabling it, i.e., overriding the default behavior.

I'm sure one can come up with a reasonable justification for pretty much any order 🙂

Some devices seem to never report the Full state despite reaching 100%
charging level.

Signed-off-by: Martin Kampas <martin.kampas@jolla.com>
Make the apply-thresholds-after-full option effective just once - change
to apply-thresholds once fully charged. Do the same also when the
charger gets disconnected, irrespective of the battery level.

Clear battery full seen when changing the mode or it would require to
reconnect the charger in order to set apply-thresholds-after-full after
reaching the upper threshold.

Signed-off-by: Martin Kampas <martin.kampas@jolla.com>
@martyone
Copy link
Member Author

Fixed two issues:

  • Mode not changed back to apply-thresholds after fully charged
  • Not possible to activate apply-thresholds-after-full after reaching the upper threshold

@martyone
Copy link
Member Author

The diff to look at is 9bd6235..aebe3a9

Copy link
Member

@vigejolla vigejolla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@spiiroin spiiroin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary new dbus methods should be removed [and any client side code should be changes to use mce settings dbus methods]

@@ -1720,6 +1720,15 @@ udevdevice_evaluate_battery(udevdevice_t *self, mcebat_t *mcebat)
mcebat->battery_status = BATTERY_STATUS_OK;
if( self->udd_full && capacity >= BATTERY_CAPACITY_FULL )
mcebat->battery_status = BATTERY_STATUS_FULL;
/* Some devices never report Full state */
else if ( capacity >= 100 ) {
mcebat->battery_status = BATTERY_STATUS_FULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ought to be already taken care by "charging -> not-charging transition while capacity >= limit" heuristics few lines below... or do you mean that there is some device that gets stuck in "charging" state forever?

(Not getting battery full immediately after reaching 100% is more or less expected and change like this would trigger premature battery full signaling on well behaving devices).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my X10 II seems to stuck forever in Charging state. It was at 100% capacity for longer time and I never saw Full under sysfs. And since the code below is in an else if block, it never reaches it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg. yet another kind of potential weird behavior... As I have x10 ii as daily device and I do not recall seeing such thing: how was your charging setup? pc/wall charger? display on/off? live tracing over wlan? other sources of battery drain? i.e. anything abnormal that would/could affect final stages of charging.

It would be nice to not have weird scenarios affecting well behaving devices, but maybe this kind of kiss solution is okay in the context of this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally tested with cable connected to laptop, later using a wall charger, both behaving equally WRT this bug. Both with display on and off, monitoring over wlan but also checking journal afterwards. It took a while to determine what actually happens there so I could exercise various options :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically IMO: if you just connect a charger/pc, allow display to blank, leave the device to charge without doing anything special and it reaches battery full in somewhat sane proximity to 100% (led pattern / after the fact journal inspection) -> we should not add heuristics to second guess kernel reporting.

@@ -366,6 +394,13 @@ mch_policy_evaluate_charging_state(void)

if( usb_cable_state == USB_CABLE_DISCONNECTED ) {
switch( mch_charging_mode ) {
case CHARGING_MODE_APPLY_THRESHOLDS_AFTER_FULL:
if ( mch_charging_mode_evaluated_with_cable_connected ) {
mce_setting_set_int(MCE_SETTING_CHARGING_MODE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks suspicious (from mce pov settings are read-only - apart from sanitizing changes made by client side)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah.. when you think of the use case more generally, it is like user scheduling an action by raising a flag and the flag needs to be dropped when it happens. We have two options: either introduce a completely new mechanism (from persistence to UI) or use settings for that. What would you choose?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disconnecting should already clear battery-full-seen flag. If it does not, it is a bug.

What should happen when charger is connected, battery has been full and user toggles back and forth between apply and apply-after-full is somewhat murky and subjective. (iirc the original behavior was to apply-limits, triggering one time charge to full without disconnecting could be achieved by clearing battery-full-seen under suitable conditions when after-full is seen to get selected?)

In any case there is behavioral change here (overriding policy setting that I as an user have selected) and I do not get why such thing would be done / beneficial.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really dislike that policy mode is changed here as it completely breaks existing functionality that I happen to use and rely on...

A live and let live solution could be: use separate boolean override for this new "charge once" behavior, detach settings ui from underlying reality a bit more than what it already is (say, by treating apply-thresholds-after-full as it were apply-thresholds) -> command line can still be used for tweaking by people not served by ui.

modules/charging.c Outdated Show resolved Hide resolved
modules/charging.h Outdated Show resolved Hide resolved
@@ -366,6 +394,13 @@ mch_policy_evaluate_charging_state(void)

if( usb_cable_state == USB_CABLE_DISCONNECTED ) {
switch( mch_charging_mode ) {
case CHARGING_MODE_APPLY_THRESHOLDS_AFTER_FULL:
if ( mch_charging_mode_evaluated_with_cable_connected ) {
mce_setting_set_int(MCE_SETTING_CHARGING_MODE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disconnecting should already clear battery-full-seen flag. If it does not, it is a bug.

What should happen when charger is connected, battery has been full and user toggles back and forth between apply and apply-after-full is somewhat murky and subjective. (iirc the original behavior was to apply-limits, triggering one time charge to full without disconnecting could be achieved by clearing battery-full-seen under suitable conditions when after-full is seen to get selected?)

In any case there is behavioral change here (overriding policy setting that I as an user have selected) and I do not get why such thing would be done / beneficial.

@@ -1720,6 +1720,15 @@ udevdevice_evaluate_battery(udevdevice_t *self, mcebat_t *mcebat)
mcebat->battery_status = BATTERY_STATUS_OK;
if( self->udd_full && capacity >= BATTERY_CAPACITY_FULL )
mcebat->battery_status = BATTERY_STATUS_FULL;
/* Some devices never report Full state */
else if ( capacity >= 100 ) {
mcebat->battery_status = BATTERY_STATUS_FULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg. yet another kind of potential weird behavior... As I have x10 ii as daily device and I do not recall seeing such thing: how was your charging setup? pc/wall charger? display on/off? live tracing over wlan? other sources of battery drain? i.e. anything abnormal that would/could affect final stages of charging.

It would be nice to not have weird scenarios affecting well behaving devices, but maybe this kind of kiss solution is okay in the context of this PR.

Signed-off-by: Martin Kampas <martin.kampas@jolla.com>
@martyone martyone changed the title Expose charging hysteresis control on DBus. JB#58372 charging: Apply thresholds after full just once. JB#58372 Sep 15, 2022
@martyone
Copy link
Member Author

martyone commented Nov 7, 2022

Superseded by #16

@martyone martyone closed this Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants