ブログ:
i.MX8QM 多核应用开发性能测试

2019年11月12日火曜日

NXP 发布的 i.MX8 处理器具有多种规格,最高配置的 i.MX8QM 具有双核 Cortex-A72 和四核 Cortex-A53。这种大小核组合的处理器,为用户带来更大的性能灵活性,利用高性能的大核快速完成运算,低性能小核则提供优化的功耗表现。下面我们将以 Apalis iMX8QM 核心板为例,介绍如何利用这种特性,并观察功耗差异。

单核性能测试

Cortex-A72 最高时钟 1.6GHz,Cortex-A53 最高为 1.2GHz。Cortex-A72 和 Cortex-A53 在架构也上存在很大的差异,虽然同属于 ARMv8.0-A,但是在流水线深度、乱序执行、缓存等特性上却有所不同,从而带来处理性能的差异。理论上 Cortex-A72 性能会高于 Cortex-A53。

为了测试在 Cortex-A72 和 Cortex-A53 上的单核性能表现,我们将使用 encode-flac,测试压缩一个WAV音频文件所消耗的时间。该工具是单线程运行,适合做单核计算测试。

首先下载 SDK,编译 encode-flac。

$ . environment-setup-aarch64-tdx-linux
$ cd encode-flac
$ ./configure --prefix=~/encode-flac-bin  --host=aarch64-tdx-linux --build=x86_64-linux
$ make
$ make install


在~/encode-flac-bin 能找到到本次测试所需的 flac 程序。Taskset 工具能够指定应用运行在哪个处理器上面。Taskset 通过设置 CPU 掩码来选择 CPU。我们可以用cpufreq-info 命令查看所有可用的CPU。

# cpufreq-info
cpufrequtils 008: cpufreq-info (C) Dominik Brodowski 2004-2009
Report errors and bugs to cpufreq@vger.kernel.org, please.
analyzing CPU 0:
driver: imx8-cpufreq
CPUs which run at the same hardware frequency: 0 1 2 3
CPUs which need to have their frequency coordinated by software: 0 1 2 3
maximum transition latency: 61.0 us.
hardware limits: 600 MHz - 1.20 GHz
available frequency steps: 600 MHz, 900 MHz, 1.10 GHz, 1.20 GHz
available cpufreq governors: interactive, conservative, userspace, powersave, ondemand, performance, schedutil
current policy: frequency should be within 600 MHz and 1.20 GHz.
                 The governor "performance" may decide which speed to use
                 within this range.
current CPU frequency is 1.20 GHz (asserted by call to hardware).
cpufreq stats: 600 MHz:59.80%, 900 MHz:0.06%, 1.10 GHz:0.04%, 1.20 GHz:40.11%  (240)
......
analyzing CPU 5:
driver: imx8-cpufreq
CPUs which run at the same hardware frequency: 4 5
CPUs which need to have their frequency coordinated by software: 4 5
maximum transition latency: 61.0 us.
hardware limits: 600 MHz - 1.60 GHz
available frequency steps: 600 MHz, 1.06 GHz, 1.30 GHz, 1.60 GHz
available cpufreq governors: interactive, conservative, userspace, powersave, ondemand, performance, schedutil
current policy: frequency should be within 600 MHz and 1.60 GHz.
                 The governor "performance" may decide which speed to use
                 within this range.
current CPU frequency is 1.60 GHz (asserted by call to hardware).
cpufreq stats: 600 MHz:69.45%, 1.06 GHz:0.05%, 1.30 GHz:0.01%, 1.60 GHz:30.49%  (153)

这里总共有 CPU 0 到 CPU 5,其中 CPU 0~CPU 3为Cortex-A53,CPU 4~CPU 5为 Cortex-A72。

例如 0x3 0表示允许使用两个 A72 核心,0x10 表示只使用一个 A72,同样 0x01 表示只使用一个 A53,而 0x3F 则表示使用所有的处理器核心。需要注意的是,这里是指用 taskset 工具指定某一个程序所使用的处理器核心,不被指定的处理器核心仍处于工作状态,只是不用其来运行该程序。因此taskset并不能启到关闭处理器核心的功能。

我们将配合编译好的 encode-flac 和 taskset 工具来观察 i.MX8QM 不同核心的计算机能力以及功耗的差异。

在空闲状态下,我们通过功率计查看 Ixora 底板和 Apalis iMX8QM 模块以及电源适配器的功耗(本文测试仅连接以太网和调试串口和散热器风扇,不连接包括显示器在内的其他设备)为 7.6W。

  • 在一个A53内核上运行

root@apalis-imx8:~# taskset 0x0f time ./flac --best ./Perfect.wav -f -o output 2>&1
flac 1.3.2
Copyright (C) 2000-2009  Josh Coalson, 2011-2016  Xiph.Org Foundation
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

Perfect.wav: WARNING: skipping unknown chunk 'LIST' (use --keep-foreign-metadata to keep)
Perfect.wav: wrote 29478930 bytes, ratio=0.634
real   0m 41.21s
user  0m 40.90s
sys   0m 0.21s


压缩一个wav文件耗时41.2秒,功耗7.9W。

上图我们看到,单线程的 encode-flac 仅在一个 A53 处理器上满负荷运行。

  • 在一个A72内核上运行

root@apalis-imx8:~# taskset 0x20 time ./flac --best ./Perfect.wav -f -o output 2>&1

flac 1.3.2
Copyright (C) 2000-2009  Josh Coalson, 2011-2016  Xiph.Org Foundation
flac comes with ABSOLUTELY NO WARRANTY.  This is free software, and you are
welcome to redistribute it under certain conditions.  Type `flac' for details.

Perfect.wav: WARNING: skipping unknown chunk 'LIST' (use --keep-foreign-metadata to keep)
Perfect.wav: wrote 29478930 bytes, ratio=0.634
real   0m 9.23s
user  0m 9.06s
sys   0m 0.13s


压缩一个wav文件耗时9.2秒,功耗9.5W。

上图我们看到,单线程的 encode-flac 仅在一个 A72 处理器上满负荷运行。

单核性能和功耗对比

多核性能测试

我们将使用一个简单 C++ 全局光照渲染器 smallpt 在多个CPU上借助 OpenMP 实现多线程运算,测量在不同核心上完成渲染所需要的时间以及功耗。通过下面命令编译 smallpt

$ ./configure --prefix=/home/ben/temp_ram  --host=aarch64-tdx-linux --build=x86_64-linux
$ make


为了充分释放所有核心的计算能力,我们将所有的 CPU 都配置为可用的最高时钟,这时候请务必使用良好的散热器件为处理器降温。

root@apalis-imx8:~# echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
root@apalis-imx8:~# echo performance > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor


此时空闲状态下的 Ixora 底板和 Apalis iMX8QM 模块以及电源适配器的功耗为 7.9W。

  • 在 4 个 A53 同时运行

root@apalis-imx8:~# taskset 0x0f time ./smallpt 100
Rendering (100 spp) 100.00%
real   3m 19.25s
user  13m 9.33s
sys   0m 0.09s


功耗为 8.9W,耗时 3 分 19 秒。上图中看到  4个 A5 3核心处于满负荷状态。

  • 在 2 个 A72 同时运行

root@apalis-imx8:~# taskset 0x30 time ./smallpt 100
Rendering (100 spp) 100.00%
real   2m 58.71s
user  5m 56.20s
sys   0m 0.03s


功耗为10.3W,耗时 2 分 58 秒。上图中看到 2 个 A72 核心处于满负荷状态。

  • 在4个A53和2个A72同时运行

root@apalis-imx8:~# taskset 0x3f time ./smallpt 100
Rendering (100 spp) 100.00%
real   1m34.648s
user  9m20.123s
sys   0m0.127s


功耗为 11.4W,耗时 1 分 34 秒。上图中看到 2 个 A72 和 4 个 A53 核心处于均满负荷状态。

多核性能和功耗对比

总结

Apalis iMX8QM 计算机模块能够利用 A72 核心强劲的计算能力迅速完成运算任务,甚至是调用 iMX8QM 所有 6 个核心发挥其最大的 CPU 计算能力,而在 A53 核心上则能够以较低的功耗执行,这种组合方式为嵌入式产品在功耗和性能上提供了灵活的选择。除此之外 Apalis iMX8QM 还具有 DSP、双核 GPU 以及 Cortex-M4,能够借助 DSP 指令、OpenCL 并行计算带来更多的算力,同时 M4 还可以以更低的功耗运行。本次测试采用了 Toradex Linux v3.0b2 BSP,随着模块本身和软件的进一步完善,该模块会有更佳的表现。

記者: 胡珊逢,FAE,韬睿(上海)

コメントを投稿

Please login to leave a comment!
Have a Question?