Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add NVME temperatures in fan speed calculation #413

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ErichRitz
Copy link

Implement a second fan curve for NVME temperatures, and take the maximum fan speed from the CPU duty curve and the NVME duty curve and use that to set fan speed.

The NVME fan curve is hardcoded to a single table assuming 70 degrees Celsius is the hottest allowable temperature (i.e., the fans should already be at 100% before 70 degrees is reached).

Implement a second fan curve for NVME temperatures, and take the maximum
fan speed from the CPU duty curve and the NVME duty curve and use that
to set fan speed.

The NVME fan curve is hardcoded to a single table assuming 70 degrees
Celsius is the hottest allowable temperature (i.e., the fans should
already be at 100% before 70 degrees is reached).

Signed-off-by: Erich Ritz <erich.public@protonmail.com>
@ErichRitz
Copy link
Author

This tries to address #412

I tested the logic where sensor type "nvme" doesn't exist by recompiling with the match string set to "nvme__" instead of "nvme" to simulate no NVME drive sensors, and the code worked as expected.

Here is some log file output with this patch applied:

[2023-08-09 16:43:50] Starting system76-power daemon from /etc/rc.d/rc.system76-power
[INFO] Starting daemon
[INFO] Connecting to dbus system bus
[INFO] Rescanning PCI bus
[INFO] 0000:3b:00.0: NVIDIA graphics
[INFO] 0000:3b:00.0: Function for 0000:3b:00.0
[INFO] 0000:3b:00.3: Function for 0000:3b:00.0
[INFO] 0000:3b:00.1: Function for 0000:3b:00.0
[INFO] 0000:3b:00.2: Function for 0000:3b:00.0
[INFO] 0000:02:00.0: Other(1A03) graphics
[INFO] 0000:02:00.0: Function for 0000:02:00.0
[INFO] Disabling NMI Watchdog (for kernel debugging only)
[WARN] /proc/sys/kernel/nmi_watchdog does not exist
[INFO] Setting automatic graphics power
[WARN] Failed to set automatic graphics power: does not have switchable graphics
[INFO] Initializing with the balanced profile
[DEBUG] Modifying kernel parameter at "/proc/sys/vm/dirty_expire_centisecs" to 1500
[DEBUG] Modifying kernel parameter at "/proc/sys/vm/dirty_writeback_centisecs" to 1500
[DEBUG] Modifying kernel parameter at "/proc/sys/vm/laptop_mode" to 2
setting powersave with max 3700000
[WARN] Failed to set initial profile: Errors found when setting profile:
    - failed to set scsi host profiles: failed to set link time power management policy med_power_with_dipm on host8: No such file or directory (os error 2)
[INFO] Registering dbus name com.system76.PowerDaemon
[INFO] Adding dbus path /com/system76/PowerDaemon with interface com.system76.PowerDaemon
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: pch_lewisburg
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: iwlwifi_1
[DEBUG] hwmon: hidpp_battery_0
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[INFO] Handling dbus requests
[ERROR] hid_backlight: no system76_acpi::kbd_backlight led
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: pch_lewisburg
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: iwlwifi_1
[DEBUG] hwmon: hidpp_battery_0
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[DEBUG] highest hwmon cpu/gpu temp: 46000
[DEBUG] highest nvidia temp: 57
[DEBUG] current temp: Some(57000)
[DEBUG] cpu duty: Some(119)
[DEBUG] highest hwmon nvme temp: 57850
[DEBUG] highest hwmon nvme temp: 66850
[DEBUG] highest hwmon nvme temp: 69850
[DEBUG] nvme duty: Some(255)
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: pch_lewisburg
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: iwlwifi_1
[DEBUG] hwmon: hidpp_battery_0
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[DEBUG] highest hwmon cpu/gpu temp: 46000
[DEBUG] highest nvidia temp: 57
[DEBUG] current temp: Some(57000)
[DEBUG] cpu duty: Some(119)
[DEBUG] highest hwmon nvme temp: 57850
[DEBUG] highest hwmon nvme temp: 66850
[DEBUG] highest hwmon nvme temp: 69850
[DEBUG] nvme duty: Some(255)

And here is the log output with the simulated no NVME drives:

[2023-08-09 16:43:11] Starting system76-power daemon from /etc/rc.d/rc.system76-power
[INFO] Starting daemon
[INFO] Connecting to dbus system bus
[INFO] Rescanning PCI bus
[INFO] 0000:3b:00.0: NVIDIA graphics
[INFO] 0000:3b:00.0: Function for 0000:3b:00.0
[INFO] 0000:3b:00.3: Function for 0000:3b:00.0
[INFO] 0000:3b:00.1: Function for 0000:3b:00.0
[INFO] 0000:3b:00.2: Function for 0000:3b:00.0
[INFO] 0000:02:00.0: Other(1A03) graphics
[INFO] 0000:02:00.0: Function for 0000:02:00.0
[INFO] Disabling NMI Watchdog (for kernel debugging only)
[WARN] /proc/sys/kernel/nmi_watchdog does not exist
[INFO] Setting automatic graphics power
[WARN] Failed to set automatic graphics power: does not have switchable graphics
[INFO] Initializing with the balanced profile
[DEBUG] Modifying kernel parameter at "/proc/sys/vm/dirty_expire_centisecs" to 1500
[DEBUG] Modifying kernel parameter at "/proc/sys/vm/dirty_writeback_centisecs" to 1500
[DEBUG] Modifying kernel parameter at "/proc/sys/vm/laptop_mode" to 2
setting powersave with max 3700000
[WARN] Failed to set initial profile: Errors found when setting profile:
    - failed to set scsi host profiles: failed to set link time power management policy med_power_with_dipm on host8: No such file or directory (os error 2)
[INFO] Registering dbus name com.system76.PowerDaemon
[INFO] Adding dbus path /com/system76/PowerDaemon with interface com.system76.PowerDaemon
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: pch_lewisburg
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: iwlwifi_1
[DEBUG] hwmon: hidpp_battery_0
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[INFO] Handling dbus requests
[ERROR] hid_backlight: no system76_acpi::kbd_backlight led
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: pch_lewisburg
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: iwlwifi_1
[DEBUG] hwmon: hidpp_battery_0
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[DEBUG] highest hwmon cpu/gpu temp: 45000
[DEBUG] highest nvidia temp: 57
[DEBUG] current temp: Some(57000)
[DEBUG] cpu duty: Some(119)
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: pch_lewisburg
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[DEBUG] hwmon: coretemp
[DEBUG] hwmon: iwlwifi_1
[DEBUG] hwmon: hidpp_battery_0
[DEBUG] hwmon: system76_io
[DEBUG] hwmon: nvme
[DEBUG] hwmon: nvme
[DEBUG] highest hwmon cpu/gpu temp: 46000
[DEBUG] highest nvidia temp: 57
[DEBUG] current temp: Some(57000)
[DEBUG] cpu duty: Some(119)

@ErichRitz
Copy link
Author

ErichRitz commented Aug 9, 2023

I'm not a Rust programmer! You can tell I did a lot of copy/paste and tried to mimic the existing logic as much as possible. I'm sure there are better ways to accomplish what I'm trying to do. But this works for me.

Also, as mentioned in the Issue report, this is all tested on a Thelio Massive:

# cat /sys/class/dmi/id/product_version 
thelio-massive-b1

@jacobgkau jacobgkau requested review from a team August 10, 2023 19:46
@ErichRitz
Copy link
Author

I've been running with this patch for a few days now. Temps on the SSDs and HDDs are much lower now.

HDD temp isn't used for fan speed calculation, but because the fans are running hard now due to SSD temps the HDD temp is now in an acceptable range:

# smartctl -l scttemp /dev/sdc
smartctl 7.2 2020-12-30 r5155 [x86_64-linux-6.4.10-etr] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SCT Status Version:                  3
SCT Version (vendor specific):       522 (0x020a)
Device State:                        Active (0)
Current Temperature:                    49 Celsius
Power Cycle Min/Max Temperature:     46/54 Celsius
Lifetime    Min/Max Temperature:     17/78 Celsius
Under/Over Temperature Limit Count:   0/0

SCT Temperature History Version:     2
Temperature Sampling Period:         3 minutes
Temperature Logging Interval:        59 minutes
Min/Max recommended Temperature:     14/55 Celsius
Min/Max Temperature Limit:           10/60 Celsius
Temperature History Size (Index):    128 (82)

Index    Estimated Time   Temperature Celsius
  83    2023-08-06 07:05    53  **********************************
  84    2023-08-06 08:04    50  *******************************
  85    2023-08-06 09:03    50  *******************************
  86    2023-08-06 10:02    50  *******************************
  87    2023-08-06 11:01    51  ********************************
  88    2023-08-06 12:00    51  ********************************
  89    2023-08-06 12:59    51  ********************************
  90    2023-08-06 13:58    52  *********************************
  91    2023-08-06 14:57    53  **********************************
  92    2023-08-06 15:56    52  *********************************
  93    2023-08-06 16:55    52  *********************************
  94    2023-08-06 17:54    54  ***********************************
  95    2023-08-06 18:53     ?  -
  96    2023-08-06 19:52    51  ********************************
  97    2023-08-06 20:51    66  ***************************************+
  98    2023-08-06 21:50    70  ***************************************+
  99    2023-08-06 22:49    72  ***************************************+
 100    2023-08-06 23:48    70  ***************************************+
 101    2023-08-07 00:47    69  ***************************************+
 102    2023-08-07 01:46    69  ***************************************+
 103    2023-08-07 02:45    68  ***************************************+
 104    2023-08-07 03:44    68  ***************************************+
 105    2023-08-07 04:43    68  ***************************************+
 106    2023-08-07 05:42    69  ***************************************+
 107    2023-08-07 06:41    68  ***************************************+
 108    2023-08-07 07:40    68  ***************************************+
 109    2023-08-07 08:39    65  ***************************************+
 110    2023-08-07 09:38     ?  -
 111    2023-08-07 10:37    45  **************************
 112    2023-08-07 11:36    47  ****************************
 113    2023-08-07 12:35     ?  -
 114    2023-08-07 13:34    24  *****
 115    2023-08-07 14:33     ?  -
 116    2023-08-07 15:32    37  ******************
 117    2023-08-07 16:31    46  ***************************
 ...    ..(  2 skipped).    ..  ***************************
 120    2023-08-07 19:28    46  ***************************
 121    2023-08-07 20:27     ?  -
 122    2023-08-07 21:26    48  *****************************
 123    2023-08-07 22:25     ?  -
 124    2023-08-07 23:24    33  **************
 125    2023-08-08 00:23    51  ********************************
 126    2023-08-08 01:22    69  ***************************************+
 127    2023-08-08 02:21    72  ***************************************+
   0    2023-08-08 03:20    74  ***************************************+
   1    2023-08-08 04:19    72  ***************************************+
   2    2023-08-08 05:18    53  **********************************
   3    2023-08-08 06:17    52  *********************************
   4    2023-08-08 07:16    74  ***************************************+
   5    2023-08-08 08:15    77  ***************************************+
   6    2023-08-08 09:14    77  ***************************************+
   7    2023-08-08 10:13    73  ***************************************+
   8    2023-08-08 11:12    70  ***************************************+
   9    2023-08-08 12:11    70  ***************************************+
  10    2023-08-08 13:10    69  ***************************************+
  11    2023-08-08 14:09    68  ***************************************+
  12    2023-08-08 15:08    68  ***************************************+
  13    2023-08-08 16:07    67  ***************************************+
  14    2023-08-08 17:06    63  ***************************************+
  15    2023-08-08 18:05    60  ***************************************+
  16    2023-08-08 19:04    55  ************************************
  17    2023-08-08 20:03    47  ****************************
  18    2023-08-08 21:02    46  ***************************
  19    2023-08-08 22:01    46  ***************************
  20    2023-08-08 23:00    46  ***************************
  21    2023-08-08 23:59    48  *****************************
  22    2023-08-09 00:58    49  ******************************
  23    2023-08-09 01:57    52  *********************************
  24    2023-08-09 02:56    50  *******************************
  25    2023-08-09 03:55    49  ******************************
  26    2023-08-09 04:54    49  ******************************
  27    2023-08-09 05:53     ?  -
  28    2023-08-09 06:52    44  *************************
  29    2023-08-09 07:51    48  *****************************
 ...    ..(  2 skipped).    ..  *****************************
  32    2023-08-09 10:48    48  *****************************
  33    2023-08-09 11:47    55  ************************************
  34    2023-08-09 12:46    56  *************************************
  35    2023-08-09 13:45    55  ************************************
  36    2023-08-09 14:44    55  ************************************
  37    2023-08-09 15:43    53  **********************************
  38    2023-08-09 16:42    56  *************************************
  39    2023-08-09 17:41    57  **************************************
  40    2023-08-09 18:40    57  **************************************
  41    2023-08-09 19:39    56  *************************************
  42    2023-08-09 20:38    55  ************************************
  43    2023-08-09 21:37     ?  -
  44    2023-08-09 22:36    44  *************************
  45    2023-08-09 23:35     ?  -
  46    2023-08-10 00:34    36  *****************
  47    2023-08-10 01:33    42  ***********************
  48    2023-08-10 02:32    43  ************************
  49    2023-08-10 03:31    44  *************************
  50    2023-08-10 04:30    43  ************************
  51    2023-08-10 05:29    40  *********************
  52    2023-08-10 06:28    40  *********************
  53    2023-08-10 07:27    44  *************************
  54    2023-08-10 08:26     ?  -
  55    2023-08-10 09:25    40  *********************
  56    2023-08-10 10:24    47  ****************************
  57    2023-08-10 11:23    48  *****************************
  58    2023-08-10 12:22    49  ******************************
  59    2023-08-10 13:21    47  ****************************
  60    2023-08-10 14:20    48  *****************************
  61    2023-08-10 15:19    47  ****************************
  62    2023-08-10 16:18    48  *****************************
  63    2023-08-10 17:17    48  *****************************
  64    2023-08-10 18:16    40  *********************
  65    2023-08-10 19:15    39  ********************
  66    2023-08-10 20:14    41  **********************
  67    2023-08-10 21:13    46  ***************************
  68    2023-08-10 22:12    44  *************************
  69    2023-08-10 23:11    42  ***********************
  70    2023-08-11 00:10    41  **********************
  71    2023-08-11 01:09    41  **********************
  72    2023-08-11 02:08    42  ***********************
  73    2023-08-11 03:07    44  *************************
  74    2023-08-11 04:06    43  ************************
  75    2023-08-11 05:05    44  *************************
  76    2023-08-11 06:04    42  ***********************
  77    2023-08-11 07:03    44  *************************
  78    2023-08-11 08:02     ?  -
  79    2023-08-11 09:01    46  ***************************
  80    2023-08-11 10:00    48  *****************************
  81    2023-08-11 10:59    53  **********************************
  82    2023-08-11 11:58    51  ********************************

And yes, I am doing heavy I/O right now. I'm copying my data off the HDDs onto the 2 new SSDs.

Here are some plots from the last roughly 36 hours. You can see the temps drop when my 2 monitors turn off overnight, enough that the fan command drops below 100%.

sensors_fan_cmd_20230810

sensors_nvme_20230810

sensors_fan_cpu_20230810

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant