On Sun, May 17, 2020 at 12:57:26PM -0700, Andrii Nakryiko wrote:
> +
> +static inline int roundup_len(__u32 len)
> +{
> + /* clear out top 2 bits */
> + len <<= 2;
> + len >>= 2;
> + /* add length prefix */
> + len += RINGBUF_META_LEN;
> + /* round up to 8 byte alignment */
> + return (len + 7) / 8 * 8;
> +}
the same round_up again?
> +
> +static void ringbuf_custom_process_ring(struct ringbuf_custom *r)
> +{
> + unsigned long cons_pos, prod_pos;
> + int *len_ptr, len;
> + bool got_new_data;
> +
> + cons_pos = smp_load_acquire(r->consumer_pos);
> + while (true) {
> + got_new_data = false;
> + prod_pos = smp_load_acquire(r->producer_pos);
> + while (cons_pos < prod_pos) {
> + len_ptr = r->data + (cons_pos & r->mask);
> + len = smp_load_acquire(len_ptr);
> +
> + /* sample not committed yet, bail out for now */
> + if (len & RINGBUF_BUSY_BIT)
> + return;
> +
> + got_new_data = true;
> + cons_pos += roundup_len(len);
> +
> + atomic_inc(&buf_hits.value);
> + }
> + if (got_new_data)
> + smp_store_release(r->consumer_pos, cons_pos);
> + else
> + break;
> + };
> +}
copy paste from libbpf? why?