42
Overview and History of OpenMCL Commercial MCL was first released in 1987; ran on 1MB MacPlus (68K), rich IDE, GUI; fast compilation Acquired by Apple in 1989; transferred to Digitool in 1994 MCL ported to PPC Macintosh in ~1995

Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Overview and History ofOpenMCL

● Commercial MCL was first released in 1987;ran on 1MB MacPlus (68K), rich IDE, GUI;fast compilation

● Acquired by Apple in 1989; transferred toDigitool in 1994

● MCL ported to PPC Macintosh in ~1995

Page 2: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

History of OpenMCL

● Erann Gat of JPL wanted to develop a small-footprint Lisp for use in PPC embeddedsystems (rovers/robots, flight systems). Afterexploring other alternatives, MCL sourcelicense was acquired and MCL (sansGUI/IDE) was ported to VxWorks andLinuxPPC (which used the same ABI) in1998.

Page 3: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL at JPL

● Objections to use of Lisp within NASA/JPLwere perhaps based more on cultural thantechnical considerations (seehttp://flownet.com/gat/jpl-lisp.html).The port was discussed at AI conferencesand drew some interest, but JPL’s license didnot allow redistribution. This work was neverused in production systems.

Page 4: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL at Sandia

● In 2001, the Advanced Information SystemsLaboratory at Sandia National Labs, havingheard of the JPL port, expressed interest inusing it in their research. I was able topersuade Digitool to open-source the workthat had been done at JPL. A smallconsulting company formed by original MCLdevelopers hosts the open-source project athttp://openmcl.clozure.com/.

Page 5: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL History: 2001-2005

● Ported to OSX/Darwin (PPC).● Interface translation system (based on GCCfrontend.)

● Most of the (quasi-standard) MetaObjectProtocol (MOP)

● Native (preemptively-scheduled) threads● “Demo” Cocoa-based GUI/IDE● Ported to PPC64

Page 6: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Users

● Currently about 180 mailing list subscribers● Server logs suggest ~5 downloads a day● Most users seem to be using OpenMCLunder OSX/Darwin as opposed to LinuxPPC(~9:1). Linux version has had problems withNPTL and TLS, to be fixed in 0.14.4.

● A guess would be around 200-300 activeusers, but very hard to estimate

● -Probably- many more individual users thaninstitutional ones.

Page 7: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL History 2005-

● Apple’s x86 announcement● Handling of large objects in GC/EGC,handling of very large address spaces(especially on 64-bit platforms.)

● Better (e.g., “some”) lifetime analysis in thecompiler (reduce floating-point consing.)

● Metering/performance tools● Other funded work

Page 8: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL technology: GC

● OpenMCL’s GC is “precise” - the GC alwaysknows whether a “root’ (stack location ormachine register) contains a pointer to a lispobject or an immediate value. This enables itto reliably move objects (to improve locality,improve paging behavior, etc.)

Page 9: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL GC: precise vsconservative

● Precise GC (as opposed to “conservativeGC”) depends on cooperation from thecompiler and runtime system and strictadherence to register-usage conventions.

● “compiling to C” generally mandatesconservative GC.

● Register usage conventions are easier toenforce on machines that have registers.

Page 10: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL GC and threads

● For precise GC, register-usage conventionshave to be followed at any time that a GCcould occur.

● In general, native threads mean that a GCcould occur at any time (because of activityin some other thread.) See previous bullet.

● Current GC must stop other threads.

Page 11: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL GC and threads,continued.

● Newly allocated heap memory is zeroed(often by the OS.) Newly allocated stackmemory may contain random bits; stackallocation has to be done carefully in somecases.

● Some operations (consing) aren’t trulyatomic, but we pretend that they are: theruntime system can recognize these casesand ensure that an interrupted thread is in aconsistent state when the GC runs.

Page 12: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

GC Implementation Details

● Single-space GC, compacts in place● The (approximate) age of an object can bedetermined by its relative position in theheap.

● Old objects (generally) don't move; youngones generally do.

● “Ephemeral” GC depends on ability to detectthe (rare?) case when old objects aredestructively modified to point to new ones

Page 13: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

More OpenMCL GC Details

● Current releases use MMU write-protectionto implement the “write barrier” (invariantmentioned on previous slide.)

● Next release will use a software write barrier,and the runtime system understands how toensure atomicity and handle contention.

● Software write-barrier offers much bettergranularity (8/16 bytes vs 4K bytes)

Page 14: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

GC and Threads

● Threads allocate “segments” (~32KB),maintain current pointer in segment and lowlimit of segment in registers.

● Consing (allocating objects of known andsmall size) happens inline and takes about 6instructions (next slide).

● If thread X is interrupted while consing, theinterrupt-handling code completes or backsout of the instruction sequence.

Page 15: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Pseudocode for (SETQ X (CONSY Z))

● (allocptr <- (- allocptr (- cons-size cons-tag)))● (trap-if-less-than allocptr allocbase)● (rplaca allocptr y)● (rplacd allocptr z)● (x <- allocptr)● (allocptr <- clear-tag(allocptr))

Page 16: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Relocating GC implications

● Lisp object addresses can (generally) changeat any point in time.

● Hash tables that hash objects by identity(address) may need to rehash whenaddresses change due to GC activity

● Some hash table code needs to brieflydisable GC.

Page 17: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL: native threads vscooperative threads

● If N is the number of processors in a system,a program that uses more than N threadscan't (generally) run faster than one that usesN or fewer (though multithreaded programsmay be simpler to develop and maintain.)I.E, there is -some- context-switch andsynchronization overhead.

Page 18: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL threads: OSscheduling

● The OS ultimately decides how processorresources are allocated to threads andprocesses. Switching contexts between twothreads in the same process (address space)is generally cheaper than switching betweenprocesses (MMU overhead).

● Applications do not (generally) have fine-grained control over OS context switch, andhave little/no control over CPU allocation.

Page 19: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL: cooperative threads

● It's possible to switch execution contexts(stacks/registers) in user space (this is oftencalled “co-routining”); user-space contextswitching is often faster than OS contextswitching.

● A timer interrupt can invoke an application-level scheduler function, creating the illusionof preemptive scheduling (e.g, threads don'thave to worry about exceeding time quanta.)

Page 20: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL: more cooperativethreads

● Cooperatively scheduled threads can't(casually) block indefinitely on a system call,since this generally prevents the application-level scheduler from running.

● The application-level scheduler generally hasto poll for external events (I/O completion,synchronization events) in order to determinewhether or not a thread is runnable. (Thisconstitutes busy-waiting.)

Page 21: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL: cooperative threadissues

● Latency (the time between the occurrence ofan external event and the application-levelscheduler noticing that occurrence andscheduling a thread that's been waiting onthe event) can be very high.

● The trick of multiplexing multiple executioncontexts within a single OS-level threaddoesn't scale well to MP systems (wheremultiple OS threads may run concurrently.)

Page 22: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL: cooperative threads

● It's relatively simple to inhibit scheduling ofuser-space threads (WITHOUT-INTERRUPTS/WITHOUT-SCHEDULING),and these idioms are often used to guardcritical sections (especially when one is toolazy to use locking primitives.)

Page 23: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL: native threads

● OpenMCL implementations have used native(OS-level) threads since 2003.

● User-level API is very similar to cooperativethread API, except:– PROCESS-WAIT is deprecated

– WITHOUT-INTERRUPTS controls the

interruptibility of current thread, doesn't affect

scheduling

– Use of locks/semaphores strongly advocated

Page 24: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL: locks & semaphores

● Lisp semaphores are a very thin wrapperaround OS-level semaphores.

● OS-level locks are often too heavyweight tobe usable (on OSX, obtaining a lock involves2 or 3 system calls, even when there is nocontention.)

● Lisp locks use atomic memory accessprimitives to determine contention, onlyinvolve the OS when contention exists(Futexes)

Page 25: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Threads and special variables

● Shallow binding: save old value on a stack,set symbol to new value, pop old value onexit from binding construct. Access andupdate are unit-cost.

● Can't work when multiple threads areinvolved (value cell is a shared resource.)

● OpenMCL maintains per-thread localbindings; access/update constant cost (about8 instructions.)

Page 26: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL: user-level benefits ofnative threads

● N can be greater than 1 (threads can executeconcurrently on MP systems)

● Greater interoperability with foreign code; lispthreads can “casually” block waiting for I/O orother external events

● Reduced latency associated with waiting forexternal events.

● Less polling/busy-waiting, better overall CPUutilization

Page 27: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL: possible drawbacksof native threads

● Lack of very fine-grained control overscheduling.

● Threads and synchronization objects are“heavier” (involve the OS.)

● Code originally written to run under traditionalscheduling models may require carefulreview. (Use of WITHOUT-INTERRUPTS isoften suspect; shorthand for WITH-MORE-APROPRIATE-LOCKING.)

Page 28: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL Compiler

● OpenMCL's compiler tries to generate “good”code quickly. It's often successful, but thereare situations where it would need to thinkharder than it does (lifetime analysis, mostly)in order to generate “good” code.

● In general, floating-point objects have to beheap-allocated. It's worth trying to avoid thegeneral case.

Page 29: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL compiler: lifetimes offloats

(defun fsum1 (n)(let* ((sum 0.0d0))(dotimes (i n sum)(incf sum i))))

;;; (fsum1 1000) allocates 1000 double-floats(defun fsum2 (n)(let* ((sum 0))(dotimes (i n (coerce sum 'double-float))(incf sum i))))

;;; (fsum2 1000) allocates 1 double-float

Page 30: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL compiler: float-consing

● The examples on the preceding page arecontrived, but illustrate the general case that“not all floating-point results need to berepresented as lisp objects of type DOUBLE-FLOAT”. Keeping such results in FPregisters or unboxed stack locations wouldsave significant consing; when the number ofunnecessary FP-consing operations gets intothe millions or billions, the negative impact issignificant.

Page 31: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

OpenMCL compiler: otherperformance issues

● As a sweeping generalization, otherperformance issues that may be encounteredare less likely to be endemic (and more likelyto be a case of “no one's ever complained”.)

● It's hard to make (or trust) sweepinggeneralizations about the performance of anylarge system.

Page 32: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Other opportunities foroptimization

● Leaf functions aren't recognized: about 7instructions to build a stack frame, about 4 totear it down. Lisp programs are said tospend a high percentage of their executiontime near the leaves of the call tree.

● Many functions that aren't (purely) leaffunctions have “leaf” execution paths througha toplevel IF/COND/CASE etc.

Page 33: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Compiler summary

● The fact that the OpenMCL compilercompiles quickly is an attractive feature tomany users

● It can afford to be a little slower● Floating-point issues don't seem to impactACL2 much (is this true ?) but other issuesmay.

● It can get better and still be pretty quick

Page 34: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Environment & Debugging

● My excuse: “this was supposed to go inembedded systems!”. Debuggingenvironment is spartan and what's there isoften poorly documented. (Terse online helpvia :?)

● Everything (practically everything) iscompiled; there's no useful STEP macro.

● Some other environments (SLIME, theCocoa IDE) provide friendlier debuggingfacilities.

Page 35: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Performance tools

● Metering based on 100Hz clock interruptsoften yields unsatisfactory results: theinterrupts aren't guaranteed to be deliveredreliably, they may be delivered to an arbitrary(and possibly uninteresting) thread, and theresolution is at least a little low.

● Apple's CHUD performance tools use OSkernel extensions to provide high-resolutiontimer interrupts without affecting scheduler

Page 36: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Performance Tools

● User-level CHUD tools (e.g., Shark) don'tunderstand how to identify compiled Lispfunctions, but (with some limitations) can bepersuaded to do so.

● I may need help (or time) to make them moreusable with ACL2; I've been able to identifysome things (heavy use of symbol plistoperators, frequent calls to EQUAL) that maynot have been apparent otherwise.

Page 37: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Shark profiling (when it works)

Page 38: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Build process

● Show of hands: has anyone in audience builtOpenMCL ?

● Lisp implemented as a kernel (written in Cand PPC assembler) and a heap image. GC,exception handling code in C; C code onlyruns when lisp code can't.

● Build process is circular: need a heap imageto build a heap image.

● Recompiling all lisp sources and rebuildingan image takes a few minutes.

Page 39: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Development process

● Two CVS trees, “main” and “bleeding-edge”.● Bleeding-edge tree often containsexperimental/new features, may not buildwith released image. (Usually, new imagesare available in /testing directory onopenmcl.clozure.com.)

● Releases have not been as regular as onemight like; about 10 months between 0.14.2and 0.14.3, maybe 5 months for 0.14.4

Page 40: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Development process,continued.

● Bugs are often fixed in development tree,fixes don't always make it into patchreleases. (Often, there are technical reasonsfor this, involving ABI changes, but notalways.)

● Need to try to commit to regular releaseschedule (2 months ? 3 months ?)

● Releases take time to put together.

Page 41: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Documentation and Resources

● Online documentation is probably fairlyaccurate, but not extensive.

● Mailing list is medium-low volume, usuallyvery good signal-to-noise ratio.

● Clozure (the consulting company) is startingto offer commercial support options (detailsTBD.)

● Clozure has a contract to provide support forACL2 (not sure how broad; ask Warren.)

Page 42: Overview and History of OpenMCL - Clozure CLHistory of OpenMCL Erann Gat of JPL wanted to develop a small- footprint Lisp for use in PPC embedded systems (rovers/robots, flight systems)

Development Model

● It -is- an open-source project; other peopledo contribute, and hopefully more people willbe encouraged to do so.

● “internals” document on website is about 5years old (predates native threads); maybe60% accurate.

● Clozure is seeking funding for the Intel portand other work.