Skip to content

Commit

Permalink
tools: Fix runqslower invalid read error when option -t was selected
Browse files Browse the repository at this point in the history
  • Loading branch information
xingfeng2510 authored and yonghong-song committed May 1, 2022
1 parent f26b2a5 commit 6c16b2e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions tools/runqslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@
// calculate latency
int trace_run(struct pt_regs *ctx, struct task_struct *prev)
{
u32 pid, tgid, prev_pid;
u32 pid, tgid;
// ivcsw: treat like an enqueue event and store timestamp
prev_pid = prev->pid;
if (prev->STATE_FIELD == TASK_RUNNING) {
tgid = prev->tgid;
pid = prev->pid;
u64 ts = bpf_ktime_get_ns();
if (prev_pid != 0) {
if (pid != 0) {
if (!(FILTER_PID) && !(FILTER_TGID)) {
start.update(&prev_pid, &ts);
start.update(&pid, &ts);
}
}
}
Expand All @@ -144,7 +144,7 @@
struct data_t data = {};
data.pid = pid;
data.prev_pid = prev_pid;
data.prev_pid = prev->pid;
data.delta_us = delta_us;
bpf_get_current_comm(&data.task, sizeof(data.task));
bpf_probe_read_kernel_str(&data.prev_task, sizeof(data.prev_task), prev->comm);
Expand Down Expand Up @@ -181,27 +181,29 @@
// TP_PROTO(bool preempt, struct task_struct *prev, struct task_struct *next)
struct task_struct *prev = (struct task_struct *)ctx->args[1];
struct task_struct *next= (struct task_struct *)ctx->args[2];
u32 tgid, pid, prev_pid;
u32 tgid, pid;
long state;
// ivcsw: treat like an enqueue event and store timestamp
bpf_probe_read_kernel(&state, sizeof(long), (const void *)&prev->STATE_FIELD);
bpf_probe_read_kernel(&prev_pid, sizeof(prev->pid), &prev->pid);
bpf_probe_read_kernel(&pid, sizeof(prev->pid), &prev->pid);
if (state == TASK_RUNNING) {
bpf_probe_read_kernel(&tgid, sizeof(prev->tgid), &prev->tgid);
u64 ts = bpf_ktime_get_ns();
if (prev_pid != 0) {
if (pid != 0) {
if (!(FILTER_PID) && !(FILTER_TGID)) {
start.update(&prev_pid, &ts);
start.update(&pid, &ts);
}
}
}
bpf_probe_read_kernel(&pid, sizeof(next->pid), &next->pid);
u32 prev_pid;
u64 *tsp, delta_us;
prev_pid = pid;
bpf_probe_read_kernel(&pid, sizeof(next->pid), &next->pid);
// fetch timestamp and calculate delta
tsp = start.lookup(&pid);
if (tsp == 0) {
Expand Down

0 comments on commit 6c16b2e

Please sign in to comment.