Skip to content

Commit 23ff088

Browse files
authored
Add option to exclude kernel events from perf results (#995)
This commit adds an option to exclude kernel events from perf results. We include kernel events by default. Note that previously kernel events were excluded by default.
1 parent a58246d commit 23ff088

File tree

6 files changed

+17
-7
lines changed

6 files changed

+17
-7
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ mimalloc-sys = { version = "0.1.6", optional = true }
4040
mmtk-macros = { version = "0.20.0", path = "macros/" }
4141
num_cpus = "1.8"
4242
num-traits = "0.2"
43-
pfm = { version = "0.1.0-beta.3", optional = true }
44-
probe = "0.5"
43+
pfm = { version = "0.1.1", optional = true }
4544
portable-atomic = "1.4.3"
45+
probe = "0.5"
4646
regex = "1.7.0"
4747
spin = "0.9.5"
4848
static_assertions = "1.1.0"

src/scheduler/stat.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,12 @@ impl<VM: VMBinding> WorkerLocalStat<VM> {
240240
let mut counters: Vec<Box<dyn WorkCounter>> = vec![Box::new(WorkDuration::new())];
241241
#[cfg(feature = "perf_counter")]
242242
for e in &mmtk.options.work_perf_events.events {
243-
counters.push(Box::new(WorkPerfEvent::new(&e.0, e.1, e.2)));
243+
counters.push(Box::new(WorkPerfEvent::new(
244+
&e.0,
245+
e.1,
246+
e.2,
247+
*mmtk.options.perf_exclude_kernel,
248+
)));
244249
}
245250
counters
246251
}

src/scheduler/work_counter.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ mod perf_event {
162162
/// 0, -1 measures the calling thread on all CPUs
163163
/// -1, 0 measures all threads on CPU 0
164164
/// -1, -1 is invalid
165-
pub fn new(name: &str, pid: pid_t, cpu: c_int) -> WorkPerfEvent {
165+
pub fn new(name: &str, pid: pid_t, cpu: c_int, exclude_kernel: bool) -> WorkPerfEvent {
166166
let mut pe = PerfEvent::new(name, false)
167167
.unwrap_or_else(|_| panic!("Failed to create perf event {}", name));
168+
pe.set_exclude_kernel(exclude_kernel as u64);
168169
pe.open(pid, cpu)
169170
.unwrap_or_else(|_| panic!("Failed to open perf event {}", name));
170171
WorkPerfEvent {

src/util/options.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,9 @@ options! {
733733
// Measuring perf events for GC and mutators
734734
// 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.
735735
phase_perf_events: PerfEventOptions [env_var: true, command_line: true] [|_| cfg!(feature = "perf_counter")] = PerfEventOptions {events: vec![]},
736+
// Should we exclude perf events occurring in kernel space. By default we include the kernel.
737+
// Only set this option if you know the implications of excluding the kernel!
738+
perf_exclude_kernel: bool [env_var: true, command_line: true] [|_| cfg!(feature = "perf_counter")] = false,
736739
// Set how to bind affinity to the GC Workers. Default thread affinity delegates to the OS
737740
// scheduler. If a list of cores are specified, cores are allocated to threads in a round-robin
738741
// fashion. The core ids should match the ones reported by /proc/cpuinfo. Core ids are
@@ -749,7 +752,7 @@ options! {
749752
thread_affinity: AffinityKind [env_var: true, command_line: true] [|v: &AffinityKind| v.validate()] = AffinityKind::OsDefault,
750753
// Set the GC trigger. This defines the heap size and how MMTk triggers a GC.
751754
// Default to a fixed heap size of 0.5x physical memory.
752-
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),
755+
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),
753756
// Enable transparent hugepage support via madvise (only Linux is supported)
754757
transparent_hugepages: bool [env_var: true, command_line: true] [|v: &bool| !v || cfg!(target_os = "linux")] = false
755758
}

src/util/statistics/counter/perf_event.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ pub struct PerfEventDiffable {
99
}
1010

1111
impl PerfEventDiffable {
12-
pub fn new(name: &str) -> Self {
12+
pub fn new(name: &str, exclude_kernel: bool) -> Self {
1313
let mut pe = PerfEvent::new(name, true)
1414
.unwrap_or_else(|_| panic!("Failed to create perf event {}", name));
15+
pe.set_exclude_kernel(exclude_kernel as u64);
1516
// measures the calling thread (and all child threads) on all CPUs
1617
pe.open(0, -1)
1718
.unwrap_or_else(|_| panic!("Failed to open perf event {}", name));

src/util/statistics/stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Stats {
9191
shared.clone(),
9292
true,
9393
false,
94-
PerfEventDiffable::new(&e.0),
94+
PerfEventDiffable::new(&e.0, *options.perf_exclude_kernel),
9595
))));
9696
}
9797
Stats {

0 commit comments

Comments
 (0)