Skip to content

Commit

Permalink
Merge pull request eembc#4 from sifive/align_linux64
Browse files Browse the repository at this point in the history
Align linux64 performance tweak to freedom_metal
  • Loading branch information
reclusejack committed May 21, 2019
2 parents dd02091 + f390650 commit c181806
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 64 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ What is and is not allowed.
~~~
4. All source files must be compiled with the same flags.
5. All data type sizes must match size in bits such that:
* `ee_u8` is an 8 bits datatype.
* `ee_s16` is a 16 bits datatype.
* `ee_u16` is a 16 bits datatype.
* `ee_s32` is a 32 bits datatype.
* `ee_u32` is a 32 bits datatype.
* `ee_u8` is an unsigned 8-bit datatype.
* `ee_s16` is a signed 16-bit datatype.
* `ee_u16` is an unsigned 16-bit datatype.
* `ee_s32` is a signed 32-bit datatype.
* `ee_u32` is an unsigned 32-bit datatype.

## Allowed

Expand Down
8 changes: 4 additions & 4 deletions barebones/ee_printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ limitations under the License.

static char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
static char *upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static size_t strnlen(const char *s, size_t count);
static ee_size_t strnlen(const char *s, ee_size_t count);

static size_t strnlen(const char *s, size_t count)
static ee_size_t strnlen(const char *s, ee_size_t count)
{
const char *sc;
for (sc = s; *sc != '\0' && count--; ++sc);
Expand Down Expand Up @@ -183,7 +183,7 @@ static char *iaddr(char *str, unsigned char *addr, int size, int precision, int
return str;
}

#ifdef HAS_FLOAT
#if HAS_FLOAT

char *ecvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf);
char *fcvtbuf(double arg, int ndigits, int *decpt, int *sign, char *buf);
Expand Down Expand Up @@ -529,7 +529,7 @@ static int ee_vsprintf(char *buf, const char *fmt, va_list args)
case 'u':
break;

#ifdef HAS_FLOAT
#if HAS_FLOAT

case 'f':
str = flt(str, va_arg(args, double), field_width, precision, *fmt, flags | SIGN);
Expand Down
25 changes: 15 additions & 10 deletions freedom-metal/core_portme.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ Original Author: Shay Gal-on
#endif
volatile ee_s32 seed4_volatile=ITERATIONS;
volatile ee_s32 seed5_volatile=0;

unsigned long long timebase = 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.
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() {
Expand All @@ -54,36 +56,36 @@ CORETIMETYPE barebones_clock() {
#define MYTIMEDIFF(fin,ini) ((fin)-(ini))
#define TIMER_RES_DIVIDER 1
#define SAMPLE_TIME_IMPLEMENTATION 1
#define EE_TICKS_PER_SEC (CLOCKS_PER_SEC / TIMER_RES_DIVIDER)
#define EE_TICKS_PER_SEC (timebase/ TIMER_RES_DIVIDER)

/** 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)
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) {
GETMYTIME(&start_time_val );
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)
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 );
GETMYTIME(&stop_time_val );
}
/* 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,
The sample implementation returns millisecs by default,
and the resolution is controlled by <TIMER_RES_DIVIDER>
*/
CORE_TICKS get_time(void) {
Expand All @@ -104,7 +106,7 @@ secs_ret time_in_secs(CORE_TICKS ticks) {
ee_u32 default_num_contexts=1;

/* Function : portable_init
Target specific initialization code
Target specific initialization code
Test for some common mistakes.
*/
void portable_init(core_portable *p, int *argc, char *argv[])
Expand All @@ -115,10 +117,13 @@ void portable_init(core_portable *p, int *argc, char *argv[])
if (sizeof(ee_u32) != 4) {
ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
}
//get timer frequency
metal_timer_get_timebase_frequency(0, &timebase);

p->portable_id=1;
}
/* Function : portable_fini
Target specific final code
Target specific final code
*/
void portable_fini(core_portable *p)
{
Expand Down
49 changes: 25 additions & 24 deletions freedom-metal/core_portme.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Original Author: Shay Gal-on
/************************/
/* Data types and settings */
/************************/
/* Configuration : HAS_FLOAT
/* Configuration : HAS_FLOAT
Define to 1 if the platform supports floating point.
*/
#ifndef HAS_FLOAT
#ifndef HAS_FLOAT
#define HAS_FLOAT 1
#endif
/* Configuration : HAS_TIME_H
Expand Down Expand Up @@ -60,23 +60,23 @@ Original Author: Shay Gal-on
/* Definitions : COMPILER_VERSION, COMPILER_FLAGS, MEM_LOCATION
Initialize these strings per platform
*/
#ifndef COMPILER_VERSION
#ifndef COMPILER_VERSION
#ifdef __GNUC__
#define COMPILER_VERSION "GCC"__VERSION__
#else
#define COMPILER_VERSION "Please put compiler version here (e.g. gcc 4.1)"
#endif
#endif
#ifndef COMPILER_FLAGS
#ifndef COMPILER_FLAGS
#define COMPILER_FLAGS FLAGS_STR /* "Please put compiler flags here (e.g. -o3)" */
#endif
#ifndef MEM_LOCATION
#ifndef MEM_LOCATION
#define MEM_LOCATION "STACK"
#endif

/* Data Types :
To avoid compiler issues, define the data types that need ot be used for 8b, 16b and 32b in <core_portme.h>.
*Imprtant* :
ee_ptr_int needs to be the data type used to hold pointers, otherwise coremark may fail!!!
*/
Expand All @@ -85,7 +85,7 @@ typedef unsigned short ee_u16;
typedef signed int ee_s32;
typedef double ee_f32;
typedef unsigned char ee_u8;
typedef unsigned int ee_u32;
typedef signed int ee_u32;
typedef signed long ee_u64;
#if __riscv_xlen == 32
typedef ee_u32 ee_ptr_int;
Expand All @@ -102,12 +102,12 @@ typedef signed int ee_size_t;
/* Configuration : CORE_TICKS
Define type of return from the timing functions.
*/
#define CORETIMETYPE ee_u32
#define CORETIMETYPE ee_u32
typedef ee_u32 CORE_TICKS;

/* Configuration : SEED_METHOD
Defines method to get seed values that cannot be computed at compile time.
Valid values :
SEED_ARG - from command line.
SEED_FUNC - from a system function.
Expand All @@ -119,7 +119,7 @@ typedef ee_u32 CORE_TICKS;

/* Configuration : MEM_METHOD
Defines method to get a block of memry.
Valid values :
MEM_MALLOC - for platforms that implement malloc and have malloc.h.
MEM_STATIC - to use a static memory array.
Expand All @@ -130,19 +130,19 @@ typedef ee_u32 CORE_TICKS;
#endif

/* Configuration : MULTITHREAD
Define for parallel execution
Define for parallel execution
Valid values :
1 - only one context (default).
N>1 - will execute N copies in parallel.
Note :
Note :
If this flag is defined to more then 1, an implementation for launching parallel contexts must be defined.
Two sample implementations are provided. Use <USE_PTHREAD> or <USE_FORK> to enable them.
It is valid to have a different implementation of <core_start_parallel> and <core_end_parallel> in <core_portme.c>,
to fit a particular architecture.
to fit a particular architecture.
*/
#ifndef MULTITHREAD
#define MULTITHREAD 1
Expand All @@ -152,22 +152,22 @@ typedef ee_u32 CORE_TICKS;
#endif

/* Configuration : MAIN_HAS_NOARGC
Needed if platform does not support getting arguments to main.
Needed if platform does not support getting arguments to main.
Valid values :
0 - argc/argv to main is supported
1 - argc/argv to main is not supported
Note :
Note :
This flag only matters if MULTITHREAD has been defined to a value greater then 1.
*/
#ifndef MAIN_HAS_NOARGC
#ifndef MAIN_HAS_NOARGC
#define MAIN_HAS_NOARGC 0
#endif

/* Configuration : MAIN_HAS_NORETURN
Needed if platform does not support returning a value from main.
Needed if platform does not support returning a value from main.
Valid values :
0 - main returns an int, and return value will be 0.
1 - platform does not support returning a value from main
Expand Down Expand Up @@ -201,4 +201,5 @@ void portable_fini(core_portable *p);

int ee_printf(const char *fmt, ...);

extern int metal_timer_get_timebase_frequency(int hartid, unsigned long long *timebase);
#endif /* CORE_PORTME_H */
12 changes: 6 additions & 6 deletions freedom-metal/core_portme.mak
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Original Author: Shay Gal-on

#File : core_portme.mak
Expand All @@ -26,23 +26,23 @@ OUTFLAG= -o
#CC = gcc
# Flag : LD
# Use this flag to define compiler to use
#LD =
#LD =
# Flag : AS
# Use this flag to define compiler to use
#AS = gas
# Flag : CFLAGS
# Use this flag to define compiler options. Note, you can add compiler options from the command line using XCFLAGS="other flags"
PORT_CFLAGS = -specs=nano.specs -O3 -DITERATIONS=10000 -DPERFORMANCE_RUN=1 -DMAIN_HAS_NOARGC=1 -DMAIN_HAS_NORETURN=1 -DHAS_STDIO -DHAS_PRINTF -DHAS_TIME_H -DUSE_CLOCK
PORT_CFLAGS = -O3 -DITERATIONS=3000 -DPERFORMANCE_RUN=1 -DMAIN_HAS_NOARGC=1 -DMAIN_HAS_NORETURN=1 -DHAS_STDIO -DHAS_PRINTF -DHAS_TIME_H -DUSE_CLOCK
FLAGS_STR = "$(PORT_CFLAGS) $(XCFLAGS) $(XLFLAGS) $(LFLAGS_END)"
override CFLAGS += $(PORT_CFLAGS) -I$(PORT_DIR) -I. -DFLAGS_STR=\"$(FLAGS_STR)\" -Xlinker --defsym=__stack_size=0x1000
#Flag : LFLAGS_END
# Define any libraries needed for linking or other flags that should come at the end of the link line (e.g. linker scripts).
# Define any libraries needed for linking or other flags that should come at the end of the link line (e.g. linker scripts).
# Note : On certain platforms, the default clock_gettime implementation is supported but requires linking of librt.
SEPARATE_COMPILE =
# Flag : SEPARATE_COMPILE
# You must also define below how to create an object file, and how to link.
OBJOUT = -o
LFLAGS =
LFLAGS =
ASFLAGS =
OFLAG = -o
COUT = -c
Expand Down Expand Up @@ -80,7 +80,7 @@ $(OPATH)$(PORT_DIR)/%$(OEXT) : %.s
# For the purpose of this simple port, no pre or post steps needed.

.PHONY : port_prebuild port_postbuild port_prerun port_postrun port_preload port_postload
port_pre% port_post% :
port_pre% port_post% :

# FLAG : OPATH
# Path to the output folder. Default - current folder.
Expand Down

0 comments on commit c181806

Please sign in to comment.