[活动专区] 【AT-START-F457测评】+性能真的很可以

[复制链接]
179|1
across往事 发表于 2026-2-12 10:10 | 显示全部楼层 |阅读模式
本帖最后由 across往事 于 2026-2-12 10:23 编辑
上一篇利用AT32_Work_Bench+MDK进行了快速开发,体验确实不一般,非常容易而且代码仅需要编写业务逻辑即可,底层代码基本就是拿来就用,好不舒适。今天准备继续利用AT32_Work_Bench配置,实现coremark跑分,看看AT32F457开发板的性能究竟如何?敬请期待~
打开AT32_Work_Bench,由于coremark的使用需要一个基准时钟,这里我是用tmr1配置一个输出1ms的计时器,也就是将频率设置为100Hz,配置如图1所示。
       1.png
图1 AT32_Work_Bench配置AT32F457定时器界面
       然后配置好USART和printf,这里上一期已经配置过了,请看图2和图3,这里简单的略过。
2.png
图2 AT32_Work_Bench配置AT32F457USART界面

3.png
图3 AT32_Work_Bench配置AT32F457delay基准源于串口打印配置界面
       以上都配置好之后就可以输出代码工程了,输出之后即可拿MDK打开,接下来就需要下载coremark源码了。源码链接如下:https://github.com/eembc/coremark
       当下载好源码之后,将所需要的文件复制出来,这里需要以下几个文件。并且添加到工程之中。
4.png
图4 coremark所需文件
5.png
图5 创建好的工程,添加coremark
6.png
图6 修改好的coremark工程
修改的代码如下:
main.c
  1. int main(void)
  2. {
  3.   /* add user code begin 1 */

  4.   /* add user code end 1 */

  5.   /* system clock config. */
  6.   wk_system_clock_config();

  7.   /* config periph clock. */
  8.   wk_periph_clock_config();

  9.   /* nvic config. */
  10.   wk_nvic_config();

  11.   /* timebase config for
  12.      void wk_delay_us(uint32_t delay);
  13.      void wk_delay_ms(uint32_t delay); */
  14.   wk_timebase_init();

  15.   /* init gpio function. */
  16.   wk_gpio_config();

  17.   /* init usart1 function. */
  18.   wk_usart1_init();

  19.   /* init tmr1 function. */
  20.   wk_tmr1_init();
  21.         int CoreMark_Main(int argc, char *argv[]);
  22.   /* add user code begin 2 */
  23.         CoreMark_Main(0, 0);
  24.   /* add user code end 2 */

  25.   while(1)
  26.   {
  27.     /* add user code begin 3 */

  28.     /* add user code end 3 */
  29.   }
  30. }
  1. volatile uint32_t uwTick = 0;
core portme.c
  1. /*
  2. Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)

  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at

  6.     http://www.apache.org/licenses/LICENSE-2.0

  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.

  12. Original Author: Shay Gal-on
  13. */

  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include "coremark.h"
  17. #include "wk_system.h"
  18. #include "at32f45x_wk_config.h"
  19. #include "wk_usart.h"
  20. #include "wk_system.h"
  21. #include "wk_usart.h"
  22. #include "at32f45x_int.h"

  23. #if VALIDATION_RUN
  24. volatile ee_s32 seed1_volatile = 0x3415;
  25. volatile ee_s32 seed2_volatile = 0x3415;
  26. volatile ee_s32 seed3_volatile = 0x66;
  27. #endif
  28. #if PERFORMANCE_RUN
  29. volatile ee_s32 seed1_volatile = 0x0;
  30. volatile ee_s32 seed2_volatile = 0x0;
  31. volatile ee_s32 seed3_volatile = 0x66;
  32. #endif
  33. #if PROFILE_RUN
  34. volatile ee_s32 seed1_volatile = 0x8;
  35. volatile ee_s32 seed2_volatile = 0x8;
  36. volatile ee_s32 seed3_volatile = 0x8;
  37. #endif
  38. volatile ee_s32 seed4_volatile = ITERATIONS;
  39. volatile ee_s32 seed5_volatile = 0;
  40. /* Porting : Timing functions
  41.         How to capture time and convert to seconds must be ported to whatever is
  42.    supported by the platform. e.g. Read value from on board RTC, read value from
  43.    cpu clock cycles performance counter etc. Sample implementation for standard
  44.    time.h and windows.h definitions included.
  45. */
  46. /* Define : TIMER_RES_DIVIDER
  47.         Divider to trade off timer resolution and total time that can be
  48.    measured.

  49.         Use lower values to increase resolution, but make sure that overflow
  50.    does not occur. If there are issues with the return value overflowing,
  51.    increase this value.
  52.         */
  53. //#define NSECS_PER_SEC              CLOCKS_PER_SEC
  54. //#define CORETIMETYPE               clock_t
  55. //#define GETMYTIME(_t)              (*_t = clock())
  56. //#define MYTIMEDIFF(fin, ini)       ((fin) - (ini))
  57. //#define TIMER_RES_DIVIDER          1
  58. //#define SAMPLE_TIME_IMPLEMENTATION 1
  59. //#define EE_TICKS_PER_SEC           (NSECS_PER_SEC / TIMER_RES_DIVIDER)
  60. #define EE_TICKS_PER_SEC           1000
  61. #define SysTick_Counter_Disable ((uint32_t)0xFFFFFFFE)

  62. #define SysTick_Counter_Enable ((uint32_t)0x00000001)

  63. #define SysTick_Counter_Clear ((uint32_t)0x00000000)

  64. extern volatile uint32_t uwTick;

  65. uint32_t Tick;
  66. __IO uint32_t Ticks;


  67. /** Define Host specific (POSIX), or target specific global time variables. */
  68. //static CORETIMETYPE start_time_val, stop_time_val;

  69. /* Function : start_time
  70.         This function will be called right before starting the timed portion of
  71.    the benchmark.

  72.         Implementation may be capturing a system timer (as implemented in the
  73.    example code) or zeroing some system parameters - e.g. setting the cpu clocks
  74.    cycles to 0.
  75. */
  76. void
  77. start_time(void)
  78. {
  79. //    GETMYTIME(&start_time_val);
  80.                Tick = HAL_GetTick();
  81. //                                systick_interrupt_config(1000);//1ms中断
  82. }
  83. /* Function : stop_time
  84.         This function will be called right after ending the timed portion of the
  85.    benchmark.

  86.         Implementation may be capturing a system timer (as implemented in the
  87.    example code) or other system parameters - e.g. reading the current value of
  88.    cpu cycles counter.
  89. */
  90. void
  91. stop_time(void)
  92. {
  93.     //GETMYTIME(&stop_time_val);
  94.     /* Stop the Timer and get the encoding time */
  95. //     SysTick->CTRL &=SysTick_Counter_Disable;
  96. //     /* Clear the SysTick Counter */
  97. //     SysTick->VAL = SysTick_Counter_Clear;
  98. }
  99. /* Function : get_time
  100.         Return an abstract "ticks" number that signifies time on the system.

  101.         Actual value returned may be cpu cycles, milliseconds or any other
  102.    value, as long as it can be converted to seconds by <time_in_secs>. This
  103.    methodology is taken to accommodate any hardware or simulated platform. The
  104.    sample implementation returns millisecs by default, and the resolution is
  105.    controlled by <TIMER_RES_DIVIDER>
  106. */
  107. CORE_TICKS
  108. get_time(void)
  109. {
  110.         CORE_TICKS elapsed = (CORE_TICKS)(HAL_GetTick()-Tick);
  111.         return elapsed;
  112. }
  113. /* Function : time_in_secs
  114.         Convert the value returned by get_time to seconds.

  115.         The <secs_ret> type is used to accommodate systems with no support for
  116.    floating point. Default implementation implemented by the EE_TICKS_PER_SEC
  117.    macro above.
  118. */
  119. secs_ret
  120. time_in_secs(CORE_TICKS ticks)
  121. {
  122.         secs_ret retval=((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
  123.         return retval;
  124. }

  125. ee_u32 default_num_contexts = 1;

  126. /* Function : portable_init
  127.         Target specific initialization code
  128.         Test for some common mistakes.
  129. */

  130. void portable_init(core_portable *p, int *argc, char *argv[])
  131. {
  132.         //ee_printf("CoreMark run on AT32F437ZMT7 <a href="home.php?mod=space&uid=72445" target="_blank">@</a> %luHz\r\n",  crm_clocks_freq_struct.sclk_freq);

  133.         if (sizeof(ee_ptr_int) != sizeof(ee_u8*)) {
  134.                 ee_printf("ERROR! Please define ee_ptr_int to a type that holds a pointer!\r\n");
  135.         }
  136.         if (sizeof(ee_u32) != 4) {
  137.                 ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\r\n");
  138.         }
  139.         p->portable_id = 1;
  140. }
  141. /* Function : portable_fini
  142.         Target specific final code
  143. */
  144. void
  145. portable_fini(core_portable *p)
  146. {
  147.     p->portable_id = 0;
  148. }
core portme.h
  1. /*
  2. Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)

  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at

  6.     http://www.apache.org/licenses/LICENSE-2.0

  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.

  12. Original Author: Shay Gal-on
  13. */

  14. /* Topic : Description
  15.         This file contains configuration constants required to execute on
  16.    different platforms
  17. */
  18. #ifndef CORE_PORTME_H
  19. #define CORE_PORTME_H
  20. /************************/
  21. /* Data types and settings */
  22. /************************/
  23. /* Configuration : HAS_FLOAT
  24.         Define to 1 if the platform supports floating point.
  25. */
  26. #ifndef HAS_FLOAT
  27. #define HAS_FLOAT 1
  28. #endif
  29. /* Configuration : HAS_TIME_H
  30.         Define to 1 if platform has the time.h header file,
  31.         and implementation of functions thereof.
  32. */
  33. #ifndef HAS_TIME_H
  34. #define HAS_TIME_H 1
  35. #endif
  36. /* Configuration : USE_CLOCK
  37.         Define to 1 if platform has the time.h header file,
  38.         and implementation of functions thereof.
  39. */
  40. #ifndef USE_CLOCK
  41. #define USE_CLOCK 1
  42. #endif
  43. /* Configuration : HAS_STDIO
  44.         Define to 1 if the platform has stdio.h.
  45. */
  46. #ifndef HAS_STDIO
  47. #define HAS_STDIO 1
  48. #endif
  49. /* Configuration : HAS_PRINTF
  50.         Define to 1 if the platform has stdio.h and implements the printf
  51.    function.
  52. */
  53. #ifndef HAS_PRINTF
  54. #define HAS_PRINTF 1
  55. #endif

  56. /* Configuration : CORE_TICKS
  57.         Define type of return from the timing functions.
  58. */
  59. #include <time.h>
  60. typedef clock_t CORE_TICKS;

  61. /* Definitions : COMPILER_VERSION, COMPILER_FLAGS, MEM_LOCATION
  62.         Initialize these strings per platform
  63. */
  64. #ifndef COMPILER_VERSION
  65. #ifdef __GNUC__
  66. #define COMPILER_VERSION "GCC"__VERSION__
  67. #else
  68. #define COMPILER_VERSION "MDK-ARM Plus Version: 5.39.0.0"
  69. #endif
  70. #endif
  71. #ifndef COMPILER_FLAGS
  72. #define COMPILER_FLAGS   "Optimization: Level 3 (-03)" /* "Please put compiler flags here (e.g. -o3)" */
  73. #endif
  74. #ifndef MEM_LOCATION
  75. #define MEM_LOCATION "STACK"
  76. #endif
  77. #define ITERATIONS 10000;
  78. /* Data Types :
  79.         To avoid compiler issues, define the data types that need ot be used for
  80.    8b, 16b and 32b in <core_portme.h>.

  81.         *Imprtant* :
  82.         ee_ptr_int needs to be the data type used to hold pointers, otherwise
  83.    coremark may fail!!!
  84. */
  85. typedef signed short   ee_s16;
  86. typedef unsigned short ee_u16;
  87. typedef signed int     ee_s32;
  88. typedef double         ee_f32;
  89. typedef unsigned char  ee_u8;
  90. typedef unsigned int   ee_u32;
  91. typedef ee_u32         ee_ptr_int;
  92. typedef size_t         ee_size_t;
  93. /* align_mem :
  94.         This macro is used to align an offset to point to a 32b value. It is
  95.    used in the Matrix algorithm to initialize the input memory blocks.
  96. */
  97. #define align_mem(x) (void *)(4 + (((ee_ptr_int)(x)-1) & ~3))

  98. /* Configuration : SEED_METHOD
  99.         Defines method to get seed values that cannot be computed at compile
  100.    time.

  101.         Valid values :
  102.         SEED_ARG - from command line.
  103.         SEED_FUNC - from a system function.
  104.         SEED_VOLATILE - from volatile variables.
  105. */
  106. #ifndef SEED_METHOD
  107. #define SEED_METHOD SEED_VOLATILE
  108. #endif

  109. /* Configuration : MEM_METHOD
  110.         Defines method to get a block of memry.

  111.         Valid values :
  112.         MEM_MALLOC - for platforms that implement malloc and have malloc.h.
  113.         MEM_STATIC - to use a static memory array.
  114.         MEM_STACK - to allocate the data block on the stack (NYI).
  115. */
  116. #ifndef MEM_METHOD
  117. #define MEM_METHOD MEM_STACK
  118. #endif

  119. /* Configuration : MULTITHREAD
  120.         Define for parallel execution

  121.         Valid values :
  122.         1 - only one context (default).
  123.         N>1 - will execute N copies in parallel.

  124.         Note :
  125.         If this flag is defined to more then 1, an implementation for launching
  126.    parallel contexts must be defined.

  127.         Two sample implementations are provided. Use <USE_PTHREAD> or <USE_FORK>
  128.    to enable them.

  129.         It is valid to have a different implementation of <core_start_parallel>
  130.    and <core_end_parallel> in <core_portme.c>, to fit a particular architecture.
  131. */
  132. #ifndef MULTITHREAD
  133. #define MULTITHREAD 1
  134. #define USE_PTHREAD 0
  135. #define USE_FORK    0
  136. #define USE_SOCKET  0
  137. #endif




  138. /* Configuration : MAIN_HAS_NOARGC
  139.         Needed if platform does not support getting arguments to main.

  140.         Valid values :
  141.         0 - argc/argv to main is supported
  142.         1 - argc/argv to main is not supported

  143.         Note :
  144.         This flag only matters if MULTITHREAD has been defined to a value
  145.    greater then 1.
  146. */
  147. #ifndef MAIN_HAS_NOARGC
  148. #define MAIN_HAS_NOARGC 0
  149. #endif

  150. /* Configuration : MAIN_HAS_NORETURN
  151.         Needed if platform does not support returning a value from main.

  152.         Valid values :
  153.         0 - main returns an int, and return value will be 0.
  154.         1 - platform does not support returning a value from main
  155. */
  156. #ifndef MAIN_HAS_NORETURN
  157. #define MAIN_HAS_NORETURN 0
  158. #endif

  159. /* Variable : default_num_contexts
  160.         Not used for this simple port, must contain the value 1.
  161. */
  162. extern ee_u32 default_num_contexts;

  163. typedef struct CORE_PORTABLE_S
  164. {
  165.     ee_u8 portable_id;
  166. } core_portable;

  167. /* target specific init/fini */
  168. void portable_init(core_portable *p, int *argc, char *argv[]);
  169. void portable_fini(core_portable *p);

  170. #if !defined(PROFILE_RUN) && !defined(PERFORMANCE_RUN) \
  171.     && !defined(VALIDATION_RUN)
  172. #if (TOTAL_DATA_SIZE == 1200)
  173. #define PROFILE_RUN 1
  174. #elif (TOTAL_DATA_SIZE == 2000)
  175. #define PERFORMANCE_RUN 1
  176. #else
  177. #define VALIDATION_RUN 1
  178. #endif
  179. #endif

  180. #endif /* CORE_PORTME_H */
core main.c
  1. /*
  2. Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)

  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at

  6.     http://www.apache.org/licenses/LICENSE-2.0

  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.

  12. Original Author: Shay Gal-on
  13. */

  14. /* File: core_main.c
  15.         This file contains the framework to acquire a block of memory, seed
  16.    initial parameters, tun t he benchmark and report the results.
  17. */
  18. #include "coremark.h"

  19. /* Function: iterate
  20.         Run the benchmark for a specified number of iterations.

  21.         Operation:
  22.         For each type of benchmarked algorithm:
  23.                 a - Initialize the data block for the algorithm.
  24.                 b - Execute the algorithm N times.

  25.         Returns:
  26.         NULL.
  27. */
  28. static ee_u16 list_known_crc[]   = { (ee_u16)0xd4b0,
  29.                                    (ee_u16)0x3340,
  30.                                    (ee_u16)0x6a79,
  31.                                    (ee_u16)0xe714,
  32.                                    (ee_u16)0xe3c1 };
  33. static ee_u16 matrix_known_crc[] = { (ee_u16)0xbe52,
  34.                                      (ee_u16)0x1199,
  35.                                      (ee_u16)0x5608,
  36.                                      (ee_u16)0x1fd7,
  37.                                      (ee_u16)0x0747 };
  38. static ee_u16 state_known_crc[]  = { (ee_u16)0x5e47,
  39.                                     (ee_u16)0x39bf,
  40.                                     (ee_u16)0xe5a4,
  41.                                     (ee_u16)0x8e3a,
  42.                                     (ee_u16)0x8d84 };
  43. void *
  44. iterate(void *pres)
  45. {
  46.     ee_u32        i;
  47.     ee_u16        crc;
  48.     core_results *res        = (core_results *)pres;
  49.     ee_u32        iterations = res->iterations;
  50.     res->crc                 = 0;
  51.     res->crclist             = 0;
  52.     res->crcmatrix           = 0;
  53.     res->crcstate            = 0;

  54.     for (i = 0; i < iterations; i++)
  55.     {
  56.         crc      = core_bench_list(res, 1);
  57.         res->crc = crcu16(crc, res->crc);
  58.         crc      = core_bench_list(res, -1);
  59.         res->crc = crcu16(crc, res->crc);
  60.         if (i == 0)
  61.             res->crclist = res->crc;
  62.     }
  63.     return NULL;
  64. }

  65. #if (SEED_METHOD == SEED_ARG)
  66. ee_s32 get_seed_args(int i, int argc, char *argv[]);
  67. #define get_seed(x)    (ee_s16) get_seed_args(x, argc, argv)
  68. #define get_seed_32(x) get_seed_args(x, argc, argv)
  69. #else /* via function or volatile */
  70. ee_s32 get_seed_32(int i);
  71. #define get_seed(x) (ee_s16) get_seed_32(x)
  72. #endif

  73. #if (MEM_METHOD == MEM_STATIC)
  74. ee_u8 static_memblk[TOTAL_DATA_SIZE];
  75. #endif
  76. char *mem_name[3] = { "Static", "Heap", "Stack" };
  77. /* Function: main
  78.         Main entry routine for the benchmark.
  79.         This function is responsible for the following steps:

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

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

  91. */

  92. #if MAIN_HAS_NOARGC
  93. MAIN_RETURN_TYPE
  94. main(void)
  95. {
  96.     int   argc = 0;
  97.     char *argv[1];
  98. #else
  99. MAIN_RETURN_TYPE
  100. CoreMark_Main(int argc, char *argv[])
  101. {
  102. #endif
  103.     ee_u16       i, j = 0, num_algorithms = 0;
  104.     ee_s16       known_id = -1, total_errors = 0;
  105.     ee_u16       seedcrc = 0;
  106.     CORE_TICKS   total_time;
  107.     core_results results[MULTITHREAD];
  108. #if (MEM_METHOD == MEM_STACK)
  109.     ee_u8 stack_memblock[TOTAL_DATA_SIZE * MULTITHREAD];
  110. #endif
  111.     /* first call any initializations needed */
  112.     portable_init(&(results[0].port), &argc, argv);
  113.     /* First some checks to make sure benchmark will run ok */
  114.     if (sizeof(struct list_head_s) > 128)
  115.     {
  116.         ee_printf("list_head structure too big for comparable data!\n");
  117.         return MAIN_RETURN_VAL;
  118.     }
  119.     results[0].seed1      = get_seed(1);
  120.     results[0].seed2      = get_seed(2);
  121.     results[0].seed3      = get_seed(3);
  122.     results[0].iterations = get_seed_32(4);
  123. #if CORE_DEBUG
  124.     results[0].iterations = 1;
  125. #endif
  126.     results[0].execs = get_seed_32(5);
  127.     if (results[0].execs == 0)
  128.     { /* if not supplied, execute all algorithms */
  129.         results[0].execs = ALL_ALGORITHMS_MASK;
  130.     }
  131.     /* put in some default values based on one seed only for easy testing */
  132.     if ((results[0].seed1 == 0) && (results[0].seed2 == 0)
  133.         && (results[0].seed3 == 0))
  134.     { /* performance run */
  135.         results[0].seed1 = 0;
  136.         results[0].seed2 = 0;
  137.         results[0].seed3 = 0x66;
  138.     }
  139.     if ((results[0].seed1 == 1) && (results[0].seed2 == 0)
  140.         && (results[0].seed3 == 0))
  141.     { /* validation run */
  142.         results[0].seed1 = 0x3415;
  143.         results[0].seed2 = 0x3415;
  144.         results[0].seed3 = 0x66;
  145.     }
  146. #if (MEM_METHOD == MEM_STATIC)
  147.     results[0].memblock[0] = (void *)static_memblk;
  148.     results[0].size        = TOTAL_DATA_SIZE;
  149.     results[0].err         = 0;
  150. #if (MULTITHREAD > 1)
  151. #error "Cannot use a static data area with multiple contexts!"
  152. #endif
  153. #elif (MEM_METHOD == MEM_MALLOC)
  154.     for (i = 0; i < MULTITHREAD; i++)
  155.     {
  156.         ee_s32 malloc_override = get_seed(7);
  157.         if (malloc_override != 0)
  158.             results[i].size = malloc_override;
  159.         else
  160.             results[i].size = TOTAL_DATA_SIZE;
  161.         results[i].memblock[0] = portable_malloc(results[i].size);
  162.         results[i].seed1       = results[0].seed1;
  163.         results[i].seed2       = results[0].seed2;
  164.         results[i].seed3       = results[0].seed3;
  165.         results[i].err         = 0;
  166.         results[i].execs       = results[0].execs;
  167.     }
  168. #elif (MEM_METHOD == MEM_STACK)
  169. for (i = 0; i < MULTITHREAD; i++)
  170. {
  171.     results[i].memblock[0] = stack_memblock + i * TOTAL_DATA_SIZE;
  172.     results[i].size        = TOTAL_DATA_SIZE;
  173.     results[i].seed1       = results[0].seed1;
  174.     results[i].seed2       = results[0].seed2;
  175.     results[i].seed3       = results[0].seed3;
  176.     results[i].err         = 0;
  177.     results[i].execs       = results[0].execs;
  178. }
  179. #else
  180. #error "Please define a way to initialize a memory block."
  181. #endif
  182.     /* Data init */
  183.     /* Find out how space much we have based on number of algorithms */
  184.     for (i = 0; i < NUM_ALGORITHMS; i++)
  185.     {
  186.         if ((1 << (ee_u32)i) & results[0].execs)
  187.             num_algorithms++;
  188.     }
  189.     for (i = 0; i < MULTITHREAD; i++)
  190.         results[i].size = results[i].size / num_algorithms;
  191.     /* Assign pointers */
  192.     for (i = 0; i < NUM_ALGORITHMS; i++)
  193.     {
  194.         ee_u32 ctx;
  195.         if ((1 << (ee_u32)i) & results[0].execs)
  196.         {
  197.             for (ctx = 0; ctx < MULTITHREAD; ctx++)
  198.                 results[ctx].memblock[i + 1]
  199.                     = (char *)(results[ctx].memblock[0]) + results[0].size * j;
  200.             j++;
  201.         }
  202.     }
  203.     /* call inits */
  204.     for (i = 0; i < MULTITHREAD; i++)
  205.     {
  206.         if (results[i].execs & ID_LIST)
  207.         {
  208.             results[i].list = core_list_init(
  209.                 results[0].size, results[i].memblock[1], results[i].seed1);
  210.         }
  211.         if (results[i].execs & ID_MATRIX)
  212.         {
  213.             core_init_matrix(results[0].size,
  214.                              results[i].memblock[2],
  215.                              (ee_s32)results[i].seed1
  216.                                  | (((ee_s32)results[i].seed2) << 16),
  217.                              &(results[i].mat));
  218.         }
  219.         if (results[i].execs & ID_STATE)
  220.         {
  221.             core_init_state(
  222.                 results[0].size, results[i].seed1, results[i].memblock[3]);
  223.         }
  224.     }

  225.     /* automatically determine number of iterations if not set */
  226.     if (results[0].iterations == 0)
  227.     {
  228.         secs_ret secs_passed = 0;
  229.         ee_u32   divisor;
  230.         results[0].iterations = 1;
  231.         while (secs_passed < (secs_ret)1)
  232.         {
  233.             results[0].iterations *= 10;
  234.             start_time();
  235.             iterate(&results[0]);
  236.             stop_time();
  237.             secs_passed = time_in_secs(get_time());
  238.         }
  239.         /* now we know it executes for at least 1 sec, set actual run time at
  240.          * about 10 secs */
  241.         divisor = (ee_u32)secs_passed;
  242.         if (divisor == 0) /* some machines cast float to int as 0 since this
  243.                              conversion is not defined by ANSI, but we know at
  244.                              least one second passed */
  245.             divisor = 1;
  246.         results[0].iterations *= 1 + 10 / divisor;
  247.     }
  248.     /* perform actual benchmark */
  249.     start_time();
  250. #if (MULTITHREAD > 1)
  251.     if (default_num_contexts > MULTITHREAD)
  252.     {
  253.         default_num_contexts = MULTITHREAD;
  254.     }
  255.     for (i = 0; i < default_num_contexts; i++)
  256.     {
  257.         results[i].iterations = results[0].iterations;
  258.         results[i].execs      = results[0].execs;
  259.         core_start_parallel(&results[i]);
  260.     }
  261.     for (i = 0; i < default_num_contexts; i++)
  262.     {
  263.         core_stop_parallel(&results[i]);
  264.     }
  265. #else
  266.     iterate(&results[0]);
  267. #endif
  268.     stop_time();
  269.     total_time = get_time();
  270.     /* get a function of the input to report */
  271.     seedcrc = crc16(results[0].seed1, seedcrc);
  272.     seedcrc = crc16(results[0].seed2, seedcrc);
  273.     seedcrc = crc16(results[0].seed3, seedcrc);
  274.     seedcrc = crc16(results[0].size, seedcrc);

  275.     switch (seedcrc)
  276.     {                /* test known output for common seeds */
  277.         case 0x8a02: /* seed1=0, seed2=0, seed3=0x66, size 2000 per algorithm */
  278.             known_id = 0;
  279.             ee_printf("6k performance run parameters for coremark.\n");
  280.             break;
  281.         case 0x7b05: /*  seed1=0x3415, seed2=0x3415, seed3=0x66, size 2000 per
  282.                         algorithm */
  283.             known_id = 1;
  284.             ee_printf("6k validation run parameters for coremark.\n");
  285.             break;
  286.         case 0x4eaf: /* seed1=0x8, seed2=0x8, seed3=0x8, size 400 per algorithm
  287.                       */
  288.             known_id = 2;
  289.             ee_printf("Profile generation run parameters for coremark.\n");
  290.             break;
  291.         case 0xe9f5: /* seed1=0, seed2=0, seed3=0x66, size 666 per algorithm */
  292.             known_id = 3;
  293.             ee_printf("2K performance run parameters for coremark.\n");
  294.             break;
  295.         case 0x18f2: /*  seed1=0x3415, seed2=0x3415, seed3=0x66, size 666 per
  296.                         algorithm */
  297.             known_id = 4;
  298.             ee_printf("2K validation run parameters for coremark.\n");
  299.             break;
  300.         default:
  301.             total_errors = -1;
  302.             break;
  303.     }
  304.     if (known_id >= 0)
  305.     {
  306.         for (i = 0; i < default_num_contexts; i++)
  307.         {
  308.             results[i].err = 0;
  309.             if ((results[i].execs & ID_LIST)
  310.                 && (results[i].crclist != list_known_crc[known_id]))
  311.             {
  312.                 ee_printf("[%u]ERROR! list crc 0x%04x - should be 0x%04x\n",
  313.                           i,
  314.                           results[i].crclist,
  315.                           list_known_crc[known_id]);
  316.                 results[i].err++;
  317.             }
  318.             if ((results[i].execs & ID_MATRIX)
  319.                 && (results[i].crcmatrix != matrix_known_crc[known_id]))
  320.             {
  321.                 ee_printf("[%u]ERROR! matrix crc 0x%04x - should be 0x%04x\n",
  322.                           i,
  323.                           results[i].crcmatrix,
  324.                           matrix_known_crc[known_id]);
  325.                 results[i].err++;
  326.             }
  327.             if ((results[i].execs & ID_STATE)
  328.                 && (results[i].crcstate != state_known_crc[known_id]))
  329.             {
  330.                 ee_printf("[%u]ERROR! state crc 0x%04x - should be 0x%04x\n",
  331.                           i,
  332.                           results[i].crcstate,
  333.                           state_known_crc[known_id]);
  334.                 results[i].err++;
  335.             }
  336.             total_errors += results[i].err;
  337.         }
  338.     }
  339.     total_errors += check_data_types();
  340.     /* and report results */
  341.     ee_printf("CoreMark Size    : %lu\n", (long unsigned)results[0].size);
  342.     ee_printf("Total ticks      : %lu\n", (long unsigned)total_time);
  343. #if HAS_FLOAT
  344.     ee_printf("Total time (secs): %f\n", time_in_secs(total_time));
  345.     if (time_in_secs(total_time) > 0)
  346.         ee_printf("Iterations/Sec   : %f\n",
  347.                   default_num_contexts * results[0].iterations
  348.                       / time_in_secs(total_time));
  349. #else
  350.     ee_printf("Total time (secs): %d\n", time_in_secs(total_time));
  351.     if (time_in_secs(total_time) > 0)
  352.         ee_printf("Iterations/Sec   : %d\n",
  353.                   default_num_contexts * results[0].iterations
  354.                       / time_in_secs(total_time));
  355. #endif
  356.     if (time_in_secs(total_time) < 10)
  357.     {
  358.         ee_printf(
  359.             "ERROR! Must execute for at least 10 secs for a valid result!\n");
  360.         total_errors++;
  361.     }

  362.     ee_printf("Iterations       : %lu\n",
  363.               (long unsigned)default_num_contexts * results[0].iterations);
  364.     ee_printf("Compiler version : %s\n", COMPILER_VERSION);
  365.     ee_printf("Compiler flags   : %s\n", COMPILER_FLAGS);
  366. #if (MULTITHREAD > 1)
  367.     ee_printf("Parallel %s : %d\n", PARALLEL_METHOD, default_num_contexts);
  368. #endif
  369.     ee_printf("Memory location  : %s\n", MEM_LOCATION);
  370.     /* output for verification */
  371.     ee_printf("seedcrc          : 0x%04x\n", seedcrc);
  372.     if (results[0].execs & ID_LIST)
  373.         for (i = 0; i < default_num_contexts; i++)
  374.             ee_printf("[%d]crclist       : 0x%04x\n", i, results[i].crclist);
  375.     if (results[0].execs & ID_MATRIX)
  376.         for (i = 0; i < default_num_contexts; i++)
  377.             ee_printf("[%d]crcmatrix     : 0x%04x\n", i, results[i].crcmatrix);
  378.     if (results[0].execs & ID_STATE)
  379.         for (i = 0; i < default_num_contexts; i++)
  380.             ee_printf("[%d]crcstate      : 0x%04x\n", i, results[i].crcstate);
  381.     for (i = 0; i < default_num_contexts; i++)
  382.         ee_printf("[%d]crcfinal      : 0x%04x\n", i, results[i].crc);
  383.     if (total_errors == 0)
  384.     {
  385.         ee_printf(
  386.             "Correct operation validated. See README.md for run and reporting "
  387.             "rules.\n");
  388. #if HAS_FLOAT
  389.         if (known_id == 3)
  390.         {
  391.             ee_printf("CoreMark 1.0 : %f / %s %s",
  392.                       default_num_contexts * results[0].iterations
  393.                           / time_in_secs(total_time),
  394.                       COMPILER_VERSION,
  395.                       COMPILER_FLAGS);
  396. #if defined(MEM_LOCATION) && !defined(MEM_LOCATION_UNSPEC)
  397.             ee_printf(" / %s", MEM_LOCATION);
  398. #else
  399.             ee_printf(" / %s", mem_name[MEM_METHOD]);
  400. #endif

  401. #if (MULTITHREAD > 1)
  402.             ee_printf(" / %d:%s", default_num_contexts, PARALLEL_METHOD);
  403. #endif
  404.             ee_printf("\n");
  405.         }
  406. #endif
  407.     }
  408.     if (total_errors > 0)
  409.         ee_printf("Errors detected\n");
  410.     if (total_errors < 0)
  411.         ee_printf(
  412.             "Cannot validate operation for these seed values, please compare "
  413.             "with results on a known platform.\n");

  414. #if (MEM_METHOD == MEM_MALLOC)
  415.     for (i = 0; i < MULTITHREAD; i++)
  416.         portable_free(results[i].memblock[0]);
  417. #endif
  418.     /* And last call any target specific code for finalizing */
  419.     portable_fini(&(results[0].port));

  420.     return MAIN_RETURN_VAL;
  421. }


跑分如下:
7.png
图7 AT32F457跑飞结果
总的来说,移植coremark确实不麻烦,而且使用AT32_Work_Bench配合配置底层函数,非常简单便捷,看结果来说,AT32F457的性能还是不错的,很适合跑一些基础性的控制算法。这篇就到这里啦,感谢各位~

风之呢喃 发表于 2026-2-25 11:36 | 显示全部楼层
应该是行业标杆了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

87

主题

239

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部
0