From: Matt Birkholz Date: Sun, 19 Jul 2015 05:47:38 +0000 (-0700) Subject: Initialize thread-local compiler_utilities. X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=da74a4fca049a46eb29bb4a63949d0f9d5a59746;p=mit-scheme.git Initialize thread-local compiler_utilities. Split the thread-local parts of compiler_initialize into compiler_initialize_processor, those of compiler_reset into compiler_reset_processor. Split the non-thread-local parts of ASM_RESET_HOOK into ASM_INIT_HOOK. Call the _processor versions in co-processor startup and after GC waits (when necessary). Add compiler_reset_p flag to processor_t so that load-band (compiler_reset) can notify the other processors to load the new compiler_utilities into their Registers slots. --- diff --git a/src/microcode/cmpint.c b/src/microcode/cmpint.c index 90a910922..1c06ce384 100644 --- a/src/microcode/cmpint.c +++ b/src/microcode/cmpint.c @@ -254,6 +254,9 @@ long C_return_value; SCHEME_OBJECT Registers [REGBLOCK_LENGTH]; #endif +#ifndef ASM_INIT_HOOK +# define ASM_INIT_HOOK() do {} while (false) +#endif #ifndef ASM_RESET_HOOK # define ASM_RESET_HOOK() do {} while (false) #endif @@ -287,6 +290,13 @@ long C_return_value; /* Initialization */ +void +compiler_initialize_processor (void) +{ + assert (compiler_utilities != SHARP_F); + compiler_reset_processor (); +} + void compiler_initialize (bool fasl_p) { @@ -356,6 +366,17 @@ make_compiler_utilities (void) return (MAKE_CC_BLOCK (block)); } +void +compiler_reset_processor (void) +{ + SET_PRIMITIVE (SHARP_F); + SET_CLOSURE_FREE (0); + SET_CLOSURE_SPACE (0); + SET_REFLECTOR (reflect_to_interface); + + ASM_RESET_HOOK (); +} + void compiler_reset (SCHEME_OBJECT new_block) { @@ -381,11 +402,20 @@ compiler_reset (SCHEME_OBJECT new_block) compiler_utilities = new_block; return_to_interpreter = (MAKE_CC_ENTRY (trampoline_entry_addr (nbp, 0))); reflect_to_interface = (MAKE_CC_ENTRY (trampoline_entry_addr (nbp, 1))); - SET_CLOSURE_FREE (0); - SET_CLOSURE_SPACE (0); - SET_REFLECTOR (reflect_to_interface); - ASM_RESET_HOOK (); + ASM_INIT_HOOK (); + + compiler_reset_processor (); +#ifdef ENABLE_SMP + { + processor_t *p; + for (p = processors; p != NULL; p = p->next) + { + if (p != self) + p->compiler_reset_p = true; + } + } +#endif } /* Main compiled-code entry points */ diff --git a/src/microcode/cmpint.h b/src/microcode/cmpint.h index adac7a7b8..a7c540b03 100644 --- a/src/microcode/cmpint.h +++ b/src/microcode/cmpint.h @@ -417,7 +417,9 @@ extern void compiled_with_interrupt_mask extern void compiled_with_stack_marker (SCHEME_OBJECT); extern void compiler_initialize (bool); +extern void compiler_initialize_processor (void); extern void compiler_reset (SCHEME_OBJECT); +extern void compiler_reset_processor (void); extern void declare_compiled_code_block (SCHEME_OBJECT); diff --git a/src/microcode/ossmp.h b/src/microcode/ossmp.h index 7f074a277..5471575cb 100644 --- a/src/microcode/ossmp.h +++ b/src/microcode/ossmp.h @@ -44,6 +44,8 @@ typedef struct processor processor_t; struct processor { struct processor *next; char id; + /* Set by compiler_reset (load-band) when there are new compiler utilities. */ + bool compiler_reset_p; processor_state_t state; pthread_t pthread; SCHEME_OBJECT * stack_end; diff --git a/src/microcode/prossmp.c b/src/microcode/prossmp.c index c65a08cf4..7725410c2 100644 --- a/src/microcode/prossmp.c +++ b/src/microcode/prossmp.c @@ -256,6 +256,7 @@ make_processors (int id) + id * saved_processor_heap_size); new->next = processors; new->id = id; + new->compiler_reset_p = false; new->state = PROCESSOR_NEW; new->stack_start = stack_start; new->stack_end = stack_start + saved_stack_size; @@ -332,6 +333,12 @@ gc_wait (void) cond_wait (&finished, &state_mutex); trace (";%d GC wait finished.", self->id); + if (self->compiler_reset_p) + { + compiler_reset_processor (); + self->compiler_reset_p = false; + } + assert (self->state == PROCESSOR_RUNNING); } @@ -468,6 +475,8 @@ Pause a new processor.") for band-load. */ } + compiler_initialize_processor (); + Will_Push (STACK_ENV_EXTRA_SLOTS + 1); STACK_PUSH (get_smp_idle_prim ()); PUSH_APPLY_FRAME_HEADER (0);