CPU性能測試——CoreMark篇


在這里插入圖片描述
本文將介紹使用CoreMark測試程序對我們小組自研芯片進行性能的測試,記錄了CoreMarK工具的使用以及對其測試結果進行分析
測試環境:
PC OS: Ubuntu20.04 LTS
CPU: 自研CPU(ARCH=riscv64,ISA=rv64imafdc)
Kernel: CPU使用的內核為Linux4.15
CoreMark: CoreMark v1.01
GNU: riscv64-unknown-linux-gnu

1、CoreMark簡介

  CoreMark是由EEMBC(Embedded Microprocessor Benchmark Consortium)Shay Gla-On2009年提出的一項基准測試程序,CoreMark的主要目標是簡化操作,並提供一套測試單核處理器核心的方法。測試標准是在配置參數的組合下單位時間內運行的CoreMark程序次數(單位:CoreMark/MHz),該數字值越大則說明測試的性能越好。
  目前在嵌入式CPU行業中普遍公認的性能測試指標的標准主要使用以下三種,MIPSDhrystoneCoremark,而CoreMarkDhrystone一樣,擁有體積小、方便移植、易於理解、免費並且顯示單個數字基准分數。與Dhrystone不同的是,Dhrystone的主要部分實際上暴露了編譯器優化工作負載的能力,而不是實際MCUCPU的能力,的性能,而CoreMark具有特定的運行和報告規則,從而可以避免由於所使用的編譯庫不同而導致的測試結果難以比較。

2、獲取源碼

  EEMBC在將CoreMark源碼托管在GitHub上可以訪問github.com/eembc/coremark直接點擊下載獲得源碼;也可以通過git命令下載到本地。

imaginemiracle@:Download$ git clone https://github.com/eembc/coremark.git
imaginemiracle@:Download$ cd coremark/
imaginemiracle@:coremark$ ls
barebones         core_main.c  coremark.md5   core_state.c  cygwin  freebsd     linux    macos     README.md  simple
core_list_join.c  coremark.h   core_matrix.c  core_util.c   docs    LICENSE.md  linux64  Makefile  rtems

CoreMark項目的詳細介紹,可以查閱當前目錄下“coremark/docs/html/index.html”。該項目以下是當前目錄的個文件介紹:

#在tree命令的輸出中,作了部分刪除(不影響分析整個CoreMark工程)
imaginemiracle@:coremark$ tree
.
├── barebones	 --移植到裸機環境下需要修改的目錄
│   ├── core_portme.c		--移植的目標平台配置信息
│   ├── core_portme.h		--計時以及板級初始化實現
│   ├── core_portme.mak		--該子目錄的makefile
│   ├── cvt.c
│   └── ee_printf.c			--打印函數串口發送實現
├── core_list_join.c	--列表操作程序
├── core_main.c			--主程序
├── coremark.h			--項目配置與數據結構的定義頭文件
├── coremark.md5		
├── core_matrix.c		--矩陣運算程序
├── core_state.c		--狀態機控制程序
├── core_util.c			--CRC計算程序
├── cygwin				--x86 cygwin和gcc 3.4(四核,雙核和單核系統)的測試代碼
│   ├── core_portme.c
│   ├── core_portme.h
│   └── core_portme.mak
├── freebsd				--以下同理,是在不同操作系統下的測試代碼
│   ├── ...
├── LICENSE.md
├── linux
│   ├── ...
├── linux64
│   ├── ...
├── macos
│   ├── ...
├── Makefile			
├── README.md			--自述文件,CoreMark項目的基本介紹
├── rtems
│   ├── ...
└── simple
    ├── ...
    └──

3、移植到riscv64架構

[注]:若移植的平台是ARM Cortex-M系列的裸機系統,只需要修改“coremark/barebones”目錄下的文件即可。
將當前目錄下linux64目錄拷貝一份為riscv64分支:

imaginemiracle@:coremark$ cp -rf linux64/ riscv64
imaginemiracle@:coremark$ vim riscv64/core_portme.mak

修改CCriscv64-unknown-linux-gnu-gcc即可(默認已經配置好riscv64-linux-gnu工具鏈,有很多優秀的博客介紹了riscv toolchain的編譯安裝過程可以自行查閱參考):

#core_portme.mak文件

OUTFLAG= -o
# Flag: CC
#   Use this flag to define compiler to use
# ===========================Alter by me===========================
CC = riscv64-unknown-linux-gnu-gcc
# ============================End Alter============================
# 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 = -O2
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

LOAD = echo Loading done
RUN = 

OEXT = .o
# ===========================Alter by me===========================
EXE = .rvexe
# ============================End Alter============================

4、編譯生成coremark.rvexe

4.1、編譯在單核上運行的coremark.rvexe

<1> 編譯命令:

imaginemiracle@:coremark$ make PORT_DIR=riscv64

<2> 編譯結果如下,會出現錯誤

./coremark.rvexe  0x0 0x0 0x66 0 7 1 2000 > ./run1.log
/bin/sh: 1: ./coremark.rvexe: Exec format error
make[1]: *** [Makefile:112: run1.log] Error 2
make[1]: Leaving directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/test/coremark'
make: *** [Makefile:99: rerun] Error 2
imaginemiracle@:coremark$ file coremark.rvexe
coremark.rvexe: ELF 64-bit LSB executable, UCB RISC-V, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv64-lp64d.so.1, for GNU/Linux 3.0.0, with debug_info, not stripped

  仔細查看,該錯誤並不是編譯過程發生的錯誤,而是在運行編譯出的coremark.rvexe報錯,答案是肯定的,因為該可執行文件的架構是riscv64,而當前環境架構是x86

4.2、編譯在多核上運行的coremark.rvexe

<1> 首先需要修改make文件(在LFLAGAS_END變量添加-lpthread``)

imaginemiracle@:coremark$ cd riscv64
imaginemriacle@:riscv64$ vim core_portme.mak
#coremark/riscv64/core_protme.mak
#File: core_portme.mak

# 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 = riscv64-unknown-linux-gnu-gcc
#CC = 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 = -O2 -fno-common -funroll-loops -finline-functions --param max-inline-insns-auto=20 -falign-functions=4 -falign-jumps=4 -falign-loops=4 -
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.
#===============================Alter by me===========================
LFLAGS_END += -lrt -lpthread                                          
#===============================Alter by me===========================                                                                                
# Flag: PORT_SRCS
# Port specific source files can be added here
PORT_SRCS = $(PORT_DIR)/core_portme.c

<2> 編譯生成coremark.rvexe

可以使用XCFLAGS=-DMULTITHREAD=N其中的N是需要並行運行的線程數,如下使用的編譯命令則是使用POSIX Threads API將源碼編譯在4個內核上運行的CoreMark測試:

imaginemiracle@:coremark$ make PORT_DIR=riscv64  XCFLAGS="-DMULTITHREAD=4 -DUSE_PTHREAD"

編譯結果如下,會出現錯誤。

make XCFLAGS="-DMULTITHREAD=4 -DUSE_PTHREAD -DPERFORMANCE_RUN=1" load run1.log
make[1]: Entering directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
make port_prebuild
make[2]: Entering directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
make[2]: Nothing to be done for 'port_prebuild'.
make[2]: Leaving directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
make link
make[2]: Entering directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
riscv64-unknown-linux-gnu-gcc -O2 -fno-common -funroll-loops -finline-functions --param max-inline-insns-auto=20 -falign-functions=4 -falign-jumps=4 -falign-loops=4 --param inline-min-speedup=10 -Iriscv64 -I. -DFLAGS_STR=\""-O2 -fno-common -funroll-loops -finline-functions --param max-inline-insns-auto=20 -falign-functions=4 -falign-jumps=4 -falign-loops=4 --param inline-min-speedup=10 -DMULTITHREAD=4 -DUSE_PTHREAD -DPERFORMANCE_RUN=1  -lrt -lpthread"\" -DITERATIONS=0 -DMULTITHREAD=4 -DUSE_PTHREAD -DPERFORMANCE_RUN=1 core_list_join.c core_main.c core_matrix.c core_state.c core_util.c riscv64/core_portme.c -o ./coremark.rvexe -lrt -lpthread
Link performed along with compile
make[2]: Leaving directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
make port_postbuild
make[2]: Entering directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
make[2]: Nothing to be done for 'port_postbuild'.
make[2]: Leaving directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
make port_preload
make[2]: Entering directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
make[2]: Nothing to be done for 'port_preload'.
make[2]: Leaving directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
echo Loading done ./coremark.rvexe
Loading done ./coremark.rvexe
make port_postload
make[2]: Entering directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
make[2]: Nothing to be done for 'port_postload'.
make[2]: Leaving directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
make port_prerun
make[2]: Entering directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
make[2]: Nothing to be done for 'port_prerun'.
make[2]: Leaving directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
./coremark.rvexe  0x0 0x0 0x66 0 7 1 2000 > ./run1.log
/bin/sh: 1: ./coremark.rvexe: Exec format error
make[1]: *** [Makefile:112: run1.log] Error 2
make[1]: Leaving directory '/media/imaginemiracle/Disk_D/Linux_Workspace/riscv-project/File_System_test/sifive_coremark/coremark-riscv64'
make: *** [Makefile:99: rerun] Error 2

與上面的錯誤類似,都是在運行非X86架構的程序報的錯誤信息,因此不必擔心,直接將編譯好的coremark.rvexe拷貝到目標平台即可。

5、在目標平台上運行coremark.rvexe測試性能

下圖是在我們自研CPU上CoreMark的測試結果,其中Iterations/Sec就是在跑分榜上CoreMark的值,根據該值和其它參數可以對比各微處理器的性能。

<1> 運行coremark.rvexe

執行命令:./coremark.rvexe
[注] 多核與單核coremark測試相同,直接運行coremark的可執行程序即可,下圖是單核coremark的測試結果
在這里插入圖片描述

6、CoreMark跑分榜

目前可以看到EEMBC已經上傳了592款型號的微控制器CoreMark跑分結果,可以在EEMBC的coremark/scores里看到。(注:下圖獲取時間為2020-12-31
在這里插入圖片描述


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM