Skip to content

Commit

Permalink
YJIT: Make compiled_* stats available by default (#8379)
Browse files Browse the repository at this point in the history
* YJIT: Make compiled_* stats available by default

* Update comment about default counters [ci skip]

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>

---------

Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
  • Loading branch information
k0kubun and maximecb committed Sep 6, 2023
1 parent dee383b commit a334077
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
3 changes: 2 additions & 1 deletion yjit/src/asm/mod.rs
Expand Up @@ -6,6 +6,7 @@ use crate::core::IseqPayload;
use crate::core::for_each_off_stack_iseq_payload;
use crate::core::for_each_on_stack_iseq_payload;
use crate::invariants::rb_yjit_tracing_invalidate_all;
use crate::stats::incr_counter;
use crate::virtualmem::WriteError;

#[cfg(feature = "disasm")]
Expand Down Expand Up @@ -652,7 +653,7 @@ impl CodeBlock {
ocb.unwrap().freed_pages = new_freed_pages;
assert_eq!(1, Rc::strong_count(&old_freed_pages)); // will deallocate

CodegenGlobals::incr_code_gc_count();
incr_counter!(code_gc_count);
}

pub fn inline(&self) -> bool {
Expand Down
15 changes: 3 additions & 12 deletions yjit/src/codegen.rs
Expand Up @@ -249,6 +249,9 @@ pub enum JCCKinds {

#[inline(always)]
fn gen_counter_incr(asm: &mut Assembler, counter: Counter) {
// Assert that default counters are not incremented by generated code as this would impact performance
assert!(!DEFAULT_COUNTERS.contains(&counter), "gen_counter_incr incremented {:?}", counter);

if get_option!(gen_stats) {
asm.comment(&format!("increment counter {}", counter.get_name()));
let ptr = get_counter_ptr(&counter.get_name());
Expand Down Expand Up @@ -8581,9 +8584,6 @@ pub struct CodegenGlobals {

/// Page indexes for outlined code that are not associated to any ISEQ.
ocb_pages: Vec<usize>,

/// How many times code GC has been executed.
code_gc_count: usize,
}

/// For implementing global code invalidation. A position in the inline
Expand Down Expand Up @@ -8679,7 +8679,6 @@ impl CodegenGlobals {
global_inval_patches: Vec::new(),
method_codegen_table: HashMap::new(),
ocb_pages,
code_gc_count: 0,
};

// Register the method codegen functions
Expand Down Expand Up @@ -8841,14 +8840,6 @@ impl CodegenGlobals {
pub fn get_ocb_pages() -> &'static Vec<usize> {
&CodegenGlobals::get_instance().ocb_pages
}

pub fn incr_code_gc_count() {
CodegenGlobals::get_instance().code_gc_count += 1;
}

pub fn get_code_gc_count() -> usize {
CodegenGlobals::get_instance().code_gc_count
}
}

#[cfg(test)]
Expand Down
30 changes: 25 additions & 5 deletions yjit/src/stats.rs
Expand Up @@ -163,6 +163,17 @@ macro_rules! make_counters {
}
}

/// The list of counters that are available without --yjit-stats.
/// They are incremented only by `incr_counter!` and don't use `gen_counter_incr`.
pub const DEFAULT_COUNTERS: [Counter; 6] = [
Counter::code_gc_count,
Counter::compiled_iseq_entry,
Counter::compiled_iseq_count,
Counter::compiled_blockid_count,
Counter::compiled_block_count,
Counter::compiled_branch_count,
];

/// Macro to increase a counter by name and count
macro_rules! incr_counter_by {
// Unsafe is ok here because options are initialized
Expand Down Expand Up @@ -424,6 +435,8 @@ make_counters! {
// executable memory, so this should be 0.
exec_mem_non_bump_alloc,

code_gc_count,

num_gc_obj_refs,

num_send,
Expand Down Expand Up @@ -571,9 +584,6 @@ fn rb_yjit_gen_stats_dict(context: bool) -> VALUE {
// Live pages
hash_aset_usize!(hash, "live_page_count", cb.num_mapped_pages() - freed_page_count);

// Code GC count
hash_aset_usize!(hash, "code_gc_count", CodegenGlobals::get_code_gc_count());

// Size of memory region allocated for JIT code
hash_aset_usize!(hash, "code_region_size", cb.mapped_region_size());

Expand All @@ -594,13 +604,23 @@ fn rb_yjit_gen_stats_dict(context: bool) -> VALUE {
hash_aset_usize!(hash, "vm_insns_count", rb_vm_insns_count as usize);
}

// If we're not generating stats, the hash is done
// If we're not generating stats, put only default counters
if !get_option!(gen_stats) {
for counter in DEFAULT_COUNTERS {
// Get the counter value
let counter_ptr = get_counter_ptr(&counter.get_name());
let counter_val = unsafe { *counter_ptr };

// Put counter into hash
let key = rust_str_to_sym(&counter.get_name());
let value = VALUE::fixnum_from_usize(counter_val as usize);
unsafe { rb_hash_aset(hash, key, value); }
}

return hash;
}

// If the stats feature is enabled

unsafe {
// Indicate that the complete set of stats is available
rb_hash_aset(hash, rust_str_to_sym("all_stats"), Qtrue);
Expand Down

0 comments on commit a334077

Please sign in to comment.