summaryrefslogtreecommitdiff
path: root/fibers.scm (follow)
Commit message (Expand)AuthorAgeFilesLines
* run-fibers returns when initial fiber finishes•••* epoll.c (scm_primitive_epoll_wait): Accept timeout in internal time units instead of milliseconds. Avoid some overhead if the timeout is zero. * fibers/epoll.scm (epoll): Adapt to primitive-epoll-wait chance. Change get-timeout callback to an "expiry" argument and an update-expiry last-minute function. Tighten the window around the "waiting" epoll-state. * fibers.scm (%run-fibers): Remove current-read-waiter / current-write-waiter parameterization, given that fibers individually each have this parameterization. (run-fibers): Add #:drain? argument. * fibers/internal.scm (schedule-runnables-for-next-turn): Simplify a bit, inlining scheduler-poll-timeout and adapting to epoll change. (scheduler-work-pending?): New function. (run-scheduler): Simplify finish? logic. * tests/basic.scm: * tests/speedup.scm: Update to drain where needed. * fibers.texi: Update for new run-fibers termination condition. Andy Wingo2017-02-191-14/+16
* Lower preemption overhead•••* fibers/interrupts.scm (with-interrupts/sigprof): (with-interrupts/thread-cputime, with-interrupts): Separate predicate from interrupt routine, so that predicate can run off-thread. * fibers.scm (%run-fibers): Adapt. Andy Wingo2017-02-171-4/+5
* Prevent spurious preemption•••* fibers/internal.scm (<scheduler>, make-scheduler): (scheduler-runcount, run-scheduler): Maintain a count of run fibers. * fibers.scm (%run-fibers): Only cause the current fiber to suspend if the runcount isn't advancing. Andy Wingo2017-02-171-1/+7
* Cope with migration of initial fiber•••* fibers.scm (run-fibers): Allow migration of main fiber. Andy Wingo2017-02-121-1/+4
* Randomized round-robin work sharing/stealing•••* fibers.scm (start-auxiliary-threads, stop-auxiliary-threads): Adapt to scheduler-remote-peers change. (spawn-fiber): Adapt to use choose-parallel-scheduler. * fibers/internal.scm (<scheduler>): Add choose-parallel-scheduler field. (shuffle, make-selector): New helpers. (make-scheduler): Adapt to initialize choose-parallel-scheduler field. (choose-parallel-scheduler): New public function. (run-scheduler): Use fiber-stealer. Andy Wingo2017-01-181-35/+22
* Pin worker threads to CPUs if appropriate•••* fibers.scm (with-affinity): New helper. (%run-fibers): Add affinity argument. (start-auxiliary-threads): Add affinities argument. (compute-affinities): New helper. (run-fibers): If the parallelism is complete, pin threads to CPUs. Andy Wingo2017-01-171-21/+58
* create-fiber always captures dynamic state•••* fibers/internal.scm (create-fiber): Remove dynamic-state argument; always capture the current dynamic state. * fibers/timers.scm (timer-operation): * fibers.scm (spawn-fiber): Adapt. Andy Wingo2017-01-081-2/+1
* Enable preemption by default•••* fibers.scm (run-fibers): Enable preemption by default with a period of 10ms. Andy Wingo2017-01-081-3/+2
* Allow run-fibers thread to be cleanly cancelled•••* fibers.scm (run-fibers): Spawn and cancel aux threads within a dynamic-wind. Andy Wingo2017-01-061-3/+4
* Fix spawn-fiber outside run-fibers•••* fibers.scm (run-fibers): Require init thunk for run-fibers without a scheduler. (spawn-fiber): Incorporate helper procedures, remove dynamic-state argument (as it's always the current dynamic state), and add parallel? argument. Ensure the fiber will have the right read/write waiters. * tests/basic.scm: Update. Andy Wingo2016-12-301-23/+47
* Enable parallelism by default•••* fibers.scm (run-fibers): Default to use all current processor cores. (%run-fibers, start-auxiliary-threads, stop-auxiliary-threads): New helpers. Andy Wingo2016-12-291-18/+50
* Remove #:keep-scheduler? arg•••* fibers.scm (run-fibers): Remove #:keep-scheduler? argument; instead, only destroy schedulers that we create. * fibers.texi (Using Fibers): Update run-fibers docs. * web/server/fibers.scm (server-read): Adapt. Andy Wingo2016-12-271-19/+19
* Enable work stealing in run-scheduler•••* fibers.scm (run-fibers): Store result in an atomic box, given that the initial fiber could migrate. * fibers/internal.scm (<scheduler>): Add remote-peers field. (<fiber>): Add set-fiber-scheduler!. (make-scheduler): Adapt to <scheduler> change. (scheduler-finished?): New helper. (scheduler-poll-timeout): Take a finished? predicate to know when to wait and when to return directly. (schedule-runnables-for-next-turn): Plumb finished? predicate through. (run-scheduler): Avoid returning until finished? is true. Refactor to add work stealing. (steal-fiber!): New helper. Andy Wingo2016-12-221-6/+5
* Get current scheduler from current fiber•••* fibers.scm (run-fibers): Refine #:keep-scheduler? default. (current-fiber-scheduler): Rename from require-current-scheduler, and use the current fiber to get at the scheduler. (spawn-fiber): Let create-fiber handle dynamic state shenanigans, as it needs to ensure that current-fiber is bound in the thunk. * fibers/internal.scm (with-scheduler): Don't parameterize current-scheduler, as that binding for a given scheduler needs to change over time, and the with-dynamic-state prevents this from happening. (schedule-fiber!): Wake schedulers not on the current kernel thread. (run-fiber): Don't parameterize current-fiber; it's lost across the with-dynamic-state. (create-fiber): Instead set current-fiber inside the with-dynamic-state. (suspend-current-fiber, yield-current-fiber): Get current scheduler from current fiber. Andy Wingo2016-12-221-14/+12
* Factor interrupt generation to separate facility•••* fibers/interrupts.scm: New file. * fibers/internal.scm (<scheduler>): Remove Hz field and adapt users. (run-scheduler): Remove preemption; (fibers) handles this now. (yield-current-fiber): New primitive. * fibers.scm (run-fibers): Use interrupts module and wrap run-scheduler in `with-interrupts'. * Makefile.am: Add new file. Andy Wingo2016-12-161-11/+15
* Add support for preemption•••* Makefile.am: Add new test. * TODO.md: Remove stale TODO entries. * fibers.scm (run-fibers): Add #:hz parameter. * fibers.texi (Design): Mention that we support preemption. (Using Fibers): Update for preemption. * fibers/internal.scm (<scheduler>): Add hz field. (make-scheduler): Add #:hz initarg. (maybe-preemptive): New helper. (run-scheduler): Use maybe-preemptive. * tests/preemption.scm: New test. Andy Wingo2016-12-121-1/+1
* Fibers inherit dynamic state of parent.•••* fibers.scm (spawn-fiber): Fibers inherit dynamic state of parent. * tests/parameters.scm: New test. * Makefile.am: Add new file. Andy Wingo2016-12-121-2/+7
* Internals twiddles•••* fibers/internal.scm (current-scheduler/public): Document. (current-fiber/public): New accessor. (resume-on-timer): Document. * fibers.scm: Adapt to use current-fiber directly from the internals. Remove kill-fiber. Andy Wingo2016-10-121-14/+4
* Rework internals resume interface•••* fibers/internal.scm (resume-on-fd-events, resume-on-readable-fd) (resume-on-writable-fd, resume-on-timer): Rework primitive resume interface. * fibers.scm: * fibers/timers.scm: Adapt users. Andy Wingo2016-10-121-10/+6
* Lighter fibers•••* fibers/internal.scm: Remove fiber-state; this is managed implicitly now by ensuring that a fiber is only resumed at most once per suspend. We no longer record fiber return values; that should be up to the fiber's init continuation. Replace scheduler inbox with making the runqueue atomic. * fibers.scm (run-fibers): Adapt to run-scheduler change. * fibers/repl.scm (fibers): Adapt to fiber-data change. Andy Wingo2016-10-111-7/+10
* Timeout CML operations•••* fibers/timers.scm: New file. * fibers/internal.scm (add-timer!): Take expiry as absolute time. * fibers.scm (fibers): Re-export sleep from (fibers timers). * Makefile.am: Adapt. Andy Wingo2016-10-031-9/+2
* Sleep refactor•••* fibers/internal.scm: Rename sleepers to timers, and be callbacks instead of waking fibers directly. * fibers.scm (sleep): Adapt. Andy Wingo2016-10-031-1/+4
* Add support for ,spawn-fiberAndy Wingo2016-09-201-10/+11
* Add ,fibers command.Andy Wingo2016-09-201-0/+1
* run-fibers returns values from initial thread•••* fibers.scm (run-fibers): * fibers/internal.scm (run-scheduler): If there is an init thunk, keep the scheduler running until the corresponding fiber is finished. Return the values returned from the fiber. * tests/basic.scm (assert-run-fibers-terminates): Return values. (assert-run-fibers-returns): New helper. Use it. Andy Wingo2016-09-101-3/+7
* Tidy up fibers imports•••* fibers.scm (fibers): Trim imports. Andy Wingo2016-09-071-5/+2
* Separate public and private fibers interfaces•••* fibers/internal.scm: New file, factored out of (fibers). * fibers.scm: Refactor to be just the public interface. * fibers/channels.scm: * web/server/fibers.scm: * examples/memcached-client.scm: * examples/memcached-server.scm: * examples/ping-client.scm: * examples/ping-server.scm: Adapt to interface changes. * Makefile.am (SOURCES): Add (fibers internal). Andy Wingo2016-09-071-250/+38
* Add channels implementation•••* fibers/channels.scm: New file. * fibers.scm: Add comment. * Makefile.am: Add new file. Andy Wingo2016-09-061-0/+5
* Add support for FD finalization•••* fibers.scm (finalize-fd, wait-for-events): Arrange for close-port to call into the scheduler. Andy Wingo2016-09-021-0/+16
* Slight internal refactor•••* fibers.scm (run): Inline `next-fiber' into its only use. Andy Wingo2016-09-021-14/+12
* Readability refactors to fibers.scm•••* fibers.scm (schedule-fibers-for-fd): New function, factored out of poll-for-events. (poll-for-events): Comments and style refactorings. Andy Wingo2016-07-061-38/+44
* Add (fibers) module•••* fibers.scm: New file. * Makefile.am: Add new file. Andy Wingo2016-07-031-0/+265