test_bench.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "ctest.h"
  4. #include "nuclei_sdk_soc.h"
  5. // uncomment below to disable nmsis bench api
  6. //#define DISABLE_NMSIS_BENCH
  7. #include "nmsis_bench.h"
  8. BENCH_DECLARE_VAR();
  9. unsigned long test_mem[32];
  10. CTEST(bench, bench)
  11. {
  12. BENCH_INIT();
  13. BENCH_START(memset);
  14. memset(test_mem, 0xa5, sizeof(test_mem));
  15. BENCH_END(memset);
  16. BENCH_ERROR(memset);
  17. BENCH_STATUS(memset);
  18. BENCH_RESET(memsetloop);
  19. for (int i = 0; i < 10; i ++) {
  20. BENCH_START(memsetloop);
  21. memset(test_mem, 0xa5, sizeof(test_mem));
  22. BENCH_SAMPLE(memsetloop);
  23. }
  24. BENCH_STOP(memsetloop);
  25. BENCH_STAT(memsetloop);
  26. printf("usecyc:%lu, lpcnt:%lu, sumcyc:%lu\n", (unsigned long)BENCH_GET_USECYC(), (unsigned long)BENCH_GET_LPCNT(), (unsigned long)BENCH_GET_SUMCYC());
  27. }
  28. // Declare HPMCOUNTER3 and HPMCOUNTER4
  29. HPM_DECLARE_VAR(3);
  30. HPM_DECLARE_VAR(4);
  31. // Define HPMEVENT3 and HPMEVENT4
  32. // HPMEVENT3 value macro: event_sel: 0, event_idx: 8, m/s/uevent_enable: 0xf
  33. // means Select the instruction commit events, record conditional branch event for all M/S/U mode
  34. #define HPM_EVENT3 HPM_EVENT(0, 8, 0xf)
  35. // HPMEVENT4 value macro: event_sel: 0, event_idx: 4, m/s/uevent_enable: 0x1
  36. // means Select the instruction commit events, record integer store instruction (includes SC) event for only U mode
  37. #define HPM_EVENT4 HPM_EVENT(0, 4, 0x1)
  38. CTEST(bench, hpm)
  39. {
  40. // Init HPM bench, only need to do it once
  41. HPM_INIT();
  42. // start to record hpm3 and hpm4
  43. HPM_START(3, memset, HPM_EVENT3);
  44. HPM_START(4, memset, HPM_EVENT4);
  45. memset(test_mem, 0x5a, sizeof(test_mem));
  46. // finish record and print hpm value
  47. HPM_END(3, memset, HPM_EVENT3);
  48. HPM_END(4, memset, HPM_EVENT4);
  49. HPM_RESET(3, memsetloop, HPM_EVENT3);
  50. HPM_RESET(4, memsetloop, HPM_EVENT4);
  51. for (int i = 0; i < 10; i ++) {
  52. HPM_START(3, memsetloop, HPM_EVENT3);
  53. HPM_START(4, memsetloop, HPM_EVENT4);
  54. memset(test_mem, 0x5a, sizeof(test_mem));
  55. // finish record and print hpm value
  56. HPM_SAMPLE(3, memsetloop, HPM_EVENT3);
  57. HPM_SAMPLE(4, memsetloop, HPM_EVENT4);
  58. }
  59. HPM_STOP(3, memsetloop, HPM_EVENT3);
  60. HPM_STOP(4, memsetloop, HPM_EVENT4);
  61. HPM_STAT(3, memsetloop, HPM_EVENT3);
  62. HPM_STAT(4, memsetloop, HPM_EVENT4);
  63. printf("hpm3, usecyc:%lu, lpcnt:%lu, sumcyc:%lu\n", (unsigned long)HPM_GET_USECYC(3), (unsigned long)HPM_GET_LPCNT(3), (unsigned long)HPM_GET_SUMCYC(3));
  64. printf("hpm4, usecyc:%lu, lpcnt:%lu, sumcyc:%lu\n", (unsigned long)HPM_GET_USECYC(4), (unsigned long)HPM_GET_LPCNT(4), (unsigned long)HPM_GET_SUMCYC(4));
  65. }