Skip to content

Commit

Permalink
Try request count warmup heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Jul 14, 2023
1 parent 291bb4a commit 19945c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion yjit/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct Options {
// Initialize the options to default values
pub static mut OPTIONS: Options = Options {
exec_mem_size: 128 * 1024 * 1024,
call_threshold: 30,
call_threshold: 5,
greedy_versioning: false,
no_type_prop: false,
max_versions: 4,
Expand Down
22 changes: 20 additions & 2 deletions yjit/src/yjit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ use crate::stats::YjitExitLocations;
use crate::stats::incr_counter;

use std::os::raw;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};

/// For tracking whether the user enabled YJIT through command line arguments or environment
/// variables. AtomicBool to avoid `unsafe`. On x86 it compiles to simple movs.
/// See <https://doc.rust-lang.org/std/sync/atomic/enum.Ordering.html>
/// See [rb_yjit_enabled_p]
static YJIT_ENABLED: AtomicBool = AtomicBool::new(false);


static YJIT_REQUEST_COUNT: AtomicUsize = AtomicUsize::new(0);



/// When false, we don't compile new iseqs, but might still service existing branch stubs.
static COMPILE_NEW_ISEQS: AtomicBool = AtomicBool::new(false);

Expand Down Expand Up @@ -52,7 +57,20 @@ pub extern "C" fn rb_yjit_threshold_hit(iseq: IseqPtr) -> bool {
let call_threshold = get_option!(call_threshold) as u64;
let total_calls = unsafe { rb_get_iseq_body_total_calls(iseq) } as u64;

return total_calls == call_threshold;
if total_calls < call_threshold {
return false;
}

// Increment the request count
let req_count: usize = YJIT_REQUEST_COUNT.fetch_add(1, Ordering::Relaxed);

//println!("req_count={}\n", req_count);

if req_count % 120 == 0 {
return true;
}

return false;
}

/// This function is called from C code
Expand Down

0 comments on commit 19945c5

Please sign in to comment.