linrunner / TLP

TLP - Optimize Linux Laptop Battery Life
https://linrunner.de/tlp
GNU General Public License v2.0
2.51k stars 129 forks source link

Battery care for MSI laptops #707

Open ElSargo opened 9 months ago

ElSargo commented 9 months ago

There is a GUI program called MControlCenter that provides battery care functionality such as charge limits amongst other things. However it's a qt GUI program that's only packaged for opensuse and this really seems like the kind of thing that belongs in tlp.

Could tlp implement some of the features? Is there anything I can do to help? Thanks.

linrunner commented 9 months ago

In fact since March there is a driver in the mainline kernel seemingly implementing the standard attributes charge_control_start/end_threshold.

So let's see if your kernel is recent enough. Please show:

sudo tlp-stat -s -b
ElSargo commented 9 months ago

Here it is

--- TLP 1.5.0 --------------------------------------------

+++ System Info
System         = Micro-Star International Co., Ltd. REV:1.0 Summit E14Evo A12M
BIOS           = E14F1IMS.11B
OS Release     = NixOS 23.05 (Stoat)
Kernel         = 6.5.1 #1-NixOS SMP PREEMPT_DYNAMIC Sat Sep  2 07:13:30 UTC 2023 x86_64
/proc/cmdline  = initrd=\efi\nixos\jc70zm4b04lmr094k75w7ird64ajwgzc-initrd-linux-6.5.1-initrd.efi init=/nix/store/x3icvkrddrz9vbzhisnpq3kg6rdlr3d1-nixos-system-SargoSummit-23.05.20230907.4f77ea6/init i915.force_probe=46a6 loglevel=4
Init system    = systemd 
Boot mode      = UEFI

+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 19:41:32,      6 sec(s) ago
Mode           = AC
Power source   = AC

+++ Battery Care
Plugin: generic
Supported features: none available

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = MSI
/sys/class/power_supply/BAT1/model_name                     = BIF0_9
/sys/class/power_supply/BAT1/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT1/charge_full_design             =   4546 [mAh]
/sys/class/power_supply/BAT1/charge_full                    =   4498 [mAh]
/sys/class/power_supply/BAT1/charge_now                     =   2821 [mAh]
/sys/class/power_supply/BAT1/current_now                    =      0 [mA]
/sys/class/power_supply/BAT1/status                         = Not charging

/sys/class/power_supply/BAT1/charge_control_start_threshold = (not available) 
/sys/class/power_supply/BAT1/charge_control_end_threshold   = (not available) 

Charge                                                      =   62.7 [%]
Capacity                                                    =   98.9 [%]

I'm on the latest kernel but I think NixOS doesn't have the msi-ec module installed by default. lsmod | rg msi-ec no output I didn't know about this driver before so I'll try installing it and see if it works and update this issue.

ElSargo commented 9 months ago

Ok after a bit of digging it looks like msi-ec is in but not enabled by default. But the module refuses to load because my firmware is more up to date than the one the driver is looking for 14F1EMS1.118 on my system vs 14F1EMS1.115 in the driver. Ill try to find a workaround

ElSargo commented 9 months ago

The addresses for battery control in mcontrolcenter work flawlessly without msi-ec, and haven't been changed in over a year, so I am assuming that a patch for msi-ec changing the firmware id should be all thats required for the driver to function.

linrunner commented 9 months ago

I find the approach of restricting the driver to individual BIOS versions strange.

Before I start programming a TLP plugin for MSI, I would like to be sure that you are available for testing. Once you have managed to load the driver, I could get started.

Do you know of any restrictions on the value of the charge thresholds besides this hint in the driver commit?

note, that start and end thresholds control the same EC parameter and are always 10% apart

Otherwise I would assume 10 <= charge_control_end_threshold <= 100. Values < 10 for charge_control_end_threshold make no sense because of the calculation rule for charge_control_start_threshold.

ElSargo commented 9 months ago

Judging from mcontrolcenter, it looks like any value from 30% <= charge_control_end_threshold <= 100% is fair game. In the msi-ec driver the limits for the threshold are set to 0x8a <= charge_control_end_threshold <= 0xe4 although it isn't obvious to me what percentage that is 53% - 89%?

The driver has lists of firmware versions to check against and find valid configurations for so I think it's just a case of no-one has tested this version.

ElSargo commented 9 months ago

OK after patching the module it loads fine and appears to be working correctly. Tlp is also able to read the charge thresholds

--- TLP 1.5.0 --------------------------------------------

+++ System Info
System         = Micro-Star International Co., Ltd. REV:1.0 Summit E14Evo A12M
BIOS           = E14F1IMS.11B
OS Release     = openSUSE Tumbleweed
Kernel         = 6.5.2-1-default #1 SMP PREEMPT_DYNAMIC Fri Sep  8 07:32:27 UTC 2023 (fdde566) x86_64
/proc/cmdline  = BOOT_IMAGE=/boot/vmlinuz-6.5.2-1-default root=UUID=73c5bc00-fc93-413f-98ec-ad88b2770c3c splash=silent resume=/dev/disk/by-uuid/05609abd-53d1-4a7e-a6c2-6b25e80867a3 mitigations=auto quiet security=apparmor
Init system    = systemd 
Boot mode      = UEFI

+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 07:16:08 AM,    410 sec(s) ago
Mode           = AC
Power source   = AC

Error: tlp.service is not enabled, power saving will not apply on boot.
>>> Invoke 'systemctl enable tlp.service' to correct this!

+++ Battery Care
Plugin: generic
Supported features: none available

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = MSI
/sys/class/power_supply/BAT1/model_name                     = BIF0_9
/sys/class/power_supply/BAT1/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT1/charge_full_design             =   4546 [mAh]
/sys/class/power_supply/BAT1/charge_full                    =   4496 [mAh]
/sys/class/power_supply/BAT1/charge_now                     =   2798 [mAh]
/sys/class/power_supply/BAT1/current_now                    =      0 [mA]
/sys/class/power_supply/BAT1/status                         = Not charging

/sys/class/power_supply/BAT1/charge_control_start_threshold =     50 [%]
/sys/class/power_supply/BAT1/charge_control_end_threshold   =     60 [%]

Charge                                                      =   62.2 [%]
Capacity                                                    =   98.9 [%]
ElSargo commented 9 months ago
And yes I will be able to test anything. Also the driver comes with batter charge presets Preset start stop
min 50% 60%
medium 70% 80%
max none 100%

as well as a "super battery" mode, could be useful if you are making a plugin for msi

linrunner commented 9 months ago

Sorry for the late reply, I was busy with 1.6.1.

In the meantime I have read the driver code. It clarifies a few things. From looking at charge_control_threshold_show() and charge_control_threshold_store() I reckon there is only one EC register to control the charge threshold(s) and the hardware dictates stop = start + 10. From data structures like

static struct msi_ec_conf CONF0 __initdata = {
    .allowed_fw = ALLOWED_FW_0,
    .charge_control = {
        .address      = 0xef,
        .offset_start = 0x8a,
        .offset_end   = 0x80,
        .range_min    = 0x8a,
        .range_max    = 0xe4,
    },

one can also conclude that 0 <= start <= 90 and 10 <= stop <= 100

I would detect the hardware in two steps:

  1. Is it an MSI laptop?
  2. Does it support charge thresholds?

Does your laptop load only the _msiec module or also _msilaptop?

ElSargo commented 9 months ago

The msi_laptop module appears to be for older hardware, my laptop (Summit e14) auto-loads the msi_wmi driver along with msi-ec.

linrunner commented 8 months ago

Hi.

I completed an initial implementation in branch feature/bat.d. If you don't want to build a package yourself, you may just install bat.d/55-msi to /usr/share/tlp/bat.d by hand.

I need the output of

sudo tlp-stat -s -b

I also provide an automated test unit-tests/charge-thresholds_msi. To run it you need to install the tool clitest. Please show the output of the test script.

Thanks in advance for testing.

EDIT: branch changed

ElSargo commented 8 months ago

Sorry for late reply, here is the output:

--- TLP 1.6.1 --------------------------------------------

+++ System Info
System         = Micro-Star International Co., Ltd. REV:1.0 Summit E14Evo A12M
BIOS           = E14F1IMS.11B
OS Release     = openSUSE Tumbleweed
Kernel         = 6.5.4-1-default #1 SMP PREEMPT_DYNAMIC Wed Sep 20 05:07:04 UTC 2023 (fdd7e9e) x86_64
/proc/cmdline  = BOOT_IMAGE=/boot/vmlinuz-6.5.4-1-default root=UUID=73c5bc00-fc93-413f-98ec-ad88b2770c3c splash=silent resume=/dev/disk/by-uuid/05609abd-53d1-4a7e-a6c2-6b25e80867a3 mitigations=auto quiet security=apparmor
Init system    = systemd 
Boot mode      = UEFI
Suspend mode   = [s2idle] deep

+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 05:07:32 PM, 35 sec(s) ago
Mode           = AC
Power source   = AC

+++ Battery Care
Plugin: generic
Supported features: none available

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = MSI
/sys/class/power_supply/BAT1/model_name                     = BIF0_9
/sys/class/power_supply/BAT1/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT1/charge_full_design             =   4546 [mAh]
/sys/class/power_supply/BAT1/charge_full                    =   4403 [mAh]
/sys/class/power_supply/BAT1/charge_now                     =   2532 [mAh]
/sys/class/power_supply/BAT1/current_now                    =      0 [mA]
/sys/class/power_supply/BAT1/status                         = Not charging

/sys/class/power_supply/BAT1/charge_control_start_threshold =     50 [%]
/sys/class/power_supply/BAT1/charge_control_end_threshold   =     60 [%]

Charge                                                      =   57.5 [%]
Capacity                                                    =   96.9 [%]

And the unit test

#1      # +++ MSI ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2      #
#3      # --- tlp start
#4      sudo tlp start -- START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0= START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#5      sudo tlp start -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#6      sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="9" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #6, line 16] sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="9" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
@@ -1,2 +1 @@
-Error in configuration at STOP_CHARGE_THRESH_BAT1="9": not specified, invalid or out of range (10..100). Battery skipped.
 TLP started in AC mode (auto).
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#7      sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#8      sudo tlp start -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#9      sudo tlp start -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#10     sudo tlp start -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#11     #
#12     # --- tlp setcharge w/o arguments
#13     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #13, line 29] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  =  90
-  start =  80 (changed to meet hardware constraint)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#14     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #14, line 33] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  =  90 (no change)
-  start =  80 (no change)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#15     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="XYZZY"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #15, line 37] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="XYZZY"
@@ -1 +1 @@
-Error in configuration at STOP_CHARGE_THRESH_BAT1="XYZZY": not specified, invalid or out of range (10..100). Aborted.
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#16     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="9"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #16, line 39] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="9"
@@ -1 +1 @@
-Error in configuration at STOP_CHARGE_THRESH_BAT1="9": not specified, invalid or out of range (10..100). Aborted.
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#17     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #17, line 41] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101"
@@ -1 +1 @@
-Error in configuration at STOP_CHARGE_THRESH_BAT1="101": not specified, invalid or out of range (10..100). Aborted.
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#18     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #18, line 43] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97"
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  =  97
-  start =  87 (changed to meet hardware constraint)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#19     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #19, line 47] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  =  96
-  start =  86 (changed to meet hardware constraint)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#20     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #20, line 51] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  =  96 (no change)
-  start =  86 (no change)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#21     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF"
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #21, line 55] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF"
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  = 100
-  start =  90 (changed to meet hardware constraint)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#22     sudo tlp setcharge -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF"
#23     #
#24     # --- tlp setcharge w/ arguments
#25     sudo tlp setcharge 70 90 BAT1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #25, line 63] sudo tlp setcharge 70 90 BAT1
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  =  90
-  start =  80 (changed to meet hardware constraint)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#26     sudo tlp setcharge 70 90
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #26, line 67] sudo tlp setcharge 70 90
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  =  90 (no change)
-  start =  80 (no change)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#27     sudo tlp setcharge 0 XYZZY
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #27, line 71] sudo tlp setcharge 0 XYZZY
@@ -1 +1 @@
-Error: stop charge threshold (XYZZY) for BAT1 is not specified, invalid or out of range (10..100). Aborted.
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#28     sudo tlp setcharge 0 9
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #28, line 73] sudo tlp setcharge 0 9
@@ -1 +1 @@
-Error: stop charge threshold (9) for BAT1 is not specified, invalid or out of range (10..100). Aborted.
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#29     sudo tlp setcharge 0 101
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #29, line 75] sudo tlp setcharge 0 101
@@ -1 +1 @@
-Error: stop charge threshold (101) for BAT1 is not specified, invalid or out of range (10..100). Aborted.
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#30     sudo tlp setcharge 97 97
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #30, line 77] sudo tlp setcharge 97 97
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  =  97
-  start =  87 (changed to meet hardware constraint)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#31     sudo tlp setcharge 95 96
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #31, line 81] sudo tlp setcharge 95 96
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  =  96
-  start =  86 (changed to meet hardware constraint)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#32     sudo tlp setcharge 95 96
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #32, line 85] sudo tlp setcharge 95 96
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  =  96 (no change)
-  start =  86 (no change)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#33     sudo tlp setcharge DEF DEF
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #33, line 89] sudo tlp setcharge DEF DEF
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  = 100
-  start =  90 (changed to meet hardware constraint)
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#34     sudo tlp setcharge BAT0
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #34, line 93] sudo tlp setcharge BAT0
@@ -1 +1 @@
-Error: battery BAT0 not present.
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#35     sudo tlp setcharge 0 3 BAT0
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #35, line 95] sudo tlp setcharge 0 3 BAT0
@@ -1 +1 @@
-Error: battery BAT0 not present.
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#36     sudo tlp setcharge XYZZY ABCDE BAT0
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #36, line 97] sudo tlp setcharge XYZZY ABCDE BAT0
@@ -1 +1 @@
-Error: battery BAT0 not present.
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#37     #
#38     # --- Reset to hardware defaults
#39     sudo tlp setcharge DEF DEF
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #39, line 101] sudo tlp setcharge DEF DEF
@@ -1,3 +1 @@
-Setting temporary charge thresholds for BAT1:
-  stop  = 100
-  start =  90
+Error: battery charge thresholds not available.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#40     # --- tlp-stat
#41     sudo tlp-stat -b | grep -E 'charge_control'
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #41, line 106] sudo tlp-stat -b | grep -E 'charge_control'
@@ -1,2 +1,2 @@
-/sys/class/power_supply/BAT1/charge_control_start_threshold =     90 [%]
-/sys/class/power_supply/BAT1/charge_control_end_threshold   =    100 [%]
+/sys/class/power_supply/BAT1/charge_control_start_threshold =     50 [%]
+/sys/class/power_supply/BAT1/charge_control_end_threshold   =     60 [%]
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#42     #

FAIL: 24 of 42 tests failed

Many of the tests failed, do you know if this could be an error on my end? Anything that could be interfering with it?

linrunner commented 8 months ago

Oops. Plugin does not work at all:

+++ Battery Care Plugin: generic Supported features: none available

Let's see what happens. Please add the following line to your TLP config:

TLP_DEBUG="bat ps run"

Show outputs:

sudo tlp noop
sudo tlp-stat -T
ls -la /usr/share/tlp/bat.d/
ls -l /sys/module/msi*
grep . /sys/class/power_supply/BAT1/*
ElSargo commented 8 months ago

I'm so sorry I had not installed the plugin correctly in the previous test, I re-ran the tests and many more of them pass now and the plugin seems to be loaded correctly. sudo tlp-stat -s -b

--- TLP 1.6.1 --------------------------------------------

+++ System Info
System         = Micro-Star International Co., Ltd. REV:1.0 Summit E14Evo A12M
BIOS           = E14F1IMS.11B
OS Release     = openSUSE Tumbleweed
Kernel         = 6.5.4-1-default #1 SMP PREEMPT_DYNAMIC Wed Sep 20 05:07:04 UTC 2023 (fdd7e9e) x86_64
/proc/cmdline  = BOOT_IMAGE=/boot/vmlinuz-6.5.4-1-default root=UUID=73c5bc00-fc93-413f-98ec-ad88b2770c3c splash=silent resume=/dev/disk/by-uuid/05609abd-53d1-4a7e-a6c2-6b25e80867a3 mitigations=auto quiet security=apparmor
Init system    = systemd 
Boot mode      = UEFI
Suspend mode   = [s2idle] deep

+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 08:36:49 PM, 242 sec(s) ago
Mode           = AC
Power source   = AC

+++ Battery Care
Plugin: msi
Supported features: charge thresholds
Driver usage:
* natacpi (msi_ec) = active (charge thresholds)
Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  don't care (hardware enforces stop - 10)
* STOP_CHARGE_THRESH_BAT0/1:   10..100(default)

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = MSI
/sys/class/power_supply/BAT1/model_name                     = BIF0_9
/sys/class/power_supply/BAT1/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT1/charge_full_design             =   4546 [mAh]
/sys/class/power_supply/BAT1/charge_full                    =   4628 [mAh]
/sys/class/power_supply/BAT1/charge_now                     =   2992 [mAh]
/sys/class/power_supply/BAT1/current_now                    =   2359 [mA]
/sys/class/power_supply/BAT1/status                         = Charging

/sys/class/power_supply/BAT1/charge_control_start_threshold =     90 [%]
/sys/class/power_supply/BAT1/charge_control_end_threshold   =    100 [%]

Charge                                                      =   64.6 [%]
Capacity                                                    =  101.8 [%]

MSI unit test

#1      # +++ MSI ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2      #
#3      # --- tlp start
#4      sudo tlp start -- START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0= START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#5      sudo tlp start -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#6      sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="9" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#7      sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #7, line 19] sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
@@ -1 +1,2 @@
+Error in configuration at STOP_CHARGE_THRESH_BAT1="101": not specified, invalid or out of range (10..100). Battery skipped.
 TLP started in AC mode (auto).
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#8      sudo tlp start -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#9      sudo tlp start -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#10     sudo tlp start -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#11     #
#12     # --- tlp setcharge w/o arguments
#13     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #13, line 29] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  90
-  start =  80 (changed to meet hardware constraint)
+  start =  80 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#14     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
#15     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="XYZZY"
#16     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="9"
#17     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101"
#18     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #18, line 43] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97"
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  97
-  start =  87 (changed to meet hardware constraint)
+  start =  87 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#19     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #19, line 47] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  96
-  start =  86 (changed to meet hardware constraint)
+  start =  86 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#20     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
#21     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #21, line 55] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF"
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  = 100
-  start =  90 (changed to meet hardware constraint)
+  start =  90 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#22     sudo tlp setcharge -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF"
#23     #
#24     # --- tlp setcharge w/ arguments
#25     sudo tlp setcharge 70 90 BAT1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #25, line 63] sudo tlp setcharge 70 90 BAT1
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  90
-  start =  80 (changed to meet hardware constraint)
+  start =  80 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#26     sudo tlp setcharge 70 90
#27     sudo tlp setcharge 0 XYZZY
#28     sudo tlp setcharge 0 9
#29     sudo tlp setcharge 0 101
#30     sudo tlp setcharge 97 97
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #30, line 77] sudo tlp setcharge 97 97
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  97
-  start =  87 (changed to meet hardware constraint)
+  start =  87 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#31     sudo tlp setcharge 95 96
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #31, line 81] sudo tlp setcharge 95 96
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  96
-  start =  86 (changed to meet hardware constraint)
+  start =  86 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#32     sudo tlp setcharge 95 96
#33     sudo tlp setcharge DEF DEF
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #33, line 89] sudo tlp setcharge DEF DEF
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  = 100
-  start =  90 (changed to meet hardware constraint)
+  start =  90 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#34     sudo tlp setcharge BAT0
#35     sudo tlp setcharge 0 3 BAT0
#36     sudo tlp setcharge XYZZY ABCDE BAT0
#37     #
#38     # --- Reset to hardware defaults
#39     sudo tlp setcharge DEF DEF
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #39, line 101] sudo tlp setcharge DEF DEF
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
-  stop  = 100
-  start =  90
+  stop  = 100 (no change)
+  start =  90 (no change)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#40     # --- tlp-stat
#41     sudo tlp-stat -b | grep -E 'charge_control'
#42     #

Additionally here is the debug info you requested sudo tlp noop :Debug: no operation performed. sudo tlp-stat -T

Oct 10 20:47:37 localhost.localdomain tlp[25050]: +++ noop (1.6.1) ++++++++++++++++++++++++++++++++++++++++
Oct 10 20:47:37 localhost.localdomain tlp[25050]: SHELL=/usr/bin/bash; umask=0022
Oct 10 20:47:37 localhost.localdomain tlp[25050]: get_sys_power_supply(ADP1).ac_online: syspwr=0
Oct 10 20:47:37 localhost.localdomain tlp[25050]: power_source=ac
Oct 10 20:47:37 localhost.localdomain tlp[25050]: manual_mode=none
Oct 10 20:47:37 localhost.localdomain tlp[25050]: power_mode=ac
Oct 10 20:47:37 localhost.localdomain tlp[25050]: check_thinkpad.not_a_thinkpad: model=REV:1.0
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.thinkpad.not_a_thinkpad
Oct 10 20:47:37 localhost.localdomain tlp[25050]: check_thinkpad.not_a_thinkpad: model=REV:1.0
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.thinkpad-legacy.not_a_thinkpad
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.asus.no_match
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.huawei.no_match
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.lenovo.no_match
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.samsung.no_match
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.lg.no_match
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.lg-legacy.no_match
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.sony.no_match
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.system76.no_match
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.toshiba.no_match
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv_init.msi: batteries=BAT1; natacpi=0; thresh=natacpi; bn_start=charge_control_start_threshold; bn_stop=charge_control_end_threshold;
Oct 10 20:47:37 localhost.localdomain tlp[25050]: batdrv.msi.select_battery(DEF): bat_str=BAT1; bd_read=/sys/class/power_supply/BAT1; bf_start=/sys/class/power_supply/BAT1/charge_control_start_threshold; bf_stop=/sys/class/power_supply/BAT1/charge_control_end_threshold
Oct 10 20:47:38 localhost.localdomain tlp[25050]: save_runconf.ok: /run/tlp/tlp-run.conf_tmpY3Q5tb -> /run/tlp/run.conf

ls -la /usr/share/tlp/bat.d/

total 308
drwxr-xr-x 1 root root   266 Oct 10 20:33 ./
drwxr-xr-x 1 root root   216 Sep 30 20:02 ../
-rwxr-xr-x 1 root root 50701 Sep 27 09:09 05-thinkpad*
-rwxr-xr-x 1 root root 33086 Sep 27 09:09 10-thinkpad-legacy*
-rwxr-xr-x 1 root root 16902 Sep 27 09:09 15-asus*
-rwxr-xr-x 1 root root 16974 Sep 27 09:09 20-huawei*
-rwxr-xr-x 1 root root 15552 Sep 27 09:09 25-lenovo*
-rwxr-xr-x 1 root root 15527 Sep 27 09:09 30-samsung*
-rwxr-xr-x 1 root root 17143 Sep 27 09:09 35-lg*
-rwxr-xr-x 1 root root 15736 Sep 27 09:09 36-lg-legacy*
-rwxr-xr-x 1 root root 15696 Sep 27 09:09 40-sony*
-rwxr-xr-x 1 root root 20549 Sep 27 09:09 45-system76*
-rwxr-xr-x 1 root root 16936 Sep 27 09:09 50-toshiba*
-rwxr-xr-x 1 root root 18847 Oct 10 20:33 55-msi*
-rwxr-xr-x 1 root root  7329 Sep 27 09:09 90-generic*
-rwxr-xr-x 1 root root 21393 Sep 27 09:09 TEMPLATE*

ls -l /sys/module/msi*

/sys/module/msi_ec:
total 0
-r--r--r-- 1 root root 4096 Oct 10 20:30 coresize
drwxr-xr-x 2 root root    0 Oct 10 20:30 drivers/
drwxr-xr-x 2 root root    0 Oct 10 20:30 holders/
-r--r--r-- 1 root root 4096 Oct 10 20:30 initsize
-r--r--r-- 1 root root 4096 Oct 10 20:30 initstate
drwxr-xr-x 2 root root    0 Oct 10 20:30 notes/
-r--r--r-- 1 root root 4096 Oct 10 20:30 refcnt
drwxr-xr-x 2 root root    0 Oct 10 20:30 sections/
-r--r--r-- 1 root root 4096 Oct 10 20:30 srcversion
-r--r--r-- 1 root root 4096 Oct 10 20:30 taint
--w------- 1 root root 4096 Oct 10 20:30 uevent
-r--r--r-- 1 root root 4096 Oct 10 20:30 version

/sys/module/msi_wmi:
total 0
-r--r--r-- 1 root root 4096 Oct 10 20:30 coresize
drwxr-xr-x 2 root root    0 Oct 10 20:30 holders/
-r--r--r-- 1 root root 4096 Oct 10 20:30 initsize
-r--r--r-- 1 root root 4096 Oct 10 20:30 initstate
drwxr-xr-x 2 root root    0 Oct 10 20:30 notes/
-r--r--r-- 1 root root 4096 Oct 10 20:30 refcnt
drwxr-xr-x 2 root root    0 Oct 10 20:30 sections/
-r--r--r-- 1 root root 4096 Oct 10 20:30 srcversion
-r--r--r-- 1 root root 4096 Oct 10 20:30 taint
--w------- 1 root root 4096 Oct 10 20:30 uevent

grep . /sys/class/power_supply/BAT1/*

/sys/class/power_supply/BAT1/alarm:0
/sys/class/power_supply/BAT1/capacity:72
/sys/class/power_supply/BAT1/capacity_level:Normal
/sys/class/power_supply/BAT1/charge_control_end_threshold:100
/sys/class/power_supply/BAT1/charge_control_start_threshold:90
/sys/class/power_supply/BAT1/charge_full:4628000
/sys/class/power_supply/BAT1/charge_full_design:4546000
/sys/class/power_supply/BAT1/charge_now:3357000
/sys/class/power_supply/BAT1/current_now:2233000
/sys/class/power_supply/BAT1/cycle_count:0
grep: /sys/class/power_supply/BAT1/device: Is a directory
grep: /sys/class/power_supply/BAT1/hwmon0: Is a directory
/sys/class/power_supply/BAT1/manufacturer:MSI
/sys/class/power_supply/BAT1/model_name:BIF0_9
grep: /sys/class/power_supply/BAT1/power: Is a directory
/sys/class/power_supply/BAT1/present:1
/sys/class/power_supply/BAT1/status:Charging
grep: /sys/class/power_supply/BAT1/subsystem: Is a directory
/sys/class/power_supply/BAT1/technology:Li-ion
/sys/class/power_supply/BAT1/type:Battery
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_NAME=BAT1
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_TYPE=Battery
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_STATUS=Charging
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_PRESENT=1
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_TECHNOLOGY=Li-ion
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_CYCLE_COUNT=0
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_VOLTAGE_MIN_DESIGN=15400000
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_VOLTAGE_NOW=16868000
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_CURRENT_NOW=2233000
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_CHARGE_FULL_DESIGN=4546000
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_CHARGE_FULL=4628000
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_CHARGE_NOW=3357000
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_CAPACITY=72
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_CAPACITY_LEVEL=Normal
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_MODEL_NAME=BIF0_9
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_MANUFACTURER=MSI
/sys/class/power_supply/BAT1/uevent:POWER_SUPPLY_SERIAL_NUMBER=
/sys/class/power_supply/BAT1/voltage_min_design:15400000
/sys/class/power_supply/BAT1/voltage_now:16868000
linrunner commented 8 months ago

@ElSargo Thanks. That looks much better.

I fixed line 19 of the unit test. The remaining discrepancies are due to the fact that you did not use the latest version of charge-thresholds_msi.

Please make sure you are running with the HEAD of the branch feature.d/bat. Since I reordered the commit history, you will need a git pull --force. Then install 60-macbook from it and test with charge-thresholds_msi:

sudo tlp-stat -b
unit-tests/charge-thresholds_msi
ElSargo commented 8 months ago

Ok I checked it out from the latest version, it seems like the failing tests are due to the driver automatically setting the start threshold 10% bellow the end. Can confirm it is changing the thresholds, I woke up to find my battery at 100% 🥲.

sudo tlp-stat -b


--- TLP 1.6.1 --------------------------------------------

+++ Battery Care
Plugin: msi
Supported features: charge thresholds
Driver usage:
* natacpi (msi_ec) = active (charge thresholds)
Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  don't care (hardware enforces stop - 10)
* STOP_CHARGE_THRESH_BAT0/1:   10..100(default)

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = MSI
/sys/class/power_supply/BAT1/model_name                     = BIF0_9
/sys/class/power_supply/BAT1/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT1/charge_full_design             =   4546 [mAh]
/sys/class/power_supply/BAT1/charge_full                    =   4456 [mAh]
/sys/class/power_supply/BAT1/charge_now                     =   4456 [mAh]
/sys/class/power_supply/BAT1/current_now                    =      0 [mA]
/sys/class/power_supply/BAT1/status                         = Full

/sys/class/power_supply/BAT1/charge_control_start_threshold =     90 [%]
/sys/class/power_supply/BAT1/charge_control_end_threshold   =    100 [%]

Charge                                                      =  100.0 [%]
Capacity                                                    =   98.0 [%]

unit-tests/charge-thresholds_msi

#1      # +++ MSI ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2      #
#3      # --- tlp start
#4      sudo tlp start -- START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0= START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #4, line 12] sudo tlp start -- START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0= START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1 +1 @@
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#5      sudo tlp start -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #5, line 14] sudo tlp start -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
@@ -1 +1 @@
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#6      sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="9" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #6, line 16] sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="9" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
@@ -1,2 +1,2 @@
 Error in configuration at STOP_CHARGE_THRESH_BAT1="9": not specified, invalid or out of range (10..100). Battery skipped.
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#7      sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #7, line 19] sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
@@ -1,2 +1,2 @@
-Error in configuration at STOP_CHARGE_THRESH_BAT1="101": not specified, invalid or out of range (10..100). Battery skipped
-TLP started in AC mode (auto).
+Error in configuration at STOP_CHARGE_THRESH_BAT1="101": not specified, invalid or out of range (10..100). Battery skipped.
+TLP started in battery mode (auto).
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#8      sudo tlp start -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #8, line 22] sudo tlp start -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
@@ -1 +1 @@
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#9      sudo tlp start -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #9, line 24] sudo tlp start -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
@@ -1 +1 @@
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#10     sudo tlp start -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #10, line 26] sudo tlp start -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
@@ -1 +1 @@
-TLP started in AC mode (auto).
+TLP started in battery mode (auto).
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#11     #
#12     # --- tlp setcharge w/o arguments
#13     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #13, line 30] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  90
-  start =  80 (changed to meet hardware constraint)
+  start =  80 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#14     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
#15     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="XYZZY"
#16     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="9"
#17     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101"
#18     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #18, line 44] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97"
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  97
-  start =  87 (changed to meet hardware constraint)
+  start =  87 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#19     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #19, line 48] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  96
-  start =  86 (changed to meet hardware constraint)
+  start =  86 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#20     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
#21     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #21, line 56] sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF"
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  = 100
-  start =  90 (changed to meet hardware constraint)
+  start =  90 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#22     sudo tlp setcharge -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF"
#23     #
#24     # --- tlp setcharge w/ arguments
#25     sudo tlp setcharge 70 90 BAT1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #25, line 64] sudo tlp setcharge 70 90 BAT1
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  90
-  start =  80 (changed to meet hardware constraint)
+  start =  80 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#26     sudo tlp setcharge 70 90
#27     sudo tlp setcharge 0 XYZZY
#28     sudo tlp setcharge 0 9
#29     sudo tlp setcharge 0 101
#30     sudo tlp setcharge 97 97
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #30, line 78] sudo tlp setcharge 97 97
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  97
-  start =  87 (changed to meet hardware constraint)
+  start =  87 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#31     sudo tlp setcharge 95 96
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #31, line 82] sudo tlp setcharge 95 96
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  =  96
-  start =  86 (changed to meet hardware constraint)
+  start =  86 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#32     sudo tlp setcharge 95 96
#33     sudo tlp setcharge DEF DEF
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #33, line 90] sudo tlp setcharge DEF DEF
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
   stop  = 100
-  start =  90 (changed to meet hardware constraint)
+  start =  90 (due to hardware constraint)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#34     sudo tlp setcharge BAT0
#35     sudo tlp setcharge 0 3 BAT0
#36     sudo tlp setcharge XYZZY ABCDE BAT0
#37     #
#38     # --- Reset to hardware defaults
#39     sudo tlp setcharge DEF DEF
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #39, line 102] sudo tlp setcharge DEF DEF
@@ -1,3 +1,3 @@
 Setting temporary charge thresholds for BAT1:
-  stop  = 100
-  start =  90
+  stop  = 100 (no change)
+  start =  90 (no change)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#40     # --- tlp-stat
#41     sudo tlp-stat -b | grep -E 'charge_control'
#42     #
linrunner commented 8 months ago

The unit test version I provided yesterday still did not match the newest plugin. Sorry.

Please get unit-tests/charge-thresholds_msi again and re-test:

unit-tests/charge-thresholds_msi

Important: the test must be run on AC power or many output strings won't match.

linrunner commented 8 months ago

Additionally, I would like to know if the MSI hardware retains the thresholds over a suspend/resume cycle. Otherwise, TLP would have to set the thresholds again after resume.

  1. Please configure some thresholds in /etc/tlp.conf (or in your own config snippet below /etc/tlp.d/):
START_CHARGE_THRESH_BAT1=70
STOP_CHARGE_THRESH_BAT1=80
  1. Apply them with sudo tlp setcharge.
  2. Show the output of sudo tlp-stat --cdiff -b
  3. Suspend and resume the machine
  4. Show the output of sudo tlp-stat -b again

Have a nice weekend.

ElSargo commented 8 months ago

Much Better! All tests passed Except for 1. unit-tests/charge-thresholds_msi

#1      # +++ MSI ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#2      #
#3      # --- tlp start
#4      sudo tlp start -- START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0= START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
[sudo] password for root: 
#5      sudo tlp start -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90" START_CHARGE_THRESH_BAT1= STOP_CHARGE_THRESH_BAT1=
#6      sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="9" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#7      sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[FAILED #7, line 19] sudo tlp start -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
@@ -1,2 +1,2 @@
-Error in configuration at STOP_CHARGE_THRESH_BAT1="101": not specified, invalid or out of range (10..100). Battery skipped
+Error in configuration at STOP_CHARGE_THRESH_BAT1="101": not specified, invalid or out of range (10..100). Battery skipped.
 TLP started in AC mode (auto).
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#8      sudo tlp start -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#9      sudo tlp start -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#10     sudo tlp start -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF" START_CHARGE_THRESH_BAT0= STOP_CHARGE_THRESH_BAT0=
#11     #
#12     # --- tlp setcharge w/o arguments
#13     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
#14     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="70" STOP_CHARGE_THRESH_BAT1="90"
#15     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="XYZZY"
#16     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="9"
#17     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="0" STOP_CHARGE_THRESH_BAT1="101"
#18     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="97" STOP_CHARGE_THRESH_BAT1="97"
#19     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
#20     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="95" STOP_CHARGE_THRESH_BAT1="96"
#21     sudo tlp setcharge -- START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF"
#22     sudo tlp setcharge -- NATACPI_ENABLE=0 START_CHARGE_THRESH_BAT1="DEF" STOP_CHARGE_THRESH_BAT1="DEF"
#23     #
#24     # --- tlp setcharge w/ arguments
#25     sudo tlp setcharge 70 90 BAT1
#26     sudo tlp setcharge 70 90
#27     sudo tlp setcharge 0 XYZZY
#28     sudo tlp setcharge 0 9
#29     sudo tlp setcharge 0 101
#30     sudo tlp setcharge 97 97
#31     sudo tlp setcharge 95 96
#32     sudo tlp setcharge 95 96
#33     sudo tlp setcharge BAT0
#34     sudo tlp setcharge 0 3 BAT0
#35     sudo tlp setcharge XYZZY ABCDE BAT0
#36     #
#37     # --- Reset to hardware defaults
#38     sudo tlp setcharge DEF DEF
#39     # --- tlp-stat
#40     sudo tlp-stat -b | grep -E 'charge_control'
#41     #

FAIL: 1 of 41 tests failed

Also I believe the charge thresholds are persisted indefinitely, as they are preserved after reboot or even booting another distro without any battery software at all! Here are the results just to make sure though: sudo tlp setcharge

Setting temporary charge thresholds for BAT1:
  stop  =  80
  start =  70 (due to hardware constraint)

sudo tlp-stat --cdiff -b

--- TLP 1.6.1 --------------------------------------------

+++ Configured Settings (only differences to defaults):
/etc/tlp.conf L0542: START_CHARGE_THRESH_BAT1="70"
/etc/tlp.conf L0544: STOP_CHARGE_THRESH_BAT1="80"
/etc/tlp.conf L0587: TLP_DEBUG="bat ps run"

+++ Battery Care
Plugin: msi
Supported features: charge thresholds
Driver usage:
* natacpi (msi_ec) = active (charge thresholds)
Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  don't care (hardware enforces stop - 10)
* STOP_CHARGE_THRESH_BAT0/1:   10..100(default)

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = MSI
/sys/class/power_supply/BAT1/model_name                     = BIF0_9
/sys/class/power_supply/BAT1/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT1/charge_full_design             =   4546 [mAh]
/sys/class/power_supply/BAT1/charge_full                    =   4306 [mAh]
/sys/class/power_supply/BAT1/charge_now                     =   2966 [mAh]
/sys/class/power_supply/BAT1/current_now                    =   2227 [mA]
/sys/class/power_supply/BAT1/status                         = Charging

/sys/class/power_supply/BAT1/charge_control_start_threshold =     70 [%]
/sys/class/power_supply/BAT1/charge_control_end_threshold   =     80 [%]

Charge                                                      =   68.9 [%]
Capacity                                                    =   94.7 [%]

sudo tlp-stat -b


+++ Battery Care
Plugin: msi
Supported features: charge thresholds
Driver usage:
* natacpi (msi_ec) = active (charge thresholds)
Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  don't care (hardware enforces stop - 10)
* STOP_CHARGE_THRESH_BAT0/1:   10..100(default)

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = MSI
/sys/class/power_supply/BAT1/model_name                     = BIF0_9
/sys/class/power_supply/BAT1/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT1/charge_full_design             =   4546 [mAh]
/sys/class/power_supply/BAT1/charge_full                    =   4306 [mAh]
/sys/class/power_supply/BAT1/charge_now                     =   3010 [mAh]
/sys/class/power_supply/BAT1/current_now                    =   2395 [mA]
/sys/class/power_supply/BAT1/status                         = Charging

/sys/class/power_supply/BAT1/charge_control_start_threshold =     70 [%]
/sys/class/power_supply/BAT1/charge_control_end_threshold   =     80 [%]

Charge                                                      =   69.9 [%]
Capacity                                                    =   94.7 [%]

Appears to be working well!

linrunner commented 8 months ago

Perfect! Thank you very much for testing this.

The deviation is just a cosmetic issue (missing dot) in the test script. Fixed.

So what about the necessary kernel module patch for your machine - will you submit it for inclusion in the mainline kernel?

ElSargo commented 8 months ago

Yes of course, the thing is though that the driver isn't working 100%. Reading the temperature of the GPU and the speed of the right fan isn't working, which should just be a matter of changing an address the code. I plan on resolving this issue before I submit a patch, but I haven't got round to it yet. These features aren't really important though so maybe I should submit it and fix it later? Anyhow thanks a lot for all your hard work on the plugin and on the rest of this incredible project!

linrunner commented 8 months ago

A full customization for your model is better. Finish first and let me know here please.

I expect that quite a few users of the msi plugin will find that their model is not recognized by the kernel driver. I don't know yet how to deal with this support-wise.

linrunner commented 8 months ago

Now merged into main branch

ElSargo commented 8 months ago

If you look at the driver, you see that most of the addresses across all configurations are identical. I think a solution could be to modify it to load a generic confoguration that contains only the standard features ( including battery care ) when a specifc version isn't found. Of course the reason why it isn't like this already could be because there is no guarantee that these values won't change for future models ect, and writing wrong values to the ec can be dangerous.

linrunner commented 7 months ago

@ElSargo I endorse the "generic" approach. Any news on the mainline kernel patch?

@ALL More testing is welcome!

gabrielmalaspina commented 4 months ago

Hello, I hope I'm not hijacking the thread, the topic seems to be generic enough to write here. Any chance we get a patch for another MSI laptop? I'm ready to test :) I tried adding the firmware ver. to msi-ec.c but it didn't work. (Firmware ver. is 14F1EMS1.207) msi_wmi was loaded by default, msi_laptop was not.

Please see below: `--- TLP 1.6.1 --------------------------------------------

+++ System Info System = Micro-Star International Co., Ltd. REV:1.0 Prestige 14Evo B13M BIOS = E14F1IMS.506 OS Release = Ubuntu 23.10 Kernel = 6.5.0-17-generic #17-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 11 14:01:59 UTC 2024 x86_64 /proc/cmdline = BOOT_IMAGE=/@/boot/vmlinuz-6.5.0-17-generic root=UUID=9bf95c02-d737-4ada-be46-ba28aa81643f ro rootflags=subvol=@ quiet splash vt.handoff=7 Init system = systemd v253 (253.5-1ubuntu6.1) Boot mode = UEFI Suspend mode = [s2idle] deep

+++ TLP Status State = enabled RDW state = enabled Last run = 16:56:01, 724 sec(s) ago Mode = battery Power source = battery

+++ Battery Care Plugin: generic Supported features: none available

+++ Battery Status: BAT1 /sys/class/power_supply/BAT1/manufacturer = MSI /sys/class/power_supply/BAT1/model_name = BIF0_9 /sys/class/power_supply/BAT1/cycle_count = 0 (or not supported) /sys/class/power_supply/BAT1/charge_full_design = 4546 [mAh] /sys/class/power_supply/BAT1/charge_full = 4470 [mAh] /sys/class/power_supply/BAT1/charge_now = 2790 [mAh] /sys/class/power_supply/BAT1/current_now = 363 [mA] /sys/class/power_supply/BAT1/status = Discharging

/sys/class/power_supply/BAT1/charge_control_start_threshold = (not available) /sys/class/power_supply/BAT1/charge_control_end_threshold = (not available)

Charge = 62.4 [%] Capacity = 98.3 [%] ` Thanks a lot !

gabrielmalaspina commented 4 months ago

Apologies, I didn't know how to post the output. I'll use "reference"? the next time

ElSargo commented 4 months ago

I think at this point TLP already has all the required functionality to support this. @gabrielmalaspina any issues regarding firmware versions should be directed to the msi-ec GitHub page as that's where the issue lies and there isn't really anything for TLP to do.

There are dozens of open issues there for various firmware versions so in the meantime I think you need to add

"14F1EMS1.207",

Below line 591 to add partial support for your your version, or at least to try and load it. Make sure to find the ec reset switch before you try it and be careful!

gabrielmalaspina commented 4 months ago

Hi, Thanks for replying. I added it after line 691? and installed it with dkms but it's still doesn't work. I unloaded msi_wmi and loaded msi-ec manually. dmesg

[ 8414.695266] ACPI: battery: new extension: msi-ec
[ 8414.695427] msi_ec: module_init

...but when I run tlp-stat -s -b plugin is still generic

--- TLP 1.6.1 --------------------------------------------

+++ System Info
System         = Micro-Star International Co., Ltd. REV:1.0 Prestige 14Evo B13M
BIOS           = E14F1IMS.506
OS Release     = Ubuntu 23.10
Kernel         = 6.5.0-17-generic #17-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 11 14:01:59 UTC 2024 x86_64
/proc/cmdline  = BOOT_IMAGE=/@/boot/vmlinuz-6.5.0-17-generic root=UUID=9bf95c02-d737-4ada-be46-ba28aa81643f ro rootflags=subvol=@ quiet splash vt.handoff=7
Init system    = systemd v253 (253.5-1ubuntu6.1)
Boot mode      = UEFI
Suspend mode   = [s2idle] deep

+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 20:39:31, 324 sec(s) ago
Mode           = AC
Power source   = AC

+++ Battery Care
Plugin: generic
Supported features: none available

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = MSI
/sys/class/power_supply/BAT1/model_name                     = BIF0_9
/sys/class/power_supply/BAT1/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT1/charge_full_design             =   4546 [mAh]
/sys/class/power_supply/BAT1/charge_full                    =   4470 [mAh]
/sys/class/power_supply/BAT1/charge_now                     =   4425 [mAh]
/sys/class/power_supply/BAT1/current_now                    =    182 [mA]
/sys/class/power_supply/BAT1/status                         = Charging

/sys/class/power_supply/BAT1/charge_control_start_threshold =      0 [%]
/sys/class/power_supply/BAT1/charge_control_end_threshold   =      0 [%]

Charge                                                      =   99.0 [%]
Capacity                                                    =   98.3 [%]

thresholds are now in percentage rather than "not available", though Thanks for your help !

user529 commented 4 months ago

Hi! Since dear 'all' has been invited to testing, here's description of my try for MSI GS65 Stealth 9E running Debian 12.

First of all, as it's already mentioned earlier, it's required to have the msi_ec module loaded. Right after I build default module, I found that my firmware is not supported yet. So I loaded it for debug purpose:

# insmod /lib/modules/6.1.0-18-amd64/updates/dkms/msi-ec.ko debug=1

then I found my firmawre version with:

# cat /sys/devices/platform/msi-ec/debug/fw_version
16Q4EMS1.110

then I found that msi_ec already supports GS66 Stealth 11UE (16V4EMS1). And its firmware saved in static const char *ALLOWED_FW_4[] so I decided to put my firmware next to it (next after line 377, if it's matters) and rebuild msi_ec module. Finally, the custom msi_ec module has been loaded successfully:

# dmesg | grep msi
[    3.675871] msi_ec: loading out-of-tree module taints kernel.
[    3.675894] msi_ec: module verification failed: signature and/or required key missing - tainting kernel
[    3.684678] ACPI: battery: new extension: msi-ec
[    3.684679] msi_ec: module_init

# lsmod | grep msi
msi_wmi                20480  0
sparse_keymap          16384  1 msi_wmi
msi_ec                 32768  0
battery                28672  1 msi_ec
video                  65536  3 msi_wmi,i915,nvidia_modeset
wmi                    36864  5 video,intel_wmi_thunderbolt,wmi_bmof,msi_wmi,mxm_wmi

Next step I copied bat.d/55-msi to /usr/share/tlp/bat.d folder and try to run it.

# tlp-stat -s -b
--- TLP 1.5.0 --------------------------------------------

+++ System Info
System         = Micro-Star International Co., Ltd. REV:1.0 GS65 Stealth 9SE
BIOS           = E16Q4IMS.115
OS Release     = Debian GNU/Linux 12 (bookworm)
Kernel         = 6.1.0-18-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.76-1 (2024-02-01) x86_64
/proc/cmdline  = BOOT_IMAGE=/boot/vmlinuz-6.1.0-18-amd64 root=UUID=cef90e79-6815-454a-a3bc-d11b2a7b85ce ro acpi_osi=! "acpi_osi=Windows 2009" quiet nvidia-drm.modeset=1 nouveau.modeset=0
Init system    = systemd v252 (252.22-1~deb12u1)
Boot mode      = UEFI

+++ TLP Status
State          = enabled
RDW state      = enabled
Last run       = 07:47:08 PM,   1947 sec(s) ago
Mode           = battery
Power source   = battery

+++ Battery Care
Plugin: msi
Supported features: charge thresholds
Driver usage:
* natacpi (msi_ec) = active (charge thresholds)
Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  don't care (hardware enforces stop - 10)
* STOP_CHARGE_THRESH_BAT0/1:   10..100(default)

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = MSI
/sys/class/power_supply/BAT1/model_name                     = BIF0_9
/sys/class/power_supply/BAT1/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT1/charge_full_design             =   5280 [mAh]
/sys/class/power_supply/BAT1/charge_full                    =   3388 [mAh]
/sys/class/power_supply/BAT1/charge_now                     =   2069 [mAh]
/sys/class/power_supply/BAT1/current_now                    =    985 [mA]
/sys/class/power_supply/BAT1/status                         = Discharging

/sys/class/power_supply/BAT1/charge_control_start_threshold =      0 [%]
/sys/class/power_supply/BAT1/charge_control_end_threshold   =      0 [%]

Charge                                                      =   61.1 [%]
Capacity                                                    =   64.2 [%]

Unfortunately, success ends there. When I try to set thresholds in /etc/tlp.conf

START_CHARGE_THRESH_BAT1="70"
STOP_CHARGE_THRESH_BAT1="80"

and then run tlp setcharge I get negative thresholds

# tlp-stat -b
--- TLP 1.5.0 --------------------------------------------

+++ Battery Care
Plugin: msi
Supported features: charge thresholds
Driver usage:
* natacpi (msi_ec) = active (charge thresholds)
Parameter value ranges:
* START_CHARGE_THRESH_BAT0/1:  don't care (hardware enforces stop - 10)
* STOP_CHARGE_THRESH_BAT0/1:   10..100(default)

+++ Battery Status: BAT1
/sys/class/power_supply/BAT1/manufacturer                   = MSI
/sys/class/power_supply/BAT1/model_name                     = BIF0_9
/sys/class/power_supply/BAT1/cycle_count                    =      0 (or not supported)
/sys/class/power_supply/BAT1/charge_full_design             =   5280 [mAh]
/sys/class/power_supply/BAT1/charge_full                    =   3388 [mAh]
/sys/class/power_supply/BAT1/charge_now                     =   1633 [mAh]
/sys/class/power_supply/BAT1/current_now                    =   1018 [mA]
/sys/class/power_supply/BAT1/status                         = Discharging

/sys/class/power_supply/BAT1/charge_control_start_threshold =    -96 [%]
/sys/class/power_supply/BAT1/charge_control_end_threshold   =    -86 [%]

Charge                                                      =   48.2 [%]
Capacity                                                    =   64.2 [%]

and in a few seconds something forces my laptop to reboot. I'd appreciate any ideas on how to debug this and figure out exactly what's happens.

ElSargo commented 4 months ago

Can you verify that the driver is in fact working correctly without TLP? Try interacting with the driver directly with the functionality exposed under /sys/devices/platform/msi-ec/ and verify that the charge thresholds are working.

user529 commented 4 months ago

Thanks for the tip! I checked /sys/devices/platform/msi-ec/ and there is no charge_control

# ls -la /sys/devices/platform/msi-ec/ 
total 0
drwxr-xr-x  5 root root    0 Feb 25  2024 .
drwxr-xr-x 23 root root    0 Feb 25  2024 ..
drwxr-xr-x  2 root root    0 Feb 25 13:43 cpu
lrwxrwxrwx  1 root root    0 Feb 25  2024 driver -> ../../../bus/platform/drivers/msi-ec
drwxr-xr-x  2 root root    0 Feb 25 13:43 gpu
drwxr-xr-x  2 root root    0 Feb 25 13:43 power
lrwxrwxrwx  1 root root    0 Feb 25  2024 subsystem -> ../../../bus/platform
-r--r--r--  1 root root 4096 Feb 25 13:43 available_fan_modes
-r--r--r--  1 root root 4096 Feb 25 13:43 available_shift_modes
-rw-r--r--  1 root root 4096 Feb 25 13:43 battery_mode
-rw-r--r--  1 root root 4096 Feb 25 13:43 cooler_boost
-rw-r--r--  1 root root 4096 Feb 25 13:43 driver_override
-rw-r--r--  1 root root 4096 Feb 25 13:43 fan_mode
-r--r--r--  1 root root 4096 Feb 25 13:43 fw_release_date
-r--r--r--  1 root root 4096 Feb 25 13:43 fw_version
-r--r--r--  1 root root 4096 Feb 25 13:43 modalias
-rw-r--r--  1 root root 4096 Feb 25 13:43 shift_mode
-rw-r--r--  1 root root 4096 Feb 25  2024 uevent
-rw-r--r--  1 root root 4096 Feb 25 13:43 webcam
-rw-r--r--  1 root root 4096 Feb 25 13:43 webcam_block

It seems I have to make one step back and return to deal with the msi_ec module.

linrunner commented 4 months ago

@gabrielmalaspina @user529 You should discuss how to properly patch the msi_ec kernel driver for your hardware at its repository: https://github.com/BeardOverflow/msi-ec/issues