Skip to content

Commit

Permalink
fix(libpman): manage discarded events
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Terzolo <[email protected]>
  • Loading branch information
Andreagit97 authored and poiana committed May 7, 2024
1 parent d67ff09 commit 5560701
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions userspace/libpman/src/ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ static inline void *ringbuf__get_first_ring_event(struct ring *r, int pos)
{
int *len_ptr = NULL;
int len = 0;
void *sample = NULL;

/* If the consumer reaches the producer update the producer position to
* get the newly collected events.
Expand All @@ -275,16 +274,20 @@ static inline void *ringbuf__get_first_ring_event(struct ring *r, int pos)
return NULL;
}

/* Save the size of the event if we need to increment the consumer */
g_state.last_event_size = roundup_len(len);

/* the sample is not discarded kernel side. */
if((len & BPF_RINGBUF_DISCARD_BIT) == 0)
{
sample = (void *)len_ptr + BPF_RINGBUF_HDR_SZ;
/* Save the size of the event if we need to increment the consumer */
g_state.last_event_size = roundup_len(len);
return (void *)len_ptr + BPF_RINGBUF_HDR_SZ;
}
else
{
/* Discard the event kernel side and update the consumer position */
g_state.cons_pos[pos] += roundup_len(len);
smp_store_release(r->consumer_pos, g_state.cons_pos[pos]);
return NULL;
}

return sample;
}

static void ringbuf__consume_first_event(struct ring_buffer *rb, struct ppm_evt_hdr **event_ptr, int16_t *buffer_id)
Expand Down

0 comments on commit 5560701

Please sign in to comment.