OpenCores
URL https://opencores.org/ocsvn/neorv32/neorv32/trunk

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [example/] [coremark/] [core_portme.c] - Blame information for rev 38

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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
 
19 38 zero_gravi
/* Modified for the NEORV32 Processor - by Stephan Nolting */
20
 
21 2 zero_gravi
#include "coremark.h"
22
#include "core_portme.h"
23
 
24
#if VALIDATION_RUN
25 38 zero_gravi
volatile ee_s32 seed1_volatile = 0x3415;
26
volatile ee_s32 seed2_volatile = 0x3415;
27
volatile ee_s32 seed3_volatile = 0x66;
28 2 zero_gravi
#endif
29
#if PERFORMANCE_RUN
30 38 zero_gravi
volatile ee_s32 seed1_volatile = 0x0;
31
volatile ee_s32 seed2_volatile = 0x0;
32
volatile ee_s32 seed3_volatile = 0x66;
33 2 zero_gravi
#endif
34
#if PROFILE_RUN
35 38 zero_gravi
volatile ee_s32 seed1_volatile = 0x8;
36
volatile ee_s32 seed2_volatile = 0x8;
37
volatile ee_s32 seed3_volatile = 0x8;
38 2 zero_gravi
#endif
39 38 zero_gravi
volatile ee_s32 seed4_volatile = ITERATIONS;
40
volatile ee_s32 seed5_volatile = 0;
41 2 zero_gravi
/* Porting : Timing functions
42 38 zero_gravi
        How to capture time and convert to seconds must be ported to whatever is
43
   supported by the platform. e.g. Read value from on board RTC, read value from
44
   cpu clock cycles performance counter etc. Sample implementation for standard
45
   time.h and windows.h definitions included.
46 2 zero_gravi
*/
47 38 zero_gravi
CORETIMETYPE
48
barebones_clock()
49
{
50
/*
51
#error \
52
    "You must implement a method to measure time in barebones_clock()! This function should return current time.\n"
53
*/
54
  return 0;
55
}
56 2 zero_gravi
/* Define : TIMER_RES_DIVIDER
57 38 zero_gravi
        Divider to trade off timer resolution and total time that can be
58
   measured.
59 2 zero_gravi
 
60 38 zero_gravi
        Use lower values to increase resolution, but make sure that overflow
61
   does not occur. If there are issues with the return value overflowing,
62
   increase this value.
63
        */
64
#define GETMYTIME(_t)              (*_t = (CORETIMETYPE)neorv32_cpu_get_cycle())
65
#define MYTIMEDIFF(fin, ini)       ((fin) - (ini))
66
#define TIMER_RES_DIVIDER          1
67 2 zero_gravi
#define SAMPLE_TIME_IMPLEMENTATION 1
68 38 zero_gravi
#define EE_TICKS_PER_SEC           (CLOCKS_PER_SEC / TIMER_RES_DIVIDER)
69 2 zero_gravi
 
70
/** Define Host specific (POSIX), or target specific global time variables. */
71 38 zero_gravi
static CORETIMETYPE start_time_val, stop_time_val;
72 2 zero_gravi
 
73
/* Function : start_time
74 38 zero_gravi
        This function will be called right before starting the timed portion of
75
   the benchmark.
76 2 zero_gravi
 
77 38 zero_gravi
        Implementation may be capturing a system timer (as implemented in the
78
   example code) or zeroing some system parameters - e.g. setting the cpu clocks
79
   cycles to 0.
80 2 zero_gravi
*/
81 38 zero_gravi
void
82
start_time(void)
83
{
84
    GETMYTIME(&start_time_val);
85 2 zero_gravi
}
86
/* Function : stop_time
87 38 zero_gravi
        This function will be called right after ending the timed portion of the
88
   benchmark.
89 2 zero_gravi
 
90 38 zero_gravi
        Implementation may be capturing a system timer (as implemented in the
91
   example code) or other system parameters - e.g. reading the current value of
92
   cpu cycles counter.
93 2 zero_gravi
*/
94 38 zero_gravi
void
95
stop_time(void)
96
{
97
    GETMYTIME(&stop_time_val);
98 2 zero_gravi
}
99
/* Function : get_time
100 38 zero_gravi
        Return an abstract "ticks" number that signifies time on the system.
101
 
102
        Actual value returned may be cpu cycles, milliseconds or any other
103
   value, as long as it can be converted to seconds by <time_in_secs>. This
104
   methodology is taken to accomodate any hardware or simulated platform. The
105
   sample implementation returns millisecs by default, and the resolution is
106
   controlled by <TIMER_RES_DIVIDER>
107 2 zero_gravi
*/
108 38 zero_gravi
CORE_TICKS
109
get_time(void)
110
{
111
    CORE_TICKS elapsed
112
        = (CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
113
    return elapsed;
114 2 zero_gravi
}
115
/* Function : time_in_secs
116 38 zero_gravi
        Convert the value returned by get_time to seconds.
117 2 zero_gravi
 
118 38 zero_gravi
        The <secs_ret> type is used to accomodate systems with no support for
119
   floating point. Default implementation implemented by the EE_TICKS_PER_SEC
120
   macro above.
121 2 zero_gravi
*/
122 38 zero_gravi
secs_ret
123
time_in_secs(CORE_TICKS ticks)
124
{
125
    /* NEORV32-specific */
126
    secs_ret retval = ((secs_ret)ticks) / (secs_ret)SYSINFO_CLK;
127
    return retval;
128 2 zero_gravi
}
129
 
130 38 zero_gravi
ee_u32 default_num_contexts = 1;
131 2 zero_gravi
 
132
/* Function : portable_init
133 38 zero_gravi
        Target specific initialization code
134
        Test for some common mistakes.
135 2 zero_gravi
*/
136 38 zero_gravi
#ifndef RUN_COREMARK
137
void
138
__attribute__((__noreturn__))
139
portable_init(core_portable *p, int *argc, char *argv[])
140
#else
141
void
142
portable_init(core_portable *p, int *argc, char *argv[])
143
#endif
144 2 zero_gravi
{
145 38 zero_gravi
  /* NEORV32-specific */
146
  neorv32_cpu_dint(); // no interrupt, thanks
147
  neorv32_rte_setup(); // capture all exceptions and give debug information
148
  neorv32_uart_setup(BAUD_RATE, 0, 0); // setup UART
149 2 zero_gravi
 
150
 
151 38 zero_gravi
// Disable coremark compilation by default
152
#ifndef RUN_COREMARK
153
  #warning COREMARK HAS NOT BEEN COMPILED! Use >>make USER_FLAGS+=-DRUN_COREMARK clean_all exe<< to compile it.
154 2 zero_gravi
 
155 38 zero_gravi
  // inform the user if you are actually executing this
156
  neorv32_uart_printf("ERROR! CoreMark has not been compiled. Use >>make USER_FLAGS+=-DRUN_COREMARK clean_all exe<< to compile it.\n");
157
 
158
  while(1);
159
#endif
160
 
161
 
162 12 zero_gravi
  neorv32_uart_printf("NEORV32: Processor running at %u Hz\n", (uint32_t)SYSINFO_CLK);
163 2 zero_gravi
  neorv32_uart_printf("NEORV32: Executing coremark (%u iterations). This may take some time...\n\n", (uint32_t)ITERATIONS);
164
 
165 38 zero_gravi
/*
166
#error \
167
    "Call board initialization routines in portable init (if needed), in particular initialize UART!\n"
168
*/
169
    if (sizeof(ee_ptr_int) != sizeof(ee_u8 *))
170
    {
171
        ee_printf(
172
            "ERROR! Please define ee_ptr_int to a type that holds a "
173
            "pointer!\n");
174
    }
175
    if (sizeof(ee_u32) != 4)
176
    {
177
        ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
178
    }
179
    p->portable_id = 1;
180
 
181
#ifndef RUN_COREMARK
182
  while(1);
183
#endif
184 2 zero_gravi
}
185
/* Function : portable_fini
186 38 zero_gravi
        Target specific final code
187 2 zero_gravi
*/
188 38 zero_gravi
void
189
portable_fini(core_portable *p)
190 2 zero_gravi
{
191 38 zero_gravi
    p->portable_id = 0;
192 2 zero_gravi
 
193 38 zero_gravi
  /* NORVĀ§"-specific */
194
 
195 2 zero_gravi
  // show executed instructions, required cycles and resulting average CPI
196
  union {
197
    uint64_t uint64;
198
    uint32_t  uint32[sizeof(uint64_t)/2];
199
  } exe_instructions, exe_time;
200
 
201 38 zero_gravi
  exe_time.uint64 = (uint64_t)get_time();
202 12 zero_gravi
  exe_instructions.uint64 = neorv32_cpu_get_instret();
203 2 zero_gravi
 
204 22 zero_gravi
  neorv32_uart_printf("\nNEORV32: All reported numbers only show the integer results.\n\n");
205
 
206
  neorv32_uart_printf("NEORV32: Executed instructions      0x%x_%x\n", (uint32_t)exe_instructions.uint32[1], (uint32_t)exe_instructions.uint32[0]);
207 12 zero_gravi
  neorv32_uart_printf("NEORV32: CoreMark core clock cycles 0x%x_%x\n", (uint32_t)exe_time.uint32[1], (uint32_t)exe_time.uint32[0]);
208 2 zero_gravi
 
209 38 zero_gravi
  uint64_t average_cpi_int = exe_time.uint64 / exe_instructions.uint64;
210
  neorv32_uart_printf("NEORV32: Average CPI (integer part only): %u cycles/instruction\n", (uint32_t)average_cpi_int);
211
 
212 2 zero_gravi
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.