rickysarraf / laptop-mode-tools

Power Savings tool for Linux
https://www.researchut.com/tags/laptop-mode-tools/
GNU General Public License v2.0
550 stars 47 forks source link

race condition between cpuhotplug and cpufreq #201

Open Ronemisimus opened 1 year ago

Ronemisimus commented 1 year ago

Describe the bug when cpufreq and cpuhotplug are enabled, hotplug works as expected when unplugging however when switching to AC cpufreq is changing the governor only in core that aren't hotpluged meaning online cores change their governor as expected while the rest are reset to the same governor for me it's schedutil

P.s i'd love to help in anyway i can - if you can point me to a direction in the code i'll try to find a solution but it looks like some race condition to me

To Reproduce Steps to reproduce the behavior:

  1. enable cpufreq module
  2. enable cpuhotplug module
  3. plug the charger and manually set all cores to performance governor
  4. unplug charger and see 1/4 of core remaining online with schedutil as expected
  5. plug charger again - all cores are online, cores that were disabled are now in schedutil the rest behave correctly

Expected behavior the cores are switched to the same governor regardless of hotplug state, meaning all are on performance when the charger is plugged in

Important Information:

sudo cpupower -c 0-15 frequency-info -p
analyzing CPU 0:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 1:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 2:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 3:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 4:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 5:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 6:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 7:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 8:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 9:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 10:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 11:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 12:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 13:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 14:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 15:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.

after unplug:

sudo cpupower -c 0-15 frequency-info -p
analyzing CPU 0:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 1:
 *is offline

analyzing CPU 2:
 *is offline

analyzing CPU 3:
 *is offline

analyzing CPU 4:
 *is offline

analyzing CPU 5:
 *is offline

analyzing CPU 6:
 *is offline

analyzing CPU 7:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 8:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 9:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 10:
 *is offline

analyzing CPU 11:
 *is offline

analyzing CPU 12:
 *is offline

analyzing CPU 13:
 *is offline

analyzing CPU 14:
 *is offline

analyzing CPU 15:
 *is offline

replugging the power we see the error:

sudo cpupower -c 0-15 frequency-info -p
analyzing CPU 0:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 1:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 2:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 3:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 4:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 5:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 6:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 7:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 8:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 9:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "performance" may decide which speed to use
                  within this range.
analyzing CPU 10:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 11:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 12:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 13:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 14:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.
analyzing CPU 15:
  current policy: frequency should be within 1.20 GHz and 3.20 GHz.
                  The governor "schedutil" may decide which speed to use
                  within this range.

Additional context here are my setting in both modules: cpufreq:

BATT_CPU_MAXFREQ=3200000
BATT_CPU_MINFREQ=slowest
BATT_CPU_GOVERNOR=schedutil
BATT_CPU_IGNORE_NICE_LOAD=1
LM_AC_CPU_MAXFREQ=fastest
LM_AC_CPU_MINFREQ=slowest
LM_AC_CPU_GOVERNOR=performance
LM_AC_CPU_IGNORE_NICE_LOAD=1
NOLM_AC_CPU_MAXFREQ=fastest
NOLM_AC_CPU_MINFREQ=slowest
NOLM_AC_CPU_GOVERNOR=performance
NOLM_AC_CPU_IGNORE_NICE_LOAD=0

cpuhotplug:

CONTROL_CPU_HOTPLUG=1
DISABLE_AVAILABLE_CPU="3quarter"
BATT_CPU_HOTPLUG=1
LM_AC_CPU_HOTPLUG=0
NOLM_AC_CPU_HOTPLUG=0
Ronemisimus commented 1 year ago

after another look in the logs it look like maybe the governor is set during unplug to schedutil before hot plugging the cores and when they come back online they are not reset to the correct governor (maybe they are still offline during the governor update)