diff options
author | Jean Boussier <[email protected]> | 2021-08-24 12:32:07 +0200 |
---|---|---|
committer | Alan Wu <[email protected]> | 2021-10-20 18:19:39 -0400 |
commit | 0dc3bba6f2b2b1b23e1ec9dd2ec29f932c292db0 (patch) | |
tree | c9db52ed439e6cf7fc3f48622718ce418f3b3849 /yjit_codegen.c | |
parent | 2ba090a1f9258035b40374f9ff9da3ff920701cd (diff) |
Allow to compile with --yjit-stats support but not the full RUBY_DEBUG
RUBY_DEBUG have a very significant performance overhead. Enough that
YJIT with RUBY_DEBUG is noticeably slower than the interpreter without
RUBY_DEBUG.
This makes it hard to collect yjit-stats in production environments.
By allowing to collect JIT statistics without the RUBy_DEBUG overhead,
I hope to make such use cases smoother.
Diffstat (limited to 'yjit_codegen.c')
-rw-r--r-- | yjit_codegen.c | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/yjit_codegen.c b/yjit_codegen.c index 3f9169a74b..a5f39d273b 100644 --- a/yjit_codegen.c +++ b/yjit_codegen.c @@ -159,30 +159,7 @@ jit_save_sp(jitstate_t* jit, ctx_t* ctx) static bool jit_guard_known_klass(jitstate_t *jit, ctx_t* ctx, VALUE known_klass, insn_opnd_t insn_opnd, VALUE sample_instance, const int max_chain_depth, uint8_t *side_exit); #if RUBY_DEBUG - -// Increment a profiling counter with counter_name -#define GEN_COUNTER_INC(cb, counter_name) _gen_counter_inc(cb, &(yjit_runtime_counters . counter_name)) -static void -_gen_counter_inc(codeblock_t *cb, int64_t *counter) -{ - if (!rb_yjit_opts.gen_stats) return; - mov(cb, REG0, const_ptr_opnd(counter)); - cb_write_lock_prefix(cb); // for ractors. - add(cb, mem_opnd(64, REG0, 0), imm_opnd(1)); -} - -// Increment a counter then take an existing side exit. -#define COUNTED_EXIT(side_exit, counter_name) _counted_side_exit(side_exit, &(yjit_runtime_counters . counter_name)) -static uint8_t * -_counted_side_exit(uint8_t *existing_side_exit, int64_t *counter) -{ - if (!rb_yjit_opts.gen_stats) return existing_side_exit; - - uint8_t *start = cb_get_ptr(ocb, ocb->write_pos); - _gen_counter_inc(ocb, counter); - jmp_ptr(ocb, existing_side_exit); - return start; -} +# define YJIT_STATS 1 // Add a comment at the current position in the code block static void @@ -268,14 +245,50 @@ verify_ctx(jitstate_t *jit, ctx_t *ctx) } #else +#ifndef YJIT_STATS +#define YJIT_STATS 0 +#endif // ifndef YJIT_STATS -#define GEN_COUNTER_INC(cb, counter_name) ((void)0) -#define COUNTED_EXIT(side_exit, counter_name) side_exit #define ADD_COMMENT(cb, comment) ((void)0) #define verify_ctx(jit, ctx) ((void)0) #endif // if RUBY_DEBUG +#if YJIT_STATS + +// Increment a profiling counter with counter_name +#define GEN_COUNTER_INC(cb, counter_name) _gen_counter_inc(cb, &(yjit_runtime_counters . counter_name)) +static void +_gen_counter_inc(codeblock_t *cb, int64_t *counter) +{ + if (!rb_yjit_opts.gen_stats) return; + mov(cb, REG0, const_ptr_opnd(counter)); + cb_write_lock_prefix(cb); // for ractors. + add(cb, mem_opnd(64, REG0, 0), imm_opnd(1)); +} + +// Increment a counter then take an existing side exit. +#define COUNTED_EXIT(side_exit, counter_name) _counted_side_exit(side_exit, &(yjit_runtime_counters . counter_name)) +static uint8_t * +_counted_side_exit(uint8_t *existing_side_exit, int64_t *counter) +{ + if (!rb_yjit_opts.gen_stats) return existing_side_exit; + + uint8_t *start = cb_get_ptr(ocb, ocb->write_pos); + _gen_counter_inc(ocb, counter); + jmp_ptr(ocb, existing_side_exit); + return start; +} + + +#else + +#define GEN_COUNTER_INC(cb, counter_name) ((void)0) +#define COUNTED_EXIT(side_exit, counter_name) side_exit + +#endif // if YJIT_STATS + + // Generate an exit to return to the interpreter static uint8_t * yjit_gen_exit(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb) @@ -302,7 +315,7 @@ yjit_gen_exit(jitstate_t *jit, ctx_t *ctx, codeblock_t *cb) mov(cb, member_opnd(REG_CFP, rb_control_frame_t, pc), RAX); // Accumulate stats about interpreter exits -#if RUBY_DEBUG +#if YJIT_STATS if (rb_yjit_opts.gen_stats) { mov(cb, RDI, const_ptr_opnd(exit_pc)); call_ptr(cb, RSI, (void *)&rb_yjit_count_side_exit_op); |