Implement --zjit-call-threshold
As a preparation for introducing a profiling layer, we need to be able to raise the threshold to run a few cycles for profiling.
This commit is contained in:
parent
06d875b979
commit
53bee25068
Notes:
git
2025-04-18 13:48:36 +00:00
2
.github/workflows/zjit-macos.yml
vendored
2
.github/workflows/zjit-macos.yml
vendored
@ -30,7 +30,7 @@ jobs:
|
|||||||
configure: '--enable-zjit=dev'
|
configure: '--enable-zjit=dev'
|
||||||
|
|
||||||
- test_task: 'btest'
|
- test_task: 'btest'
|
||||||
zjit_opts: '--zjit'
|
zjit_opts: '--zjit-call-threshold=1'
|
||||||
configure: '--enable-zjit=dev'
|
configure: '--enable-zjit=dev'
|
||||||
btests: '../src/bootstraptest/test_zjit.rb'
|
btests: '../src/bootstraptest/test_zjit.rb'
|
||||||
|
|
||||||
|
2
.github/workflows/zjit-ubuntu.yml
vendored
2
.github/workflows/zjit-ubuntu.yml
vendored
@ -35,7 +35,7 @@ jobs:
|
|||||||
configure: '--enable-zjit=dev'
|
configure: '--enable-zjit=dev'
|
||||||
|
|
||||||
- test_task: 'btest'
|
- test_task: 'btest'
|
||||||
zjit_opts: '--zjit'
|
zjit_opts: '--zjit-call-threshold=1'
|
||||||
configure: '--enable-zjit=dev'
|
configure: '--enable-zjit=dev'
|
||||||
btests: '../src/bootstraptest/test_zjit.rb'
|
btests: '../src/bootstraptest/test_zjit.rb'
|
||||||
|
|
||||||
|
3
vm.c
3
vm.c
@ -437,9 +437,10 @@ jit_compile(rb_execution_context_t *ec)
|
|||||||
// Increment the ISEQ's call counter and trigger JIT compilation if not compiled
|
// Increment the ISEQ's call counter and trigger JIT compilation if not compiled
|
||||||
#if USE_ZJIT
|
#if USE_ZJIT
|
||||||
extern bool rb_zjit_enabled_p;
|
extern bool rb_zjit_enabled_p;
|
||||||
|
extern uint64_t rb_zjit_call_threshold;
|
||||||
if (body->jit_entry == NULL && rb_zjit_enabled_p) {
|
if (body->jit_entry == NULL && rb_zjit_enabled_p) {
|
||||||
body->jit_entry_calls++;
|
body->jit_entry_calls++;
|
||||||
if (body->jit_entry_calls == 1) {
|
if (body->jit_entry_calls == rb_zjit_call_threshold) {
|
||||||
extern void rb_zjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception);
|
extern void rb_zjit_compile_iseq(const rb_iseq_t *iseq, rb_execution_context_t *ec, bool jit_exception);
|
||||||
rb_zjit_compile_iseq(iseq, ec, false);
|
rb_zjit_compile_iseq(iseq, ec, false);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
use std::{ffi::CStr, os::raw::c_char};
|
use std::{ffi::CStr, os::raw::c_char};
|
||||||
|
|
||||||
|
// This option is exposed to the C side in a global variable for performance, see vm.c
|
||||||
|
// Number of method calls after which to start generating code
|
||||||
|
// Threshold==1 means compile on first execution
|
||||||
|
#[no_mangle]
|
||||||
|
#[allow(non_upper_case_globals)]
|
||||||
|
pub static mut rb_zjit_call_threshold: u64 = 1;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
/// Enable debug logging
|
/// Enable debug logging
|
||||||
@ -79,6 +86,11 @@ fn parse_option(options: &mut Options, str_ptr: *const std::os::raw::c_char) ->
|
|||||||
match (opt_name, opt_val) {
|
match (opt_name, opt_val) {
|
||||||
("", "") => {}, // Simply --zjit
|
("", "") => {}, // Simply --zjit
|
||||||
|
|
||||||
|
("call-threshold", _) => match opt_val.parse() {
|
||||||
|
Ok(n) => unsafe { rb_zjit_call_threshold = n },
|
||||||
|
Err(_) => return None,
|
||||||
|
},
|
||||||
|
|
||||||
("debug", "") => options.debug = true,
|
("debug", "") => options.debug = true,
|
||||||
|
|
||||||
("dump-ssa", "") => options.dump_ssa = Some(DumpSSA::WithoutSnapshot),
|
("dump-ssa", "") => options.dump_ssa = Some(DumpSSA::WithoutSnapshot),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user