From a14e93cde6466b1d274c66aeb7ce7372b8fe07de Mon Sep 17 00:00:00 2001 From: Matt Birkholz Date: Sat, 20 Dec 2014 12:08:15 -0700 Subject: [PATCH] smp: share: storage.o --- README.txt | 127 +++++++++++++++++++++++----------------- src/microcode/extern.h | 12 ++-- src/microcode/memmag.c | 19 +++++- src/microcode/purify.c | 2 +- src/microcode/storage.c | 12 ++-- 5 files changed, 103 insertions(+), 69 deletions(-) diff --git a/README.txt b/README.txt index 132e880cc..842de1e32 100644 --- a/README.txt +++ b/README.txt @@ -466,61 +466,80 @@ command line. The remaining 12 belong to the 7 microcode modules and step.o: storage.o: - 000002a0 D Abort_Names - 00000015 B Bignum_Debug - 00000004 D CONT_PRINT_EXPR_MESSAGE - 00000000 D CONT_PRINT_RETURN_MESSAGE - 0000000d B Cont_Debug - 00000010 B Define_Debug - 00000013 B Dump_Debug - 000002e0 D Error_Names - 00000008 B Eval_Debug - 0000000a B File_Load_Debug - 00000000 B Free_primitive - 00000011 B GC_Debug - 00000009 B Hex_Input_Debug - 0000000c B Intern_Debug - 0000000f B Lookup_Debug - 00000010 D MAX_RETURN - 00000016 B Per_File - 0000000e B Primitive_Debug - 0000000c D RESTORE_CONT_EXPR_MESSAGE - 00000008 D RESTORE_CONT_RETURN_MESSAGE - 0000000b B Reloc_Debug - 00000020 D Return_Names - 000003e0 D Term_Names - 00000014 B Trace_On_Error - 00000012 B Upgrade_Debug - 00000004 C constant_alloc_next - 00000004 C constant_end - 00000004 C constant_start - 00000190 C debug_circle - 0000001c B debug_nslots - 00000018 B debug_slotno - 00000000 B ephemeron_array - 00000004 B ephemeron_count - 00000001 C ephemeron_request_hard_p + 000002a0 D Abort_Names read-only + 00000015 B Bignum_Debug gdb + 00000004 D CONT_PRINT_EXPR_MESSAGE read-only + 00000000 D CONT_PRINT_RETURN_MESSAGE read-only + 0000000d B Cont_Debug gdb + 00000010 B Define_Debug gdb + 00000013 B Dump_Debug gdb + 000002e0 D Error_Names read-only + 00000008 B Eval_Debug gdb + 0000000a B File_Load_Debug gdb + 00000000 B Free_primitive __thread + 00000011 B GC_Debug gdb + 00000009 B Hex_Input_Debug gdb + 0000000c B Intern_Debug gdb + 0000000f B Lookup_Debug gdb + 00000010 D MAX_RETURN read-only + 00000016 B Per_File gdb + 0000000e B Primitive_Debug gdb + 0000000c D RESTORE_CONT_EXPR_MESSAGE read-only + 00000008 D RESTORE_CONT_RETURN_MESSAGE read-only + 0000000b B Reloc_Debug gdb + 00000020 D Return_Names read-only + 000003e0 D Term_Names read-only + 00000014 B Trace_On_Error gdb + 00000012 B Upgrade_Debug gdb + 00000004 C constant_alloc_next gc-wait + 00000004 C constant_end gc-wait + 00000004 C constant_start gc-wait + 00000190 C debug_circle __thread + 0000001c B debug_nslots __thread + 00000018 B debug_slotno __thread + 00000000 B ephemeron_array gc-wait, locked + 00000004 B ephemeron_count gc-wait, locked + 00000001 C ephemeron_request_hard_p gc-wait, locked 00000004 C fixed_objects - 000004e0 D fixed_objects_names - 00000018 B gc_shared_space_needed - 00000014 B gc_space_needed - 00000004 C heap_reserved - 00000004 B heap_start - 0000000c B last_return_code - 00000190 C local_circle - 00000024 B local_nslots - 00000020 B local_slotno - 00000004 C memory_block_end - 00000004 C memory_block_start - 00000004 C n_ephemerons_requested - 00000004 C p0_heap_start - 00000004 C shared_heap_end - 00000004 C shared_heap_free - 00000004 C shared_heap_start - 00000008 B stack_end - 00000460 D term_messages - 00000010 B trapping - 000001a0 D type_names + 000004e0 D fixed_objects_names read-only + 00000018 B gc_shared_space_needed __thread + 00000014 B gc_space_needed __thread + 00000004 C heap_reserved gc-wait + 00000004 B heap_start __thread + 0000000c B last_return_code __thread + 00000190 C local_circle __thread + 00000024 B local_nslots __thread + 00000020 B local_slotno __thread + 00000004 C memory_block_end read-only, init by ALLOCATE_HEAP_SPACE + 00000004 C memory_block_start read-only, init by ALLOCATE_HEAP_SPACE + 00000004 C n_ephemerons_requested gc-wait, locked + 00000004 C p0_heap_start read-only, reset_allocator_parameters + 00000004 C shared_heap_end read-only, reset_allocator_parameters + 00000004 C shared_heap_free gc-wait, locked + 00000004 C shared_heap_start read-only, reset_allocator_parameters + 00000008 B stack_end __thread + 00000460 D term_messages read-only + 00000010 B trapping __thread + 000001a0 D type_names read-only + + OK. Debugging flags apply to all processors(?). local_circle + is modified by EVAL_UCODE_HOOK and debug_circle is a copy made + in Do_Micro_Error. They and their associates are now thread- + local. + + Prim_make_ephemeron reserves space in the shared heap. It is + already guaranteed not to conflict with GC, but multiple + threads allocating ephemerons simultaneously could be a + problem. Thus use of Prim_make_ephemeron is serialized by a + mutex. + + fixed_objects is modified only by Prim_band_load or + Prim_set_fixed_objects_vector. Multiple threads hacking + fixed_objects should not happen. + + heap_reserved is initialized (reset) by reset_allocator_ + parameters and is modified only by Prim_garbage_collect and + Prim_primitive_purify. string.o: 00000000 b external_strings diff --git a/src/microcode/extern.h b/src/microcode/extern.h index 3df6fd8b8..6518f59fe 100644 --- a/src/microcode/extern.h +++ b/src/microcode/extern.h @@ -114,12 +114,12 @@ extern void set_ulong_register (unsigned int, unsigned long); extern bool verify_heap (void); extern void Pop_Return_Break_Point (void); - extern unsigned int debug_slotno; - extern unsigned int debug_nslots; - extern unsigned int local_slotno; - extern unsigned int local_nslots; - extern unsigned int debug_circle []; - extern unsigned int local_circle []; + extern __thread unsigned int debug_slotno; + extern __thread unsigned int debug_nslots; + extern __thread unsigned int local_slotno; + extern __thread unsigned int local_nslots; + extern __thread unsigned int debug_circle []; + extern __thread unsigned int local_circle []; #else # define Eval_Debug 0 # define Hex_Input_Debug 0 diff --git a/src/microcode/memmag.c b/src/microcode/memmag.c index 01a68fdf7..438017433 100644 --- a/src/microcode/memmag.c +++ b/src/microcode/memmag.c @@ -74,6 +74,10 @@ unsigned long saved_stack_size; #ifdef ENABLE_SMP int saved_processor_count; unsigned long saved_processor_heap_size; +static pthread_mutex_t mutex = MUTEX_INITIALIZER; +# ifdef ENABLE_DEBUGGING_TOOLS +static bool locked_p = false; +# endif #endif static gc_tospace_allocator_t allocate_tospace; @@ -434,6 +438,7 @@ which is the number of reserved words at the top of the heap, to\n\ SAFETY-MARGIN, which must be a non-negative integer. Finally, runs\n\ the primitive GC daemons before returning.") { + unsigned long safety_margin = 0; PRIMITIVE_HEADER (1); canonicalize_primitive_context (); @@ -455,8 +460,7 @@ the primitive GC daemons before returning.") if ((ARG_HEAP_RESERVED (1)) < (heap_end - heap_start)) { - heap_reserved = (ARG_HEAP_RESERVED (1)); - heap_alloc_limit = (heap_end - heap_reserved); + safety_margin = (ARG_HEAP_RESERVED (1)); } POP_PRIMITIVE_FRAME (1); @@ -483,6 +487,12 @@ the primitive GC daemons before returning.") #endif /* ENABLE_SMP */ + if (safety_margin) + { + heap_reserved = safety_margin; + heap_alloc_limit = (heap_end - heap_reserved); + } + initialize_weak_chain (); ephemeron_count = 0; @@ -718,6 +728,7 @@ compute_extra_ephemeron_space (unsigned long n) void guarantee_extra_ephemeron_space (unsigned long n) { + LOCK(); ephemeron_count = n; if (!ephemeron_array_big_enough_p (n)) { @@ -725,6 +736,7 @@ guarantee_extra_ephemeron_space (unsigned long n) assert (SHARED_HEAP_AVAILABLE_P (VECTOR_DATA + length)); ephemeron_array = make_ephemeron_vector (length); } + UNLOCK(); } static void @@ -744,6 +756,7 @@ gc_if_needed_for_ephemeron (unsigned long table_space) { n_ephemerons_requested = 1; ephemeron_request_hard_p = true; + UNLOCK(); Primitive_GC (EPHEMERON_SIZE); } #endif @@ -752,6 +765,7 @@ gc_if_needed_for_ephemeron (unsigned long table_space) DEFINE_PRIMITIVE ("MAKE-EPHEMERON", Prim_make_ephemeron, 2, 2, 0) { PRIMITIVE_HEADER (2); + LOCK(); ephemeron_count += 1; if (ephemeron_array_big_enough_p (ephemeron_count)) gc_if_needed_for_ephemeron (0); @@ -770,6 +784,7 @@ DEFINE_PRIMITIVE ("MAKE-EPHEMERON", Prim_make_ephemeron, 2, 2, 0) (*Free++) = SHARP_F; /* list */ (*Free++) = SHARP_F; /* queue */ assert ((Free - addr) == EPHEMERON_SIZE); + UNLOCK(); PRIMITIVE_RETURN (MAKE_POINTER_OBJECT (TC_EPHEMERON, addr)); } } diff --git a/src/microcode/purify.c b/src/microcode/purify.c index e4d6c11ae..19f058428 100644 --- a/src/microcode/purify.c +++ b/src/microcode/purify.c @@ -67,8 +67,8 @@ PURE? is ignored.") POP_PRIMITIVE_FRAME (3); ENTER_CRITICAL_SECTION ("purify"); - heap_reserved = safety_margin; SMP_GC_START (); + heap_reserved = safety_margin; purify (object); Will_Push (CONTINUATION_SIZE); diff --git a/src/microcode/storage.c b/src/microcode/storage.c index e1d453888..5e5e0308d 100644 --- a/src/microcode/storage.c +++ b/src/microcode/storage.c @@ -136,12 +136,12 @@ bool ephemeron_request_hard_p; bool Trace_On_Error = false; bool Bignum_Debug = false; bool Per_File = false; - unsigned int debug_slotno = 0; - unsigned int debug_nslots = 0; - unsigned int local_slotno = 0; - unsigned int local_nslots = 0; - unsigned int debug_circle [100]; - unsigned int local_circle [100]; + __thread unsigned int debug_slotno = 0; + __thread unsigned int debug_nslots = 0; + __thread unsigned int local_slotno = 0; + __thread unsigned int local_nslots = 0; + __thread unsigned int debug_circle [100]; + __thread unsigned int local_circle [100]; #endif const char * CONT_PRINT_RETURN_MESSAGE = "SAVE_CONT, return code"; -- 2.25.1