Skip to content

Commit

Permalink
trace-cmd library: Fix tracecmd_iterate_events_multi() CPU clean up
Browse files Browse the repository at this point in the history
In tracecmd_iterate_events_multi(), the clean up code at the end of the
function that unlocks and frees the remaining records, iterated the CPUs via
a for loop of 0 through all_cpus. But the kbuffer_read_at_offset() function,
expects the CPU passed in to be that of the handle and not of all the
handles.

That is, if there are two trace.dat files being read, and one has 4 CPUs and
the other has 2, the "all_cpus" variable will be 6. When iterating at the
clean up, when it gets passed 3 (4 CPUs is represented by 0-3) it will then
go to 4 and then 5 for the 2 CPUs trace.dat file. Passing in 4 or 5 to
kbuffer_read_at_offset() will fail. It needs to use the local CPU count of
the trace.dat file.

Link: https://lore.kernel.org/linux-trace-devel/[email protected]

Fixes: 7f0a59a ("trace-cmd library: Have tracecmd_iterate_events() start where it left off")
Signed-off-by: Steven Rostedt (Google) <[email protected]>
  • Loading branch information
rostedt committed Dec 29, 2023
1 parent 5274db3 commit 66d3beb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/trace-cmd/trace-input.c
Original file line number Diff line number Diff line change
Expand Up @@ -3143,7 +3143,7 @@ int tracecmd_iterate_events_multi(struct tracecmd_input **handles,
offset = (int)(records[cpu].record->offset & (handle->page_size - 1));
free_next(handle, local_cpu);
/* Reset the buffer to read the cached record again */
kbuffer_read_at_offset(handle->cpu_data[cpu].kbuf, offset, NULL);
kbuffer_read_at_offset(handle->cpu_data[local_cpu].kbuf, offset, NULL);
}

free(records);
Expand Down

0 comments on commit 66d3beb

Please sign in to comment.