Rely on getclockofday for CLOCK_MONOTONIC, avoid needless
variables, and rely on overflow protection from timespec_add
instead of coding our own.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62459 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (timeval_for): tv_usec is suseconds_t which may be
smaller than long.
* thread_pthread.c (native_cond_timeout): ret is now used in
CLOCK_MONOTONIC case only.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This results in fewer conversion on common modern systems with
support for clock_gettime, pthread_cond_timedwait and ppoll.
gettimeofday is declared obsolete by POSIX.1-2008, so it is yet
another reason to move away from it. This also appears to result
in the reduction of compatibility code required for dealing
with inconsistent implementations of "struct timeval".tv_sec
In the future, this will also result in fewer conversions for
kqueue and pselect if we elect to use them.
[ruby-core:85416] [Feature #14452]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62272 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (rb_thread_create_mjit_thread): cast
worker_func pointer to void pointer inside. adjusted to the
declaration in mjit.c and the definition in thread_win32.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
No implicit cast is defined between these types. Should be explicit.
Also, NULL is defined to be ((void*)0) so not usable as a function
pointer value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
that allows to JIT-compile Ruby methods by generating C code and
using C compiler. See the first comment of mjit.c to know what this
file does.
mjit.c is authored by Vladimir Makarov <vmakarov@redhat.com>.
After he invented great method JIT infrastructure for MRI as MJIT,
Lars Kanis <lars@greiz-reinsdorf.de> sent the patch to support MinGW
in MJIT. In addition to merging it, I ported pthread to Windows native
threads. Now this MJIT infrastructure can be compiled on Visual Studio.
This commit simplifies mjit.c to decrease code at initial merge. For
example, this commit does not provide multiple JIT threads support.
We can resurrect them later if we really want them, but I wanted to minimize
diff to make it easier to review this patch.
`/tmp/_mjitXXX` file is renamed to `/tmp/_ruby_mjitXXX` because non-Ruby
developers may not know the name "mjit" and the file name should make
sure it's from Ruby and not from some harmful programs. TODO: it may be
better to store this to some temporary directory which Ruby is already using
by Tempfile, if it's not bad for performance.
mjit.h: New. It has `mjit_exec` interface similar to `vm_exec`, which is
for triggering MJIT. This drops interface for AOT compared to the original
MJIT.
Makefile.in: define macros to let MJIT know the path of MJIT header.
Probably we can refactor this to reduce the number of macros (TODO).
win32/Makefile.sub: ditto.
common.mk: compile mjit.o and mjit_compile.o. Unlike original MJIT, this
commit separates MJIT infrastructure and JIT compiler code as independent
object files. As initial patch is NOT going to have ultra-fast JIT compiler,
it's likely to replace JIT compiler, e.g. original MJIT's compiler or some
future JIT impelementations which are not public now.
inits.c: define MJIT module. This is added because `MJIT.enabled?` was
necessary for testing.
test/lib/zombie_hunter.rb: skip if `MJIT.enabled?`. Obviously this
wouldn't work with current code when JIT is enabled.
test/ruby/test_io.rb: skip this too. This would make no sense with MJIT.
ruby.c: define MJIT CLI options. As major difference from original MJIT,
"-j:l"/"--jit:llvm" are renamed to "--jit-cc" because I want to support
not only gcc/clang but also cl.exe (Visual Studio) in the future. But it
takes only "--jit-cc=gcc", "--jit-cc=clang" for now. And only long "--jit"
options are allowed since some Ruby committers preferred it at Ruby
developers Meeting on January, and some of options are renamed.
This file also triggers to initialize MJIT thread and variables.
eval.c: finalize MJIT worker thread and variables.
test/ruby/test_rubyoptions.rb: fix number of CLI options for --jit.
thread_pthread.c: change for pthread abstraction in MJIT. Prefix rb_ for
functions which are used by other files.
thread_win32.c: ditto, for Windows. Those pthread porting is one of major
works that YARV-MJIT created, which is my fork of MJIT, in Feature 14235.
thread.c: follow rb_ prefix changes
vm.c: trigger MJIT call on VM invocation. Also trigger `mjit_mark` to avoid
SEGV by race between JIT and GC of ISeq. The improvement was provided by
wanabe <s.wanabe@gmail.com>.
In JIT compiler I created and am going to add in my next commit, I found
that having `mjit_exec` after `vm_loop_start:` is harmful because the
JIT-ed function doesn't proceed other ISeqs on RESTORE_REGS of leave insn.
Executing non-FINISH frame is unexpected for my JIT compiler and
`exception_handler` triggers executions of such ISeqs. So `mjit_exec`
here should be executed only when it directly comes from `vm_exec` call.
`RubyVM::MJIT` module and `.enabled?` method is added so that we can skip
some tests which don't expect JIT threads or compiler file descriptors.
vm_insnhelper.h: trigger MJIT on method calls during VM execution.
vm_core.h: add fields required for mjit.c. `bp` must be `cfp[6]` because
rb_control_frame_struct is likely to be casted to another struct. The
last position is the safest place to add the new field.
vm_insnhelper.c: save initial value of cfp->ep as cfp->bp. This is an
optimization which are done in both MJIT and YARV-MJIT. So this change
is added in this commit. Calculating bp from ep is a little heavy work,
so bp is kind of cache for it.
iseq.c: notify ISeq GC to MJIT. We should know which iseq in MJIT queue
is GCed to avoid SEGV. TODO: unload some GCed units in some safe way.
gc.c: add hooks so that MJIT can wait GC, and vice versa. Simultaneous
JIT and GC executions may cause SEGV and so we should synchronize them.
cont.c: save continuation information in MJIT worker. As MJIT shouldn't
unload JIT-ed code which is being used, MJIT wants to know full list of
saved execution contexts for continuation and detect ISeqs in use.
mjit_compile.c: added empty JIT compiler so that you can reuse this commit
to build your own JIT compiler. This commit tries to compile ISeqs but
all of them are considered as not supported in this commit. So you can't
use JIT compiler in this commit yet while we added --jit option now.
Patch author: Vladimir Makarov <vmakarov@redhat.com>.
Contributors:
Takashi Kokubun <takashikkbn@gmail.com>.
wanabe <s.wanabe@gmail.com>.
Lars Kanis <lars@greiz-reinsdorf.de>.
Part of Feature 12589 and 14235.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
"get_stack_of" was only in a proposed patch for [Feature #8793]
https://bugs.ruby-lang.org/issues/8793 and never applied.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61750 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (rb_thread_create_timer_thread): round up
additional stack size to PTHREAD_STACK_MIN, to get rid of
EINVAL at pthread_attr_setstacksize().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
These were added for NaCL support in r36022, and we dropped NaCL
in r60374.
IMHO, any pthreads implementation without these basic functions
is not worth the time to support.
[ruby-core:84758] [Misc #14342]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61720 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
ifdefs make code confusing for my easily-confused mind :<
These were added for NaCL support in r36022, and we dropped NaCL
in r60374. There are more #ifdefs to remove...
[ruby-core:84758] [Misc #14342]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
However, I don't think EAGAIN on pthread_create can really
be fixed in our code. I suspect test machines are overloaded.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
"warning: pthread_create failed for timer: Resource temporarily
unavailable, scheduling broken" still occurs randomly. This change will
allow us to debug the issue.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
It's easier to read this macro from ccan than open-coding pointer
arithmetic.
thread_pthread.c (ubf_wakeup_all_threads): use container_of
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
TL;DR see http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2031.htm
Suppose we have:
struct X {
struct Y {
z_t z;
} y;
} x;
then, you _cant_ infer offsetof(struct X, y.z). The ISO C99 section
7.17 says nothing about such situation. At least clang warns this
being an extension to the language (-Wextended-offsetof).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
to represent execution context [Feature #14038]
* vm_core.h (rb_thread_t): rb_thread_t::ec is now a pointer.
There are many code using `th` to represent execution context
(such as cfp, VM stack and so on). To access `ec`, they need to
use `th->ec->...` (adding one indirection) so that we need to
replace them by passing `ec` instead of `th`.
* vm_core.h (GET_EC()): introduced to access current ec. Also
remove `ruby_current_thread` global variable.
* cont.c (rb_context_t): introduce rb_context_t::thread_ptr instead of
rb_context_t::thread_value.
* cont.c (ec_set_vm_stack): added to update vm_stack explicitly.
* cont.c (ec_switch): added to switch ec explicitly.
* cont.c (rb_fiber_close): added to terminate fibers explicitly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This fixes stuck test/ruby/test_io.rb with FIBER_USE_NATIVE=0 on
GNU/Linux because linked-list pointers used by glibc get
corrupted when fiber stacks are copied.
Thanks to wanabe for finding the bug and original patch.
* thread_pthread (native_thread_init_stack): fix stack corruption
[ruby-core:82737] [Bug #13387]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Because NaCl and PNaCl are already sunset status.
see https://bugs.chromium.org/p/chromium/issues/detail?id=239656#c160
configure.ac: Patch for this file was provided by @nobu.
[Feature #14041][ruby-core:83497][fix GH-1726]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Setting a small stack size can fail due to having 3rd-party
libraries (e.g. libkqueue) loaded, if those libraries use
thread-local-storage (__thread) heavily. This causes
pthread_create to fail with small stacks; even if our
timer_thread function does not hit any of the TLS-using code
paths.
Today, some RubyGems are capable of using libkqueue (or __thread
storage directly), and future versions of Ruby may use kqueue
internally.
cf. https://www.akkadia.org/drepper/tls.pdf
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58874 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (ruby_init_stack): check stack bounds even if
get_main_stack succeeded, on the "co-routine" case.
https://github.com/ruby/ruby/commit/53953ee#commitcomment-18887413
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (gvl_atfork): used in rb_thread_atfork_internal
only if HAVE_WORKING_FORK is defined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55085 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (rb_thread_setname): defer setting native thread name
set in initialize until the native thread is created.
[ruby-core:74963] [Bug #12290]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54600 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
pthread_getthrds_np() is wrong on AIX. Use
__pi_stackend - __pi_stackaddr instead.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This fixes an occasional [ASYNC BUG] failure in
bootstraptest/test_fork.rb '[ruby-dev:37934]'
which tests fork/pthread_create failure by setting
RLIMIT_NPROC to 1 and triggering EAGAIN on pthread_create
when attempting to recreate the timer thread.
The problem timeline is as follows:
thread 1 thread 2
---------------------------------------------------------------
rb_thread_create_timer_thread
setup_communication_pipe
rb_thread_wakeup_timer_thread_low
pthread_create fails pipe looks valid, write!
CLOSE_INVALIDATE (x4) EBADF -> ASYNC BUG
The checks in rb_thread_wakeup_timer_thread_low only tried to
guarantee proper ordering with native_stop_timer_thread, not
rb_thread_create_timer_thread :x
Now, this should allow rb_thread_create_timer_thread to
synchronize properly with rb_thread_wakeup_timer_thread_low by
delaying the validation marking of the timer_thread_pipe until
we are certain the timer thread is alive.
In this version, rb_thread_wakeup_timer_thread_low becomes a
noop. Threading is still completely broken with NPROC==1, but
there's not much we can do about it beside warn the user.
We no longer spew a scary [ASYNC BUG] message or dump core
on them.
* thread_pthread.c (setup_communication_pipe): delay setting owner
(rb_thread_create_timer_thread): until thread creation succeeds
[ruby-core:72590] [Bug #11922]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53373 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* configure.in: separate SET_CURRENT_THREAD_NAME, which can set
the name of current thread only, and SET_ANOTHER_THREAD_NAME,
which can set the name of other threads.
* thread.c (rb_thread_setname): use SET_ANOTHER_THREAD_NAME. OS X
is not possible to set another thread name.
* thread_pthread.c (native_set_thread_name, thread_timer): use
SET_CURRENT_THREAD_NAME.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (native_stop_timer_thread): explicit type of
old value to suppress a pointer-sign warning.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Shutting down the timer thread now always closes pipes to free FDs.
In fact, we close the write ends of the pipes is done in the main
RubyVM to signal the timer thread shutdown.
To effectively close pipes, we implement userspace locks via
atomics to force the pipe closing thread to wait on any signal
handlers which may be waking up.
While we're at it, improve robustness during resource exhaustion and
allow it to limp along non-fatally if restarting a timer thread
fails.
This reverts r51268
Note: this change is tested with VM_CHECK_MODE 1 in vm_core.h
* process.c (close_unless_reserved): add extra check
(dup2_with_divert): remove
(redirect_dup2): use dup2 without divert
(before_exec_non_async_signal_safe): adjust call + comment
(rb_f_exec): stop timer thread for all OSes
(rb_exec_without_timer_thread): remove
* eval.c (ruby_cleanup): adjust call
* thread.c (rb_thread_stop_timer_thread): always close pipes
* thread_pthread.c (struct timer_thread_pipe): add writing field,
mark owner_process volatile for signal handlers
(rb_thread_wakeup_timer_thread_fd): check valid FD
(rb_thread_wakeup_timer_thread): set writing flag to prevent close
(rb_thread_wakeup_timer_thread_low): ditto
(CLOSE_INVALIDATE): new macro
(close_invalidate): new function
(close_communication_pipe): removed
(setup_communication_pipe_internal): make errors non-fatal
(setup_communication_pipe): ditto
(thread_timer): close reading ends inside timer thread
(rb_thread_create_timer_thread): make errors non-fatal
(native_stop_timer_thread): close write ends only, always,
wait for signal handlers to finish
(rb_divert_reserved_fd): remove
* thread_win32.c (native_stop_timer_thread): adjust (untested)
(rb_divert_reserved_fd): remove
* vm_core.h: adjust prototype
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
with one of the timer thread FDs, the internal FD is diverted.
[Bug #11336] [ruby-core:69886] [Bug #11350] [ruby-core:69961]
* process.c (dup2_with_divert): new function for the above purpose.
* thread_pthread.c (rb_divert_reserved_fd): new function for
diverting reserved FD. If the given FD is the same as one of the
reserved FDs, the reserved FD number is internally changed.
It returns -1 when error. Otherwise, returns 0. It also returns
0 if there is no need to change reserved FD number.
* thread_win32.c (rb_divert_reserved_fd): always returns 0 because
of no reserved FDs.
* internal.h (rb_divert_reserved_fd): prototype declaration.
It is Ruby internal use only.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
reserved FD. It should be closed in the exec system call due to the
O_CLOEXEC or FD_CLOEXEC flag. [Bug #11353] [ruby-core:69977]
* process.c (close_unless_reserved): new function to close FD unless
it is reserved for internal communication.
* thread_pthread.c (rb_reserved_fd_p): should check owner_process pid
to avoid false positive in forked child process.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
for FreeBSD, and don't define it if both pthread_setname_np
and pthread_set_name_np don't exist.
* thread_pthread.c (SET_THREAD_NAME): don't define if they don't exist.
* thread_pthread.c (native_set_thread_name): run if SET_THREAD_NAME
is defined.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (reserve_stack): keep sp safe zone to get rid
of crash by -fstack-check. [ruby-core:68740] [Bug #11030]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (timer_thread_pipe.owner_process): process ID
should be pid_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49796 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (reserve_stack): fix intermittent SIGBUS on
Linux, by reserving the stack virtual address space at process
start up so that it will not clash with the heap space.
[Fix GH-822]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49452 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread.c (struct join_arg): restructure and make smaller
(thread_join_sleep): avoid timeofday() call if forever
(thread_join): pass join_arg.delay directly
(rb_thread_inspect_msg): remove, inline into rb_thread_inspect
(rb_thread_inspect): reduce branching and string creation
* thread_pthread.c (native_set_thread_name): create string directly
to avoid reparsing. [Misc #10723]
This reduces time in benchmark/bm_vm_thread_create_join.rb by
a few percent.
Minor improvements only:
target 0: 2.1.5 (ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-linux])
target 1: trunk (ruby 2.3.0dev (2015-01-16 trunk 49282) [x86_64-linux])
target 2: built (ruby 2.3.0dev (2015-01-16 trunk 49282) [x86_64-linux])
benchmark results:
minimum results in each 3 measurements.
Execution time (sec)
name 2.1.5 trunk built
vm_thread_create_join 1.049 1.242 1.138
Speedup ratio: compare with the result of `2.1.5' (greater is better)
name trunk built
vm_thread_create_join 0.845 0.923
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49430 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
set thread name visible with ps command on GNU/Linux.
Ex. ps -o %c -L
* thread.c (thread_start_func_2): Call native_set_thread_name at
beginning.
(rb_thread_inspect_msg): Extract from rb_thread_inspect.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This will make it easier for us to try alternative mutex/condvar
implementations while still using pthreads for thread management.
[Feature #10134]
* thread_pthread.h: define RB_NATIVETHREAD_LOCK_INIT and
RB_NATIVETHREAD_COND_INIT macros
* thread_pthread.c (native_mutex_lock, native_mutex_unlock,
native_mutex_trylock, native_mutex_initialize,
native_mutex_destroy, native_cond_wait):
use rb_nativethread_lock_t instead of pthread_mutex_t
* thread_pthread.c (native_mutex_debug): make argument type-agnostic
to avoid later cast.
* thread_pthread.c (register_cached_thread_and_wait):
replace PTHREAD_COND_INITIALIZER with RB_NATIVETHREAD_COND_INIT,
use native_mutex_{lock,unlock}
* thread_pthread.c (use_cached_thread):
use native_mutex_{lock,unlock}
* thread_pthread.c (native_sleep):
use rb_nativethread_lock_t to match th->interrupt_lock,
use native_mutex_{lock,unlock}
* thread_pthread.c (timer_thread_lock): use rb_nativethread_lock_t type
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47185 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* configure.in (rb_cv_scalar_pthread_t): pthread_t is not required
to be a scalar type.
* thread.c (fill_thread_id_string, thread_id_str): dump pthread_t
in hexadecimal form if it is not a scalar type, assume it can be
represented in a pointer form otherwise. based on the patch by
Rei Odaira at [ruby-core:62867]. [ruby-core:62857] [Bug #9884]
* thread_pthread.c (Init_native_thread, thread_start_func_1),
(native_thread_create): set thread_id_str if needed.
* vm_core.h (rb_thread_t): add thread_id_string if needed.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (timer_thread): add a flag to tell timer thread
is created, since 0 may be a valid value as pthread_t.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (rb_thread_wakeup_timer_thread_fd): use a local
variable for errno.
* thread_pthread.c (consume_communication_pipe): ditto. add
EWOULDBLOCK case.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (ubf_select): compare thread_id with
pthread_equal() but not directly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45906 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (timer_thread_sleep): use a local variable for
errno.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* configure.in: check if pthread_setname_np is available.
* thread_pthread.c: pthread_setname_np is not available on old
Darwins. [ruby-core:60524] [Bug #9492]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_core.h (rb_thread_struct): aggregate cpu stuff into a struct,
so that a debugger can show its content at once.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (ruby_stack_overflowed_p): range of rlim_cur
may be larger than size_t. [ruby-core:60113] [Bug #9454]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c: get current main thread stack size, which may
be expanded than allocated size at initialization, by rlimit().
[ruby-core:60113] [Bug #9454]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (rb_thread_create_timer_thread): fix for platforms
where PTHREAD_STACK_MIN is a dynamic value and not a compile-time
constant. [ruby-dev:47911] [Bug #9436]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (rb_thread_create_timer_thread): expand timer
thread stack size to get rid of segfault on FreeBSD/powerpc64.
based on the patch by Steve Wills at [ruby-core:59923].
[ruby-core:56590] [Bug #8783]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (ruby_init_stack): set stack_start properly by
get_main_stack() if possible.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (thread_timer): set timer thread name on OSX too.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (native_thread_init_stack): wait the creator thread
to fill machine stack info, if get_stack_of() is available.
* thread_pthread.c (native_thread_create): fill the created thread
stack info after starting, if get_stack_of() is available.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (native_thread_create): define attr only if it is
used, and merge pthread_create() calls.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (get_main_stack): separate function to get stack of
main thread.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (hpux_attr_getstackaddr): vps_pagesize is defaulted
to 16 and in Kbytes. [ruby-core:56863]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (hpux_attr_getstackaddr): basic support for the
get_stack() under HP-UX. based on the patch by michal@rokos.cz
(Michal Rokos) at [ruby-core:56645]. [Feature #8793]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42716 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Move native thread related lines from vm_core.h.
And declare several functions "rb_nativethread_lock_*",
manipulate locking.
* common.mk: add thread_native.h.
* thread.c: add functions "rb_nativethread_lock_*".
* thraed.c, thread_[pthread,win32].[ch]: rename rb_thread_lock_t
to rb_nativethread_lock_t to make it clear that this lock is for
native thraeds, not for ruby threads.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42133 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This fixes a compilation failure while cross-compiling for Tensilica
Xtensa Processor.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This fixes a compilation failure while cross-compiling for ARM.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
.. #endif sections. This fixes a build error on NativeClient.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40103 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (poll.h): already included in ruby/io.h from
thread.c.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (gvl_acquire_common): use low priority
notification for avoiding timer thread interval confusion.
If we use timer_thread_pipe[1], every gvl_yield() request
one more gvl_yield(). It lead to thread starvation.
[Bug #7999] [ruby-core:53095]
* thread_pthread.c (rb_reserved_fd_p): adds timer_thread_pipe_low
to reserved fds.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
creating communication pipe logic into separate function.
* thread_pthread.c (setup_communication_pipe): new helper function.
* thread_pthread.c (set_nonblock): moves a definition before
setup_communication_pipe.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
select(). select doesn't work if timer_thread_pipe[0] is
greater than FD_SETSIZE.
* thread_pthread.c (USE_SLEEPY_TIMER_THREAD): add a dependency
against poll.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39681 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Specified by the following environment variaables:
- RUBY_THREAD_VM_STACK_SIZE: vm stack size used at thread creation.
default: 128KB (32bit CPU) or 256KB (64bit CPU).
- RUBY_THREAD_MACHINE_STACK_SIZE: machine stack size used at thread
creation. default: 512KB or 1024KB.
- RUBY_FIBER_VM_STACK_SIZE: vm stack size used at fiber creation.
default: 64KB or 128KB.
- RUBY_FIBER_MACHINE_STACK_SIZE: machine stack size used at fiber
creation. default: 256KB or 256KB.
This values are specified at launched timing. You can not change
these values at running time.
Environ variables are only *hints* because:
- They are aligned to 4KB.
- They have minimum values (depend on OSs).
- Machine stack settings are ignored by some OSs.
Default values especially fiber stack sizes are increased.
This change affect Fiber's behavior:
(1) You can run more complex program on a Fiber.
(2) You can not make many (thousands) Fibers because of
lack of address space (on 32bit CPU).
If (2) bothers you,
(a) Use 64bit CPU with big memory, or
(b) Specify RUBY_FIBER_(VM|MACHINE)_STACK_SIZE correctly.
You need to choose correct stack size carefully. These values
are completely rely on systems (OS/compiler and so on).
* vm_core.h (rb_vm_t::default_params): add to record above settings.
* vm.c (RubyVM::DEFAULT_PARAMS): add new constant to see
above setting.
* thread_pthread.c: support RUBY_THREAD_MACHINE_STACK_SIZE.
* cont.c: support RUBY_FIBER_(VM|MACHINE)_STACK_SIZE.
* test/ruby/test_fiber.rb: add tests for above.
* test/ruby/test_thread.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38478 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
that prevented the ifdef ever being true.
[Bug #7281] [ruby-core:48940]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37483 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
removed HAVE_PTHREAD_CONDATTR_INIT check because this silly
#ifdef makes use-uninitialized-var issue and (2) native_cond_initialize()
already have a right platform and caller don't need any additional care.
[Bug #6825]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (RUBY_STACK_MIN): may not a compile time constant.
fix r37079. [ruby-dev:46322] [Bug #7247]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37402 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (ruby_init_stack): use getrlimit() for the main
thread on Mac OS X, since pthread_get_stack{addr,size}_np() and
return the default value always, but not the ulimit value.
[ruby-dev:46174] [Bug #7084]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37072 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
after using it. Patch by Stanislav Sedov. Thank you.
[Bug #7041] [ruby-core:47619]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37001 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (get_stack): define guard only when it is used.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (timer_thread_sleep): Extracted out a function from
thread_timer(). Added an alternative implementation for platforms
that lacks select(2) or pipe(2).
(rb_thread_create_timer_thread, native_cond_initialize,
native_cond_destroy): Replaced wrong HAVE_XXX checks.
* configure.in (pthread_attr_init): New check.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (get_stack): seems stack size does not include
guard size on Mac OS X.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36014 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (ruby_init_stack): adjust stack size for offset of
addr from the bottom.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (ruby_init_stack): use stack info if possible.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* configure.in: fix function name to be checked, to initialize
rb_thread_cond_t properly.
* thread_pthread.c (native_cond_initialize, native_cond_destroy):
fix macro name.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35676 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Patch by Google Inc. [ruby-core:45073].
* configure.in (RUBY_NACL): New M4 func to configure variables for
NaCl.
(RUBY_NACL_CHECK_PEPPER_TYPES): New M4 func to check the old names
of Pepper interface types.
(BTESTRUBY): New variable to specify which ruby should be run on
"make btest". NaCl can run the built binary by sel_ldr, but it need
rbconfig.rb. So this variable is distinguished from $MINIRUBY.
* thread_pthread.c: Disabled some features on NaCl.
* io.c: ditto.
* process.c: ditto.
* signal.c: ditto.
* file.c: ditto.
* missing/flock.c: ditto.
* nacl/pepper_main.c: An example implementation of Pepper application
that embeds Ruby.
* nacl/example.html: An example of web page that uses the Pepper
application.
* nacl/nacl-config.rb: Detects variants of NaCl SDK.
* nacl/GNUmakefile.in: Makefile template for NaCl specific build
process.
* nacl/package.rb: script for packaging a NaCl-Ruby embedding
application.
* nacl/reate_nmf.rb: Wrapper script of create_nmf.py
* dln.c (dln_load): Added a hack to call on NaCl.
* util.c (ruby_getcwd): Path to the current directort is not available
on NaCl.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (check_signal_thread_list): add a new function to
check if signal thread list is empty.
* thread_pthread.c (thread_timer): check signal thread list after
timer_thread_function(). main thread might be added into signal thread
list during timer_thread_function().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34099 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
only when it is not timer_thread. [Bug #5757] [ruby-dev:44985]
patched by Tomoyuki Chikanaga.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34038 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* thread_pthread.c (thread_timer): call prctl(PR_SET_NAME) to change
thread name. It may help to debug.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33912 b2dd03c8-39d4-4d8f-98ff-823fe69b080e