How to measure power using sensors and stress individual cores?

Showing results for 
Search instead for 
Did you mean: 

How to measure power using sensors and stress individual cores?

No ratings

How to measure power using sensors and stress individual cores?

The below steps describe how to measure the CPU power using sensors and also describe how to stress individual cores of CPU.

Steps are explained with an example of LX2160A SoC. However, these steps are applicable to all Layerscape devices.

  1. Download Flexbuild and add packages in Ubuntu:Lite
  2. Generate Ubuntu-based Lite userland (Ubuntu:Lite)
  3. Enable system monitoring unit and build kernel
  4. Generate .itb image
  5. Load .itb image from TFTP server to Layerscape board
  6. Validate stress package and measure CPU power using sensors

Step 1: Download Flexbuild and add packages in Ubuntu:lite

  1. On a Linux machine, download Layerscape Software Development Kit - <version>.
  2. Go to Download tabs at Enter login details, accept the agreement to download the Flexbuild source tarball in the name format flexbuild_<version>.tgz.
  3. Run the following commands to extract Flexbuild files from tar archived file.

    $ tar xvzf flexbuild_<version>.tgz

    $ cd flexbuild_<verison>

    $ source setup.env

    $ flex-builder -h

  4. Add packages for stress and power sensors in the additional_lite_packages_list file available in the flexbuild_<version>/configs/ubuntu/ folder. Add ‘stress’ and ‘lm-sensors’ packages for Ubuntu Lite as shown below:package.gif
  5. Save and exit the file.

Step 2 – Generate Ubuntu:Lite image

  1. Change directory to flexbuild_<version>.
  2. Clean obsolete cache data. This step is needed in case the source/configuration has changed.

    $ source setup.env

    $ flex-builder -i clean-rfs -r ubuntu:lite

  3. Generate Ubuntu-based Lite userland using the following command:

    $ flex-builder -i mkrfs -r ubuntu:lite

    This generates rootfs_lsdk<version>_ubuntu_lite_arm64 file. For example: rootfs_lsdk2004_ubuntu_lite_arm64 file.

  4. Pack userland in tgz format (Optional step).

    $ flex-builder -i packrfs -r ubuntu:lite

    For example: rootfs_lsdk2004_ubuntu_lite_arm64.tgz (~180 M)


Step 3 Enable system monitoring unit and build kernel

  1. Change directory to flexbuild_<version>/packages/linux/linux.
  2. Enable environmental setting for cross-compiling. The following setting is applicable when you configure and build kernel on a different architecture from the target. For example, compiling an Armv8 kernel on an X86 computer. Run the following commands on Ubuntu Linux:

    $ export CROSS_COMPILE=aarch64-linux-gnu-

    $ export ARCH=arm64

  3. Run make menuconfig command to configure settings to enable system monitoring unit for sensing power.

    $ make menuconfig

    The command opens the kernel configuration [tree-view structure] prompt. Use the Arrow keys to navigate the menu and Enter to select the submenu.

  4. Navigate to Device Drivers --> <*> Hardware Monitoring Support --> [M] Texas Instruments INA219 and compatibles option.

    Device Drivers-->Hardware Monitoring SupportDevice Drivers-->Hardware Monitoring Support

  5. Press Y key to include the option. [*] symbol indicates the option is included (shown in below figure). This enables INA220.

    Texas Instruments INA219 and Compatibles option includedTexas Instruments INA219 and Compatibles option included

  6. Similarly, include the following options to enable I2C block device driver support and I2C bus multiplexing PC9547.

    Kernel Configure Tree View OptionKernel Configure Tree View Option

  7. After you include all options as mentioned in the above table, save the configuration with a file name. For example,  save the configuration file as power.config.
  8. Exit to come out of the Kernel Configuration prompt.
  9. Copy the configuration file to arch/arm64/configs folder.

    $ cp <config filename> arch/arm64/configs/

    For example, $ cp power.config arch/arm64/configs/

  10. Configure the kernel. Load the changed configuration for Layerscape Armv8 platform in 64-bit mode for LSDK.

    $ export CROSS_COMPILE=aarch64-linux-gnu-

    $ export ARCH=arm64

    $ make distclean

    $ make defconfig <config filename>

  11. Build kernel image and device tree image.

    $ make -j8

Step 4 - Generate .itb file

Generate .itb file, which includes stress package and thermal monitoring unit installed, for kernel booting.

  1. Copy the Image and Image.gz files from the /flexbuild_<version>/packages/linux/linux/arch/arm64/boot folder and to the /flexbuild_<version>/build/linux/kernel/arm64/LS folder.
  2. Change directory to flexbuild_<version>.
  3. Generate .itb image using flex-builder.

    $ source setup.env

    $ flex-builder -i mkitb -r ubuntu:lite

    This generates lsdk<version>_ubuntu_lite_LS_arm64.itb file. For example, lsdk2004_ubuntu_lite_LS_arm64.itb

  4. Copy the .itb image to the TFTP server.

Step 5 - Load .itb image from TFTP server to Layerscape board

  1. Set up Ethernet connection between the board (for example, LX2160ARDB) and host machine on which you have configured the TFTP server.
    1. Boot the board to U-Boot prompt. U-Boot prints a list of enabled Ethernet interfaces. For example, LX2160ARDB U-Boot prints following Ethernet interfaces.

      DPMAC2@xlaui4, DPMAC3@xgmii, DPMAC4@xgmii, DPMAC5@25g-aui, DPMAC6@25g-aui, DPMAC17@rgmii-id, DPMAC18@rgmii-id 

    2. Set server IP address to the IP address of the host machine on which you have configured the TFTP server.

      => setenv serverip <ipaddress1>

    3. Set ethact and ethprime as the ethernet interface connected to the TFTP server.

      See LX2160ARDB Ethernet Port Mapping  for the mapping of Ethernet port names appearing on the chassis front panel with the port names in U-Boot and Linux.

      => setenv ethprime <name of interface connected to TFTP server>

      For example:

      => setenv ethprime DPMAC3@xgmii

      => setenv ethact <name of interface connected to TFTP server>

      For example:

      => setenv ethact DPMAC3@xgmii

    4. Set IP address of the board. You can set a static IP address or, if the board can connect to a dhcp server, you can use the dhcp command. 

      Static IP address assignment:
      => setenv ipaddr <ipaddress2>
      => setenv netmask <subnet mask>

      Dynamic IP address assignment:
      => dhcp

    5. Save the settings.

      => saveenv

    6. Check the connection between the board and the TFTP server.

      => ping $serverip

      Using DPMAC3@xgmii device

      host is alive

  2. Load the .itb image from TFTP server to DDR memory of the board.

    => tftp 0xa0000000 <itb_file_name>

    For example: => tftp 0xa0000000 sdk2004_ubuntu_lite_LS_arm64.itb

  3. Boot the kernel with .itb image as follows:

    => bootm 0xa0000000#<board_name>

    For example: => bootm 0xa0000000#lx2160ardb

    Board boots to Linux prompt.

Step 6 – Validate stress package and measure CPU power using sensors

  1. Validate if stress and sensors packages have been installed properly.

    $ which stress


     $ which sensors


  2. Measure CPU power before applying stress to the cores.

    $ sensors

    CPU power before stressCPU power before stress

  3. Apply stress to CPU cores using the following command.

    # stress -c <number of cores> -i <number of IO> -m <number of vm> --vm-bytes 128M -t <time in seconds> &

    For example:


    The command applies stress for 60 seconds. For more information on stress command, run stress-h command for help.

  4. Measure CPU power after applying stress in given time interval.

$ sensors


Version history
Revision #:
10 of 10
Last update:
‎12-21-2020 03:42 AM
Updated by: