Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to exclude kernel events from perf results #995

Merged
merged 5 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ mimalloc-sys = { version = "0.1.6", optional = true }
mmtk-macros = { version = "0.20.0", path = "macros/" }
num_cpus = "1.8"
num-traits = "0.2"
pfm = { version = "0.1.0-beta.3", optional = true }
probe = "0.5"
pfm = { version = "0.1.1", optional = true }
portable-atomic = "1.4.3"
probe = "0.5"
regex = "1.7.0"
spin = "0.9.5"
static_assertions = "1.1.0"
Expand Down
7 changes: 6 additions & 1 deletion src/scheduler/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ impl<VM: VMBinding> WorkerLocalStat<VM> {
let mut counters: Vec<Box<dyn WorkCounter>> = vec![Box::new(WorkDuration::new())];
#[cfg(feature = "perf_counter")]
for e in &mmtk.options.work_perf_events.events {
counters.push(Box::new(WorkPerfEvent::new(&e.0, e.1, e.2)));
counters.push(Box::new(WorkPerfEvent::new(
&e.0,
e.1,
e.2,
*mmtk.options.perf_exclude_kernel,
)));
}
counters
}
Expand Down
3 changes: 2 additions & 1 deletion src/scheduler/work_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ mod perf_event {
/// 0, -1 measures the calling thread on all CPUs
/// -1, 0 measures all threads on CPU 0
/// -1, -1 is invalid
pub fn new(name: &str, pid: pid_t, cpu: c_int) -> WorkPerfEvent {
pub fn new(name: &str, pid: pid_t, cpu: c_int, exclude_kernel: bool) -> WorkPerfEvent {
let mut pe = PerfEvent::new(name, false)
.unwrap_or_else(|_| panic!("Failed to create perf event {}", name));
pe.set_exclude_kernel(exclude_kernel as u64);
pe.open(pid, cpu)
.unwrap_or_else(|_| panic!("Failed to open perf event {}", name));
WorkPerfEvent {
Expand Down
5 changes: 4 additions & 1 deletion src/util/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,9 @@ options! {
// Measuring perf events for GC and mutators
// TODO: Ideally this option should only be included when the features 'perf_counter' are enabled. The current macro does not allow us to do this.
phase_perf_events: PerfEventOptions [env_var: true, command_line: true] [|_| cfg!(feature = "perf_counter")] = PerfEventOptions {events: vec![]},
// Should we exclude perf events occurring in kernel space. By default we include the kernel.
// Only set this option if you know the implications of excluding the kernel!
perf_exclude_kernel: bool [env_var: true, command_line: true] [|_| cfg!(feature = "perf_counter")] = false,
// Set how to bind affinity to the GC Workers. Default thread affinity delegates to the OS
// scheduler. If a list of cores are specified, cores are allocated to threads in a round-robin
// fashion. The core ids should match the ones reported by /proc/cpuinfo. Core ids are
Expand All @@ -749,7 +752,7 @@ options! {
thread_affinity: AffinityKind [env_var: true, command_line: true] [|v: &AffinityKind| v.validate()] = AffinityKind::OsDefault,
// Set the GC trigger. This defines the heap size and how MMTk triggers a GC.
// Default to a fixed heap size of 0.5x physical memory.
gc_trigger : GCTriggerSelector [env_var: true, command_line: true] [|v: &GCTriggerSelector| v.validate()] = GCTriggerSelector::FixedHeapSize((crate::util::memory::get_system_total_memory() as f64 * 0.5f64) as usize),
gc_trigger: GCTriggerSelector [env_var: true, command_line: true] [|v: &GCTriggerSelector| v.validate()] = GCTriggerSelector::FixedHeapSize((crate::util::memory::get_system_total_memory() as f64 * 0.5f64) as usize),
// Enable transparent hugepage support via madvise (only Linux is supported)
transparent_hugepages: bool [env_var: true, command_line: true] [|v: &bool| !v || cfg!(target_os = "linux")] = false
}
Expand Down
3 changes: 2 additions & 1 deletion src/util/statistics/counter/perf_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ pub struct PerfEventDiffable {
}

impl PerfEventDiffable {
pub fn new(name: &str) -> Self {
pub fn new(name: &str, exclude_kernel: bool) -> Self {
let mut pe = PerfEvent::new(name, true)
.unwrap_or_else(|_| panic!("Failed to create perf event {}", name));
pe.set_exclude_kernel(exclude_kernel as u64);
k-sareen marked this conversation as resolved.
Show resolved Hide resolved
// measures the calling thread (and all child threads) on all CPUs
pe.open(0, -1)
.unwrap_or_else(|_| panic!("Failed to open perf event {}", name));
Expand Down
2 changes: 1 addition & 1 deletion src/util/statistics/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Stats {
shared.clone(),
true,
false,
PerfEventDiffable::new(&e.0),
PerfEventDiffable::new(&e.0, *options.perf_exclude_kernel),
))));
}
Stats {
Expand Down
Loading