Apalis I.MX8: change CPU frequency in BSP

Hello All,

We are trying to change CPU frequency of Apalis i.MX8. We are using Apalis i.MX8 SOM and Yocto toradex reference multimedia image for development.
We are following below article for changing CPU frequency.

We are able to set CPU frequency from user space after following the steps given in the article.

root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
896000
root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq
896000
root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_cur_freq
896000
root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_cur_freq
896000
root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq
600000
root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq
1056000

The cpu0, cpu1, cpu2, cpu3 frequency is changed successfully. cpu4 frequency is not changed.

root@apalis-imx8-07106406:~# echo 1104000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
1104000
root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
1104000
root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq
1104000
root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_cur_freq
1104000
root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu3/cpufreq/cpuinfo_cur_freq
1104000
root@apalis-imx8-07106406:~# cat /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq
1056000

Below is cpuinfo.

root@apalis-imx8-07106406:~# cat /proc/cpuinfo
processor : 0
BogoMIPS : 16.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4

processor : 1
BogoMIPS : 16.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4

processor : 2
BogoMIPS : 16.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4

processor : 3
BogoMIPS : 16.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4

processor : 4
BogoMIPS : 16.00
Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid
CPU implementer : 0x41
CPU architecture: 8
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 2

root@apalis-imx8-07106406:~#

Can you please share how can we set default CPU frequency in yocto buuld?

Regards,
Prathamesh Kulkarni

Hello All,

Please share your input.

Regards,
Prathamesh

Hi @prathamesh.kulkarni,

You can check below device tree for setting clock speed for cpu.
https://git.toradex.com/cgit/linux-toradex.git/tree/arch/arm64/boot/dts/freescale/imx8qm.dtsi?h=toradex_5.15-2.1.x-imx#n171

Also please do check below link, I am not sure if this is working as we have not tested same

For setting cpu4 and cpu5 first one needs to set scaling_governor to userspace and there after set scaling_setspeed

root@apalis-imx8:/sys/devices/system/cpu/cpu4/cpufreq# echo userspace > scaling_governor 
root@apalis-imx8:/sys/devices/system/cpu/cpu4/cpufreq# echo 1056000 > scaling_setspeed 
root@apalis-imx8:/sys/devices/system/cpu/cpu4/cpufreq# cat cpuinfo_cur_freq 
1056000
root@apalis-imx8:/sys/devices/system/cpu/cpu4/cpufreq# echo 600000 > scaling_setspeed                                                    
root@apalis-imx8:/sys/devices/system/cpu/cpu4/cpufreq# cat cpuinfo_cur_freq 
600000

Best Regards
Ritesh Kumar

Hello @ritesh.tx ,

Thanks for your input. I will test above commands for CPU4 and CPU5.
From device tree you shared. I found CPU node and operating points table a53_opp_table where all the frequencies are listed.


            A53_0: cpu@0 {
                    device_type = "cpu";
                    compatible = "arm,cortex-a53", "arm,armv8";
                    reg = <0x0 0x0>;
                    clocks = <&clk IMX_SC_R_A53 IMX_SC_PM_CLK_CPU>;
                    enable-method = "psci";
                    next-level-cache = <&A53_L2>;
                    operating-points-v2 = <&a53_opp_table>;
                    #cooling-cells = <2>;
            };

        a53_opp_table: a53-opp-table {
                compatible = "operating-points-v2";
                opp-shared;

                opp-600000000 {
                        opp-hz = /bits/ 64 <600000000>;
                        opp-microvolt = <900000>;
                        clock-latency-ns = <150000>;
                };

                opp-896000000 {
                        opp-hz = /bits/ 64 <896000000>;
                        opp-microvolt = <1000000>;
                        clock-latency-ns = <150000>;
                };

                opp-1104000000 {
                        opp-hz = /bits/ 64 <1104000000>;
                        opp-microvolt = <1100000>;
                        clock-latency-ns = <150000>;
                };

                opp-1200000000 {
                        opp-hz = /bits/ 64 <1200000000>;
                        opp-microvolt = <1100000>;
                        clock-latency-ns = <150000>;
                        opp-suspend;
                };
        };

But I am not able locate the place where we should select the frequency we want to set.
Could you please help me, where should I set the expected frequency?

Regards,
Prathamesh Kulkarni

Hello @ritesh.tx ,

Please share your input.

Regards,
Prathamesh Kulkarni

Hi @prathamesh.kulkarni,

But I am not able locate the place where we should select the frequency we want to set.
Could you please help me, where should I set the expected frequency?

There is no specific place/file to set cpu clock, on boot a default scaling governor is selected automatically. Below are couple of ways you can try to set cpu clock speed.

As already mentioned starting from kernel 5.9, there is kernel command line option cpufreq.default_governor to set governor. To include this change you need to override exiting kernel recipe and add your command line parameter and build custom linux image. We have not tested this option.

Alternatively, one can make a custom user space script to modify governor once system boots. here also you will need to create custom recipe which will build image with script and start at system boot using systemd.

Let me know if you have any queries.
Best Regards
Ritesh Kumar