Skip to content

Commit

Permalink
Fix call threshold issue with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Oct 2, 2023
1 parent e30a0e5 commit 7a194ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ jit_compile_exception(rb_execution_context_t *ec)
rb_yjit_compile_iseq(iseq, ec, true);
}
}

return body->jit_exception;
}

Expand Down
4 changes: 2 additions & 2 deletions yjit/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,8 +981,8 @@ pub struct IseqPayload {
// The code GC will free them later.
pub dead_blocks: Vec<BlockRef>,

// Number of calls when we hit the threshold for this ISEQs
pub call_count_at_threshold: u64,
// Used to estimate how frequently this ISEQ gets called
pub call_count_at_interv: u64,
}

impl IseqPayload {
Expand Down
18 changes: 11 additions & 7 deletions yjit/src/yjit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ pub fn yjit_enabled_p() -> bool {
// Counter to serve as a proxy for execution time, total number of calls
static mut TOTAL_ENTRY_HITS: u64 = 0;

// Number of calls used to estimate how hot an ISEQ is
static CALL_COUNT_INTERV: u64 = 20;

/// Test whether we are ready to compile an ISEQ or not
#[no_mangle]
pub extern "C" fn rb_yjit_threshold_hit(iseq: IseqPtr, total_calls: u64) -> bool {

let call_threshold = get_option!(call_threshold) as u64;

unsafe { TOTAL_ENTRY_HITS += 1; }
Expand All @@ -64,23 +68,23 @@ pub extern "C" fn rb_yjit_threshold_hit(iseq: IseqPtr, total_calls: u64) -> bool
// We expect threshold 1 to compile everything immediately
// We need to compare for equality here because otherwise we
// can get a deaclock with ractors
if call_threshold == 1 && total_calls == call_threshold {
return true;
if call_threshold < CALL_COUNT_INTERV {
return total_calls == call_threshold;
}

// If we are at the threshold
if total_calls == call_threshold {
// Record the number of calls at the beginning of the interval
if total_calls == call_threshold - CALL_COUNT_INTERV {
let payload = get_or_create_iseq_payload(iseq);
let call_count = unsafe { TOTAL_ENTRY_HITS };
payload.call_count_at_threshold = call_count;
payload.call_count_at_interv = call_count;
}

// Try to estimate the total time taken (total number of calls) to reach 20 calls to this ISEQ
// This give us a ratio of how hot/cold this ISEQ is
if total_calls == call_threshold + 20 {
if total_calls == call_threshold {
let payload = get_or_create_iseq_payload(iseq);
let call_count = unsafe { TOTAL_ENTRY_HITS };
let num_calls = call_count - payload.call_count_at_threshold;
let num_calls = call_count - payload.call_count_at_interv;

// Reject ISEQs that don't get called often enough
if num_calls > get_option!(cold_threshold) as u64 {
Expand Down

0 comments on commit 7a194ff

Please sign in to comment.