<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ruby.git/thread_none.h, branch v4.0.2</title>
<subtitle>The Ruby Programming Language</subtitle>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/'/>
<entry>
<title>M:N thread scheduler for Ractors</title>
<updated>2023-10-12T05:47:01+00:00</updated>
<author>
<name>Koichi Sasada</name>
<email>ko1@atdot.net</email>
</author>
<published>2023-04-10T01:53:13+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=be1bbd5b7d40ad863ab35097765d3754726bbd54'/>
<id>be1bbd5b7d40ad863ab35097765d3754726bbd54</id>
<content type='text'>
This patch introduce M:N thread scheduler for Ractor system.

In general, M:N thread scheduler employs N native threads (OS threads)
to manage M user-level threads (Ruby threads in this case).
On the Ruby interpreter, 1 native thread is provided for 1 Ractor
and all Ruby threads are managed by the native thread.

From Ruby 1.9, the interpreter uses 1:1 thread scheduler which means
1 Ruby thread has 1 native thread. M:N scheduler change this strategy.

Because of compatibility issue (and stableness issue of the implementation)
main Ractor doesn't use M:N scheduler on default. On the other words,
threads on the main Ractor will be managed with 1:1 thread scheduler.

There are additional settings by environment variables:

`RUBY_MN_THREADS=1` enables M:N thread scheduler on the main ractor.
Note that non-main ractors use the M:N scheduler without this
configuration. With this configuration, single ractor applications
run threads on M:1 thread scheduler (green threads, user-level threads).

`RUBY_MAX_CPU=n` specifies maximum number of native threads for
M:N scheduler (default: 8).

This patch will be reverted soon if non-easy issues are found.

[Bug #19842]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch introduce M:N thread scheduler for Ractor system.

In general, M:N thread scheduler employs N native threads (OS threads)
to manage M user-level threads (Ruby threads in this case).
On the Ruby interpreter, 1 native thread is provided for 1 Ractor
and all Ruby threads are managed by the native thread.

From Ruby 1.9, the interpreter uses 1:1 thread scheduler which means
1 Ruby thread has 1 native thread. M:N scheduler change this strategy.

Because of compatibility issue (and stableness issue of the implementation)
main Ractor doesn't use M:N scheduler on default. On the other words,
threads on the main Ractor will be managed with 1:1 thread scheduler.

There are additional settings by environment variables:

`RUBY_MN_THREADS=1` enables M:N thread scheduler on the main ractor.
Note that non-main ractors use the M:N scheduler without this
configuration. With this configuration, single ractor applications
run threads on M:1 thread scheduler (green threads, user-level threads).

`RUBY_MAX_CPU=n` specifies maximum number of native threads for
M:N scheduler (default: 8).

This patch will be reverted soon if non-easy issues are found.

[Bug #19842]
</pre>
</div>
</content>
</entry>
<entry>
<title>introduce struct `rb_native_thread`</title>
<updated>2022-04-22T18:08:27+00:00</updated>
<author>
<name>Koichi Sasada</name>
<email>ko1@atdot.net</email>
</author>
<published>2022-04-22T12:19:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=03d21a4fb099da7c52e6591e17704c297871b7db'/>
<id>03d21a4fb099da7c52e6591e17704c297871b7db</id>
<content type='text'>
`rb_thread_t` contained `native_thread_data_t` to represent
thread implementation dependent data. This patch separates
them and rename it `rb_native_thread` and point it from
`rb_thraed_t`.

Now, 1 Ruby thread (`rb_thread_t`) has 1 native thread (`rb_native_thread`).
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
`rb_thread_t` contained `native_thread_data_t` to represent
thread implementation dependent data. This patch separates
them and rename it `rb_native_thread` and point it from
`rb_thraed_t`.

Now, 1 Ruby thread (`rb_thread_t`) has 1 native thread (`rb_native_thread`).
</pre>
</div>
</content>
</entry>
<entry>
<title>rename thread internal naming</title>
<updated>2022-04-21T22:54:09+00:00</updated>
<author>
<name>Koichi Sasada</name>
<email>ko1@atdot.net</email>
</author>
<published>2022-04-16T18:40:23+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=1c4fc0241d125879e1e5169f267f26637772f3a7'/>
<id>1c4fc0241d125879e1e5169f267f26637772f3a7</id>
<content type='text'>
Now GVL is not process *Global* so this patch try to use
another words.

* `rb_global_vm_lock_t` -&gt; `struct rb_thread_sched`
  * `gvl-&gt;owner` -&gt; `sched-&gt;running`
  * `gvl-&gt;waitq` -&gt; `sched-&gt;readyq`
* `rb_gvl_init` -&gt; `rb_thread_sched_init`
* `gvl_destroy` -&gt; `rb_thread_sched_destroy`
* `gvl_acquire` -&gt; `thread_sched_to_running` # waiting -&gt; ready -&gt; running
* `gvl_release` -&gt; `thread_sched_to_waiting` # running -&gt; waiting
* `gvl_yield`   -&gt; `thread_sched_yield`
* `GVL_UNLOCK_BEGIN` -&gt; `THREAD_BLOCKING_BEGIN`
* `GVL_UNLOCK_END` -&gt; `THREAD_BLOCKING_END`

* removed
  * `rb_ractor_gvl`
  * `rb_vm_gvl_destroy` (not used)

There are GVL functions such as `rb_thread_call_without_gvl()` yet
but I don't have good name to replace them. Maybe GVL stands for
"Greate Valuable Lock" or something like that.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Now GVL is not process *Global* so this patch try to use
another words.

* `rb_global_vm_lock_t` -&gt; `struct rb_thread_sched`
  * `gvl-&gt;owner` -&gt; `sched-&gt;running`
  * `gvl-&gt;waitq` -&gt; `sched-&gt;readyq`
* `rb_gvl_init` -&gt; `rb_thread_sched_init`
* `gvl_destroy` -&gt; `rb_thread_sched_destroy`
* `gvl_acquire` -&gt; `thread_sched_to_running` # waiting -&gt; ready -&gt; running
* `gvl_release` -&gt; `thread_sched_to_waiting` # running -&gt; waiting
* `gvl_yield`   -&gt; `thread_sched_yield`
* `GVL_UNLOCK_BEGIN` -&gt; `THREAD_BLOCKING_BEGIN`
* `GVL_UNLOCK_END` -&gt; `THREAD_BLOCKING_END`

* removed
  * `rb_ractor_gvl`
  * `rb_vm_gvl_destroy` (not used)

There are GVL functions such as `rb_thread_call_without_gvl()` yet
but I don't have good name to replace them. Maybe GVL stands for
"Greate Valuable Lock" or something like that.
</pre>
</div>
</content>
</entry>
<entry>
<title>[wasm] add no thread variant for freestanding environment</title>
<updated>2022-01-19T02:19:06+00:00</updated>
<author>
<name>Yuta Saito</name>
<email>kateinoigakukun@gmail.com</email>
</author>
<published>2022-01-15T15:37:54+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=420622b5a793186dfa533e7702913fd5e4764e0f'/>
<id>420622b5a793186dfa533e7702913fd5e4764e0f</id>
<content type='text'>
This implementation does nothing around preemptive context switching
because there is no native thread.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This implementation does nothing around preemptive context switching
because there is no native thread.
</pre>
</div>
</content>
</entry>
</feed>
