痞子衡嵌入式:微控制器CPU性能測試基准(EEMBC-CoreMark)



  大家好,我是痞子衡,是正經搞技術的痞子。今天痞子衡給大家介紹的是微控制器CPU性能測試基准CoreMark

  在嵌入式系統行業用於評價CPU性能指標的標准主要有三種:Dhrystone、MIPS、CoreMark,其中CoreMark是一種新興流行的嵌入式系統處理器測試基准,被認為是比Dhrystone和MIPS更具有實際價值的測試基准。今天痞子衡就和大家詳細聊一聊CoreMark。

一、EEMBC協會

  在講CoreMark之前,必須要先提EEMBC(Embedded Microprocessor Benchmark Consortium)即嵌入式微處理器基准評測協會,它是一個非盈利性組織,該組織目前為止(2018.03)共發布了46個性能測試基准,有了這些性能基准參考,嵌入式設計人員可以快速有效地選擇處理器。
  EEMBC測試是基於每秒鍾算法執行的次數和編譯代碼大小的綜合統計結果。眾所周知,編譯器選項會對代碼大小和執行效率會產生巨大的影響,所以每種測試必須包括足夠多的編譯器信息並設置不同的優化項。
  EEMBC發展勢頭很好,其很有可能發展成為嵌入式系統開發人員進行處理器和編譯器性能比較的工業標准。關於EEMBC的更多介紹可移步它的官方網站 http://www.eembc.org/

二、CoreMark標准

  CoreMark是由EEMBC的Shay Gla-On於2009年提出的一項基准測試程序,其主要目標是測試處理器核心性能。
  CoreMark標准的測試方法很簡單,就是在某配置參數組合下單位時間內跑了多少次CoreMark程序,其指標單位為CoreMark/MHz。CoreMark數字越高,意味着性能更高。

2.1 獲取程序

  CoreMark程序的目前(2018.03)最新版本是1.01。

核心程序下載 http://www.eembc.org/coremark/download.php
平台移植示例 http://www.eembc.org/coremark/ports.php

  核心程序包下載后,在\coremark_v1.0\readme.txt里可見基本介紹,在\coremark_v1.0\docs\Coremark-requirements.doc里可見設計需求。詳細文件目錄如下:

\coremark_v1.0
              \barebones            --移植到裸機下需要修改的文件
			            \core_portme.h    -- 移植平台工程具體配置信息
						\core_portme.c    -- 計時以及板級初始化實現  
						\cvt.c
						\ee_printf.c      -- 打印函數串口發送實現
              \cygwin               --移植到cygwin下需要修改的文件
              \linux                --移植到linux下需要修改的文件
              \linux64              --移植到linux64下需要修改的文件
              \simple               --基本移植需要修改的文件

              core_main.c           --主程序入口
              core_state.c          --狀態機控制子程序
              core_list_join.c      --列表操作子程序
              core_matrix.c         --矩陣運算子程序
              core_util.c           --CRC計算子程序
              coremark.h            --工程配置與數據結構定義

              \docs                 --設計文檔
              coremark.md5
              LICENSE.txt
              Makefile
              readme.txt            --基本介紹
              release_notes.txt     --版本說明

  如果是移植到ARM Cortex-M平台下裸系統運行,一般只需要修改\barebones目錄下的文件即可(僅需改動三個函數portable_init()、barebones_clock()、uart_send_char()以及core_portme.h中若干宏定義),其余代碼文件不需要修改。關於\barebones下的文件修改,EEMBC上有如下4個示例平台可參考:

2.2 配置參數

  前面講到做平台移植時除了必須要改動3個函數外,還需要設置core_portme.h中若干宏定義,這些宏定義即為配置參數,需要根據要移植到的具體平台的屬性而定。一共如下14個宏:

解釋 示例
HAS_FLOAT Define to 1 if the platform supports floating point 1
HAS_TIME_H Define to 1 if platform has the time.h header file and implementation of functions thereof 0
USE_CLOCK Define to 1 if platform has the time.h header file and implementation of functions thereof 0
HAS_STDIO Define to 1 if the platform has stdio.h. 0
HAS_PRINTF Define to 1 if the platform has stdio.h and implements the printf function. 0
COMPILER_VERSION Please put compiler version here (e.g. gcc 4.1) "IAR EWARM v8.20.2"
COMPILER_FLAGS Please put compiler flags here (e.g. -o3) "High - Speed - No size constraints"
MEM_LOCATION Please put the mem location of code execution here (e.g STACK) "STACK"
CORETIMETYPE Define type of return from the timing functions. ee_u32
SEED_METHOD Defines method to get seed values that cannot be computed at compile time. SEED_VOLATILE
MEM_METHOD Defines method to get a block of memry. MEM_STATIC
MULTITHREAD Define for parallel execution 1
MAIN_HAS_NOARGC Needed if platform does not support getting arguments to main. 1
MAIN_HAS_NORETURN Needed if platform does not support returning a value from main. 0

  細心的朋友應該能注意到core_portme.h文件的最后有如下條件編譯,實際上CoreMark主程序的運行有3種模式可選,即PROFILE_RUN(原型模式)/PERFORMANCE_RUN(性能模式)/VALIDATION_RUN(驗證模式)

#if !defined(PROFILE_RUN) && !defined(PERFORMANCE_RUN) && !defined(VALIDATION_RUN)
#if (TOTAL_DATA_SIZE==1200)
#define PROFILE_RUN 1
#elif (TOTAL_DATA_SIZE==2000)
#define PERFORMANCE_RUN 1
#else
#define VALIDATION_RUN 1
#endif
#endif

  而在coremark.h文件的最開始就定義了缺省的TOTAL_DATA_SIZE的值為2000,即CoreMark程序默認跑在PERFORMANCE_RUN(性能模式)下。如果你想修改運行模式,需要在編譯器預編譯選項里自定義TOTAL_DATA_SIZE。

/* Configuration: TOTAL_DATA_SIZE
	Define total size for data algorithms will operate on
*/
#ifndef TOTAL_DATA_SIZE 
#define TOTAL_DATA_SIZE 2*1000
#endif

2.3 程序解析

  CoreMark程序使用C語言寫成,包含如下四類運算法則:數學矩陣操作(普通矩陣運算)、列舉(尋找並排序)、狀態機(用來確定輸入流中是否包含有效數字)、CRC(循環冗余校驗),都是在真實的嵌入式應用中很常見的操作,這也是CoreMark比其他測試標准更有實際價值的原因所在。

a. Matrix multiply (allow for use of MAC operations, common math use)
b. Linked list search/sort/read (common pointer use)
c. State machine (common use of data dependent branches)
d. CRC (common in embedded)

  讓我們嘗試分析CoreMark主函數入口main(以2.2節中配置示例值為例):

/* Function: main
	Main entry routine for the benchmark.
	This function is responsible for the following steps:

	1 - Initialize input seeds from a source that cannot be determined at compile time.
	2 - Initialize memory block for use.
	3 - Run and time the benchmark.
	4 - Report results, testing the validity of the output if the seeds are known.

	Arguments:
	1 - first seed  : Any value
	2 - second seed : Must be identical to first for iterations to be identical
	3 - third seed  : Any value, should be at least an order of magnitude less then the input size, but bigger then 32.
	4 - Iterations  : Special, if set to 0, iterations will be automatically determined such that the benchmark will run between 10 to 100 secs

*/
MAIN_RETURN_TYPE main(void) {
	int argc=0;
	char *argv[1];
	ee_u16 i,j=0,num_algorithms=0;
	ee_s16 known_id=-1,total_errors=0;
	ee_u16 seedcrc=0;
	CORE_TICKS total_time;
	core_results results[MULTITHREAD];

	// 系統板級初始化
	portable_init(&(results[0].port), &argc, argv);

	// ...
	// 設置PERFORMANCE_RUN的初始參數
	results[0].seed1=get_seed(1);  //0x0
	results[0].seed2=get_seed(2);  //0x0
	results[0].seed3=get_seed(3);  //0x66
	results[0].iterations=get_seed_32(4);  //ITERATIONS
	// execs參數為需要跑的算法使能位
	results[0].execs=get_seed_32(5);       //0x0
	if (results[0].execs==0) { /* if not supplied, execute all algorithms */
		results[0].execs=ALL_ALGORITHMS_MASK;
	}
	// ...

	results[0].memblock[0]=(void *)static_memblk;
	results[0].size=TOTAL_DATA_SIZE;
	results[0].err=0;

	/* Data init */ 
	/* Find out how space much we have based on number of algorithms */
	// ...

	// 各算法子程序初始化(共LIST, MATRIX, STATE三種)
	for (i=0 ; i<MULTITHREAD; i++) {
		if (results[i].execs & ID_LIST) {
			results[i].list=core_list_init(results[0].size,results[i].memblock[1],results[i].seed1);
		}
		if (results[i].execs & ID_MATRIX) {
			core_init_matrix(results[0].size, results[i].memblock[2], (ee_s32)results[i].seed1 | (((ee_s32)results[i].seed2) << 16), &(results[i].mat) );
		}
		if (results[i].execs & ID_STATE) {
			core_init_state(results[0].size,results[i].seed1,results[i].memblock[3]);
		}
	}

	/* automatically determine number of iterations if not set */
	// ...

	// 開始跑CoreMark程序且記錄累計消耗時間
	start_time();
	iterate(&results[0]);
	stop_time();
	total_time=get_time();

    // ...
	// 最終信息的打印
    // ...
	if (total_errors==0) {
		ee_printf("Correct operation validated. See readme.txt for run and reporting rules.\n");
		if (known_id==3) {
			ee_printf("CoreMark 1.0 : %f / %s %s",default_num_contexts*results[0].iterations/time_in_secs(total_time),COMPILER_VERSION,COMPILER_FLAGS);
			ee_printf("\n");
		}
	}
    // ...

	/* And last call any target specific code for finalizing */
	portable_fini(&(results[0].port));

	return MAIN_RETURN_VAL;	
}

2.4 結果格式

  當移植好CoreMark程序后,便可以開始跑起來了,在跑程序的時候,EEMBC同時制定了必須要遵守規則(不遵守的話,跑分結果不被EEMBC所認可),詳見 https://www.eembc.org/coremark/CoreMarkRunRules.pdf
  當得到跑分結果后可將結果提交到EEMBC網站上,跑分結果需按如下標准格式進行提交:

	CoreMark 1.0 : N / C [/ P] [/ M]

	N - Number of iterations per second with seeds 0,0,0x66,size=2000)
	C - Compiler version and flags
	P - Parameters such as data and code allocation specifics
		- This parameter *may* be omitted if all data was allocated on the heap in RAM.
		- This parameter *may not* be omitted when reporting CoreMark/MHz
	M - Type of parallel execution (if used) and number of contexts
		This parameter may be omitted if parallel execution was not used.

	e.g.
	> CoreMark 1.0 : 128 / GCC 4.1.2 -O2 -fprofile-use / Heap in TCRAM / FORK:2
	or
	> CoreMark 1.0 : 1400 / GCC 3.4 -O4

	If reporting scaling results, the results must be reported as follows:

	CoreMark/MHz 1.0 : N / C / P [/ M]

	P - When reporting scaling results, memory parameter must also indicate memory frequency:core frequency ratio.
		- If the core has cache and cache frequency to core frequency ratio is configurable, that must also be included.

	e.g.
	> CoreMark/MHz 1.0 : 1.47 / GCC 4.1.2 -O2 / DDR3(Heap) 30:1 Memory 1:1 Cache

  如果移植的CoreMark能夠正確運行,你應該可以看到串口會打印出類似如下格式的信息,上述要求的CoreMark標准結果就在打印信息的最后。

2K performance run parameters for coremark. (Run type)
CoreMark Size       : 666                   (Buffer size)
Total ticks         : 25875                 (platform dependent value)
Total time (secs)   : 25.875000             (actual time in seconds)
Iterations/Sec      : 3864.734300           (Performance value to report)
Iterations          : 100000                (number of iterations used)
Compiler version    : GCC3.4.4              (Compiler and version)
Compiler flags      : -O2                   (Compiler and linker flags)
Memory location     : Code in flash, data in on chip RAM
seedcrc             : 0xe9f5                (identifier for the input seeds)
[0]crclist          : 0xe714                (validation for list part)
[0]crcmatrix        : 0x1fd7                (validation for matrix part)
[0]crcstate         : 0x8e3a                (validation for state part)
[0]crcfinal         : 0x33ff                (iteration dependent output)
Correct operation validated. See readme.txt for run and reporting rules.  (*Only when run is successful*)
CoreMark 1.0 : 6508.490622 / GCC3.4.4 -O2 / Heap                          (*Only on a successful performance run*)

2.5 跑分榜

  截止到目前(2018.03),EEMBC網站共記錄535款微控制器的CoreMark跑分結果(注意並不是所有跑分結果都經過EEMBC核實),所有跑分結果可在這里查詢 https://www.eembc.org/coremark/scores.php,下圖是跑分榜部分結果(按提交日期排序)。如果是設計人員根據性能選型的話,可以選按得分高低排序。

2.6 結果示例

  在上節介紹的跑分榜里可點擊微控制器型號查看具體結果,也可選擇多個微控制器進行結果對比。最近兩家ARM Cortex-M微控制器知名廠商恩智浦半導體和意法半導體在高性能微控制器上正一決雌雄,恩智浦推出的i.MX RT1050和意法半導體推出的STM32H743均是基於Cortex-M7內核,且都在2017.10實現初版量產,我們且來比比看這兩款微控制器:

  從對比結果來看,i.MX RT1050在性能上完爆STM32H743,其3036的總得分在Cortex-M微控制器里獨孤求敗,這個跑分結果雖未經過EEMBC認證,但與恩智浦官方給的數據3020基本吻合。
  關於i.MX RT系列微控制器簡介可詳見我的另一篇文章 飛思卡爾i.MX RT系列微控制器介紹篇(1)- 概覽,對於i.MX RT1050跑分結果的驗證與復現可詳見我的文章 飛思卡爾i.MX RT系列微控制器介紹篇(2)- 性能CoreMark

  至此,微控制器CPU性能測試基准CoreMark痞子衡便介紹完畢了,掌聲在哪里~~~

歡迎訂閱

文章會同時發布到我的 博客園主頁CSDN主頁微信公眾號 平台上。

微信搜索"痞子衡嵌入式"或者掃描下面二維碼,就可以在手機上第一時間看了哦。


免責聲明!

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



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