Skip to content

Commit

Permalink
bperf: Do not use BPF_CORE_READ (#196)
Browse files Browse the repository at this point in the history
Summary:

Use direct BTF access to be faster.

We need bpf_rdonly_cast() here, to cast "struct cgroup_subsys_state *"
to "struct cgroup *"

Reviewed By: anakryiko

Differential Revision: D51837046
  • Loading branch information
liu-song-6 authored and facebook-github-bot committed Dec 5, 2023
1 parent 9318665 commit 4b0839c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions hbt/src/perf_event/bpf/bperf_leader_cgroup.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ int cpu_cnt = 0;

#define PF_IDLE 0x00000002

void *bpf_rdonly_cast(void *, __u32) __ksym __weak;

static void update_cgroup_output(struct bpf_perf_event_value* diff_val) {
struct task_struct* task = bpf_get_current_task_btf();
struct cgroup* cgrp;
Expand All @@ -64,13 +66,14 @@ static void update_cgroup_output(struct bpf_perf_event_value* diff_val) {
if (task->flags & PF_IDLE)
return;

cgrp = BPF_CORE_READ(task, cgroups, dfl_cgrp);
cgrp = task->cgroups->dfl_cgrp;

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

cgrp = (struct cgroup*)BPF_CORE_READ(cgrp, self.parent);
cgrp = bpf_rdonly_cast(cgrp->self.parent,
bpf_core_type_id_kernel(struct cgroup));
if (cgrp == NULL)
break;

Expand Down

0 comments on commit 4b0839c

Please sign in to comment.