Skip to content

Commit

Permalink
Add new configure option --enable-threads=[yes|no] to control using m…
Browse files Browse the repository at this point in the history
…ulti thread or not.

 - Default is enable.
  • Loading branch information
kito-cheng committed Jan 21, 2019
1 parent a77db03 commit 26fe768
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 66 deletions.
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ instbasedir := $(DESTDIR)$(prefix)
bmarkdir := $(abs_top_src_dir)/benchmarks
isa_src_dir := $(abs_top_src_dir)/isa
debug_src_dir := $(abs_top_src_dir)/debug
enable_multi_threads := @MULTI_THREADS@

all: benchmarks isa

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ RISCV_LINK_OPTS ?= -static -nostdlib -nostartfiles -lm -lgcc -T $(src_dir)/commo
RISCV_OBJDUMP ?= $(RISCV_PREFIX)objdump --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.data
RISCV_SIM ?= spike --isa=rv$(XLEN)gc

incs += -I$(src_dir)/../env -I$(src_dir)/common $(addprefix -I$(src_dir)/, $(bmarks))
incs += -I$(src_dir)/../env -I$(src_dir)/common -I$(src_dir)/../ $(addprefix -I$(src_dir)/, $(bmarks))
objs :=

define compile_template
Expand Down
1 change: 1 addition & 0 deletions benchmarks/common/crt.S
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# See LICENSE for license details.

#include "encoding.h"
#include "config.h"

#if __riscv_xlen == 64
# define LREG ld
Expand Down
8 changes: 5 additions & 3 deletions benchmarks/common/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ int __attribute__((weak)) main(int argc, char** argv)

static void init_tls()
{
#if ENABLE_THREADS
register void* thread_pointer asm("tp");
extern char _tls_data;
extern __thread char _tdata_begin, _tdata_end, _tbss_end;
extern THREAD_LOCAL char _tdata_begin, _tdata_end, _tbss_end;
size_t tdata_size = &_tdata_end - &_tdata_begin;
memcpy(thread_pointer, &_tls_data, tdata_size);
size_t tbss_size = &_tbss_end - &_tdata_end;
memset(thread_pointer + tdata_size, 0, tbss_size);
#endif
}

void _init(int cid, int nc)
Expand All @@ -126,8 +128,8 @@ void _init(int cid, int nc)
#undef putchar
int putchar(int ch)
{
static __thread char buf[64] __attribute__((aligned(64)));
static __thread int buflen = 0;
static THREAD_LOCAL char buf[64] __attribute__((aligned(64)));
static THREAD_LOCAL int buflen = 0;

buf[buflen++] = ch;

Expand Down
13 changes: 12 additions & 1 deletion benchmarks/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@
extern void setStats(int enable);

#include <stdint.h>
#include "config.h"

#define static_assert(cond) switch(0) { case 0: case !!(long)(cond): ; }

#ifndef ENABLE_THREADS
#define ENABLE_THREADS 1
#endif

#if ENABLE_THREADS
#define THREAD_LOCAL __thread
#else
#define THREAD_LOCAL
#endif

static int verify(int n, const volatile int* test, const int* verify)
{
int i;
Expand Down Expand Up @@ -45,7 +56,7 @@ static void __attribute__((noinline)) barrier(int ncores)
{
static volatile int sense;
static volatile int count;
static __thread int threadsense;
static THREAD_LOCAL int threadsense;

__sync_synchronize();

Expand Down
22 changes: 22 additions & 0 deletions config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* config.in. Generated from configure.ac by autoheader. */

/* Define to 1 if you want to test with multi-thread. */
#undef ENABLE_THREADS

/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT

/* Define to the full name of this package. */
#undef PACKAGE_NAME

/* Define to the full name and version of this package. */
#undef PACKAGE_STRING

/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME

/* Define to the home page for this package. */
#undef PACKAGE_URL

/* Define to the version of this package. */
#undef PACKAGE_VERSION
Loading

0 comments on commit 26fe768

Please sign in to comment.