From: Eric Wong <normalperson@yhbt.net>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:81244] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip]
Date: Fri, 19 May 2017 04:34:44 +0000 [thread overview]
Message-ID: <20170519043443.GA8538@starla> (raw)
In-Reply-To: <20170510100423.GA23016@starla>
Work-in-progress patch:
https://80x24.org/spew/20170519042738.7174-1-e@80x24.org/raw
Currently, IO scheduling seems to work, waitpid/sleep/other scheduling
is not done, yet; but we do not need to support everything at
once during dev.
main API:
Fiber#start -> enable auto-scheduling and run Fiber until it
automatically yields (due to EAGAIN/EWOULDBLOCK)
The following behave like their Thread counterparts:
Fiber#join - run internal scheduler until Fiber is terminated
Fiber#value - ditto
Fiber#run (in prelude.rb)
Fiber.start (ditto)
I think we can iron out the internal APIs and behavior, first,
and gradually add support for auto-Fiber.yield points.
Right now, it takes over rb_wait_for_single_fd() function
if the running Fiber is auto-enabled (cont.c::rb_fiber_auto_sched_p)
Changes to existing functions are minimal.
New files (important structs and relations should be documented):
iom.h - internal API for the rest of RubyVM (incomplete?)
iom_common.h - common stuff internal to iom_*.h
iom_select.h - select()-specific pieces
Changes to existing data structures:
rb_thread_t.afhead - list of fibers to auto-resume
rb_fiber_t.afnode - link to th->afhead
rb_vm_t.iom - Ruby I/O Manager (rb_iom_t) :)
Besides rb_iom_t, all the new structs are stack-only and
relies extensively on ccan/list for O(1) insert/delete.
Right now, I reuse some static functions in thread.c,
so thread.c includes iom_select.h
TODO:
Hijack other blocking functions (waitpid, IO.select, ...)
iom_epoll.h + iom_kqueue.h (easy once iom.h definitions are done)
I am using "double" for timeout since it is more convenient for
arithmetic like parts of thread.c. Most platforms have good FP,
I think. Also, all "blocking" functions (rb_iom_wait*) will
have timeout support
git repo info:
The following changes since commit c26a9a733848a0696976bb98abfe623e15ba2979:
Fix strange indentation (2017-05-18 15:13:30 +0000)
are available in the git repository at:
git://80x24.org/ruby.git iom_select
for you to fetch changes up to 8ee92fbc908fe67f52372443a1492fc490431de0:
auto fiber scheduling and friends (VERY LIGHTLY TESTED) (2017-05-19 03:51:28 +0000)
----------------------------------------------------------------
Eric Wong (1):
auto fiber scheduling and friends (VERY LIGHTLY TESTED)
common.mk | 3 +
configure.in | 2 +-
cont.c | 156 +++++++++++++++++++-
include/ruby/io.h | 2 +
iom.h | 82 +++++++++++
iom_common.h | 93 ++++++++++++
iom_select.h | 419 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
prelude.rb | 12 ++
thread.c | 22 +++
vm.c | 7 +-
vm_core.h | 5 +-
11 files changed, 795 insertions(+), 8 deletions(-)
create mode 100644 iom.h
create mode 100644 iom_common.h
create mode 100644 iom_select.h
(I will revert the -O0 change in configure.in, of course :)
next prev parent reply other threads:[~2017-05-19 3:49 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20170402011414.AEA9B64CEE@svn.ruby-lang.org>
[not found] ` <8a2b82e3-dc07-1945-55f9-5a474e89130b@ruby-lang.org>
2017-04-02 2:35 ` [ruby-core:80531] Re: [ruby-cvs:65407] normal:r58236 (trunk): thread.c: comments on M:N threading [ci skip] Eric Wong
2017-04-02 3:05 ` [ruby-core:80532] " SASADA Koichi
2017-04-03 4:42 ` [ruby-core:80540] " Eric Wong
2017-05-08 0:33 ` [ruby-core:81027] " Eric Wong
2017-05-08 1:53 ` [ruby-core:81028] " SASADA Koichi
2017-05-08 2:16 ` [ruby-core:81029] " SASADA Koichi
2017-05-08 3:01 ` [ruby-core:81031] " Eric Wong
2017-05-08 3:42 ` [ruby-core:81033] " SASADA Koichi
2017-05-08 6:36 ` [ruby-core:81035] " Eric Wong
2017-05-09 2:18 ` [ruby-core:81042] " SASADA Koichi
2017-05-09 3:38 ` [ruby-core:81044] " Eric Wong
2017-05-09 4:11 ` [ruby-core:81045] " SASADA Koichi
2017-05-09 5:12 ` [ruby-core:81047] " Eric Wong
2017-05-09 5:47 ` [ruby-core:81049] " SASADA Koichi
2017-05-09 6:23 ` [ruby-core:81053] " Eric Wong
2017-05-09 6:44 ` [ruby-core:81054] " SASADA Koichi
2017-05-09 18:51 ` [ruby-core:81078] " Eric Wong
2017-05-10 3:24 ` [ruby-core:81083] " SASADA Koichi
2017-05-10 10:04 ` [ruby-core:81089] " Eric Wong
2017-05-19 4:34 ` Eric Wong [this message]
2017-06-20 19:16 ` [ruby-core:81733] " Eric Wong
2017-05-09 5:54 ` [ruby-core:81050] " SASADA Koichi
2017-05-09 6:15 ` [ruby-core:81052] " Eric Wong
2017-05-08 2:56 ` [ruby-core:81030] " Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170519043443.GA8538@starla \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).