smcFanControl icon indicating copy to clipboard operation
smcFanControl copied to clipboard

smc: support writing FP values like fan speed (tested on MBP 16,1)

Open Blaisorblade opened this issue 4 years ago • 19 comments

Needed to help with https://github.com/hholtmann/smcFanControl/issues/77 — to set fan speeds by hand. TODO:

  • [ ] update README

I've only tested this on my machine and I haven't programmed in C for a long while, but I've tried to be careful.

Example usage:

$ sudo ./smc -k F0Md -w 01
$ sudo ./smc -k F1Md -w 01
$ sudo ./smc -k F0Tg -p 3000
$ sudo ./smc -k F1Tg -p 3000
$ ./smc -f
Total fans in system: 2

Fan #0:
    Actual speed : 2980
    Minimum speed: 1836
    Maximum speed: 5297
    Safe speed   : 0
    Target speed : 3000
    Mode         : forced

Fan #1:
    Actual speed : 3007
    Minimum speed: 1700
    Maximum speed: 4905
    Safe speed   : 0
    Target speed : 3000
    Mode         : forced

$ ./smc -l|grep F.Tg
  F0Tg  [flt ]  3000 (bytes 00 80 3b 45)
  F1Tg  [flt ]  3000 (bytes 00 80 3b 45)

Blaisorblade avatar Aug 08 '20 14:08 Blaisorblade

(For some minimal testing code for this, see https://github.com/Blaisorblade/smcFanControl/pull/1).

Blaisorblade avatar Aug 08 '20 15:08 Blaisorblade

Wow, it works! I'm amazed. Thank you very much! Does the mode have to be set back to automatic to stop the fan control?

jlehrer1 avatar Aug 08 '20 18:08 jlehrer1

@jlehrer1 I'm not sure as I've only studied the parsing code, but it seems so, as before. I did disable force mode via sudo ./smc -k F0Md -w 00; sudo ./smc -k F1Md -w 00. Sample output:

$ ./smc -f
Total fans in system: 2

Fan #0:
    Actual speed : 5012
    Minimum speed: 1836
    Maximum speed: 5297
    Safe speed   : 0
    Target speed : 5000
    Mode         : forced

Fan #1:
    Actual speed : 4900
    Minimum speed: 1700
    Maximum speed: 4905
    Safe speed   : 0
    Target speed : 4900
    Mode         : forced
$ sudo ./smc -k F1Md -w 00
$ sudo ./smc -k F0Md -w 00
$ ./smc -f
Total fans in system: 2

Fan #0:
    Actual speed : 2562
    Minimum speed: 1836
    Maximum speed: 5297
    Safe speed   : 0
    Target speed : 1836
    Mode         : auto

Fan #1:
    Actual speed : 1812
    Minimum speed: 1700
    Maximum speed: 4905
    Safe speed   : 0
    Target speed : 1700
    Mode         : auto

Blaisorblade avatar Aug 08 '20 18:08 Blaisorblade

@Blaisorblade Interesting. Resetting the values back to 00 keeps the mode in forced for me, but it could be because I have Macs Fan Control running as well. Also, I'm testing this on a Macbook Pro 13" and it works.

Edit: Yes its Macs Fan Control. Closing the app / deleting the smc write resets the fans to auto. Thanks again for this commit, I'm excited to get working.

jlehrer1 avatar Aug 08 '20 19:08 jlehrer1

@jlehrer1 which MBP13''? Do you have production year or model number? And remember combining fan control apps is not really supported; make sure to not trigger bugs that melt your computer :-)

Blaisorblade avatar Aug 08 '20 20:08 Blaisorblade

@Blaisorblade heh yeah I won't, although I'm not too worried. Neither program can override the fans hardware speed limits. It's from 2020.

jlehrer1 avatar Aug 08 '20 20:08 jlehrer1

@Blaisorblade The only thing I'm not sure of is why setting the fan in forced mode is a different key than the fan key? Per your example, F0Tg vs F0Md. How did you know to set F0Md? Thanks again for this.

jlehrer1 avatar Aug 08 '20 20:08 jlehrer1

How did you know to set F0Md?

That's from https://github.com/hholtmann/smcFanControl/issues/77#issuecomment-660781379 and https://github.com/hholtmann/smcFanControl/issues/77#issuecomment-661623897.

The harder part was F0Tg; I took that from the README, but the instructions were contradicted by the code; basically, SMCPrintFans knows how to turn the raw data from SMC into actual values, and I just wrote the inverse, also looking at #105 and the surrounding code. It seems smcFanControl itself is fixed, but the smc command wasn't extended — but I can't tell since I haven't tried to build smcFanControl.

The only thing I'm not sure of is why setting the fan in forced mode is a different key than the fan key?

No clue, that's what other contributors figured out :-)

Blaisorblade avatar Aug 08 '20 21:08 Blaisorblade

@Blaisorblade would this work with setting minimum values too? My friend with a 2020 Intel MacBook Air tried it out and it seems the minimum value didn't change.

quackduck avatar Mar 20 '21 16:03 quackduck

@quackduck Unfortunately I forgot the details, I've been using other (paid) tools, and I lack the time to try to help further; this patch fixes just one piece and wasn't tested on other laptops.

Blaisorblade avatar Mar 20 '21 17:03 Blaisorblade

Alright, but would this work on F0Mn on the laptop you tested this on?

quackduck avatar Mar 20 '21 17:03 quackduck

@quackduck But IIRC the output of smc -l is helpful; if the relevant "fan speed" field is in flt mode (floating point), you need this patch to encode the values correctly.

Blaisorblade avatar Mar 20 '21 17:03 Blaisorblade

okay, I tried a moment... but the minimum speed doesn't seem settable. Indeed, even the README implies the minimum is read-only. Concrete test:

$ ./smc -l|grep F0Mn
  F0Mn  [flt ]  1836 (bytes 00 80 e5 44)
$ sudo ./smc -k F0Mn -p 3000
Writing:         [flt ]  3000 (bytes 00 80 3b 45)

$ ./smc -l|grep F0Mn
  F0Mn  [flt ]  1836 (bytes 00 80 e5 44)
$ ./smc -f
Total fans in system: 2

Fan #0:
    Actual speed : 1838
    Minimum speed: 1836
    Maximum speed: 5297
    Safe speed   : 0
    Target speed : 1836
    Mode         : auto

Fan #1:
    Actual speed : 1707
    Minimum speed: 1700
    Maximum speed: 4905
    Safe speed   : 0
    Target speed : 1700
    Mode         : auto

Blaisorblade avatar Mar 20 '21 17:03 Blaisorblade

That's strange because the min speed is settable on older macs. The smcFanControl GUI works by setting min fan speeds.

quackduck avatar Mar 21 '21 03:03 quackduck

IIRC the smc readme already acknowledges this interface change, from minimum to target...

Blaisorblade avatar Mar 23 '21 12:03 Blaisorblade

Hmm, is there a way for me to set a speed that can still be overridden by smc (as per default thermal management)?

Say, for example, I set the fan speed to 1200 when the CPU is at 105 C. Of course, the smc would by default set the fan speed to something higher, so I want it such that if the speed I set it to is less than the default, the fans will run at the default speed.

quackduck avatar Mar 23 '21 12:03 quackduck

Also, doesn't the GUI smcFanControl work by setting min speeds? Right, @hholtmann?

quackduck avatar Mar 23 '21 12:03 quackduck

I've just tested this on an M1 13" macbook pro and it works brilliantly, thanks @Blaisorblade !

ruipatcheco avatar Jun 18 '23 14:06 ruipatcheco

Why its not merged yet?

OleksandrKucherenko avatar Aug 23 '23 08:08 OleksandrKucherenko