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

Subversion Repositories neorv32

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

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
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
  elapsed_cycles = neorv32_mtime_get_time();
75
        //GETMYTIME(&start_time_val );      
76
}
77
/* Function : stop_time
78
        This function will be called right after ending the timed portion of the benchmark.
79
 
80
        Implementation may be capturing a system timer (as implemented in the example code)
81
        or other system parameters - e.g. reading the current value of cpu cycles counter.
82
*/
83
void stop_time(void) {
84
        //GETMYTIME(&stop_time_val );      
85
}
86
/* Function : get_time
87
        Return an abstract "ticks" number that signifies time on the system.
88
 
89
        Actual value returned may be cpu cycles, milliseconds or any other value,
90
        as long as it can be converted to seconds by <time_in_secs>.
91
        This methodology is taken to accomodate any hardware or simulated platform.
92
        The sample implementation returns millisecs by default,
93
        and the resolution is controlled by <TIMER_RES_DIVIDER>
94
*/
95
CORE_TICKS get_time(void) {
96
        CORE_TICKS elapsed = ((CORE_TICKS)neorv32_mtime_get_time()) - elapsed_cycles;
97
  elapsed_cycles = elapsed;
98
  //CORE_TICKS elapsed=(CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
99
        return elapsed;
100
}
101
/* Function : time_in_secs
102
        Convert the value returned by get_time to seconds.
103
 
104
        The <secs_ret> type is used to accomodate systems with no support for floating point.
105
        Default implementation implemented by the EE_TICKS_PER_SEC macro above.
106
*/
107
secs_ret time_in_secs(CORE_TICKS ticks) {
108
        //secs_ret retval=((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
109
        secs_ret retval=(secs_ret)(ticks / neorv32_cpu_csr_read(CSR_MCLOCK));
110
        return retval;
111
}
112
 
113
ee_u32 default_num_contexts=1;
114
 
115
/* Function : portable_init
116
        Target specific initialization code
117
        Test for some common mistakes.
118
*/
119
void portable_init(core_portable *p, int *argc, char *argv[])
120
{
121
  // no interrupts, thanks
122
  neorv32_cpu_dint();
123
 
124
  // capture all exceptions and give debug information
125
  neorv32_rte_enable_debug_mode();
126
 
127
  // setup neorv32 UART
128
  neorv32_uart_setup(BAUD_RATE, 0, 0);
129
 
130
  // check if MTIME unit was synthesized
131
  if (!neorv32_mtime_available()) {
132
    neorv32_uart_printf("NEORV32: Error! No MTIME unit synthesized!");
133
    while(1);
134
  }
135
 
136
  neorv32_uart_printf("NEORV32: Processor running at %u Hz\n", (uint32_t)neorv32_cpu_csr_read(CSR_MCLOCK));
137
  neorv32_uart_printf("NEORV32: Executing coremark (%u iterations). This may take some time...\n\n", (uint32_t)ITERATIONS);
138
 
139
        if (sizeof(ee_ptr_int) != sizeof(ee_u8 *)) {
140
                ee_printf("ERROR! Please define ee_ptr_int to a type that holds a pointer!\n");
141
        }
142
        if (sizeof(ee_u32) != 4) {
143
                ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
144
        }
145
        p->portable_id=1;
146
}
147
/* Function : portable_fini
148
        Target specific final code
149
*/
150
void portable_fini(core_portable *p)
151
{
152
        p->portable_id=0;
153
 
154
  // show executed instructions, required cycles and resulting average CPI
155
  union {
156
    uint64_t uint64;
157
    uint32_t  uint32[sizeof(uint64_t)/2];
158
  } exe_cycles;
159
 
160
  union {
161
    uint64_t uint64;
162
    uint32_t  uint32[sizeof(uint64_t)/2];
163
  } exe_instructions, exe_time;
164
 
165
  exe_time.uint64 = (uint64_t)elapsed_cycles;
166
  exe_cycles.uint32[0] = neorv32_cpu_csr_read(CSR_TIME);
167
  exe_cycles.uint32[1] = neorv32_cpu_csr_read(CSR_TIMEH);
168
  exe_instructions.uint32[0] = neorv32_cpu_csr_read(CSR_INSTRET);
169
  exe_instructions.uint32[1] = neorv32_cpu_csr_read(CSR_INSTRETH);
170
 
171
  neorv32_uart_printf("\nNEORV32: Executed instructions       0x%x_%x\n", (uint32_t)exe_instructions.uint32[1], (uint32_t)exe_instructions.uint32[0]);
172
  neorv32_uart_printf("NEORV32: Total required clock cycles 0x%x_%x\n", (uint32_t)exe_cycles.uint32[1], (uint32_t)exe_cycles.uint32[0]);
173
  neorv32_uart_printf("NEORV32: CoreMark core clock cycles  0x%x_%x\n", (uint32_t)exe_time.uint32[1], (uint32_t)exe_time.uint32[0]);
174
 
175
  uint64_t average_cpi = exe_cycles.uint64 / exe_instructions.uint64;
176
  neorv32_uart_printf("NEORV32: Average CPI (integer part only): %u cycles/instruction\n", (uint32_t)average_cpi);
177
}

powered by: WebSVN 2.1.0

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