core_portme.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 "coremark.h"
  15. #include "core_portme.h"
  16. #if VALIDATION_RUN
  17. volatile ee_s32 seed1_volatile = 0x3415;
  18. volatile ee_s32 seed2_volatile = 0x3415;
  19. volatile ee_s32 seed3_volatile = 0x66;
  20. #endif
  21. #if PERFORMANCE_RUN
  22. volatile ee_s32 seed1_volatile = 0x0;
  23. volatile ee_s32 seed2_volatile = 0x0;
  24. volatile ee_s32 seed3_volatile = 0x66;
  25. #endif
  26. #if PROFILE_RUN
  27. volatile ee_s32 seed1_volatile = 0x8;
  28. volatile ee_s32 seed2_volatile = 0x8;
  29. volatile ee_s32 seed3_volatile = 0x8;
  30. #endif
  31. volatile ee_s32 seed4_volatile = ITERATIONS;
  32. volatile ee_s32 seed5_volatile = 0;
  33. /* Porting : Timing functions
  34. How to capture time and convert to seconds must be ported to whatever is
  35. supported by the platform. e.g. Read value from on board RTC, read value from
  36. cpu clock cycles performance counter etc. Sample implementation for standard
  37. time.h and windows.h definitions included.
  38. */
  39. CORETIMETYPE
  40. barebones_clock()
  41. {
  42. extern long luat_mcu_ticks(void);
  43. return (CORETIMETYPE)luat_mcu_ticks();
  44. }
  45. /* Define : TIMER_RES_DIVIDER
  46. Divider to trade off timer resolution and total time that can be
  47. measured.
  48. Use lower values to increase resolution, but make sure that overflow
  49. does not occur. If there are issues with the return value overflowing,
  50. increase this value.
  51. */
  52. #define GETMYTIME(_t) (*_t = barebones_clock())
  53. #define MYTIMEDIFF(fin, ini) ((fin) - (ini))
  54. #define TIMER_RES_DIVIDER 1
  55. #define SAMPLE_TIME_IMPLEMENTATION 1
  56. #define EE_TICKS_PER_SEC (CLOCKS_PER_SEC / TIMER_RES_DIVIDER)
  57. /** Define Host specific (POSIX), or target specific global time variables. */
  58. static CORETIMETYPE start_time_val, stop_time_val;
  59. /* Function : start_time
  60. This function will be called right before starting the timed portion of
  61. the benchmark.
  62. Implementation may be capturing a system timer (as implemented in the
  63. example code) or zeroing some system parameters - e.g. setting the cpu clocks
  64. cycles to 0.
  65. */
  66. void
  67. start_time(void)
  68. {
  69. GETMYTIME(&start_time_val);
  70. }
  71. /* Function : stop_time
  72. This function will be called right after ending the timed portion of the
  73. benchmark.
  74. Implementation may be capturing a system timer (as implemented in the
  75. example code) or other system parameters - e.g. reading the current value of
  76. cpu cycles counter.
  77. */
  78. void
  79. stop_time(void)
  80. {
  81. GETMYTIME(&stop_time_val);
  82. }
  83. /* Function : get_time
  84. Return an abstract "ticks" number that signifies time on the system.
  85. Actual value returned may be cpu cycles, milliseconds or any other
  86. value, as long as it can be converted to seconds by <time_in_secs>. This
  87. methodology is taken to accommodate any hardware or simulated platform. The
  88. sample implementation returns millisecs by default, and the resolution is
  89. controlled by <TIMER_RES_DIVIDER>
  90. */
  91. CORE_TICKS
  92. get_time(void)
  93. {
  94. CORE_TICKS elapsed
  95. = (CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
  96. return elapsed;
  97. }
  98. /* Function : time_in_secs
  99. Convert the value returned by get_time to seconds.
  100. The <secs_ret> type is used to accommodate systems with no support for
  101. floating point. Default implementation implemented by the EE_TICKS_PER_SEC
  102. macro above.
  103. */
  104. secs_ret
  105. time_in_secs(CORE_TICKS ticks)
  106. {
  107. secs_ret retval = ((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
  108. return retval;
  109. }
  110. ee_u32 default_num_contexts = 1;
  111. /* Function : portable_init
  112. Target specific initialization code
  113. Test for some common mistakes.
  114. */
  115. void
  116. portable_init(core_portable *p, int *argc, char *argv[])
  117. {
  118. if (sizeof(ee_ptr_int) != sizeof(ee_u8 *))
  119. {
  120. ee_printf(
  121. "ERROR! Please define ee_ptr_int to a type that holds a "
  122. "pointer!\n");
  123. }
  124. if (sizeof(ee_u32) != 4)
  125. {
  126. ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
  127. }
  128. p->portable_id = 1;
  129. }
  130. /* Function : portable_fini
  131. Target specific final code
  132. */
  133. void
  134. portable_fini(core_portable *p)
  135. {
  136. p->portable_id = 0;
  137. }