Skip to content

Commit 11b2712

Browse files
author
Yvan Tortorella
committed
Migrate Cheshire-specific files to avoid Coremark fork.
1 parent 65f5962 commit 11b2712

File tree

6 files changed

+1068
-3
lines changed

6 files changed

+1068
-3
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
# Exclude generated headers (no license checker support for optional lines)
2828
exclude_paths: |
2929
sw/include/regs/*.h
30+
sw/include/coremark/*
31+
sw/lib/coremark/*
3032
3133
lint-sv:
3234
runs-on: ubuntu-latest

sw/include/coremark/core_portme.h

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
// Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)
2+
//
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+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// Original Author: Shay Gal-on
16+
17+
#include "regs/cheshire.h"
18+
#include "dif/clint.h"
19+
#include "dif/uart.h"
20+
#include "params.h"
21+
#include "util.h"
22+
23+
/* Topic : Description
24+
This file contains configuration constants required to execute on
25+
different platforms
26+
*/
27+
#ifndef CORE_PORTME_H
28+
#define CORE_PORTME_H
29+
/************************/
30+
/* Data types and settings */
31+
/************************/
32+
/* Configuration : HAS_FLOAT
33+
Define to 1 if the platform supports floating point.
34+
*/
35+
#ifndef HAS_FLOAT
36+
#define HAS_FLOAT 1
37+
#endif
38+
/* Configuration : HAS_TIME_H
39+
Define to 1 if platform has the time.h header file,
40+
and implementation of functions thereof.
41+
*/
42+
#ifndef HAS_TIME_H
43+
#define HAS_TIME_H 0
44+
#endif
45+
/* Configuration : USE_CLOCK
46+
Define to 1 if platform has the time.h header file,
47+
and implementation of functions thereof.
48+
*/
49+
#ifndef USE_CLOCK
50+
#define USE_CLOCK 0
51+
#endif
52+
/* Configuration : HAS_STDIO
53+
Define to 1 if the platform has stdio.h.
54+
*/
55+
#ifndef HAS_STDIO
56+
#define HAS_STDIO 0
57+
#endif
58+
/* Configuration : HAS_PRINTF
59+
Define to 1 if the platform has stdio.h and implements the printf
60+
function.
61+
*/
62+
#ifndef HAS_PRINTF
63+
#define HAS_PRINTF 0
64+
#endif
65+
66+
/* Definitions : COMPILER_VERSION, COMPILER_FLAGS, MEM_LOCATION
67+
Initialize these strings per platform
68+
*/
69+
#ifndef COMPILER_VERSION
70+
#ifdef __GNUC__
71+
#define COMPILER_VERSION "GCC"__VERSION__
72+
#else
73+
#define COMPILER_VERSION "Please put compiler version here (e.g. gcc 4.1)"
74+
#endif
75+
#endif
76+
#ifndef COMPILER_FLAGS
77+
#define COMPILER_FLAGS \
78+
FLAGS_STR /* "Please put compiler flags here (e.g. -o3)" */
79+
#endif
80+
#ifndef MEM_LOCATION
81+
#define MEM_LOCATION "STACK"
82+
#endif
83+
84+
/* Data Types :
85+
To avoid compiler issues, define the data types that need ot be used for
86+
8b, 16b and 32b in <core_portme.h>.
87+
88+
*Imprtant* :
89+
ee_ptr_int needs to be the data type used to hold pointers, otherwise
90+
coremark may fail!!!
91+
*/
92+
typedef signed short ee_s16;
93+
typedef unsigned short ee_u16;
94+
typedef signed int ee_s32;
95+
typedef float ee_f32;
96+
typedef double ee_f64;
97+
typedef unsigned char ee_u8;
98+
typedef unsigned int ee_u32;
99+
typedef unsigned long ee_u64;
100+
typedef ee_u64 ee_ptr_int;
101+
typedef ee_u64 ee_size_t;
102+
#define NULL ((void *)0)
103+
/* align_mem :
104+
This macro is used to align an offset to point to a 32b value. It is
105+
used in the Matrix algorithm to initialize the input memory blocks.
106+
*/
107+
#define align_mem(x) (void *)(4 + (((ee_ptr_int)(x)-1) & ~3))
108+
109+
/* Configuration : CORE_TICKS
110+
Define type of return from the timing functions.
111+
*/
112+
#define CORETIMETYPE ee_u32
113+
typedef ee_u32 CORE_TICKS;
114+
115+
/* Configuration : SEED_METHOD
116+
Defines method to get seed values that cannot be computed at compile
117+
time.
118+
119+
Valid values :
120+
SEED_ARG - from command line.
121+
SEED_FUNC - from a system function.
122+
SEED_VOLATILE - from volatile variables.
123+
*/
124+
#ifndef SEED_METHOD
125+
#define SEED_METHOD SEED_VOLATILE
126+
#endif
127+
128+
/* Configuration : MEM_METHOD
129+
Defines method to get a block of memry.
130+
131+
Valid values :
132+
MEM_MALLOC - for platforms that implement malloc and have malloc.h.
133+
MEM_STATIC - to use a static memory array.
134+
MEM_STACK - to allocate the data block on the stack (NYI).
135+
*/
136+
#ifndef MEM_METHOD
137+
#define MEM_METHOD MEM_STATIC
138+
#endif
139+
140+
/* Configuration : MULTITHREAD
141+
Define for parallel execution
142+
143+
Valid values :
144+
1 - only one context (default).
145+
N>1 - will execute N copies in parallel.
146+
147+
Note :
148+
If this flag is defined to more then 1, an implementation for launching
149+
parallel contexts must be defined.
150+
151+
Two sample implementations are provided. Use <USE_PTHREAD> or <USE_FORK>
152+
to enable them.
153+
154+
It is valid to have a different implementation of <core_start_parallel>
155+
and <core_end_parallel> in <core_portme.c>, to fit a particular architecture.
156+
*/
157+
#ifndef MULTITHREAD
158+
#define MULTITHREAD 1
159+
#define USE_PTHREAD 0
160+
#define USE_FORK 0
161+
#define USE_SOCKET 0
162+
#endif
163+
164+
/* Configuration : MAIN_HAS_NOARGC
165+
Needed if platform does not support getting arguments to main.
166+
167+
Valid values :
168+
0 - argc/argv to main is supported
169+
1 - argc/argv to main is not supported
170+
171+
Note :
172+
This flag only matters if MULTITHREAD has been defined to a value
173+
greater then 1.
174+
*/
175+
#ifndef MAIN_HAS_NOARGC
176+
#define MAIN_HAS_NOARGC 0
177+
#endif
178+
179+
/* Configuration : MAIN_HAS_NORETURN
180+
Needed if platform does not support returning a value from main.
181+
182+
Valid values :
183+
0 - main returns an int, and return value will be 0.
184+
1 - platform does not support returning a value from main
185+
*/
186+
#ifndef MAIN_HAS_NORETURN
187+
#define MAIN_HAS_NORETURN 0
188+
#endif
189+
190+
/* Variable : default_num_contexts
191+
Not used for this simple port, must contain the value 1.
192+
*/
193+
extern ee_u32 default_num_contexts;
194+
195+
typedef struct CORE_PORTABLE_S
196+
{
197+
ee_u8 portable_id;
198+
} core_portable;
199+
200+
/* target specific init/fini */
201+
void portable_init(core_portable *p, int *argc, char *argv[]);
202+
void portable_fini(core_portable *p);
203+
204+
#if !defined(PROFILE_RUN) && !defined(PERFORMANCE_RUN) \
205+
&& !defined(VALIDATION_RUN)
206+
#if (TOTAL_DATA_SIZE == 1200)
207+
#define PROFILE_RUN 1
208+
#elif (TOTAL_DATA_SIZE == 2000)
209+
#define PERFORMANCE_RUN 1
210+
#else
211+
#define VALIDATION_RUN 1
212+
#endif
213+
#endif
214+
215+
int ee_printf(const char *fmt, ...);
216+
217+
#endif /* CORE_PORTME_H */

sw/lib/coremark/core_portme.c

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC)
2+
//
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+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// Original Author: Shay Gal-on
16+
17+
#include "coremark.h"
18+
#include "core_portme.h"
19+
20+
#if VALIDATION_RUN
21+
volatile ee_s32 seed1_volatile = 0x3415;
22+
volatile ee_s32 seed2_volatile = 0x3415;
23+
volatile ee_s32 seed3_volatile = 0x66;
24+
#endif
25+
#if PERFORMANCE_RUN
26+
volatile ee_s32 seed1_volatile = 0x0;
27+
volatile ee_s32 seed2_volatile = 0x0;
28+
volatile ee_s32 seed3_volatile = 0x66;
29+
#endif
30+
#if PROFILE_RUN
31+
volatile ee_s32 seed1_volatile = 0x8;
32+
volatile ee_s32 seed2_volatile = 0x8;
33+
volatile ee_s32 seed3_volatile = 0x8;
34+
#endif
35+
volatile ee_s32 seed4_volatile = ITERATIONS;
36+
volatile ee_s32 seed5_volatile = 0;
37+
/* Porting : Timing functions
38+
How to capture time and convert to seconds must be ported to whatever is
39+
supported by the platform. e.g. Read value from on board RTC, read value from
40+
cpu clock cycles performance counter etc. Sample implementation for standard
41+
time.h and windows.h definitions included.
42+
*/
43+
CORETIMETYPE
44+
barebones_clock()
45+
{
46+
CORETIMETYPE cycle_count;
47+
asm volatile("csrr %0, mcycle" : "=r"(cycle_count));
48+
return cycle_count;
49+
}
50+
/* Define : TIMER_RES_DIVIDER
51+
Divider to trade off timer resolution and total time that can be
52+
measured.
53+
54+
Use lower values to increase resolution, but make sure that overflow
55+
does not occur. If there are issues with the return value overflowing,
56+
increase this value.
57+
*/
58+
#define GETMYTIME(_t) (*_t = barebones_clock())
59+
#define MYTIMEDIFF(fin, ini) ((fin) - (ini))
60+
#define TIMER_RES_DIVIDER 1
61+
#define SAMPLE_TIME_IMPLEMENTATION 1
62+
#define EE_TICKS_PER_SEC (CLOCKS_PER_SEC / TIMER_RES_DIVIDER)
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
69+
the benchmark.
70+
71+
Implementation may be capturing a system timer (as implemented in the
72+
example code) or zeroing some system parameters - e.g. setting the cpu clocks
73+
cycles to 0.
74+
*/
75+
void
76+
start_time(void)
77+
{
78+
GETMYTIME(&start_time_val);
79+
}
80+
/* Function : stop_time
81+
This function will be called right after ending the timed portion of the
82+
benchmark.
83+
84+
Implementation may be capturing a system timer (as implemented in the
85+
example code) or other system parameters - e.g. reading the current value of
86+
cpu cycles counter.
87+
*/
88+
void
89+
stop_time(void)
90+
{
91+
GETMYTIME(&stop_time_val);
92+
}
93+
/* Function : get_time
94+
Return an abstract "ticks" number that signifies time on the system.
95+
96+
Actual value returned may be cpu cycles, milliseconds or any other
97+
value, as long as it can be converted to seconds by <time_in_secs>. This
98+
methodology is taken to accommodate any hardware or simulated platform. The
99+
sample implementation returns millisecs by default, and the resolution is
100+
controlled by <TIMER_RES_DIVIDER>
101+
*/
102+
CORE_TICKS
103+
get_time(void)
104+
{
105+
CORE_TICKS elapsed
106+
= (CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
107+
return elapsed;
108+
}
109+
/* Function : time_in_secs
110+
Convert the value returned by get_time to seconds.
111+
112+
The <secs_ret> type is used to accommodate systems with no support for
113+
floating point. Default implementation implemented by the EE_TICKS_PER_SEC
114+
macro above.
115+
*/
116+
secs_ret
117+
time_in_secs(CORE_TICKS ticks)
118+
{
119+
secs_ret retval = ((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
120+
return retval;
121+
}
122+
123+
ee_u32 default_num_contexts = 1;
124+
125+
/* Function : portable_init
126+
Target specific initialization code
127+
Test for some common mistakes.
128+
*/
129+
void
130+
portable_init(core_portable *p, int *argc, char *argv[])
131+
{
132+
133+
ee_u32 rtc_freq = *reg32(&__base_regs, CHESHIRE_RTC_FREQ_REG_OFFSET);
134+
ee_u64 reset_freq = clint_get_core_freq(rtc_freq, 2500);
135+
uart_init(&__base_uart, reset_freq, __BOOT_BAUDRATE);
136+
137+
(void)argc; // prevent unused warning
138+
(void)argv; // prevent unused warning
139+
140+
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *))
141+
{
142+
ee_printf(
143+
"ERROR! Please define ee_ptr_int to a type that holds a "
144+
"pointer!\n\r");
145+
}
146+
if (sizeof(ee_u32) != 4)
147+
{
148+
ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n\r");
149+
}
150+
p->portable_id = 1;
151+
}
152+
/* Function : portable_fini
153+
Target specific final code
154+
*/
155+
void
156+
portable_fini(core_portable *p)
157+
{
158+
p->portable_id = 0;
159+
}

0 commit comments

Comments
 (0)