aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Rostedt (Google) <rostedt@goodmis.org>2024-01-08 12:34:20 -0500
committerSteven Rostedt (Google) <rostedt@goodmis.org>2024-01-08 15:10:48 -0500
commit4b2286c3ef8317239ed5290f381970c14d8b3fe9 (patch)
treee7ad23ce0e1c914990a5bf2eacaa90813e8838ff
parentce0acec384c8b9cd3859291362272107c24fb20e (diff)
downloadlibtraceevent-4b2286c3ef8317239ed5290f381970c14d8b3fe9.tar.gz
kbuffer: Always walk the events to calculate timestamp in kbuffer_read_buffer()
If the buffer to read the kbuffer subbuffer is big enough to hold the entire buffer, it was simply copied. But this is not good enough, as the next read should include the events after what was copied. That means the timestamps need to be calculated. Just copying the data is not enough as the timestamp of any event is an offset of the previous event. To know the event timestamp after what was copied, the timestamps of the events before it need to be read, to know what the offset is against of the following event. Link: https://lore.kernel.org/linux-trace-devel/ZZwFvyGvm0C38eBh@google.com/ Link: https://lore.kernel.org/linux-trace-devel/20240108123420.5e227075@gandalf.local.home Fixes: 05821189 ("kbuffer: Add kbuffer_read_buffer()") Reported-by: Vincent Donnefort <vdonnefort@google.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--src/kbuffer-parse.c28
1 files changed, 5 insertions, 23 deletions
diff --git a/src/kbuffer-parse.c b/src/kbuffer-parse.c
index d43fe5d..691d536 100644
--- a/src/kbuffer-parse.c
+++ b/src/kbuffer-parse.c
@@ -947,19 +947,12 @@ kbuffer_raw_get(struct kbuffer *kbuf, void *subbuf, struct kbuffer_raw_info *inf
*/
int kbuffer_read_buffer(struct kbuffer *kbuf, void *buffer, int len)
{
- int subbuf_size = kbuf->start + kbuf->size;
unsigned long long ts;
unsigned int type_len_ts;
bool do_swap = false;
int last_next;
int save_curr;
- if (!kbuf->curr && len >= subbuf_size) {
- memcpy(buffer, kbuf->subbuffer, subbuf_size);
- set_curr_to_end(kbuf);
- return kbuf->size;
- }
-
/* Are we at the end of the buffer */
if (kbuf->curr >= kbuf->size)
return 0;
@@ -982,24 +975,13 @@ int kbuffer_read_buffer(struct kbuffer *kbuf, void *buffer, int len)
save_curr = kbuf->curr;
- /* Copy the rest of the buffer if it fits */
- if (len >= kbuf->size - kbuf->curr) {
- set_curr_to_end(kbuf);
- last_next = kbuf->size;
- } else {
- /*
- * The length doesn't hold the rest,
- * need to find the last that fits
- */
+ /* Due to timestamps, we must save the current next to use */
+ last_next = kbuf->next;
- /* Due to timestamps, we must save the current next to use */
+ while (len >= kbuf->next - save_curr) {
last_next = kbuf->next;
-
- while (len > kbuf->next - save_curr) {
- last_next = kbuf->next;
- if (!kbuffer_next_event(kbuf, &ts))
- break;
- }
+ if (!kbuffer_next_event(kbuf, &ts))
+ break;
}
len = last_next - save_curr;