Power Consumption Adjustment Guide

1. Overview

This document is provided as a guide to the power consumption optimization of the Sigmastar PureLinux & DualOs platform. An introduction of the clock switch and frequency adjustment method is provided for each module.

2. Configuration

The PureLinux & DualOs platform is currently connected to the CCF(Common Clock Framework), and by default unused modules will be disabled during the Linux system startup phase.

You need to make sure to enable the following configuration:

PureLinux:

Symbol: COMMON_CLK [=y]
Type  : bool
Defined at drivers/clk/Kconfig:25
  Prompt: Common Clock Framework
  Depends on: !HAVE_LEGACY_CLK [=n]

DualOs:

Symbol: SSTAR_CLK_OS_MANAGE [=y]
Type  : tristate
Defined at drivers/sstar/clk/Kconfig:4
  Prompt: Sstar CLK OS Manage
  Depends on: SSTAR_DRIVERS [=y]
  Location:
    -> Device Drivers
      -> Sstar SoC platform drivers (SSTAR_DRIVERS [=y])

After the above configuration is enabled, clock enable/disable and clock dependencies will be taken over by CCF. Each module only needs to be connected with the interface provided by CCF. For users, the points that need attention are mainly divided into:

  1. Module Addition and Removal

    Most BSP modules will enable the clock when they are in use, but some modules will enable the clock during the loading phase (probe). These modules need to ensure that they are not loaded when not in use, such as the USB module.

  2. Module Frequency Adjustment

    This part is mainly aimed at streaming modules with high power consumption. Users can adjust the appropriate frequency suitable for the scene to reduce power consumption.

In addition, some special modules will be introduced in further detail, such as CPU,DDR.

2.1. Module Addition and Removal

This section introduces the configuration and operation for adding and removing modules.

2.1.1. USB

USB will be divided into host-side controller and device-side controller, which will be introduced separately here.

usb 2.0 host controller:

1. Controler driver:

Symbol: USB_EHCI_HCD [=m]
Type  : tristate
Defined at drivers/usb/host/Kconfig:129
  Prompt: EHCI HCD (USB 2.0) support
  Depends on: USB_SUPPORT [=y] && USB [=y] && HAS_DMA [=y] && HAS_IOMEM [=y]
  Location:
    -> Device Drivers
      -> USB support (USB_SUPPORT [=y])
  Corresponding module driver: ehci-hcd.ko

2. PHY driver:

Symbol: SSTAR_USB2_PHY [=m]
Type  : tristate
Defined at drivers/sstar/usb/phy/Kconfig:13
  Prompt: SStar USB2 PHY Driver
  Depends on: SSTAR_DRIVERS [=y]
  Location:
    -> Device Drivers
(2)   -> Sstar SoC platform drivers (SSTAR_DRIVERS [=y])
Selects: GENERIC_PHY [=y] && USB_PHY [=y] && MFD_SYSCON [=y]
  Corresponding module driver: sstar-usb2-phy.ko

usb 2.0 device side controller:

Symbol: USB_SSTAR_MSB250X_UDC [=m]
Type  : tristate
Defined at drivers/sstar/usb/gadget/udc/usb20/Kconfig:1
  Prompt: Sstar MSB250X USB 2.0 Device Controller
  Depends on: USB_SUPPORT [=y] && USB_GADGET [=m]
  Location:
    -> Device Drivers
      -> USB support (USB_SUPPORT [=y])
        -> USB Gadget Support (USB_GADGET [=m])
          -> USB Peripheral Controller
  Corresponding module driver: udc-msb250x.ko

2.1.3. sdmmc

Symbol: SSTAR_SDMMC [=m]
Type  : tristate
Defined at drivers/sstar/sdmmc/Kconfig:1
  Prompt: SStar SD/MMC Card Interface Support
  Depends on: SSTAR_DRIVERS [=y] && MMC [=m]
  Location:
    -> Device Drivers
      -> Sstar SoC platform drivers (SSTAR_DRIVERS [=y])
  Corresponding module driver: kdrv_sdmmc.ko

2.1.4. crypto

This module is mainly used for encryption and decryption operations.

Symbol: SSTAR_CRYPTO [=y]
Type  : tristate
Defined at drivers/sstar/crypto/Kconfig:1
  Prompt: SigmaStar Crypto driver
  Depends on: MSTAR_DRIVERS [=y]
  Location:
    -> Device Drivers
      -> SStar SoC platform drivers (MSTAR_DRIVERS [=y])
  Corresponding module driver: mdrv_crypto.ko

2.2. Module Frequency Adjustment

All modules listed in this chapter support frequency adjustment. Modules related to streaming are mainly divided into Debug interface and Formal interface.

2.2.1. Debug interface

Debug interface supports Clock Level Viewing and Clock Level Configuration.

This interface is only used to adjust the appropriate clock frequency. The displayed clock is divided into two parts, the clock source level and the current clock frequency. Since the module clock may support divider, the actual clock may be the clock source subdivision level.

2.2.2. Formal interface

Formal interface is set through modparam.json:

After confirming the clock through the debugging interface, configure it through this interface. This interface supports DualOs and PureLinux settings modparam.json is a unified initialization interface. For detailed usage, please see the mi_common usage.

2.2.3. Tips for confirming clock level

Clock level: The module clock level viewing only provides the level of the clock source. Some modules support divider, so there will be more clock levels (based on clock source frequency division). During actual configuration, you can first confirm whether the large clock source level meets the requirements, and then subdivide and configure smaller clock levels.

The clock frequency required for module processing tasks is related to the frame rate and image resolution of the hardware processing, so there is no way to give a relatively unified formula level to estimate the clock frequency. Therefore, the current way to obtain the clock frequency is to constantly try to configure the level, confirm whether the module is working properly, and gradually approach the final level. It can be roughly divided into the following steps:

  1. In the complete scene, based on the normal working condition of the scene, obtain the basic clock frequency at this time

  2. Start adjusting the clock frequency from the front-end module (sensor). It needs to be based on the basic clock frequency and proceed from high to low until a suitable clock is obtained. If the frame rate of the module decreases, or problems such as fifo full occur, it means that the clock frequency has reached the bottom. At this time, the relevant clock level needs to be adjusted to a higher level; if the scene is a hardware direct connection mode, the direct connection mode can be switched to frame mode to avoid mutual influence between front and rear stages

  3. Increase the obtained clock frequency by a margin. Because the clock frequency is continuously debugged, it will tend to be the limit frequency value of the hardware processing in this scene. If the bandwidth is reduced or the scene is fine-tuned, the frame rate of the module processing may be insufficient, so it is necessary to add appropriate margin to the frequency adjusted in the second step at this time .

2.2.4. Sensor frequency adjustment

Clock Level Viewing:

/ # cat /proc/mi_modules/mi_sensor/debug_hal/csi_clk0
[0] 432000000 <--
[1] 288000000
[2] 320000000
[3] 172000000
Current CLK:432000000

csi_clk0 corresponds to sensor0, csi_clk1 corresponds to sensor1

Clock Level Configuration:

/ # echo 226000000 > /proc/mi_modules/mi_sensor/debug_hal/csi_clk0
/ # cat /proc/mi_modules/mi_sensor/debug_hal/csi_clk0
[0] 432000000
[1] 288000000
[2] 320000000
[3] 172000000
Extend CLK 234000000:288000000 * 26 / 32

Extend CLK: Represents using dfs for level segmentation

Formal interface:

{
    "E_MI_MODULE_ID_SNR" :
    {
        "csi_clk": [234000000,234000000]
    }
}

csi_clk: The parameters configured here is csi_clk0, csi_clk1

2.2.5. VIF frequency adjustment

Clock Level Viewing:

/ # cat /proc/mi_modules/mi_vif/debug_hal/vif_clk
[0] 288000000 <--
[1] 240000000
[2] 192000000
[3] 320000000
Current CLK:288000000

Clock Level Configuration:

/ # echo 140000000 > /proc/mi_modules/mi_vif/debug_hal/vif_clk
/ # cat /proc/mi_modules/mi_vif/debug_hal/vif_clk
[0] 288000000
[1] 240000000
[2] 192000000
[3] 320000000
Extend CLK 144000000:192000000 * 24 / 32

Formal interface:

{
    "E_MI_MODULE_ID_VIF" :
    {
        "vif_clk": 144000000
    }
}

2.2.6. ISP frequency adjustment

Clock Level Viewing:

/ # cat /proc/mi_modules/mi_isp/debug_hal/isp_clk
[0] 288000000
[1] 240000000
[2] 192000000
[3] 320000000
Extend CLK:144000000 = 192000000 * 24 / 32

Clock Level Configuration:

/ # echo 123000000 > /proc/mi_modules/mi_isp/debug_hal/isp_clk
/ # cat /proc/mi_modules/mi_isp/debug_hal/isp_clk
[0] 288000000
[1] 240000000
[2] 192000000
[3] 320000000
Extend CLK:126000000 = 192000000 * 21 / 32

Formal interface:

{
    "E_MI_MODULE_ID_ISP" :
    {
        "isp_clk": 126000000
    }
}

2.2.7. SCL frequency adjustment

Clock Level Viewing:

/ # cat /proc/mi_modules/mi_scl/debug_hal/clk
[0] 144000000
[1] 192000000
[2] 216000000
[3] 240000000
[4] 288000000
[5] 320000000
ExtClock[121500000]:
[0] [144000000 * 27 / 32] = 121500000 <-------

Clock Level Configuration:

/ # echo 152000000 > /proc/mi_modules/mi_scl/debug_hal/clk
/ # cat /proc/mi_modules/mi_scl/debug_hal/clk
[0] 144000000
[1] 192000000
[2] 216000000
[3] 240000000
[4] 288000000
[5] 320000000
ExtClock[152000000]:
[1] [192000000 * 26 / 32] = 156000000 <-------

Formal interface:

{
    "E_MI_MODULE_ID_SCL" :
    {
        "u32FClk1RateHz": 156000000
    }
}

2.2.8. IPU frequency adjustment

Clock Level Viewing:

/ # cat /proc/mi_modules/mi_ipu/debug_hal/freq
current ipu clock gear: 400MHz
available frequency:
600MHz
500MHz
400MHz
300MHz

Clock Level Configuration:

/ # echo 500 > /proc/mi_modules/mi_ipu/debug_hal/freq
/ # cat /proc/mi_modules/mi_ipu/debug_hal/freq
current ipu clock gear: 500MHz
available frequency:
600MHz
500MHz
400MHz
300MHz

Formal interface:

{
    "E_MI_MODULE_ID_IPU" :
    {
        "ipu_clk": 400000000
    }
}

2.2.9. IVE frequency adjustment

Clock Level Viewing:

/ # cat /proc/mi_modules/mi_ive/debug_hal/ive_clk

----------IVE clock -----------
288000000 <--
216000000
384000000
432000000 od
Current CLK: 288000000 dfs(0/0, source=288000000)

Clock Level Configuration:

/ # echo 266000000 > /proc/mi_modules/mi_ive/debug_hal/ive_clk
/ # cat /proc/mi_modules/mi_ive/debug_hal/ive_clk

---------- IVE clock -----------
288000000 <--
216000000
384000000
432000000 od
Current CLK: 288000000 dfs(0/0, source=288000000)

Formal interface:

{
    "E_MI_MODULE_ID_IVE" :
    {
        "ive_clk": 288000000
    }
}

2.3. CPU frequency adjustment and hotplug

2.3.1. CPU frequency adjustment

CPU frequency adjustment is currently performed through the cpufreq subsystem of Linux, so the cpufreq interface will be introduced here.

Ensure that the CONFIG_SSTAR_CPU_FREQ configuration is enabled.

2.3.1.1. Node introduction

Node path: /sys/devices/system/cpu/cpufreq/policy0.

节点名 作用
cpuinfo_cur_freq The current operating frequency of the CPU is generally equal to scaling_cur_freq
cpuinfo_max_freq The maximum operating frequency that the CPU can support
cpuinfo_min_freq The minimum operating frequency supported by the CPU
scaling_available_frequencies Frequency gear supported by the regulator:
200000 400000 500000 600000 700000 800000 900000 1000000 1100000 1200000 1300000 1400000 1500000
scaling_cur_freq The regulator determines the current CPU operating frequency
scaling_available_governors Supported regulatory policies:
1. performance:performance-first mode, regardless of power consumption, only the highest frequency
2. powersave:energy saving mode, usually operating at the lowest frequency
3. userspace:user-defined mode, support for manual frequency adjustment in user space
4. ondemand:on demand mode, periodically check the load and adjust the frequency according to the load
scaling_governor View the current adjustment policy and set the adjustment policy. The default value is userspace
scaling_max_freq Maximum CPU operating frequency supported by the regulator
scaling_min_freq Minimum CPU operating frequency supported by the regulator
scaling_setspeed If userspace is selected, you can set the CPU working frequency to a certain value
2.3.1.2. Configuration constraint
  1. scaling_min_freq must be less than or equal to scaling_max_freq
  2. scaling_min_freq must be larger than or equal to cpuinfo_min_freq
  3. scaling_max_freq must be less than or equal to cpuinfo_max_freq
  4. scaling_setspeed must be within the range of scaling_min_freq and scaling_max_freq
2.3.1.3. User set frequency
# Configure current governor as userspace
/sys/devices/system/cpu/cpufreq/policy0/ # echo userspace > scaling_governor

# Check whether the frequency to be configured is within the range:
/sys/devices/system/cpu/cpufreq/policy0 # cat scaling_min_freq
200000
/sys/devices/system/cpu/cpufreq/policy0 # cat scaling_max_freq
1200000

# Configure the current frequency
/sys/devices/system/cpu/cpufreq/policy0 # echo  1000000 > scaling_setspeed
/sys/devices/system/cpu/cpufreq/policy0 # cat scaling_cur_freq
1000000

2.3.2. CPU hotplug

CPU hotplug is currently performed through the hotplug subsystem of Linux, so the hotplug interface will be introduced here.

Ensure that the CONFIG_HOTPLUG_CPU configuration is enabled.

Node path:/sys/devices/system/cpu/cpu(x)/online,Where x is the CPU to be controlled. The configuration method is as follows(This section uses CPU1 as an example):

# Obtain the current CPU1 hotplug status
/sys/devices/system/cpu/cpu1 # cat online
1

# CPU1 hotplug
/sys/devices/system/cpu/cpu1 # echo 0 > online

# Obtain the current CPU1 hotplug status again
/sys/devices/system/cpu/cpu1 # cat online
0

2.4. DDR auto str and DFS

DDR auto str and DFS control need ensure that the MIU_AUTO_STR configuration is enabled,control node path is /sys/devices/system/miu/miu0/autostr,the configuration method is as follows:

# echo timeslot [tslot]  [passcnt] >  /sys/devices/system/miu/miu0/autostr
# [tslot]   auto str with tslot us loop
# [passcnt] auto str in tslot have passcnt us time can pass cmd
echo timeslot 100 80 > /sys/devices/system/miu/miu0/autostr

# echo urgent [urgent] > /sys/devices/system/miu/miu0/autostr
# urgent: bit0 cpu, bit1 gop, bit2 cmdq,bit set 1 enable
echo urgent 7 > /sys/devices/system/miu/miu0/autostr

# trigger operation proceeding DFS1 <-> DFS0,default DFS0
# DFS0 high frequency,DFS1 low frequency
echo trigger > /sys/devices/system/miu/miu0/autostr

# auto str on
echo on > /sys/devices/system/miu/miu0/autostr
# auto str off
echo off > /sys/devices/system/miu/miu0/autostr

# print auto str status
# DFS%d freq:%d, autostr:%s, urgent[cmdq:%d, gop:%d, cpu:%d], timeslot:%d, passwindow:%d
# timeslot/passcnt is clk number,The value after conversion according to setting us
cat /sys/devices/system/miu/miu0/autostr

Note that all parameter adjustments must ensure that auto str is in the off state.