X-Git-Url: http://git.liburcu.org/?p=lttng-modules.git;a=blobdiff_plain;f=lib%2Fringbuffer%2Ffrontend_internal.h;h=39f2b7701783c4b57b6ce1a6cd0c6028263b5323;hp=32785853b721bb3a6d0aebedce45607bab8efb0b;hb=5b4ea313ddc10d96388a20a42e118c758479a553;hpb=aece661f429d4ca54cf1e47bacc556679c28f342 diff --git a/lib/ringbuffer/frontend_internal.h b/lib/ringbuffer/frontend_internal.h index 32785853..39f2b770 100644 --- a/lib/ringbuffer/frontend_internal.h +++ b/lib/ringbuffer/frontend_internal.h @@ -1,33 +1,17 @@ -#ifndef _LIB_RING_BUFFER_FRONTEND_INTERNAL_H -#define _LIB_RING_BUFFER_FRONTEND_INTERNAL_H - -/* +/* SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only) + * * linux/ringbuffer/frontend_internal.h * * Ring Buffer Library Synchronization Header (internal helpers). * * Copyright (C) 2005-2012 Mathieu Desnoyers * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; only - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Author: - * Mathieu Desnoyers - * * See ring_buffer_frontend.c for more information on wait-free algorithms. */ +#ifndef _LIB_RING_BUFFER_FRONTEND_INTERNAL_H +#define _LIB_RING_BUFFER_FRONTEND_INTERNAL_H + #include #include #include @@ -150,7 +134,8 @@ int last_tsc_overflow(const struct lib_ring_buffer_config *config, #endif extern -int lib_ring_buffer_reserve_slow(struct lib_ring_buffer_ctx *ctx); +int lib_ring_buffer_reserve_slow(struct lib_ring_buffer_ctx *ctx, + void *client_ctx); extern void lib_ring_buffer_switch_slow(struct lib_ring_buffer *buf, @@ -167,9 +152,10 @@ void lib_ring_buffer_check_deliver_slow(const struct lib_ring_buffer_config *con extern void lib_ring_buffer_switch_remote(struct lib_ring_buffer *buf); - extern void lib_ring_buffer_switch_remote_empty(struct lib_ring_buffer *buf); +extern +void lib_ring_buffer_clear(struct lib_ring_buffer *buf); /* Buffer write helpers */ @@ -201,6 +187,33 @@ void lib_ring_buffer_reserve_push_reader(struct lib_ring_buffer *buf, consumed_new) != consumed_old)); } +/* + * Move consumed position to the beginning of subbuffer in which the + * write offset is. Should only be used on ring buffers that are not + * actively being written into, because clear_reader does not take into + * account the commit counters when moving the consumed position, which + * can make concurrent trace producers or consumers observe consumed + * position further than the write offset, which breaks ring buffer + * algorithm guarantees. + */ +static inline +void lib_ring_buffer_clear_reader(struct lib_ring_buffer *buf, + struct channel *chan) +{ + const struct lib_ring_buffer_config *config = &chan->backend.config; + unsigned long offset, consumed_old, consumed_new; + + do { + offset = v_read(config, &buf->offset); + consumed_old = atomic_long_read(&buf->consumed); + CHAN_WARN_ON(chan, (long) (subbuf_trunc(offset, chan) + - subbuf_trunc(consumed_old, chan)) + < 0); + consumed_new = subbuf_trunc(offset, chan); + } while (unlikely(atomic_long_cmpxchg(&buf->consumed, consumed_old, + consumed_new) != consumed_old)); +} + static inline int lib_ring_buffer_pending_data(const struct lib_ring_buffer_config *config, struct lib_ring_buffer *buf, @@ -288,9 +301,9 @@ static inline void lib_ring_buffer_write_commit_counter(const struct lib_ring_buffer_config *config, struct lib_ring_buffer *buf, struct channel *chan, - unsigned long idx, unsigned long buf_offset, - unsigned long commit_count) + unsigned long commit_count, + struct commit_counters_hot *cc_hot) { unsigned long commit_seq_old; @@ -306,10 +319,9 @@ void lib_ring_buffer_write_commit_counter(const struct lib_ring_buffer_config *c if (unlikely(subbuf_offset(buf_offset - commit_count, chan))) return; - commit_seq_old = v_read(config, &buf->commit_hot[idx].seq); - while ((long) (commit_seq_old - commit_count) < 0) - commit_seq_old = v_cmpxchg(config, &buf->commit_hot[idx].seq, - commit_seq_old, commit_count); + commit_seq_old = v_read(config, &cc_hot->seq); + if (likely((long) (commit_seq_old - commit_count) < 0)) + v_set(config, &cc_hot->seq, commit_count); } extern int lib_ring_buffer_create(struct lib_ring_buffer *buf,