#include "lttng/core.h"
#include "ltt-tracer.h"
+static int lttng_ust_abi_close_in_progress;
+
static
int lttng_abi_tracepoint_list(void);
buf = priv->buf;
channel = priv->ltt_chan;
free(priv);
- channel->ops->buffer_read_close(buf, channel->handle);
+ /*
+ * If we are at ABI exit, we don't want to close the
+ * buffer opened for read: it is being shared between
+ * the parent and child (right after fork), and we don't
+ * want the child to close it for the parent. For a real
+ * exit, we don't care about marking it as closed, as
+ * the consumer daemon (if there is one) will do fine
+ * even if we don't mark it as "closed" for reading on
+ * our side.
+ * We only mark it as closed if it is being explicitely
+ * released by the session daemon with an explicit
+ * release command.
+ */
+ if (!lttng_ust_abi_close_in_progress)
+ channel->ops->buffer_read_close(buf, channel->handle);
return lttng_ust_objd_unref(channel->objd);
}
void lttng_ust_abi_exit(void)
{
+ lttng_ust_abi_close_in_progress = 1;
objd_table_destroy();
+ lttng_ust_abi_close_in_progress = 0;
}
handle, shmobj);
}
-void lib_ring_buffer_backend_free(struct lttng_ust_lib_ring_buffer_backend *bufb)
-{
- /* bufb->buf_wsb will be freed by shm teardown */
- /* bufb->array[i] will be freed by shm teardown */
- /* bufb->array will be freed by shm teardown */
- bufb->allocated = 0;
-}
-
void lib_ring_buffer_backend_reset(struct lttng_ust_lib_ring_buffer_backend *bufb,
struct lttng_ust_shm_handle *handle)
{
return 0;
free_bufs:
- if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
- for_each_possible_cpu(i) {
- struct lttng_ust_lib_ring_buffer *buf = shmp(handle, chanb->buf[i].shmp);
-
- if (!buf->backend.allocated)
- continue;
- lib_ring_buffer_free(buf, handle);
- }
- }
/* We only free the buffer data upon shm teardown */
end:
return -ENOMEM;
void channel_backend_free(struct channel_backend *chanb,
struct lttng_ust_shm_handle *handle)
{
- const struct lttng_ust_lib_ring_buffer_config *config = &chanb->config;
- unsigned int i;
-
- if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
- for_each_possible_cpu(i) {
- struct lttng_ust_lib_ring_buffer *buf = shmp(handle, chanb->buf[i].shmp);
-
- if (!buf->backend.allocated)
- continue;
- lib_ring_buffer_free(buf, handle);
- }
- } else {
- struct lttng_ust_lib_ring_buffer *buf = shmp(handle, chanb->buf[0].shmp);
-
- CHAN_WARN_ON(chanb, !buf->backend.allocated);
- lib_ring_buffer_free(buf, handle);
- }
- /* We only free the buffer data upon shm teardown */
+ /* SHM teardown takes care of everything */
}
/**
__thread unsigned int lib_ring_buffer_nesting;
+/*
+ * TODO: this is unused. Errors are saved within the ring buffer.
+ * Eventually, allow consumerd to print these errors.
+ */
static
void lib_ring_buffer_print_errors(struct channel *chan,
struct lttng_ust_lib_ring_buffer *buf, int cpu,
struct lttng_ust_shm_handle *handle);
-/*
- * Must be called under cpu hotplug protection.
- */
-void lib_ring_buffer_free(struct lttng_ust_lib_ring_buffer *buf,
- struct lttng_ust_shm_handle *handle)
-{
- struct channel *chan = shmp(handle, buf->backend.chan);
-
- lib_ring_buffer_print_errors(chan, buf, buf->backend.cpu, handle);
- /* buf->commit_hot will be freed by shm teardown */
- /* buf->commit_cold will be freed by shm teardown */
-
- lib_ring_buffer_backend_free(&buf->backend);
-}
-
/**
* lib_ring_buffer_reset - Reset ring buffer to initial values.
* @buf: Ring buffer.
free_commit:
/* commit_hot will be freed by shm teardown */
free_chanbuf:
- lib_ring_buffer_backend_free(&buf->backend);
return ret;
}
void channel_destroy(struct channel *chan, struct lttng_ust_shm_handle *handle,
int shadow)
{
- const struct lttng_ust_lib_ring_buffer_config *config = &chan->backend.config;
- int cpu;
-
if (shadow) {
channel_release(chan, handle, shadow);
return;
channel_unregister_notifiers(chan, handle);
- if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
- for_each_channel_cpu(cpu, chan) {
- struct lttng_ust_lib_ring_buffer *buf = shmp(handle, chan->backend.buf[cpu].shmp);
-
- if (config->cb.buffer_finalize)
- config->cb.buffer_finalize(buf,
- channel_get_private(chan),
- cpu, handle);
- if (buf->backend.allocated)
- lib_ring_buffer_switch_slow(buf, SWITCH_FLUSH,
- handle);
- /*
- * Perform flush before writing to finalized.
- */
- cmm_smp_wmb();
- CMM_ACCESS_ONCE(buf->finalized) = 1;
- //wake_up_interruptible(&buf->read_wait);
- }
- } else {
- struct lttng_ust_lib_ring_buffer *buf = shmp(handle, chan->backend.buf[0].shmp);
+ /*
+ * Note: the consumer takes care of finalizing and switching the
+ * buffers.
+ */
- if (config->cb.buffer_finalize)
- config->cb.buffer_finalize(buf, channel_get_private(chan), -1, handle);
- if (buf->backend.allocated)
- lib_ring_buffer_switch_slow(buf, SWITCH_FLUSH,
- handle);
- /*
- * Perform flush before writing to finalized.
- */
- cmm_smp_wmb();
- CMM_ACCESS_ONCE(buf->finalized) = 1;
- //wake_up_interruptible(&buf->read_wait);
- }
- CMM_ACCESS_ONCE(chan->finalized) = 1;
- //wake_up_interruptible(&chan->hp_wait);
- //wake_up_interruptible(&chan->read_wait);
/*
* sessiond/consumer are keeping a reference on the shm file
* descriptor directly. No need to refcount.