CPU Performance测试(CoreMark、BenchMark)

本文详述了CPU性能测试工具CoreMark的使用,尤其针对ARM SOC平台,适合对C/C++和Linux有一定了解的读者。CoreMark用于评估CPU性能,包括浮点、整数、缓存和内存测试,适用于32位和64位CPU。文章还介绍了如何修改源码以支持不同架构,并提供了编译和测试过程。
摘要由CSDN通过智能技术生成

1)本章主要讲解CPU性能测试工具CoreMark使用说明,其他ARM SOC厂商(MTK/海思/Mstar/Amlogic/SigmaStar/全志/RockChip平台)都适用。

2)适用于对C/C++语言有基本的认识,以及对Linux环境有基本的掌握能力。

3)内容属于原创,若转载,请说明出处。

4)本人提供相关问题有偿答疑和技术支持。

简介:CoreMark是一款用于评估CPU Performance性能BenchMark的基准测试程序,CoreMark目前取代了过时的 Dhrystone 基准测试,它包含了多种不同的计算任务,包括浮点数、整数、缓存、内存等方面的测试。CoreMark的测试结果通常被用来作为ARM/RISC-V 32位、64位  CPU性能的参考,它可以帮助开发人员和系统管理员评估不同处理器和系统的性能,比较不同处理器之间的性能差异,也可以用来测试处理器在多线程并行计算方面的性能。

官网地址:https://www.eembc.org
通过对原生的工具做修改修改添加不同平台架构支持,如下多种架构CPU的支持项:(后面贴如何新增以及对应的修改记录)
Cortex-A7 
Cortex-A9 
Cortex-A32 
Cortex-A35 
Cortex-A53 
Cortex-A55
aarch64 Cortex-A35 
aarch64 Cortex-A55
Risc-V
.......等等

编译:
1:首先需要修改对应架构下的core_portme.mak文件
2:添加编译参数:-mcpu=cortex-a32 -mfpu=neon -static -O3
3:修改编译器CC:arm-linux-gnueabihf-
如下一个参考的配置:

#File: core_portme.mak
CROSS_COMPILE = arm-linux-gnueabihf-
# Flag: OUTFLAG
#	Use this flag to define how to to get an executable (e.g -o)
OUTFLAG= -o
# Flag: CC
#	Use this flag to define compiler to use
CC = $(CROSS_COMPILE)gcc
# Flag: CFLAGS
#	Use this flag to define compiler options. Note, you can add compiler options from the command line using XCFLAGS="other flags"
PORT_CFLAGS = -mcpu=cortex-a32 -mfpu=neon -static -O3
FLAGS_STR = "$(PORT_CFLAGS) $(XCFLAGS) $(XLFLAGS) $(LFLAGS_END)"
CFLAGS = $(PORT_CFLAGS) -I$(PORT_DIR) -I. -DFLAGS_STR=\"$(FLAGS_STR)\"
#Flag: LFLAGS_END
#	Define any libraries needed for linking or other flags that should come at the end of the link line (e.g. linker scripts). 
#	Note: On certain platforms, the default clock_gettime implementation is supported but requires linking of librt.
LFLAGS_END += -lrt
# Flag: PORT_SRCS
# Port specific source files can be added here
PORT_SRCS = $(PORT_DIR)/core_portme.c
# Flag: LOAD
#	Define this flag if you need to load to a target, as in a cross compile environment.

# Flag: RUN
#	Define this flag if running does not consist of simple invocation of the binary.
#	In a cross compile environment, you need to define this.

#For flashing and using a tera term macro, you could use
#LOAD = flash ADDR 
#RUN =  ttpmacro coremark.ttl

#For copying to target and executing via SSH connection, you could use
#LOAD = scp $(OUTFILE)  user@target:~
#RUN = ssh user@target -c  

#For native compilation and execution
LOAD = echo Loading done
RUN = 

OEXT = .o
EXE = .exe

# Flag: SEPARATE_COMPILE
# Define if you need to separate compilation from link stage. 
# In this case, you also need to define below how to create an object file, and how to link.
ifdef SEPARATE_COMPILE

LD		= $(CROSS_COMPILE)gcc
OBJOUT 	= -o
LFLAGS 	=
OFLAG 	= -o
COUT 	= -c
# Flag: PORT_OBJS
# Port specific object files can be added here
PORT_OBJS = $(PORT_DIR)/core_portme$(OEXT)
PORT_CLEAN = *$(OEXT)

$(OPATH)%$(OEXT) : %.c
	$(CC) $(CFLAGS) $(XCFLAGS) $(COUT) $< $(OBJOUT) $@
.....
.....
.....

为了编译不同架构的测试程序,我新建一个编译的工具:

build.sh为了编译32位架构的CPU CoreMark测试程序,build_aarch64.sh是为了编译64位架构的CPU CoreMark测试程序,如下是32位程序编译产物:

测试:(CA32平台测试)

/tmp # ls
coremark-arm_ca32
/tmp # ./coremark-arm_ca32 
2K performance run parameters for coremark.
CoreMark Size    : 666
Total ticks      : 14167
Total time (secs): 14.167000
Iterations/Sec   : 2117.597233
Iterations       : 30000
Compiler version : GCC11.1.0
Compiler flags   : -mcpu=cortex-a32 -mfpu=neon -static -O3   -lrt
Memory location  : Please put data memory location here
                        (e.g. code in flash, data on heap etc)
seedcrc          : 0xe9f5
[0]crclist       : 0xe714
[0]crcmatrix     : 0x1fd7
[0]crcstate      : 0x8e3a
[0]crcfinal      : 0x5275
Correct operation validated. See readme.txt for run and reporting rules.
CoreMark 1.0 : 2117.597233 / GCC11.1.0 -mcpu=cortex-a32 -mfpu=neon -static -O3   -lrt / Heap

CoreMark 1.0 : 2117.597233即为本次测试得分,类似于手机的安兔兔跑分一样,分值越高性能越好。如下是完整的修改源码:

#File: core_portme.mak
CROSS_COMPILE = arm-linux-gnueabihf-
# Flag: OUTFLAG
#	Use this flag to define how to to get an executable (e.g -o)
OUTFLAG= -o
# Flag: CC
#	Use this flag to define compiler to use
CC = $(CROSS_COMPILE)gcc
# Flag: CFLAGS
#	Use this flag to define compiler options. Note, you can add compiler options from the command line using XCFLAGS="other flags"
PORT_CFLAGS = -mcpu=cortex-a32 -mfpu=neon -static -O3
FLAGS_STR = "$(PORT_CFLAGS) $(XCFLAGS) $(XLFLAGS) $(LFLAGS_END)"
CFLAGS = $(PORT_CFLAGS) -I$(PORT_DIR) -I. -DFLAGS_STR=\"$(FLAGS_STR)\"
#Flag: LFLAGS_END
#	Define any libraries needed for linking or other flags that should come at the end of the link line (e.g. linker scripts). 
#	Note: On certain platforms, the default clock_gettime implementation is supported but requires linking of librt.
LFLAGS_END += -lrt
# Flag:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值