megi's PinePhone Development Log RSS

Surgenons in Gaza Surgeons in Gaza

2023–01–12: Pinephone cpuidle

I received an e-mail about non-working CPUIDLE on Pinephone on pmOS and Arch (presumably Danct variant). So this is a bit of a PSA, since working cpuidle is a very nice to have power saving feature, and it would be sad for major Pinephone distros to be missing it due to a simple build config issue in TF-A.

Hello Chris,

On Wed, Jan 11, 2023 at 09:57:28PM +0000, Chris Xxxxxxxxxx wrote:
> Dear Megi,
>
> I have noticed when working with the Pinephone that cpuidle does not seem to
> be operational on distributions using your kernel, either (Postmarketos)
> with a slightly diffferent config, or Arch.
>
> Looking at  /sys/devices/system/cpu/cpuidle/current_driver  the content is
> 'none' where normally you would expect it to be something like arm_idle or
> similar.

https://megous.com/dl/tmp/9bb7d2f832ddd547.png

> This shows up in the apparently short battery life and if cpupower is
> installed you get:
>
> $ sudo cpupower idle-info
> [sudo] password for alarm:
> CPUidle driver: none
> CPUidle governor: menu
> analyzing CPU 0:
>
> CPU 0: No idle states

https://megous.com/dl/tmp/7f2d4b461e59d8e0.png

> Is this what you would expect for an Allwinner CPU? I don't have much
> experience of the Sunxi architecture, maybe C-states are not supported? The
> Config looks OK, with (Postmarketos config)

No, it's not what I'd expect. I suspect pmOS is not using a TF-A and/or crust
version that supports cpuidle, which is why cpuidle does not work on it.

Check that you build TF-A's bl31 with SUNXI_AMEND_DTB=1

For reference, my build script for TF-A/crust are here:

  https://megous.com/git/p-boot/tree/fw

The whole sunxi_prepare_dtb() function is disabled if you don't explicitly
specify SUNXI_AMEND_DTB=1 during TF-A build, and this function must be
enabled for cpuidle to work:

https://github.com/ARM-software/arm-trusted-firmware/blob/master/plat/allwinner/common/sunxi_prepare_dtb.c#L38

Default is SUNXI_AMEND_DTB=0:

https://github.com/ARM-software/arm-trusted-firmware/blob/master/plat/allwinner/common/allwinner-common.mk#L77

kind regards,
        o.

> |CONFIG_CPU_IDLE=y CONFIG_CPU_IDLE_MULTIPLE_DRIVERS=y #
> CONFIG_CPU_IDLE_GOV_LADDER is not set CONFIG_CPU_IDLE_GOV_MENU=y #
> CONFIG_CPU_IDLE_GOV_TEO is not set CONFIG_DT_IDLE_STATES=y
> CONFIG_DT_IDLE_GENPD=y # ARM CPU Idle Drivers # CONFIG_ARM_PSCI_CPUIDLE=y
> CONFIG_ARM_PSCI_CPUIDLE_DOMAIN=y The Arch Arm distribution for the Pinephone
> seems to use your defconfig unchanged, and the running result is the same.
> Best regards Chris |