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

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

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

Conversation

Blaisorblade
Copy link

@Blaisorblade Blaisorblade commented Aug 8, 2020

Needed to help with #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
Copy link
Author

(For some minimal testing code for this, see Blaisorblade#1).

@jlehrer1
Copy link

jlehrer1 commented Aug 8, 2020

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?

@Blaisorblade Blaisorblade changed the title smc: support writing FP values like fan speed smc: support writing FP values like fan speed (tested on MBP 16,1) Aug 8, 2020
@Blaisorblade
Copy link
Author

@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

@jlehrer1
Copy link

jlehrer1 commented Aug 8, 2020

@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.

@Blaisorblade
Copy link
Author

@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 :-)

@jlehrer1
Copy link

jlehrer1 commented Aug 8, 2020

@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
Copy link

jlehrer1 commented Aug 8, 2020

@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.

@Blaisorblade
Copy link
Author

How did you know to set F0Md?

That's from #77 (comment) and #77 (comment).

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 :-)

@quackduck
Copy link

@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.

@Blaisorblade
Copy link
Author

@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.

@quackduck
Copy link

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

@Blaisorblade
Copy link
Author

@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
Copy link
Author

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

@quackduck
Copy link

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

@Blaisorblade
Copy link
Author

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

@quackduck
Copy link

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
Copy link

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

NickLaMuro added a commit to NickLaMuro/dotfiles that referenced this pull request May 16, 2022
The interface from the "custom smc" bin that I use from here:

hholtmann/smcFanControl#108

Which allows this program to run on newer versions of OSX, has changed.
The "homebrew" version of this program from smcFanControl is out of
date, but can be used for older versions, and when I custom build this
version, I need a different set of flags passed.

This change allows supporting both.
@ruipatcheco
Copy link

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

@OleksandrKucherenko
Copy link

Why its not merged yet?

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.

5 participants