[MM32软件] Dhrystone移植说明

[复制链接]
 楼主| MindMotion 发表于 2024-8-9 16:24 | 显示全部楼层 |阅读模式
本帖最后由 MindMotion 于 2024-8-9 16:25 编辑

1. Dhrystone简介

Dhrystone是由Reinhold P. Weicker在1984年提出来的一个基准测试程序,其主要目的是测试处理器的整数运算和逻辑运算的性能。Dhrystone首先用Ada语言发布,后来Rick Richardson为Unix开发了用C语言编写的Version 1.1,这个版本也成功的推动了Dhrystone的广泛应用。

Dhrystone标准的测试方法很简单,就是单位时间内跑了多少次Dhrystone程序,其指标单位为DMIPS/MHz。MIPS是Million Instructions Per Second的缩写,每秒处理的百万级的机器语言指令数。DMIPS中的D是Dhrystone的缩写,它表示了在Dhrystone标准的测试方法下的MIPS。

DMIPS表示的是一个相对值,由于历史原因将VAX-11/780机器上每秒运行1757次 Dhrystone程序定义为1 DMIPS,因此在其他平台测试到的每秒Dhrystone次数应除以1757,才是DMIPS数值。

DMIPS/MHz:表示CPU在每1MHz的运行速度下可以执行多少个DMIPS,由于DMIPS与CPU频率具有正相关性,所以这一分数更容易比较不同的CPU在不同的时钟频率下运行Dhrystone的结果。



作为一项基准程序Dhrystone具有以下缺陷:

1) 代码与具有代表性的实际程序代码并不相同。
2) 易受编译器影响。
3) 代码量过小,在现代CPU中,它能够被放进指令缓存中,所以它并不能严格的测量取指性能。



2. 源码获取

Dhrystone程序的最新版本是2.1,其实际上于1988年便已停更。Dhrystone并没有官网,所以想下载其源程序可能会有很多来源,有各种语言版本的实现,以及各种平台下的移植程序。

Roy Longbottom,是一个来自英国政府计算机采购部门Central Computer and Telecommunications Agency (CCTA)的职员,他制作了一个PC性能测试结果网站,搜集了很多性能测试程序以及结果,其中便有Dhrystone,我们可以从他的网站下载Dhrystone源码(C语言版)。

下载地址:http://www.roylongbottom.org.uk/classic_benchmarks.tar.gz

源代码在\classic_benchmarks\source_code\dhrystone2\ 目录下,文件如下:

001.png



文件介绍:

dhry.h —— 关于兼容性的原型定义
dhry_1.c —— 主程序入口
dhry_2.c —— 算法子程序



Dhrystone其源码本是用作在PC上运行的,移植到ARM Cortex-M平台下裸系统运行,一般需要修改dhry.h和dhry_1.c文件、删除I/O的相关代码、实现计时函数和打印函数。

3. 移植

Dhrystone作为一项基准测试程序,C编译器的编译效率对测试结果也有很大影响,实测在IAR代码优化下的跑分较高。本文以MM32F5270 MCU为例,开发板型号为Mini-F5277-OB|MB-100,使用IAR 9.30.1 IDE,介绍Dhrystone程序的移植和相关配置。

3.1   创建工程

工程可以参考灵动微电子官网的MM32F5270 LibSamples(https://www.mindmotion.com.cn/products/mm32mcu/mm32f/mm32f_performance/mm32f5270/),也可以直接选择一个简单的工程稍作修改。

3.2   加入Dhrystone

在工程中新创建一个文件夹,命名为“Dhrystone”。

002.png

Dhrystone源代码在\classic_benchmarks\source_code\dhrystone2\目录,将dhry.h、dhry_1.c、dhry_2.c复制到该文件夹。

003.png

在项目栏添加DHRYSTONE组,并加入dhry_1.c、dhry_2.c文件。

在Option->C/C++ Complier菜单加入dhry.h文件包含路径。

工程结构如下:

004.png

3.3   文件修改

参考MM32F5270 LibSamples,其工程具有统一的代码结构,以及做好了硬件的初始化,为了便于移植,将dhry_1.c自带的main函数名称改为dhrystone,在硬件初始化之后调用。

005.png

Dhrystone本是用作在PC上运行的,需要删除计时部分、文件I/O部分,以适合在嵌入式平台运行。

计时部分:删除dhry_1.c文件里的#include语句、删除dhry.h文件里跟TIME宏相关的代码;

文件I/O部分:删除dhry_1.c文件里的#include语句、删除涉及Dhry.txt的代码。

修改后的代码如下:

dhry1.c文件:

  1. /*
  2. *************************************************************************
  3. *
  4. *                   "DHRYSTONE" Benchmark Program
  5. *                   -----------------------------
  6. *
  7. *  Version:    C, Version 2.1
  8. *
  9. *  File:       dhry_1.c (part 2 of 3)
  10. *
  11. *  Date:       May 25, 1988
  12. *
  13. *  Author:     Reinhold P. Weicker
  14. *
  15. *************************************************************************
  16. *
  17. *     #define options not used
  18. */


  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include "dhry.h"

  22. /* Global Variables: */

  23. Rec_Pointer     Ptr_Glob, Next_Ptr_Glob;
  24. int             Int_Glob;
  25. Boolean         Bool_Glob;
  26. char            Ch_1_Glob, Ch_2_Glob;
  27. int             Arr_1_Glob [50];
  28. int             Arr_2_Glob [50] [50];


  29. Enumeration Func_1 (Capital_Letter Ch_1_Par_Val, Capital_Letter Ch_2_Par_Val);
  30.     /*
  31.     forward declaration necessary since Enumeration may not simply be int
  32.     */

  33. #ifndef REG
  34. Boolean Reg = false;
  35. #define REG
  36.     /* REG becomes defined as empty */
  37.     /* i.e. no register variables   */
  38. #else
  39. Boolean Reg = true;
  40. #endif


  41. void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
  42. void Proc_2 (One_Fifty *Int_Par_Ref);
  43. void Proc_3 (Rec_Pointer *Ptr_Ref_Par);
  44. void Proc_4 ();
  45. void Proc_5 ();
  46. void Proc_6 (Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par);
  47. void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val, One_Fifty *Int_Par_Ref);
  48. void Proc_8 (Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref, int Int_1_Par_Val, int Int_2_Par_Val);                           
  49. Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref);


  50. /* variables for time measurement: */
  51. #define Too_Small_Time 2 /* Measurements should last at least 2 seconds */

  52. double User_Time;
  53. double Microseconds, Dhrystones_Per_Second, Vax_Mips;

  54. /* end of variables for time measurement */

  55. void dhrystone(void)
  56.     /*****/
  57.     /* main program, corresponds to procedures        */
  58.     /* Main and Proc_0 in the Ada version             */
  59. {

  60.         One_Fifty   Int_1_Loc;
  61.   REG   One_Fifty   Int_2_Loc;
  62.         One_Fifty   Int_3_Loc;
  63.   REG   char        Ch_Index;
  64.         Enumeration Enum_Loc;
  65.         Str_30      Str_1_Loc;
  66.         Str_30      Str_2_Loc;
  67.   REG   int         Run_Index;
  68.   REG   int         Number_Of_Runs;

  69.   /* Initializations */
  70.   Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
  71.   Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));

  72.   Ptr_Glob->Ptr_Comp                    = Next_Ptr_Glob;
  73.   Ptr_Glob->Discr                       = Ident_1;
  74.   Ptr_Glob->variant.var_1.Enum_Comp     = Ident_3;
  75.   Ptr_Glob->variant.var_1.Int_Comp      = 40;
  76.   strcpy (Ptr_Glob->variant.var_1.Str_Comp, "DHRYSTONE PROGRAM, SOME STRING");      
  77.   strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");

  78.   Arr_2_Glob [8][7] = 10;
  79.   /* Was missing in published program. Without this statement,   */
  80.   /* Arr_2_Glob [8][7] would have an undefined value.            */
  81.   /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
  82.   /* overflow may occur for this array element.                  */

  83.   printf ("Dhrystone Benchmark, Version 2.1 (Language: C or C++)\n");

  84.   getDetails();

  85.   if (Reg)
  86.   {
  87.     printf ("Program compiled with 'register' attribute\n");
  88.   }
  89.   else
  90.   {
  91.     printf ("Program compiled without 'register' attribute\n");
  92.   }

  93.   Number_Of_Runs = NUMBER_Of_RUNS;
  94.   printf ("Execution starts, %d runs through Dhrystone......\n", Number_Of_Runs);
  95.   /***************/
  96.   /* Start timer */
  97.   /***************/
  98.   start_time();

  99.   for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
  100.   {
  101.     Proc_5();
  102.     Proc_4();
  103.     /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
  104.     Int_1_Loc = 2;
  105.     Int_2_Loc = 3;
  106.     strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  107.     Enum_Loc = Ident_2;
  108.     Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
  109.     /* Bool_Glob == 1 */
  110.     while (Int_1_Loc < Int_2_Loc)  /* loop body executed once */
  111.     {
  112.       Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
  113.         /* Int_3_Loc == 7 */
  114.       Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
  115.         /* Int_3_Loc == 7 */
  116.       Int_1_Loc += 1;
  117.     }   /* while */
  118.       /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  119.     Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
  120.      /* Int_Glob == 5 */
  121.     Proc_1 (Ptr_Glob);
  122.     for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
  123.      /* loop body executed twice */
  124.     {
  125.       if (Enum_Loc == Func_1 (Ch_Index, 'C'))
  126.       /* then, not executed */
  127.       {
  128.          Proc_6 (Ident_1, &Enum_Loc);
  129.          strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
  130.          Int_2_Loc = Run_Index;
  131.          Int_Glob = Run_Index;
  132.       }
  133.     }
  134.     /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
  135.     Int_2_Loc = Int_2_Loc * Int_1_Loc;
  136.     Int_1_Loc = Int_2_Loc / Int_3_Loc;
  137.     Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
  138.     /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
  139.     Proc_2 (&Int_1_Loc);
  140.     /* Int_1_Loc == 5 */

  141.   } /* loop "for Run_Index" */

  142.   /**************/
  143.   /* Stop timer */
  144.   /**************/
  145.   User_Time = end_time();

  146.   printf ("Execution ends!\n");      
  147.   printf ("%12.0f runs %6.2f seconds \n",(double)Number_Of_Runs, (double)User_Time);
  148.   printf ("\n");

  149.   printf ("Final values:\n");
  150.   printf ("Int_Glob:      ");
  151.   if (Int_Glob == 5)  printf ("O.K.  ");
  152.   else                printf ("WRONG ");
  153.   printf ("%d\n", Int_Glob);

  154.   printf ("Bool_Glob:     ");
  155.   if (Bool_Glob == 1) printf ("O.K.  ");
  156.   else                printf ("WRONG ");
  157.   printf ("%d\n", Bool_Glob);

  158.   printf ("Ch_1_Glob:     ");
  159.   if (Ch_1_Glob == 'A')  printf ("O.K.  ");               
  160.   else                   printf ("WRONG ");
  161.   printf ("%c\n", Ch_1_Glob);

  162.   printf ("Ch_2_Glob:     ");
  163.   if (Ch_2_Glob == 'B')  printf ("O.K.  ");
  164.   else                   printf ("WRONG ");
  165.   printf ("%c\n",  Ch_2_Glob);

  166.   printf ("Arr_1_Glob[8]: ");
  167.   if (Arr_1_Glob[8] == 7)  printf ("O.K.  ");
  168.   else                     printf ("WRONG ");
  169.   printf ("%d\n", Arr_1_Glob[8]);

  170.   printf ("Arr_2_Glob8/7: ");
  171.   if (Arr_2_Glob[8][7] == Number_Of_Runs + 10)
  172.                          printf ("O.K.  ");
  173.   else                   printf ("WRONG ");
  174.   printf ("%10d\n", Arr_2_Glob[8][7]);

  175.   printf ("Ptr_Glob->            ");
  176.   printf ("  Ptr_Comp:       *    %d\n", (int) Ptr_Glob->Ptr_Comp);

  177.   printf ("  Discr:       ");
  178.   if (Ptr_Glob->Discr == 0)  printf ("O.K.  ");
  179.   else                       printf ("WRONG ");
  180.   printf ("%d\n", Ptr_Glob->Discr);

  181.   printf ("Enum_Comp:     ");
  182.   if (Ptr_Glob->variant.var_1.Enum_Comp == 2)
  183.                        printf ("O.K.  ");
  184.   else                printf ("WRONG ");
  185.   printf ("%d\n", Ptr_Glob->variant.var_1.Enum_Comp);

  186.   printf ("  Int_Comp:    ");
  187.   if (Ptr_Glob->variant.var_1.Int_Comp == 17)  printf ("O.K.  ");
  188.   else                                         printf ("WRONG ");
  189.   printf ("%d\n", Ptr_Glob->variant.var_1.Int_Comp);

  190.   printf ("Str_Comp:      ");
  191.   if (strcmp(Ptr_Glob->variant.var_1.Str_Comp,
  192.                        "DHRYSTONE PROGRAM, SOME STRING") == 0)
  193.                        printf ("O.K.  ");
  194.   else                printf ("WRONG ");   
  195.   printf ("%s\n", Ptr_Glob->variant.var_1.Str_Comp);

  196.   printf ("Next_Ptr_Glob->       ");
  197.   printf ("  Ptr_Comp:       *    %d", (int) Next_Ptr_Glob->Ptr_Comp);
  198.   printf (" same as above\n");

  199.   printf ("  Discr:       ");
  200.   if (Next_Ptr_Glob->Discr == 0)
  201.                        printf ("O.K.  ");
  202.   else                printf ("WRONG ");
  203.   printf ("%d\n", Next_Ptr_Glob->Discr);

  204.   printf ("Enum_Comp:     ");
  205.   if (Next_Ptr_Glob->variant.var_1.Enum_Comp == 1)
  206.                        printf ("O.K.  ");
  207.   else                printf ("WRONG ");
  208.   printf ("%d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);

  209.   printf ("  Int_Comp:    ");
  210.   if (Next_Ptr_Glob->variant.var_1.Int_Comp == 18)
  211.                        printf ("O.K.  ");
  212.   else                printf ("WRONG ");
  213.   printf ("%d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);

  214.   printf ("Str_Comp:      ");
  215.   if (strcmp(Next_Ptr_Glob->variant.var_1.Str_Comp,
  216.                        "DHRYSTONE PROGRAM, SOME STRING") == 0)
  217.                        printf ("O.K.  ");
  218.   else                printf ("WRONG ");   
  219.   printf ("%s\n", Next_Ptr_Glob->variant.var_1.Str_Comp);

  220.   printf ("Int_1_Loc:     ");
  221.   if (Int_1_Loc == 5)
  222.                        printf ("O.K.  ");
  223.   else                printf ("WRONG ");
  224.   printf ("%d\n", Int_1_Loc);

  225.   printf ("Int_2_Loc:     ");
  226.   if (Int_2_Loc == 13)
  227.                        printf ("O.K.  ");
  228.   else                printf ("WRONG ");
  229.   printf ("%d\n", Int_2_Loc);

  230.   printf ("Int_3_Loc:     ");
  231.   if (Int_3_Loc == 7)
  232.                        printf ("O.K.  ");
  233.   else                printf ("WRONG ");
  234.   printf ("%d\n", Int_3_Loc);

  235.   printf ("Enum_Loc:      ");
  236.   if (Enum_Loc == 1)
  237.                        printf ("O.K.  ");
  238.   else                printf ("WRONG ");
  239.   printf ("%d\n", Enum_Loc);


  240.   printf ("Str_1_Loc:                             ");
  241.   if (strcmp(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING") == 0)
  242.                        printf ("O.K.  ");

  243.   else                printf ("WRONG ");   
  244.   printf ("%s\n", Str_1_Loc);

  245.   printf ("Str_2_Loc:                             ");
  246.   if (strcmp(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING") == 0)
  247.                        printf ("O.K.  ");
  248.   else                printf ("WRONG ");   
  249.   printf ("%s\n", Str_2_Loc);  
  250.   printf ("\n");

  251.   if (User_Time < Too_Small_Time)
  252.   {
  253.     printf ("Measured time too small to obtain meaningful results\n");
  254.     printf ("Please increase number of runs\n");
  255.     printf ("\n");
  256.   }
  257.   else
  258.   {
  259.     Microseconds = User_Time * Mic_secs_Per_Second / (double) Number_Of_Runs;
  260.     Dhrystones_Per_Second = (double) Number_Of_Runs / User_Time;
  261.     Vax_Mips = Dhrystones_Per_Second / 1757.0;

  262.     printf ("Microseconds for one run through Dhrystone: ");
  263.     printf ("%12.2lf \n", Microseconds);
  264.     printf ("Dhrystones per Second:                      ");
  265.     printf ("%10.0lf \n", Dhrystones_Per_Second);
  266.     printf ("VAX  MIPS rating =                          ");
  267.     printf ("%12.2lf \n",Vax_Mips);
  268.     printf ("\n");
  269.     printf ("\n");
  270.     printf ("\n");
  271.   }
  272. }


  273. void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
  274. /******************/
  275.     /* executed once */
  276. {
  277.    REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;  
  278.    /* == Ptr_Glob_Next */
  279.    /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp,    */
  280.    /* corresponds to "rename" in Ada, "with" in Pascal           */

  281.    structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
  282.    Ptr_Val_Par->variant.var_1.Int_Comp = 5;
  283.    Next_Record->variant.var_1.Int_Comp = Ptr_Val_Par->variant.var_1.Int_Comp;
  284.    Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
  285.    Proc_3 (&Next_Record->Ptr_Comp);
  286.      /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp = Ptr_Glob->Ptr_Comp */
  287.    if (Next_Record->Discr == Ident_1)
  288.      /* then, executed */
  289.    {
  290.      Next_Record->variant.var_1.Int_Comp = 6;
  291.      Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp, &Next_Record->variant.var_1.Enum_Comp);
  292.      Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
  293.      Proc_7 (Next_Record->variant.var_1.Int_Comp, 10, &Next_Record->variant.var_1.Int_Comp);
  294.    }
  295.    else /* not executed */
  296.      structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
  297. } /* Proc_1 */


  298. void Proc_2 (One_Fifty *Int_Par_Ref)
  299. /******************/
  300.     /* executed once */
  301.     /* *Int_Par_Ref == 1, becomes 4 */
  302. {
  303.   One_Fifty  Int_Loc;
  304.   Enumeration   Enum_Loc;

  305.   Int_Loc = *Int_Par_Ref + 10;
  306.   do /* executed once */
  307.     if (Ch_1_Glob == 'A')
  308.       /* then, executed */
  309.     {
  310.       Int_Loc -= 1;
  311.       *Int_Par_Ref = Int_Loc - Int_Glob;
  312.       Enum_Loc = Ident_1;
  313.     } /* if */
  314.   while (Enum_Loc != Ident_1); /* true */
  315. } /* Proc_2 */


  316. void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
  317. /******************/
  318.     /* executed once */
  319.     /* Ptr_Ref_Par becomes Ptr_Glob */
  320. {
  321.   if (Ptr_Glob != Null)
  322.     /* then, executed */
  323.     *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
  324.     Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
  325. } /* Proc_3 */


  326. void Proc_4 (void) /* without parameters */
  327. /*******/
  328.     /* executed once */
  329. {
  330.   Boolean Bool_Loc;

  331.   Bool_Loc = Ch_1_Glob == 'A';
  332.   Bool_Glob = Bool_Loc | Bool_Glob;
  333.   Ch_2_Glob = 'B';
  334. } /* Proc_4 */


  335. void Proc_5 (void) /* without parameters */
  336. /*******/
  337.     /* executed once */
  338. {
  339.   Ch_1_Glob = 'A';
  340.   Bool_Glob = false;
  341. } /* Proc_5 */


  342. /* Procedure for the assignment of structures,          */
  343. /* if the C compiler doesn't support this feature       */
  344. #ifdef  NOSTRUCTASSIGN
  345. memcpy (d, s, l)
  346. register char   *d;
  347. register char   *s;
  348. register int    l;
  349. {
  350.     while (l--)
  351.         *d++ = *s++;
  352. }
  353. #endif

dhry.h文件:

  1. /* Compiler and system dependent definitions: */

  2. #define Mic_secs_Per_Second     1000000.0
  3.                 /* Berkeley UNIX C returns process times in seconds/HZ */

  4. #ifdef  NOSTRUCTASSIGN
  5. #define structassign(d, s)      memcpy(&(d), &(s), sizeof(d))
  6. #else
  7. #define structassign(d, s)      d = s
  8. #endif

  9. #ifdef  NOENUM
  10. #define Ident_1 0
  11. #define Ident_2 1
  12. #define Ident_3 2
  13. #define Ident_4 3
  14. #define Ident_5 4
  15.   typedef int   Enumeration;
  16. #else
  17.   typedef       enum    {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
  18.                 Enumeration;
  19. #endif
  20.         /* for boolean and enumeration types in Ada, Pascal */

  21. /* General definitions: */

  22. #include <stdio.h>
  23. #include <string.h>
  24.                 /* for strcpy, strcmp */

  25. #define Null 0
  26.                 /* Value of a Null pointer */

  27. #define true  1
  28. #define false 0

  29. typedef int     One_Thirty;
  30. typedef int     One_Fifty;
  31. typedef char    Capital_Letter;
  32. typedef int     Boolean;
  33. typedef char    Str_30 [31];
  34. typedef int     Arr_1_Dim [50];
  35. typedef int     Arr_2_Dim [50] [50];

  36. typedef struct record
  37.     {
  38.     struct record *Ptr_Comp;
  39.     Enumeration    Discr;
  40.     union {
  41.           struct {
  42.                   Enumeration Enum_Comp;
  43.                   int         Int_Comp;
  44.                   char        Str_Comp [31];
  45.                   } var_1;
  46.           struct {
  47.                   Enumeration E_Comp_2;
  48.                   char        Str_2_Comp [31];
  49.                   } var_2;
  50.           struct {
  51.                   char        Ch_1_Comp;
  52.                   char        Ch_2_Comp;
  53.                   } var_3;
  54.           } variant;
  55.       } Rec_Type, *Rec_Pointer;

打印函数:

工程的platform.c文件已经做好了UART初始化以及重定向相关代码,无需额外添加,源码中需要打印的地方直接用printf即可。

计时函数:

Dhrystone测试需要计算跑dhrystone程序的时间,以推算出单位时间内运行dhrystone程序的次数。这里选择使用TIM1来记录时间,定义start_time函数和end_time函数获取运行程序的时间,这两个函数已经在dhrystone主函数中调用。

006.png

为了便于计算,TIM1配置为向上计数模式。需要注意系统时钟频率,配置范围,防止溢出。

007.png

3.4   编译器优化

在Option->C/C++ Compiler界面Optimizaition选项设置优化等级如下:

008.png

4. 测试

Dhrystone测试需要配置的参数:

NUMBER_Of_RUNS,这个值是自己定义的,但要保证Dhrystone程序运行时间大于2s。

定时器的PSC和ARR,一般配置时钟频率为1KHZ,即1ms计数1次,预装载值可配置为最大值。

009.png

连接串口,运行程序,观察上位机调试助手打印情况:

110.png

其中VAX MIPS rating就是所谓的DMPIS,上面截图数据是在8MHZ跑的,一般DMIPS/MHZ信息还需要除以频率(单位MHZ),即12.10/8 = 1.5125。

tpgf 发表于 2024-8-10 09:33 | 显示全部楼层
Dhrystone移植是一个涉及修改标准Dhrystone基准测试程序,使其能够在特定微控制器单元(MCU)上运行的过程
木木guainv 发表于 2024-8-10 23:23 | 显示全部楼层
移植过程通常包括获取源码、修改源码以适应目标平台、配置相关参数,以及确保测试程序可以在新平台上正确执行
磨砂 发表于 2024-8-11 18:44 | 显示全部楼层
Dhrystone程序的最新版本是2.1,实际上在1988年便已停更
晓伍 发表于 2024-8-15 09:12 | 显示全部楼层
针对嵌入式系统,需要删除Dhrystone源码中的I/O相关代码,并重新实现计时函数和打印函数
八层楼 发表于 2024-8-15 19:31 | 显示全部楼层
由于Dhrystone测试结果受编译器效率影响较大,可能需要针对使用的编译器进行特定的优化设置,以获得准确的性能评估
观海 发表于 2024-8-16 20:57 | 显示全部楼层
针对嵌入式系统,需要删除Dhrystone源码中的I/O相关代码,并重新实现计时函数和打印函数
1115745 发表于 2024-9-10 17:04 | 显示全部楼层
请问在armv8架构下的a53处理器中一直dhrystone程序时,在malloc时出现异常,指令是B.CC处,感觉是内存对齐相关的问题,这个应该怎么解决
您需要登录后才可以回帖 登录 | 注册

本版积分规则

认证:上海灵动微电子股份有限公司
简介:上海灵动微电子股份有限公司成立于 2011 年,是中国本土通用 32 位 MCU 产品及解决方案供应商。 灵动股份的 MCU 产品以 MM32 为标识,基于 Arm Cortex-M 系列内核,自主研发软硬件和生态系统。目前已量产近 300 多款型号,累计交付超 4 亿颗,在本土通用 32 位 MCU 公司中位居前列。

93

主题

111

帖子

10

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