Skip to content

Commit

Permalink
hbt/bperf: Update array information right after array_map_mmap (#299)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #299

This is needed so that we can get valid reading before the first context
switch.

Reviewed By: Alston-Tang

Differential Revision: D63348456
  • Loading branch information
liu-song-6 authored and facebook-github-bot committed Sep 25, 2024
1 parent 5ffdf07 commit 3a6b4ae
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 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 @@ -209,13 +209,16 @@ static int __always_inline bperf_update_thread_time(struct bperf_thread_data *da

__u32 per_thread_data_id; /* map id of per_thread_data */

static void __always_inline update_next_task(struct task_struct *next, __u64 now);

/* Trace mmap of per_thread_data */
SEC("fentry/array_map_mmap")
int BPF_PROG(bperf_register_thread, struct bpf_map *map) {
struct bperf_thread_data *data;
__u32 map_id = map->id;
__u32 tid;
__u32 idx;
__u64 now;

if (map_id != per_thread_data_id)
return 0;
Expand All @@ -237,7 +240,9 @@ int BPF_PROG(bperf_register_thread, struct bpf_map *map) {
bpf_map_update_elem(&per_thread_idx, &tid, &idx, BPF_ANY);

data->runtime_until_schedin = 0;
bperf_update_thread_time(data, bpf_ktime_get_ns());
now = bpf_ktime_get_ns();
bperf_update_thread_time(data, now);
update_next_task(bpf_get_current_task_btf(), now);
return 0;
}

Expand Down

0 comments on commit 3a6b4ae

Please sign in to comment.