310 likes | 474 Views
Allegro CL 9.0 Internals. Duane Rettig ILC 2012. Overview. SMP Design Internals Fasl reader rewrite in Lisp Debugger Enhancements. SMP design goals. Low Overhead for scalar operation Source Compatible Warnings for unsafe usage Tools for smp enhanced programming. SMP: Goal Realization.
E N D
Allegro CL 9.0 Internals • Duane Rettig • ILC 2012
Overview • SMP Design Internals • Fasl reader rewrite in Lisp • Debugger Enhancements
SMP design goals • Low Overhead for scalar operation • Source Compatible • Warnings for unsafe usage • Tools for smp enhanced programming
SMP: Goal Realization • Low Overhead • 9.0 (non-smp) virtually the same as 8.2 • SMP has <10% hit over non-smp (sometimes faster) • Other lisps have 15%-100% hit over 8.2 • (YMMV)
SMP: Goal Realization • Source Compatible: Success • Exceptions: • hash-tables • threads • 4 new smp runtime-lisp files (compare 28 for new port)
SMP: Goal realization • Warnings for unsafe usage • smp-macros module (8.1 patch, integral in 8.2) • not aggressive in looking for problems • setf races • potential deadlocks • alists (but plists/getf are protected by convention)
SMP: goal realization • Tools for enhanced SMP programming • synchronizing operators and locks • Separate GC
SMP: implementation • Deprecation of SMP-unsafe Macros • New macros • Bindability and settability of specials • synchronization operators • GC
SMP: implementationS • Deprecated smp-unsafe macros • without-interrupts, without-scheduling • excl::fast / excl::atomically • excl::*warn-smp-usage*
SMP: Implementation • New Macros • fast-and-clean: replaces (excl::fast (excl::atomically ...)) • with-pinned-objects: replaces (excl::fast (excl::atomically ...)) • with-delayed-interrupts: replaces without-{interrupts,scheduling} • defvar-nonbindable
SMP:Implementation • Bindability and Settability • bindable, settable: defvar/defparameter • not bindable, settable: defvar-nonbindable • bindable, not settable: excl::defvar-nonsettable • not bindable, not settable: defconstant
SMP:implementationold 8.1wide binding symbol symbol locatives tag=2/type=#x70 tag=type=#xb sv-vector tag=2/type=#x70
SMP:implementationnew wide binding symbol symbol locatives tag=#xb/type=#x8b tag=type=#xb sv-vector tag=2/type=#x85
smp: implementation • Synchronization operators • push-atomic/pop-atomic • incf-atomic/decf-atomic • update-atomic • atomic-conditional-setf (implementor for above) • atomic-conditional-setq (special operator)
smp: implementation • Lower level smp operators • get-atomic-modify-expansion • excl::atomic-modify-form (may change!) • excl::*force-csw-opcodes* (may change!) • excl::defsetf-conditional (may change!)
SMP: implementation • excl::defsetf-conditional built-in operator conversions • excl::.inv-structure-ref • excl::.inv-svref • excl::.inv-car, excl::.inv-cdr • excl::.inv-symbol-plist • excl::.inv-global-symbol-value
SMP: implementation • Lowest level operators • gc-setf-protect-atomic • ll :cas low-level instruction form
SMP: implementation • with-locked-object • good on any lockable object • lighter weight than process-lock • use with care to avoid deadlocks • special versions for structs and streams
SMP: implementation • Other higher-level synchronizing tools • sharable-locks • barriers • queues (uses process-lock; with-locked-object is lighter weight) • condition-variables
SMP Implementation: gc • Runs in separate (non-Lisp) thread • Able to provide per-thread object allocation • Currently implemented: • conses: everywhere • floats: on x86-64 • Synchronizes with all threads • Still written in C
GC states • 0: Lisping: thread is running Lisp code; GC can’t happen • 1: Foreign: thread is running foreign code; GC can happen • 2: Blocking GC: thread is running Lisp code; GC wants it to pause • 3: Blocked by GC: thread is trying to get from foreign to Lisp; GC is running • 4: Beside GC: thread is running foreign code and GC is happening
thread goes foreign GC state diagram thread goes lisping GC Done (post thread) thread invokes GC GC Starting GC Done (thread waits) thread goes lisping GC Starting (signal thread:GC waits) thread invokes GC (thread waits) (thread waits) thread goes foreign (post gc) 22
Fasl Reader • Rewritten in Lisp runtime code • 50% faster than C version • fewer transitions to/from C • Started in 8.2; used only to load source debug info • Used exclusively in 9.0
Fasl coding example C: case ff_complex: /* tos = imag, tos-1 = real */ if (Building_BOTH) { LispVal comp = new_lisp_obj(TYPEcomplex, 0, 0); /* complex object is new */ *(nat *)((nat)comp + c_imag_adj/PtrScale) = (nat)f_pop(); *(nat *)((nat)comp + c_real_adj/PtrScale) = (nat)f_pop(); f_push(comp); } break; Lisp: (#.ff_complex (when (building-both) (let* ((imag (fasl-pop thread)) (real (fasl-pop thread)) (complex (q-qint-call sys::make-complex real imag))) (fasl-push complex thread)))) 24
DEBugger enhancements • frame descriptor caching and validation • source level debugger
Debugger: reimplementation of Api • db:next-newer-frame hard to implement • Always moving! • either cached frames become invalid or have to start over each time • :zoom on overflowed stack takes much too long
Frame descriptors • Frame-descriptors are now larger • newer, older, chain slots • validated via interlock with their real frames. • frame descriptor has argcount shadow slot
frames Stack Frame descrptor
Frame descriptors • db:next-newer-frame is no longer programming suicide!
source level debugger • Demo