aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authork0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-17 02:00:30 +0000
committerk0kubun <k0kubun@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-17 02:00:30 +0000
commitf3fbaca1950f6279b25c7f8903c7aa6a7599f5cc (patch)
treea514ffb661c5ae2767c4df6c73e69ab729fbe942
parentaee771377a4969a3c042a10931cd0b5453cc3e5d (diff)
downloadruby-f3fbaca1950f6279b25c7f8903c7aa6a7599f5cc.tar.gz
mjit.c: add timeout for --jit-wait
Sometimes test hangs in `mjit_get_iseq_func` like this: http://ci.rvm.jp/results/trunk-test@ruby-sky3/659391 It seems that a process waiting in `mjit_get_iseq_func` does no longer have MJIT worker thread. We don't wait for JIT finish forever. So I added timeout for the case. I'm not sure why there was no MJIT worker thread in ruby-sky3 test process though. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--mjit.c16
-rw-r--r--mjit.h2
2 files changed, 16 insertions, 2 deletions
diff --git a/mjit.c b/mjit.c
index ecd3ee6c0a..db2811e94f 100644
--- a/mjit.c
+++ b/mjit.c
@@ -1125,15 +1125,29 @@ mjit_add_iseq_to_process(const rb_iseq_t *iseq)
CRITICAL_SECTION_FINISH(3, "in add_iseq_to_process");
}
+/* For this timeout seconds, --jit-wait will wait for JIT compilation finish. */
+#define MJIT_WAIT_TIMEOUT_SECONDS 60
+
/* Wait for JIT compilation finish for --jit-wait. This should only return a function pointer
or NOT_COMPILABLE_JIT_ISEQ_FUNC. */
mjit_func_t
-mjit_get_iseq_func(const struct rb_iseq_constant_body *body)
+mjit_get_iseq_func(struct rb_iseq_constant_body *body)
{
struct timeval tv;
+ int tries = 0;
tv.tv_sec = 0;
tv.tv_usec = 1000;
while (body->jit_func == (mjit_func_t)NOT_READY_JIT_ISEQ_FUNC) {
+ tries++;
+ if (tries / 1000 > MJIT_WAIT_TIMEOUT_SECONDS) {
+ CRITICAL_SECTION_START(3, "in mjit_get_iseq_func to set jit_func");
+ body->jit_func = (mjit_func_t)NOT_COMPILABLE_JIT_ISEQ_FUNC; /* JIT worker seems dead. Give up. */
+ CRITICAL_SECTION_FINISH(3, "in mjit_get_iseq_func to set jit_func");
+ if (mjit_opts.warnings || mjit_opts.verbose)
+ fprintf(stderr, "MJIT warning: timed out to wait for JIT finish\n");
+ break;
+ }
+
CRITICAL_SECTION_START(3, "in mjit_get_iseq_func for a client wakeup");
rb_native_cond_broadcast(&mjit_worker_wakeup);
CRITICAL_SECTION_FINISH(3, "in mjit_get_iseq_func for a client wakeup");
diff --git a/mjit.h b/mjit.h
index 9bf2a00913..c52b253c04 100644
--- a/mjit.h
+++ b/mjit.h
@@ -56,7 +56,7 @@ extern struct mjit_options mjit_opts;
extern int mjit_init_p;
extern void mjit_add_iseq_to_process(const rb_iseq_t *iseq);
-extern mjit_func_t mjit_get_iseq_func(const struct rb_iseq_constant_body *body);
+extern mjit_func_t mjit_get_iseq_func(struct rb_iseq_constant_body *body);
RUBY_SYMBOL_EXPORT_END
extern int mjit_compile(FILE *f, const struct rb_iseq_constant_body *body, const char *funcname);