forked from lowRISC/ibex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sw] Add Coremark makefile and support files
Signed-off-by: Greg Chadwick <[email protected]>
- Loading branch information
Showing
7 changed files
with
1,188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Benchmarks | ||
|
||
This directory contains benchmarks that can be run on ibex simple system. | ||
Benchmarks may rely on code external to this directory (e.g. it may be found in | ||
`vendor/`) see the specific benchmark information below for details on how to | ||
build and run each benchmark and where benchmark code is located. | ||
|
||
## Building Simulation | ||
|
||
All of these benchmarks run on Simple System. A verilator simulation suitable | ||
for running them can be built with: | ||
|
||
``` | ||
fusesoc --cores-root=. run --target=sim --setup --build lowrisc:ibex:ibex_simple_system --RV32M=1 --RV32E=0 | ||
``` | ||
|
||
See examples/simple_system/README.md for full details. | ||
|
||
## Coremark | ||
|
||
Coremark (https://www.eembc.org/coremark/ https://github.com/eembc/coremark) is | ||
an industry standard benchmark with results available for a wide variety of | ||
systems. | ||
|
||
The Coremark source is vendored into the Ibex repository at | ||
`vendor/eembc_coremark`. Support structure and a makefile to build Coremark for | ||
running on simple system is found in `examples/sw/benchmarks/coremark`. | ||
|
||
To build Coremark: | ||
|
||
``` | ||
make -C ./examples/sw/benchmarks/coremark/ | ||
``` | ||
|
||
To run Coremark (after building a suitable simulator binary, see above): | ||
|
||
``` | ||
build/lowrisc_ibex_ibex_simple_system_0/sim-verilator/Vibex_simple_system --meminit=ram,examples/sw/benchmarks/coremark/coremark.elf | ||
``` | ||
|
||
The simulator outputs the performance counter values observed for the benchmark | ||
(the counts do not include anything from pre or post benchmark loops). | ||
|
||
Coremark should output (to `ibex_simple_system.log`) something like the | ||
following: | ||
|
||
``` | ||
2K performance run parameters for coremark. | ||
CoreMark Size : 666 | ||
Total ticks : 4244465 | ||
Total time (secs): 8 | ||
Iterations/Sec : 1 | ||
Iterations : 10 | ||
Compiler version : GCC | ||
Compiler flags : | ||
Memory location : | ||
seedcrc : 0xe9f5 | ||
[0]crclist : 0xe714 | ||
[0]crcmatrix : 0x1fd7 | ||
[0]crcstate : 0x8e3a | ||
[0]crcfinal : 0xfcaf | ||
Correct operation validated. See README.md for run and reporting rules. | ||
``` | ||
|
||
A Coremark score is given as the number of iterations executed per second. The | ||
Coremark binary is hard-coded to execute 10 iterations (see | ||
`examples/sw/benchmarks/coremark/Makefile` if you wish to alter this). To obtain | ||
a useful Coremark score from the simulation you need to choose a clock speed the | ||
Ibex implementation you are interested in would run at, e.g. 100 MHz, taking | ||
the above example: | ||
|
||
* 10 iterations take 4244465 clock cycles | ||
* So at 100 MHz Ibex would execute (100 * 10^6) / (4244465 / 10) = 235.6 | ||
Iterations in 1 second. | ||
* Coremark (at 100 MHz) is 235.6 | ||
|
||
Coremark/MHz is often used instead of a raw Coremark score. The example above | ||
gives a Coremark/MHz of 2.36 (235.6 / 100 rounded to 2 decimal places). | ||
|
||
To directly produce Coremark/MHz from the number of iterations (I) and total | ||
ticks (T) use the follow formula: | ||
|
||
``` | ||
Coremark/MHz = (10 ^ 6) * I / T | ||
``` | ||
|
||
Note that `core_main.c` from Coremark has had a minor modification to prevent it | ||
from reporting an error if it executes for less than 10 seconds. This violates | ||
the run reporting rules (though does not effect benchmark execution). It is | ||
trivial to restore `core_main.c` to the version supplied by EEMBC in the | ||
Coremark repository if an official result is desired. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright lowRISC contributors. | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Build coremark benchmark for Ibex Simple System | ||
|
||
COREMARK_DIR = ../../../../vendor/eembc_coremark | ||
|
||
export PORT_DIR = $(CURDIR)/ibex | ||
export ITERATIONS = 10 | ||
export OPATH = $(CURDIR)/ | ||
|
||
# Export OPATH above doesn't seem to work so need to explicitly give it on the | ||
# make command line | ||
all: | ||
$(MAKE) -C $(COREMARK_DIR) | ||
|
||
clean: | ||
$(MAKE) -C $(COREMARK_DIR) clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
// Copyright lowRISC contributors. | ||
// Copyright 2018 Embedded Microprocessor Benchmark Consortium (EEMBC) | ||
// Original Author: Shay Gal-on | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "core_portme.h" | ||
|
||
#include "coremark.h" | ||
|
||
#include "simple_system_common.h" | ||
|
||
#if VALIDATION_RUN | ||
volatile ee_s32 seed1_volatile = 0x3415; | ||
volatile ee_s32 seed2_volatile = 0x3415; | ||
volatile ee_s32 seed3_volatile = 0x66; | ||
#endif | ||
#if PERFORMANCE_RUN | ||
volatile ee_s32 seed1_volatile = 0x0; | ||
volatile ee_s32 seed2_volatile = 0x0; | ||
volatile ee_s32 seed3_volatile = 0x66; | ||
#endif | ||
#if PROFILE_RUN | ||
volatile ee_s32 seed1_volatile = 0x8; | ||
volatile ee_s32 seed2_volatile = 0x8; | ||
volatile ee_s32 seed3_volatile = 0x8; | ||
#endif | ||
volatile ee_s32 seed4_volatile = ITERATIONS; | ||
volatile ee_s32 seed5_volatile = 0; | ||
/* Porting : Timing functions | ||
How to capture time and convert to seconds must be ported to whatever is | ||
supported by the platform. e.g. Read value from on board RTC, read value from | ||
cpu clock cycles performance counter etc. Sample implementation for standard | ||
time.h and windows.h definitions included. | ||
*/ | ||
CORETIMETYPE barebones_clock() { | ||
ee_u32 result; | ||
|
||
PCOUNT_READ(mcycle, result); | ||
|
||
return result; | ||
} | ||
|
||
/* Define : TIMER_RES_DIVIDER | ||
Divider to trade off timer resolution and total time that can be | ||
measured. | ||
Use lower values to increase resolution, but make sure that overflow | ||
does not occur. If there are issues with the return value overflowing, | ||
increase this value. | ||
*/ | ||
#define GETMYTIME(_t) (*_t = barebones_clock()) | ||
#define MYTIMEDIFF(fin, ini) ((fin) - (ini)) | ||
#define TIMER_RES_DIVIDER 1 | ||
#define SAMPLE_TIME_IMPLEMENTATION 1 | ||
#define CLOCKS_PER_SEC 500000 | ||
#define EE_TICKS_PER_SEC (CLOCKS_PER_SEC / TIMER_RES_DIVIDER) | ||
|
||
void pcount_read(uint32_t pcount_out[]) { | ||
PCOUNT_READ(minstret, pcount_out[0]); | ||
PCOUNT_READ(mhpmcounter3, pcount_out[1]); | ||
PCOUNT_READ(mhpmcounter4, pcount_out[2]); | ||
PCOUNT_READ(mhpmcounter5, pcount_out[3]); | ||
PCOUNT_READ(mhpmcounter6, pcount_out[4]); | ||
PCOUNT_READ(mhpmcounter7, pcount_out[5]); | ||
PCOUNT_READ(mhpmcounter8, pcount_out[6]); | ||
PCOUNT_READ(mhpmcounter9, pcount_out[7]); | ||
PCOUNT_READ(mhpmcounter10, pcount_out[8]); | ||
} | ||
|
||
const char *pcount_names[] = {"Instructions Retired", | ||
"LSU Busy", | ||
"IFetch wait", | ||
"Loads", | ||
"Stores", | ||
"Jumps", | ||
"Branches", | ||
"Taken Branches", | ||
"Compressed Instructions"}; | ||
|
||
const uint32_t pcount_num = sizeof(pcount_names) / sizeof(char *); | ||
|
||
void dump_pcounts() { | ||
uint32_t pcounts[pcount_num]; | ||
|
||
pcount_read(pcounts); | ||
ee_printf( | ||
"Performance Counters\n" | ||
"--------------------\n"); | ||
for (uint32_t i = 0; i < pcount_num; ++i) { | ||
ee_printf("%s: %u\n", pcount_names[i], pcounts[i]); | ||
} | ||
ee_printf("\n"); | ||
} | ||
|
||
/** Define Host specific (POSIX), or target specific global time variables. */ | ||
static CORETIMETYPE start_time_val, stop_time_val; | ||
|
||
/* Function : start_time | ||
This function will be called right before starting the timed portion of | ||
the benchmark. | ||
Implementation may be capturing a system timer (as implemented in the | ||
example code) or zeroing some system parameters - e.g. setting the cpu clocks | ||
cycles to 0. | ||
*/ | ||
void start_time(void) { | ||
pcount_enable(0); | ||
pcount_reset(); | ||
pcount_enable(1); | ||
GETMYTIME(&start_time_val); | ||
} | ||
|
||
/* Function : stop_time | ||
This function will be called right after ending the timed portion of the | ||
benchmark. | ||
Implementation may be capturing a system timer (as implemented in the | ||
example code) or other system parameters - e.g. reading the current value of | ||
cpu cycles counter. | ||
*/ | ||
void stop_time(void) { | ||
GETMYTIME(&stop_time_val); | ||
pcount_enable(0); | ||
} | ||
|
||
/* Function : get_time | ||
Return an abstract "ticks" number that signifies time on the system. | ||
Actual value returned may be cpu cycles, milliseconds or any other | ||
value, as long as it can be converted to seconds by <time_in_secs>. This | ||
methodology is taken to accomodate any hardware or simulated platform. The | ||
sample implementation returns millisecs by default, and the resolution is | ||
controlled by <TIMER_RES_DIVIDER> | ||
*/ | ||
CORE_TICKS get_time(void) { | ||
CORE_TICKS elapsed = (CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val)); | ||
return elapsed; | ||
} | ||
/* Function : time_in_secs | ||
Convert the value returned by get_time to seconds. | ||
The <secs_ret> type is used to accomodate systems with no support for | ||
floating point. Default implementation implemented by the EE_TICKS_PER_SEC | ||
macro above. | ||
*/ | ||
secs_ret time_in_secs(CORE_TICKS ticks) { | ||
secs_ret retval = ((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC; | ||
return retval; | ||
} | ||
|
||
ee_u32 default_num_contexts = 1; | ||
|
||
/* Function : portable_init | ||
Target specific initialization code | ||
Test for some common mistakes. | ||
*/ | ||
void portable_init(core_portable *p, int *argc, char *argv[]) { | ||
ee_printf("Ibex coremark platform init...\n"); | ||
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *)) { | ||
ee_printf( | ||
"ERROR! Please define ee_ptr_int to a type that holds a pointer!\n"); | ||
} | ||
if (sizeof(ee_u32) != 4) { | ||
ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n"); | ||
} | ||
p->portable_id = 1; | ||
} | ||
/* Function : portable_fini | ||
Target specific final code | ||
*/ | ||
void portable_fini(core_portable *p) { | ||
dump_pcounts(); | ||
|
||
CORE_TICKS elapsed = get_time(); | ||
float coremark_mhz; | ||
|
||
coremark_mhz = (1000000.0f * (float)ITERATIONS) / elapsed; | ||
|
||
ee_printf("Coremark / MHz: %f\n", coremark_mhz); | ||
|
||
p->portable_id = 0; | ||
} |
Oops, something went wrong.