Skip to content

Commit

Permalink
cpudist: create sufficiently large hash table to avoid missing tasks
Browse files Browse the repository at this point in the history
This change fixes the cpudist tool to avoid issue when too many tasks
are running.

Fixes iovisor#2567 -- cpudist stop working when there are too many fork
  • Loading branch information
TristanCacqueray committed Oct 23, 2019
1 parent 9347969 commit 9b433f2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tools/cpudist.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
} pid_key_t;
BPF_HASH(start, u32, u64);
BPF_HASH(start, u32, u64, MAX_PID);
STORAGE
static inline void store_start(u32 tgid, u32 pid, u64 ts)
Expand Down Expand Up @@ -142,7 +142,7 @@
pid = "pid"
section = "tid"
bpf_text = bpf_text.replace('STORAGE',
'BPF_HISTOGRAM(dist, pid_key_t);')
'BPF_HISTOGRAM(dist, pid_key_t, MAX_PID);')
bpf_text = bpf_text.replace('STORE',
'pid_key_t key = {.id = ' + pid + ', .slot = bpf_log2l(delta)}; ' +
'dist.increment(key);')
Expand All @@ -156,7 +156,9 @@
if args.ebpf:
exit()

b = BPF(text=bpf_text)
max_pid = int(open("/proc/sys/kernel/pid_max").read())

b = BPF(text=bpf_text, cflags=["-DMAX_PID=%d" % max_pid])
b.attach_kprobe(event="finish_task_switch", fn_name="sched_switch")

print("Tracing %s-CPU time... Hit Ctrl-C to end." %
Expand Down

0 comments on commit 9b433f2

Please sign in to comment.