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

bperf: Skip cgroup walking for idle task #197

Closed
Closed
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
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