Commit 3c976bbd authored by Sasha Goldshtein's avatar Sasha Goldshtein

cpudist: Fix extraneous filtering of descheduled tasks

When the `-O` switch was provided, cpudist was unnecessarily filtering
out scheduling events arising from a task waking up when the previous
task was not running. On an idle system, this happens a lot, and causes
events to be missed. This is now fixed.
parent 4b72f052
...@@ -69,22 +69,16 @@ BPF_HASH(start, u32, u64); ...@@ -69,22 +69,16 @@ BPF_HASH(start, u32, u64);
BPF_HASH(tgid_for_pid, u32, u32); BPF_HASH(tgid_for_pid, u32, u32);
STORAGE STORAGE
#define INVALID_TGID 0xffffffff static inline u32 get_tgid(u32 pid)
static inline u32 get_tgid_if_missing(u32 tgid, u32 pid)
{ {
if (tgid == INVALID_TGID) { u32 *stored_tgid = tgid_for_pid.lookup(&pid);
u32 *stored_tgid = tgid_for_pid.lookup(&pid); if (stored_tgid != 0)
if (stored_tgid != 0) return *stored_tgid;
return *stored_tgid; return 0xffffffff;
}
return tgid;
} }
static inline void store_start(u32 tgid, u32 pid, u64 ts) static inline void store_start(u32 tgid, u32 pid, u64 ts)
{ {
tgid = get_tgid_if_missing(tgid, pid);
if (FILTER) if (FILTER)
return; return;
...@@ -93,8 +87,6 @@ static inline void store_start(u32 tgid, u32 pid, u64 ts) ...@@ -93,8 +87,6 @@ static inline void store_start(u32 tgid, u32 pid, u64 ts)
static inline void update_hist(u32 tgid, u32 pid, u64 ts) static inline void update_hist(u32 tgid, u32 pid, u64 ts)
{ {
tgid = get_tgid_if_missing(tgid, pid);
if (FILTER) if (FILTER)
return; return;
...@@ -123,17 +115,24 @@ int sched_switch(struct pt_regs *ctx) ...@@ -123,17 +115,24 @@ int sched_switch(struct pt_regs *ctx)
struct sched_switch_trace_entry args = {}; struct sched_switch_trace_entry args = {};
bpf_probe_read(&args, sizeof(args), (void *)*di); bpf_probe_read(&args, sizeof(args), (void *)*di);
// TODO: Store the comm as well
#ifdef ONCPU
if (args.prev_state == TASK_RUNNING) { if (args.prev_state == TASK_RUNNING) {
#else
if (1) {
#endif
u32 prev_pid = args.prev_pid; u32 prev_pid = args.prev_pid;
u32 prev_tgid = get_tgid(prev_pid);
if (prev_tgid == 0xffffffff)
goto BAIL;
#ifdef ONCPU #ifdef ONCPU
update_hist(INVALID_TGID, prev_pid, ts); update_hist(prev_tgid, prev_pid, ts);
#else #else
store_start(INVALID_TGID, prev_pid, ts); store_start(prev_tgid, prev_pid, ts);
#endif #endif
} }
BAIL:
#ifdef ONCPU #ifdef ONCPU
store_start(tgid, pid, ts); store_start(tgid, pid, ts);
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment