From: Matt Birkholz Date: Sat, 25 Jul 2015 21:48:11 +0000 (-0700) Subject: Make the interpreter's state thread-local. X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=67d18a54f363b632d079e9b92d19968ab7f4323a;p=mit-scheme.git Make the interpreter's state thread-local. Pull the initialization of the affected variables into a new initialize_processor_early function and call it in both main and the co-processors' "work" function. Still, stack_pointer, Free and Registers are not yet thread-local. Such declarations would be in conflict with the x86_64 assembly code. --- diff --git a/src/microcode/boot.c b/src/microcode/boot.c index 59ba6c643..ddb03fe5c 100644 --- a/src/microcode/boot.c +++ b/src/microcode/boot.c @@ -54,15 +54,16 @@ extern SCHEME_OBJECT make_microcode_identification_vector (void); # define HOOK_ENTER_INTERPRETER(func) func () #endif +extern void initialize_processor_early (void); static void start_scheme (void); static void Enter_Interpreter (void); const char * scheme_program_name; const char * OS_Name; const char * OS_Variant; -struct obstack scratch_obstack; -struct obstack ffi_obstack; -void * initial_C_stack_pointer; +__thread struct obstack scratch_obstack; +__thread struct obstack ffi_obstack; +static void * initial_C_stack_pointer; static char * reload_saved_string; static unsigned int reload_saved_string_length; @@ -108,10 +109,8 @@ main_name (int argc, const char ** argv) #ifdef __OS2__ OS2_initialize_early (); #endif - obstack_init (&scratch_obstack); - obstack_init (&ffi_obstack); - dstack_initialize (); - transaction_initialize (); + initialize_processor_early (); + reload_saved_string = 0; reload_saved_string_length = 0; read_command_line_options (argc, argv); @@ -141,6 +140,15 @@ main_name (int argc, const char ** argv) termination_init_error (); return (0); } + +void +initialize_processor_early (void) +{ + obstack_init (&scratch_obstack); + obstack_init (&ffi_obstack); + dstack_initialize (); + transaction_initialize (); +} /* Boot Scheme */ diff --git a/src/microcode/critsec.h b/src/microcode/critsec.h index 5743698b9..806913b6e 100644 --- a/src/microcode/critsec.h +++ b/src/microcode/critsec.h @@ -31,14 +31,14 @@ USA. #ifndef SCM_CRITSEC_H #define SCM_CRITSEC_H 1 -extern const char * critical_section_name; -extern bool critical_section_hook_p; -extern void (*critical_section_hook) (const char *); +extern __thread const char * critical_section_name; +extern __thread bool critical_section_hook_p; +extern __thread void (*critical_section_hook) (const char *); #define DECLARE_CRITICAL_SECTION() \ - const char * critical_section_name = 0; \ - bool critical_section_hook_p; \ - void (*critical_section_hook) (const char *) + __thread const char * critical_section_name = 0; \ + __thread bool critical_section_hook_p; \ + __thread void (*critical_section_hook) (const char *) #define ENTER_CRITICAL_SECTION(name) critical_section_name = (name) #define RENAME_CRITICAL_SECTION(name) critical_section_name = (name) diff --git a/src/microcode/dstack.h b/src/microcode/dstack.h index 1fb3061ef..23af453da 100644 --- a/src/microcode/dstack.h +++ b/src/microcode/dstack.h @@ -54,7 +54,7 @@ extern void dstack_alloc_and_protect initialize that space, and create an unwind protection frame that invokes `protector' when the stack is unwound. */ -extern void * dstack_position; +extern __thread void * dstack_position; /* The current stack pointer. */ extern void dstack_set_position (void * position); diff --git a/src/microcode/extern.h b/src/microcode/extern.h index 7ea08cdd1..c944954d8 100644 --- a/src/microcode/extern.h +++ b/src/microcode/extern.h @@ -139,10 +139,10 @@ extern void set_ulong_register (unsigned int, unsigned long); #endif extern SCHEME_OBJECT * Free; -extern SCHEME_OBJECT * Free_primitive; -extern SCHEME_OBJECT * heap_alloc_limit; -extern SCHEME_OBJECT * heap_start; -extern SCHEME_OBJECT * heap_end; +extern __thread SCHEME_OBJECT * Free_primitive; +extern __thread SCHEME_OBJECT * heap_alloc_limit; +extern __thread SCHEME_OBJECT * heap_start; +extern __thread SCHEME_OBJECT * heap_end; #ifdef ENABLE_SMP extern SCHEME_OBJECT * p0_heap_start; extern SCHEME_OBJECT * shared_heap_start; @@ -151,9 +151,9 @@ extern SCHEME_OBJECT * shared_heap_end; #endif extern SCHEME_OBJECT * stack_pointer; -extern SCHEME_OBJECT * stack_guard; -extern SCHEME_OBJECT * stack_start; -extern SCHEME_OBJECT * stack_end; +extern __thread SCHEME_OBJECT * stack_guard; +extern __thread SCHEME_OBJECT * stack_start; +extern __thread SCHEME_OBJECT * stack_end; extern SCHEME_OBJECT * constant_alloc_next; extern SCHEME_OBJECT * constant_start; @@ -161,7 +161,7 @@ extern SCHEME_OBJECT * constant_end; /* Address of the most recent return code in the stack. This is only meaningful while in compiled code. */ -extern SCHEME_OBJECT * last_return_code; +extern __thread SCHEME_OBJECT * last_return_code; extern SCHEME_OBJECT fixed_objects; extern SCHEME_OBJECT ephemeron_array; @@ -183,13 +183,13 @@ extern const char * term_messages []; extern const char * term_halt_messages []; extern const char * fixed_objects_names []; -extern bool trapping; +extern __thread bool trapping; extern const char * scheme_program_name; extern const char * OS_Name; extern const char * OS_Variant; -extern struct obstack scratch_obstack; -extern struct obstack ffi_obstack; +extern __thread struct obstack scratch_obstack; +extern __thread struct obstack ffi_obstack; extern SCHEME_OBJECT * memory_block_start; extern SCHEME_OBJECT * memory_block_end; diff --git a/src/microcode/floenv.c b/src/microcode/floenv.c index 226d4eec9..95ef02fdf 100644 --- a/src/microcode/floenv.c +++ b/src/microcode/floenv.c @@ -56,8 +56,8 @@ typedef char fenv_t; typedef char fexcept_t; #endif -static bool scheme_fenv_p = false; -static fenv_t scheme_fenv; +static __thread bool scheme_fenv_p = false; +static __thread fenv_t scheme_fenv; static void cache_float_environment (void) diff --git a/src/microcode/history.h b/src/microcode/history.h index ba175643b..bf126b40e 100644 --- a/src/microcode/history.h +++ b/src/microcode/history.h @@ -75,8 +75,8 @@ USA. # define COMPILER_END_SUBPROBLEM() do {} while (false) #endif -extern SCHEME_OBJECT * history_register; -extern unsigned long prev_restore_history_offset; +extern __thread SCHEME_OBJECT * history_register; +extern __thread unsigned long prev_restore_history_offset; extern void reset_history (void); extern SCHEME_OBJECT * make_dummy_history (void); diff --git a/src/microcode/interp.c b/src/microcode/interp.c index 420bb0d12..89759cbd9 100644 --- a/src/microcode/interp.c +++ b/src/microcode/interp.c @@ -196,7 +196,7 @@ extern void fixup_float_environment (void); /* The EVAL/APPLY yin/yang */ -interpreter_state_t interpreter_state = NULL_INTERPRETER_STATE; +__thread interpreter_state_t interpreter_state = NULL_INTERPRETER_STATE; void bind_interpreter_state (interpreter_state_t s) @@ -250,7 +250,7 @@ abort_to_interpreter_argument (void) return (interpreter_throw_argument); } -long prim_apply_error_code; +__thread long prim_apply_error_code; void Interpret (int pop_return_p) diff --git a/src/microcode/interp.h b/src/microcode/interp.h index 6cbbc25f9..b072fdbdc 100644 --- a/src/microcode/interp.h +++ b/src/microcode/interp.h @@ -155,8 +155,8 @@ struct interpreter_state_s extern void abort_to_interpreter (int) NORETURN; extern int abort_to_interpreter_argument (void); -extern interpreter_state_t interpreter_state; -extern long prim_apply_error_code; +extern __thread interpreter_state_t interpreter_state; +extern __thread long prim_apply_error_code; extern void bind_interpreter_state (interpreter_state_t); extern void unbind_interpreter_state (interpreter_state_t); diff --git a/src/microcode/prossmp.c b/src/microcode/prossmp.c index 6bb134a32..c0dc5cf10 100644 --- a/src/microcode/prossmp.c +++ b/src/microcode/prossmp.c @@ -193,6 +193,8 @@ setup_processors (int count) RESET_HISTORY (); } +extern void initialize_processor_early (void); + static void * work (void *p) { @@ -201,6 +203,7 @@ work (void *p) trace (";%d Start.", self->id); assert (self->id != 0); assert (self != processors); + initialize_processor_early (); reset_processor_allocator (self); RESET_HISTORY (); diff --git a/src/microcode/storage.c b/src/microcode/storage.c index dec79782c..3a8c119d1 100644 --- a/src/microcode/storage.c +++ b/src/microcode/storage.c @@ -36,10 +36,10 @@ USA. SCHEME_OBJECT * Free; /* value of Free on entry to primitive, or 0 if not in primitive */ -SCHEME_OBJECT * Free_primitive = 0; +__thread SCHEME_OBJECT * Free_primitive = 0; /* strict limit for Free */ -SCHEME_OBJECT * heap_alloc_limit; +__thread SCHEME_OBJECT * heap_alloc_limit; #ifdef ENABLE_SMP /* the start of From space */ @@ -54,18 +54,18 @@ SCHEME_OBJECT * shared_heap_free; #endif /* limits of local heap */ -SCHEME_OBJECT * heap_start; -SCHEME_OBJECT * heap_end; +__thread SCHEME_OBJECT * heap_start; +__thread SCHEME_OBJECT * heap_end; /* pointer to most-recently pushed item */ SCHEME_OBJECT * stack_pointer; /*-strict limit for stack_pointer */ -SCHEME_OBJECT * stack_guard; +__thread SCHEME_OBJECT * stack_guard; /* limits of stack */ -SCHEME_OBJECT * stack_start; -SCHEME_OBJECT * stack_end; +__thread SCHEME_OBJECT * stack_start; +__thread SCHEME_OBJECT * stack_end; /* next free word in constant space */ SCHEME_OBJECT * constant_alloc_next; @@ -76,7 +76,7 @@ SCHEME_OBJECT * constant_end; /* Address of the most recent return code in the stack. This is only meaningful while in compiled code. */ -SCHEME_OBJECT * last_return_code; +__thread SCHEME_OBJECT * last_return_code; SCHEME_OBJECT fixed_objects; @@ -87,7 +87,7 @@ SCHEME_OBJECT fixed_objects; SCHEME_OBJECT ephemeron_array = SHARP_F; unsigned long ephemeron_count = 0; -bool trapping; +__thread bool trapping; SCHEME_OBJECT * memory_block_start; SCHEME_OBJECT * memory_block_end; diff --git a/src/microcode/transact.c b/src/microcode/transact.c index d4452426d..207284698 100644 --- a/src/microcode/transact.c +++ b/src/microcode/transact.c @@ -46,7 +46,7 @@ struct transaction enum transaction_state state; }; -static struct transaction * current_transaction; +static __thread struct transaction * current_transaction; static void guarantee_current_transaction (const char * proc) diff --git a/src/microcode/utils.c b/src/microcode/utils.c index 5099ffb1b..10f42268f 100644 --- a/src/microcode/utils.c +++ b/src/microcode/utils.c @@ -35,8 +35,8 @@ USA. extern void OS2_handle_attention_interrupt (void); #endif -SCHEME_OBJECT * history_register; -unsigned long prev_restore_history_offset; +__thread SCHEME_OBJECT * history_register; +__thread unsigned long prev_restore_history_offset; static SCHEME_OBJECT copy_history (SCHEME_OBJECT); static void error_death (long, const char *) NORETURN; @@ -956,8 +956,8 @@ C_call_scheme (SCHEME_OBJECT proc, SCHEME_OBJECT * callers_last_return_code; #ifdef CC_IS_NATIVE - extern void * C_Frame_Pointer; - extern void * C_Stack_Pointer; + extern __thread void * C_Frame_Pointer; + extern __thread void * C_Stack_Pointer; void * cfp = C_Frame_Pointer; void * csp = C_Stack_Pointer; #ifdef CL386 diff --git a/src/microcode/wind.c b/src/microcode/wind.c index 2aa1c0360..098a26224 100644 --- a/src/microcode/wind.c +++ b/src/microcode/wind.c @@ -52,9 +52,9 @@ struct winding_record void * environment; }; -static struct obstack dstack; -static struct winding_record * current_winding_record; -void * dstack_position; +static __thread struct obstack dstack; +static __thread struct winding_record * current_winding_record; +__thread void * dstack_position; void dstack_initialize (void)