本篇文章主要在CH32V307开发板上移植coremark,看看其跑分怎么样?
之所以使用coremark跑分,是因为这是第一次使用riscv开发板,也想看看riscv架构的MCU跑分性能怎么样,另外就是coremark在单片机跑分也比较具有代表性。
一、coremark是什么?
CoreMark是一种嵌入式处理器性能评估的工具
1、具体作用如下:
1)处理器性能评估
通过标准化算法(列表处理、矩阵运算、状态机、CRC校验)模拟真实嵌入式负载,量化CPU的整数运算、控制流及内存访问效率
提供统一的性能指标(单位:CoreMark/MHz),便于比较不同架构处理器(如ARM Cortex-M、RISC-V、x86)的性能差异
2)替代传统基准测试
- 取代陈旧的Dhrystone标准,解决其依赖编译器优化、库调用干扰结果的问题,提供更客观的硬件性能反映
2、有哪些优势
开源代码(C语言实现),测试结果可复现,避免厂商特定优化干扰
支持调整迭代次数、线程数,适配从8位MCU到64位处理器
多线程测试兼容多核SoC,反映并发性能
代码量小(约千行),易于移植到资源受限的嵌入式平台
所有计算即时生成,禁止预编译优化;无外部库调用,消除库性能差异影响
二、移植coremark
1、下载源码
在coremark官网GitHub - eembc/coremark: CoreMark® is an industry-standard benchmark that measures the performance of central processing units (CPU) and embedded microcrontrollers (MCU).
2、新建一个coremark文件夹
复制如图所示的文件到coremark文件夹下
3、对core_portme.c文件进行相关修改
修改为如下
- -void
- -start_time(void)
- +volatile uint32_t startTick = 0;
- +volatile uint32_t endTick = 0;
- +
- +void start_time(void)
- {
- - GETMYTIME(&start_time_val);
- + startTick = g_msTick;
- }
- /* Function : stop_time
- This function will be called right after ending the timed portion of the
- @[url=home.php?mod=space&uid=72445]@[/url] -83,31 +91,31 @@ start_time(void)
- example code) or other system parameters - e.g. reading the current value of
- cpu cycles counter.
- */
- -void
- -stop_time(void)
- +void stop_time(void)
- {//获取跑分开始的tick
- - GETMYTIME(&stop_time_val);
- + endTick = g_msTick;
- }
- +
- /* Function : get_time
- Return an abstract "ticks" number that signifies time on the system.
- Actual value returned may be cpu cycles, milliseconds or any other
- value, as long as it can be converted to seconds by <time_in_secs>. This
- - methodology is taken to accomodate any hardware or simulated platform. The
- + methodology is taken to accommodate any hardware or simulated platform. The
- sample implementation returns millisecs by default, and the resolution is
- controlled by <TIMER_RES_DIVIDER>
- */
- CORE_TICKS
- get_time(void)
- {//获取跑分结束的tick
- - CORE_TICKS elapsed
- - = (CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
- + CORE_TICKS elapsed = (CORE_TICKS)(g_msTick - startTick);
- return elapsed;
- }
并修改上述文件的宏定义
- // #define NSECS_PER_SEC CLOCKS_PER_SEC
- // #define CORETIMETYPE clock_t
- // #define GETMYTIME(_t) (*_t = clock())
- // #define MYTIMEDIFF(fin, ini) ((fin) - (ini))
- // #define TIMER_RES_DIVIDER 1
- // #define SAMPLE_TIME_IMPLEMENTATION 1
- // #define EE_TICKS_PER_SEC (NSECS_PER_SEC / TIMER_RES_DIVIDER)
- // /** Define Host specific (POSIX), or target specific global time variables. */
- // static CORETIMETYPE start_time_val, stop_time_val;
- #define EE_TICKS_PER_SEC 1000 //1s所代表的定时器计数累加值
修改core_main.c中的main名函数为如下
- IN_RETURN_TYPE
- coremark_main(int argc, char *argv[])
添加系统时钟频率打印
- void
- portable_init(core_portable *p, int *argc, char *argv[])
- {
- (void)argc; // prevent unused warning
- (void)argv; // prevent unused warning
- ee_printf("CoreMark run on CH32V307VCT6 @ %luHz\r\n", sys_clock_hz);
4、修改core_portme.h文件
添加优化等级,修改为O3;这是系统要求定义优化等级
- #ifndef COMPILER_FLAGS
- #define COMPILER_FLAGS "-o3" /* "Please put compiler flags here (e.g. -o3)" */
5、在主函数添加coremark
- /*********************************************************************
- * @fn main
- *
- * [url=home.php?mod=space&uid=247401]@brief[/url] Main program.
- *
- * [url=home.php?mod=space&uid=266161]@return[/url] none
- */
- int main(void)
- {
- SystemCoreClockUpdate();
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- //Delay_Init();
- USART_Printf_Init(115200);
- SYSTICK_Init_Config((SystemCoreClock / 1000)-1);
- printf("SystemClk:%d\r\n",SystemCoreClock);
- sys_clock_hz = SystemCoreClock;
- printf( "ChipID:%08x\r\n", DBGMCU_GetCHIPID() );
- printf("This is printf example\r\n");
- coremark_main(0, NULL);
- while(1)
- {
- }
- }
6、添加头文件
7、下载验证
1)时钟频率为96Mhz
实际没有显示跑分的分数,如图
咨询沁恒的相关技术人员,竟然回复了,提示应该是编译器不支持打印浮点数。
修改如下:
修改优化等级为-O3
跑分如下:
优化等级为-ofast,跑分和上述一致
2)系统时钟为144Mhz
修改时钟频率为144Mhz,只需要取消144Mhz的注释即可。
优化等级为-O3
优化等级为-ofast,跑分和上述一致。不算太高,计算得出2.65coremark /Mhz,与STM32F407([color=rgba(0, 0, 0, 0.9)]2.75 coremark /Mhz) 差不多到时候抽空尝试一下最大优化是否会提高分数。分数还和编译器有关系。
总结:整体来看跑分与STM32F4相当;性能还是不错的,属于中端水平
|