1 |
2 |
zero_gravi |
/*
|
2 |
|
|
Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)
|
3 |
|
|
|
4 |
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
|
|
you may not use this file except in compliance with the License.
|
6 |
|
|
You may obtain a copy of the License at
|
7 |
|
|
|
8 |
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
9 |
|
|
|
10 |
|
|
Unless required by applicable law or agreed to in writing, software
|
11 |
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
|
|
See the License for the specific language governing permissions and
|
14 |
|
|
limitations under the License.
|
15 |
|
|
|
16 |
|
|
Original Author: Shay Gal-on
|
17 |
|
|
|
18 |
|
|
Modified for NEORV32 by Stephan Nolting
|
19 |
|
|
*/
|
20 |
|
|
|
21 |
|
|
#include <stdio.h>
|
22 |
|
|
#include <stdlib.h>
|
23 |
|
|
#include "coremark.h"
|
24 |
|
|
#include "core_portme.h"
|
25 |
|
|
|
26 |
|
|
#if VALIDATION_RUN
|
27 |
|
|
volatile ee_s32 seed1_volatile=0x3415;
|
28 |
|
|
volatile ee_s32 seed2_volatile=0x3415;
|
29 |
|
|
volatile ee_s32 seed3_volatile=0x66;
|
30 |
|
|
#endif
|
31 |
|
|
#if PERFORMANCE_RUN
|
32 |
|
|
volatile ee_s32 seed1_volatile=0x0;
|
33 |
|
|
volatile ee_s32 seed2_volatile=0x0;
|
34 |
|
|
volatile ee_s32 seed3_volatile=0x66;
|
35 |
|
|
#endif
|
36 |
|
|
#if PROFILE_RUN
|
37 |
|
|
volatile ee_s32 seed1_volatile=0x8;
|
38 |
|
|
volatile ee_s32 seed2_volatile=0x8;
|
39 |
|
|
volatile ee_s32 seed3_volatile=0x8;
|
40 |
|
|
#endif
|
41 |
|
|
volatile ee_s32 seed4_volatile=ITERATIONS;
|
42 |
|
|
volatile ee_s32 seed5_volatile=0;
|
43 |
|
|
/* Porting : Timing functions
|
44 |
|
|
How to capture time and convert to seconds must be ported to whatever is supported by the platform.
|
45 |
|
|
e.g. Read value from on board RTC, read value from cpu clock cycles performance counter etc.
|
46 |
|
|
Sample implementation for standard time.h and windows.h definitions included.
|
47 |
|
|
*/
|
48 |
|
|
/* Define : TIMER_RES_DIVIDER
|
49 |
|
|
Divider to trade off timer resolution and total time that can be measured.
|
50 |
|
|
|
51 |
|
|
Use lower values to increase resolution, but make sure that overflow does not occur.
|
52 |
|
|
If there are issues with the return value overflowing, increase this value.
|
53 |
|
|
*/
|
54 |
|
|
#define NSECS_PER_SEC 20000000
|
55 |
|
|
#define CORETIMETYPE clock_t
|
56 |
|
|
#define GETMYTIME(_t) (*_t=clock())
|
57 |
|
|
#define MYTIMEDIFF(fin,ini) ((fin)-(ini))
|
58 |
|
|
#define TIMER_RES_DIVIDER 1
|
59 |
|
|
#define SAMPLE_TIME_IMPLEMENTATION 1
|
60 |
|
|
#define EE_TICKS_PER_SEC (NSECS_PER_SEC / TIMER_RES_DIVIDER)
|
61 |
|
|
|
62 |
|
|
CORE_TICKS elapsed_cycles; // NEORV32 specific
|
63 |
|
|
|
64 |
|
|
/** Define Host specific (POSIX), or target specific global time variables. */
|
65 |
|
|
//static CORETIMETYPE start_time_val, stop_time_val;
|
66 |
|
|
|
67 |
|
|
/* Function : start_time
|
68 |
|
|
This function will be called right before starting the timed portion of the benchmark.
|
69 |
|
|
|
70 |
|
|
Implementation may be capturing a system timer (as implemented in the example code)
|
71 |
|
|
or zeroing some system parameters - e.g. setting the cpu clocks cycles to 0.
|
72 |
|
|
*/
|
73 |
|
|
void start_time(void) {
|
74 |
12 |
zero_gravi |
elapsed_cycles = 0; // this is time zero
|
75 |
|
|
neorv32_cpu_set_mcycle(0);
|
76 |
|
|
neorv32_cpu_set_minstret(0);
|
77 |
2 |
zero_gravi |
//GETMYTIME(&start_time_val );
|
78 |
|
|
}
|
79 |
|
|
/* Function : stop_time
|
80 |
|
|
This function will be called right after ending the timed portion of the benchmark.
|
81 |
|
|
|
82 |
|
|
Implementation may be capturing a system timer (as implemented in the example code)
|
83 |
|
|
or other system parameters - e.g. reading the current value of cpu cycles counter.
|
84 |
|
|
*/
|
85 |
|
|
void stop_time(void) {
|
86 |
|
|
//GETMYTIME(&stop_time_val );
|
87 |
|
|
}
|
88 |
|
|
/* Function : get_time
|
89 |
|
|
Return an abstract "ticks" number that signifies time on the system.
|
90 |
|
|
|
91 |
|
|
Actual value returned may be cpu cycles, milliseconds or any other value,
|
92 |
|
|
as long as it can be converted to seconds by <time_in_secs>.
|
93 |
|
|
This methodology is taken to accomodate any hardware or simulated platform.
|
94 |
|
|
The sample implementation returns millisecs by default,
|
95 |
|
|
and the resolution is controlled by <TIMER_RES_DIVIDER>
|
96 |
|
|
*/
|
97 |
|
|
CORE_TICKS get_time(void) {
|
98 |
12 |
zero_gravi |
CORE_TICKS elapsed = ((CORE_TICKS)neorv32_cpu_get_cycle()) - elapsed_cycles;
|
99 |
2 |
zero_gravi |
elapsed_cycles = elapsed;
|
100 |
|
|
//CORE_TICKS elapsed=(CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
|
101 |
|
|
return elapsed;
|
102 |
|
|
}
|
103 |
|
|
/* Function : time_in_secs
|
104 |
|
|
Convert the value returned by get_time to seconds.
|
105 |
|
|
|
106 |
|
|
The <secs_ret> type is used to accomodate systems with no support for floating point.
|
107 |
|
|
Default implementation implemented by the EE_TICKS_PER_SEC macro above.
|
108 |
|
|
*/
|
109 |
|
|
secs_ret time_in_secs(CORE_TICKS ticks) {
|
110 |
|
|
//secs_ret retval=((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
|
111 |
12 |
zero_gravi |
secs_ret retval=(secs_ret)(ticks / SYSINFO_CLK);
|
112 |
2 |
zero_gravi |
return retval;
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
ee_u32 default_num_contexts=1;
|
116 |
|
|
|
117 |
|
|
/* Function : portable_init
|
118 |
|
|
Target specific initialization code
|
119 |
|
|
Test for some common mistakes.
|
120 |
|
|
*/
|
121 |
|
|
void portable_init(core_portable *p, int *argc, char *argv[])
|
122 |
|
|
{
|
123 |
|
|
// no interrupts, thanks
|
124 |
|
|
neorv32_cpu_dint();
|
125 |
|
|
|
126 |
|
|
// capture all exceptions and give debug information
|
127 |
14 |
zero_gravi |
neorv32_rte_setup();
|
128 |
2 |
zero_gravi |
|
129 |
|
|
// setup neorv32 UART
|
130 |
|
|
neorv32_uart_setup(BAUD_RATE, 0, 0);
|
131 |
|
|
|
132 |
12 |
zero_gravi |
neorv32_uart_printf("NEORV32: Processor running at %u Hz\n", (uint32_t)SYSINFO_CLK);
|
133 |
2 |
zero_gravi |
neorv32_uart_printf("NEORV32: Executing coremark (%u iterations). This may take some time...\n\n", (uint32_t)ITERATIONS);
|
134 |
|
|
|
135 |
|
|
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *)) {
|
136 |
|
|
ee_printf("ERROR! Please define ee_ptr_int to a type that holds a pointer!\n");
|
137 |
|
|
}
|
138 |
|
|
if (sizeof(ee_u32) != 4) {
|
139 |
|
|
ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
|
140 |
|
|
}
|
141 |
|
|
p->portable_id=1;
|
142 |
|
|
}
|
143 |
|
|
/* Function : portable_fini
|
144 |
|
|
Target specific final code
|
145 |
|
|
*/
|
146 |
|
|
void portable_fini(core_portable *p)
|
147 |
|
|
{
|
148 |
|
|
p->portable_id=0;
|
149 |
|
|
|
150 |
|
|
// show executed instructions, required cycles and resulting average CPI
|
151 |
|
|
union {
|
152 |
|
|
uint64_t uint64;
|
153 |
|
|
uint32_t uint32[sizeof(uint64_t)/2];
|
154 |
|
|
} exe_instructions, exe_time;
|
155 |
|
|
|
156 |
|
|
exe_time.uint64 = (uint64_t)elapsed_cycles;
|
157 |
12 |
zero_gravi |
exe_instructions.uint64 = neorv32_cpu_get_instret();
|
158 |
2 |
zero_gravi |
|
159 |
12 |
zero_gravi |
neorv32_uart_printf("\nNEORV32: Executed instructions 0x%x_%x\n", (uint32_t)exe_instructions.uint32[1], (uint32_t)exe_instructions.uint32[0]);
|
160 |
|
|
neorv32_uart_printf("NEORV32: CoreMark core clock cycles 0x%x_%x\n", (uint32_t)exe_time.uint32[1], (uint32_t)exe_time.uint32[0]);
|
161 |
2 |
zero_gravi |
|
162 |
12 |
zero_gravi |
uint64_t average_cpi = exe_time.uint64 / exe_instructions.uint64;
|
163 |
2 |
zero_gravi |
neorv32_uart_printf("NEORV32: Average CPI (integer part only): %u cycles/instruction\n", (uint32_t)average_cpi);
|
164 |
|
|
}
|