Skip to content

Commit

Permalink
bperf: Skip cgroup walking for idle task (facebookincubator#197)
Browse files Browse the repository at this point in the history
Summary:

While we still need read perf events for all the context switch, we can
skip cgroup walking for idle task.

Reviewed By: anakryiko

Differential Revision: D51837045
  • Loading branch information
liu-song-6 authored and facebook-github-bot committed Dec 5, 2023
1 parent 7fc0151 commit 9318665
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion hbt/src/perf_event/bpf/bperf_leader_cgroup.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,23 @@ struct {
int event_cnt = 0;
int cpu_cnt = 0;

#define PF_IDLE 0x00000002

static void update_cgroup_output(struct bpf_perf_event_value* diff_val) {
struct task_struct* task = bpf_get_current_task_btf();
struct cgroup* cgrp = BPF_CORE_READ(task, cgroups, dfl_cgrp);
struct cgroup* cgrp;
__u32 i, level;

/* sched_switch tracepoint is triggered before current task is updated.
* If current task is idle (PF_IDLE), it means we are switching _from_
* idle to non-idle task, and current "slice" of counts belongs to idle.
* It is ok to skip cgroup walk for idle task.
*/
if (task->flags & PF_IDLE)
return;

cgrp = BPF_CORE_READ(task, cgroups, dfl_cgrp);

for (level = 0; level < MAX_CGROUP_LEVELS; level++) {
__u64 id = BPF_CORE_READ(cgrp, kn, id);
struct bpf_perf_event_value* val;
Expand Down

0 comments on commit 9318665

Please sign in to comment.