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

Enable uclamp configs to save oodles of battery life and update some kernel configs #5

Merged
merged 4 commits into from
May 17, 2024

Conversation

mkurz
Copy link

@mkurz mkurz commented May 17, 2024

First commit:
Enables uclamp, which is necessary that speakersafetd will be "pushed" to the e (efficiency) cpu cores, which safes lots of battery (you feel the difference). I got that hint from this chat log:

[18:22](https://oftc.irclog.whitequark.org/asahi/2024-02-12#32916743) <milky> I am getting this error when the speakersafetydeamon tries to run
[18:22](https://oftc.irclog.whitequark.org/asahi/2024-02-12#32916744) <milky> Could not lock elem Left Woofer 1 VSENSE Switch. alsa-lib error: Error("snd_ctl_elem_lock", ENOENT)
[18:22](https://oftc.irclog.whitequark.org/asahi/2024-02-12#32916747) <milky> also "Failed to set uclamp"
[18:23](https://oftc.irclog.whitequark.org/asahi/2024-02-12#32916748) <j`ey> milky: youre probably missing the patches that actually enables the speakers see branch: speakers/enablement-READ-COMMIT-MESSAGE
[18:23](https://oftc.irclog.whitequark.org/asahi/2024-02-12#32916749) <j`ey> and for the latter, you need CONFIG_UCLAMP_TASKS
[18:24](https://oftc.irclog.whitequark.org/asahi/2024-02-12#32916752) <j`ey> and UCLAMP_TASK_GROUP

Then I remembered I did read about that somewhere... which was the Asahi Blog entry here 😉 (also marcan wrote about it)

... While working on speaker support, we found that Pipewire and Wireplumber were constantly being mis-scheduled onto P-cores. ... To fix this, we gave Pipewire and Wireplumber the ability to use utilisation clamping, a scheduler feature ... We cap Pipewire and Wireplumber to an extremely low maximum performance so the scheduler restricts them to efficiency cores at their lowest operating point. .... we get to save oodles of battery life for our users! ... it wasn’t even enabled in the standard Fedora kernel until we asked for it to be a couple of weeks ago (CONFIG_UCLAMP_TASK)...

E.g., currently, when speakersafetd starts up you get following error:

$ journalctl -u speakersafetyd.service --grep uclamp
Mai 17 14:23:40 mkurz-macbook-pro speakersafetyd[664]: WARN  [speakersafetyd::uclamp] Failed to set uclamp

With uclamp enabled speakersafetd works correctly:

Mai 17 14:27:01 mkurz-macbook-pro speakersafetyd[672]: INFO  [speakersafetyd::uclamp] Set task uclamp to 0:64

Precious battery life saved! 🚀

See:

Second commit:
Updates some configs according to wiki and Fedora config:

It seems the wiki recommends to include most configs instead of building them as module. @joske This is up to you, please review if we should keep the configs modules or not.
I will comment separately on configs which have not been enabled yet.

Third commit:
I saw that CONFIG_RUST_PHYLIB_ABSTRACTIONS is enabled in both the Fedora and the Ubuntu kernel, so I thought because this is rust related maybe we should enable it too?

What do you think?

Of course I tested this config on my MacBook Pro (14-inch, M1 Pro, 2021) (J314sAP) and it works.

BTW:
While working on this I found out the asahi wiki page is not up to date for the 6.8 kernel config:

@@ -185,6 +186,7 @@ CONFIG_FAIR_GROUP_SCHED=y
CONFIG_CFS_BANDWIDTH=y
# CONFIG_RT_GROUP_SCHED is not set
CONFIG_SCHED_MM_CID=y
CONFIG_UCLAMP_TASK_GROUP=y
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_RUSTC_LLVM_VERSION_TEXT="17.0.6"
CONFIG_BINDGEN_VERSION_TEXT="bindgen 0.65.1"
CONFIG_BINDGEN_VERSION_TEXT="bindgen 0.69.4"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two text values changed automatically by make menuconfig.
@joske Should we keep it?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not matter much, it's only informational

@@ -750,8 +752,7 @@ CONFIG_ARCH_HAS_GCOV_PROFILE_ALL=y
# end of GCOV-based kernel profiling

CONFIG_HAVE_GCC_PLUGINS=y
CONFIG_GCC_PLUGINS=y
# CONFIG_GCC_PLUGIN_LATENT_ENTROPY is not set
# CONFIG_GCC_PLUGINS is not set
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -2692,7 +2693,7 @@ CONFIG_SWPHY=y
CONFIG_LED_TRIGGER_PHY=y
CONFIG_PHYLIB_LEDS=y
CONFIG_FIXED_PHY=y
# CONFIG_RUST_PHYLIB_ABSTRACTIONS is not set
CONFIG_RUST_PHYLIB_ABSTRACTIONS=y
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already mentiond in the initial commit.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not mentioned in the wiki, but if fedora and ubuntu do this, let's add it too

@@ -3149,7 +3151,80 @@ CONFIG_TABLET_USB_HANWANG=m
CONFIG_TABLET_USB_KBTAB=m
CONFIG_TABLET_USB_PEGASUS=m
# CONFIG_TABLET_SERIAL_WACOM4 is not set
# CONFIG_INPUT_TOUCHSCREEN is not set
CONFIG_INPUT_TOUCHSCREEN=y
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed for CONFIG_TOUCHSCREEN_APPLE_Z2

# CONFIG_TOUCHSCREEN_ADS7846 is not set
# CONFIG_TOUCHSCREEN_AD7877 is not set
# CONFIG_TOUCHSCREEN_AD7879 is not set
CONFIG_TOUCHSCREEN_APPLE_Z2=m
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -4920,6 +4995,7 @@ CONFIG_VIDEO_CMDLINE=y
CONFIG_VIDEO_NOMODESET=y
# CONFIG_AUXDISPLAY is not set
CONFIG_DRM=y
CONFIG_DRM_MIPI_DSI=y
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was enabled as dependency automatically... Also enabled by ubuntu anyway:

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks unnecessary

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can not remove it, it seems it's enabled automatically as dependency. Even if I remove it from the config file by hand and then re-run make menuconfig it gets added again. Also look here, it's selected by others (and I can not switch to it):
image

@@ -5078,7 +5211,7 @@ CONFIG_DRM_SIMPLEDRM=y
# CONFIG_DRM_LIMA is not set
# CONFIG_DRM_PANFROST is not set
# CONFIG_DRM_TIDSS is not set
# CONFIG_DRM_ADP is not set
CONFIG_DRM_ADP=m
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -5741,7 +5874,7 @@ CONFIG_USB_MON=m
CONFIG_USB_XHCI_HCD=m
# CONFIG_USB_XHCI_DBGCAP is not set
CONFIG_USB_XHCI_PCI=m
# CONFIG_USB_XHCI_PCI_RENESAS is not set
CONFIG_USB_XHCI_PCI_RENESAS=y
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again recommended in wiki and enabled in Fedora and Ubuntu

@@ -6826,7 +6959,7 @@ CONFIG_MULTIPLEXER=m
#
# CONFIG_MUX_ADG792A is not set
# CONFIG_MUX_ADGS1408 is not set
# CONFIG_MUX_APPLE_DPXBAR is not set
CONFIG_MUX_APPLE_DPXBAR=m
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again recommended in wiki and enabled in Fedora and Ubuntu

@mkurz mkurz mentioned this pull request May 17, 2024
@joske
Copy link
Owner

joske commented May 17, 2024

@mkurz Thanks for taking the time to go over this!

Can you sign off your commits please?

This may be handy 😉 https://stackoverflow.com/questions/13043357/git-sign-off-previous-commits

@mkurz
Copy link
Author

mkurz commented May 17, 2024

Can you sign off your commits please?

This may be handy 😉 https://stackoverflow.com/questions/13043357/git-sign-off-previous-commits

git rebase --signoff HEAD~4 did the magic 🪄

@joske joske merged commit 9c340e0 into joske:kernel May 17, 2024
@mkurz mkurz deleted the updated-kernel-configs branch May 17, 2024 21:13
@zzywysm
Copy link

zzywysm commented May 21, 2024

It seems the wiki recommends to include most configs instead of building them as module. @joske This is up to you, please review if we should keep the configs modules or not. I will comment separately on configs which have not been enabled yet.

If you are building a general arm64 16k kernel for Arch Linux ARM intended to be bootable on any arm64 16k hardware (much like how Fedora does it), you will want to build as many Asahi configuration options as modules as you can.

If you are building a kernel that's only ever intended to run on Apple Silicon Macs, I think it makes a lot more sense to build more of the Asahi code into the kernel image directly. My kernel config recommendations on the Asahi wiki reflect this opinion.

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