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

libbpf-tools/offcputime: Use CO-RE operation to read kernel data #4471

Closed
wants to merge 1 commit into from
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
8 changes: 4 additions & 4 deletions libbpf-tools/offcputime.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ int BPF_PROG(sched_switch, bool preempt, struct task_struct *prev, struct task_s
u32 pid;

if (allow_record(prev)) {
pid = prev->pid;
pid = BPF_CORE_READ(prev, pid);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tp_btf is BTF-awared, pointer chasing should work, right ?

Copy link
Contributor Author

@ekyooo ekyooo Feb 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... I didn't know that. Thank you for the information. Does tp_btf support depend on kernel version?
A segfault occurred when running the default version of offfcputime on my Linux v5.4 kernel environment. So I switched tp_btf to tracepoint as below. So this patch was needed.

-SEC("tp_btf/sched_switch")
+SEC("tracepoint/sched/sched_switch")

Could you please tell me if tp_btf is supported in Linux v5.4 as well?
Thank you in advance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I got information from another engineer that tp_btf is not supported in Linux v5.4. I abandon this patch. Thank you.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #4231.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh..!! Thank you. I'll read it carefully.

/* To distinguish idle threads of different cores */
if (!pid)
pid = bpf_get_smp_processor_id();
i_key.key.pid = pid;
i_key.key.tgid = prev->tgid;
i_key.key.tgid = BPF_CORE_READ(prev, tgid);
i_key.start_ts = bpf_ktime_get_ns();

if (prev->flags & PF_KTHREAD)
if (BPF_CORE_READ(prev, flags) & PF_KTHREAD)
i_key.key.user_stack_id = -1;
else
i_key.key.user_stack_id =
Expand All @@ -87,7 +87,7 @@ int BPF_PROG(sched_switch, bool preempt, struct task_struct *prev, struct task_s
bpf_map_update_elem(&info, &i_key.key, &val, BPF_NOEXIST);
}

pid = next->pid;
pid = BPF_CORE_READ(next, pid);
i_keyp = bpf_map_lookup_elem(&start, &pid);
if (!i_keyp)
return 0;
Expand Down