uint32_t ret_code; /* enum enum lttcomm_return_code */
uint32_t ret_val; /* return value */
union {
+ struct {
+ uint64_t memory_map_size;
+ } channel;
struct {
uint64_t memory_map_size;
} stream;
void *buf_addr,
size_t subbuf_size, size_t num_subbuf,
unsigned int switch_timer_interval,
- unsigned int read_timer_interval);
+ unsigned int read_timer_interval,
+ int *shm_fd, int *wait_fd,
+ uint64_t *memory_map_size);
void (*channel_destroy)(struct ltt_channel *ltt_chan);
struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan,
struct shm_handle *handle,
void *buf_addr,
size_t subbuf_size, size_t num_subbuf,
unsigned int switch_timer_interval,
- unsigned int read_timer_interval);
+ unsigned int read_timer_interval,
+ int *shm_fd, int *wait_fd,
+ uint64_t *memory_map_size);
struct ltt_channel *ltt_global_channel_create(struct ltt_session *session,
int overwrite, void *buf_addr,
size_t subbuf_size, size_t num_subbuf,
unsigned int switch_timer_interval,
- unsigned int read_timer_interval);
+ unsigned int read_timer_interval,
+ int *shm_fd, int *wait_fd,
+ uint64_t *memory_map_size);
struct ltt_event *ltt_event_create(struct ltt_channel *chan,
struct lttng_ust_event *event_param,
unsigned int switch_timer_interval; /* usecs */
unsigned int read_timer_interval; /* usecs */
enum lttng_ust_output output; /* output mode */
+ /* The following fields are used internally within UST. */
+ int shm_fd;
+ int wait_fd;
+ uint64_t memory_map_size;
};
/*
unsigned long num_subbuf; /* Number of sub-buffers for writer */
u64 start_tsc; /* Channel creation TSC value */
void *priv; /* Client-specific information */
- const struct lib_ring_buffer_config *config; /* Ring buffer configuration */
+ struct lib_ring_buffer_config config; /* Ring buffer configuration */
char name[NAME_MAX]; /* Channel name */
struct lib_ring_buffer_shmp buf[];
};
void *buf_addr,
size_t subbuf_size, size_t num_subbuf,
unsigned int switch_timer_interval,
- unsigned int read_timer_interval);
+ unsigned int read_timer_interval,
+ int *shm_fd, int *wait_fd,
+ uint64_t *memory_map_size);
+
+/* channel_handle_create - for consumer. */
+extern
+struct shm_handle *channel_handle_create(int shm_fd, int wait_fd,
+ uint64_t memory_map_size);
+
+/* channel_handle_add_stream - for consumer. */
+extern
+int channel_handle_add_stream(struct shm_handle *handle,
+ int shm_fd, int wait_fd, uint64_t memory_map_size);
/*
* channel_destroy returns the private data pointer. It finalizes all channel's
struct shm_handle *handle,
struct shm_object *shmobj)
{
- const struct lib_ring_buffer_config *config = chanb->config;
+ const struct lib_ring_buffer_config *config = &chanb->config;
set_shmp(bufb->chan, handle->chan._ref);
bufb->cpu = cpu;
struct shm_handle *handle)
{
struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
- const struct lib_ring_buffer_config *config = chanb->config;
+ const struct lib_ring_buffer_config *config = &chanb->config;
unsigned long num_subbuf_alloc;
unsigned int i;
void channel_backend_reset(struct channel_backend *chanb)
{
struct channel *chan = caa_container_of(chanb, struct channel, backend);
- const struct lib_ring_buffer_config *config = chanb->config;
+ const struct lib_ring_buffer_config *config = &chanb->config;
/*
* Don't reset buf_size, subbuf_size, subbuf_size_order,
chanb->num_subbuf = num_subbuf;
strncpy(chanb->name, name, NAME_MAX);
chanb->name[NAME_MAX - 1] = '\0';
- chanb->config = config;
+ memcpy(&chanb->config, config, sizeof(*config));
/* Per-cpu buffer size: control (prior to backend) */
shmsize = offset_align(shmsize, __alignof__(struct lib_ring_buffer));
void channel_backend_free(struct channel_backend *chanb,
struct shm_handle *handle)
{
- const struct lib_ring_buffer_config *config = chanb->config;
+ const struct lib_ring_buffer_config *config = &chanb->config;
unsigned int i;
if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
void *dest, size_t len, struct shm_handle *handle)
{
struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
- const struct lib_ring_buffer_config *config = chanb->config;
+ const struct lib_ring_buffer_config *config = &chanb->config;
ssize_t orig_len;
struct lib_ring_buffer_backend_pages_shmp *rpages;
unsigned long sb_bindex, id;
void *dest, size_t len, struct shm_handle *handle)
{
struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
- const struct lib_ring_buffer_config *config = chanb->config;
+ const struct lib_ring_buffer_config *config = &chanb->config;
ssize_t string_len, orig_offset;
char *str;
struct lib_ring_buffer_backend_pages_shmp *rpages;
{
struct lib_ring_buffer_backend_pages_shmp *rpages;
struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
- const struct lib_ring_buffer_config *config = chanb->config;
+ const struct lib_ring_buffer_config *config = &chanb->config;
unsigned long sb_bindex, id;
offset &= chanb->buf_size - 1;
size_t sbidx;
struct lib_ring_buffer_backend_pages_shmp *rpages;
struct channel_backend *chanb = &shmp(handle, bufb->chan)->backend;
- const struct lib_ring_buffer_config *config = chanb->config;
+ const struct lib_ring_buffer_config *config = &chanb->config;
unsigned long sb_bindex, id;
offset &= chanb->buf_size - 1;
struct shm_handle *handle)
{
struct channel *chan = shmp(handle, buf->backend.chan);
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
unsigned int i;
/*
struct shm_handle *handle,
struct shm_object *shmobj)
{
- const struct lib_ring_buffer_config *config = chanb->config;
+ const struct lib_ring_buffer_config *config = &chanb->config;
struct channel *chan = caa_container_of(chanb, struct channel, backend);
void *priv = chanb->priv;
unsigned int num_subbuf;
{
struct lib_ring_buffer *buf = (struct lib_ring_buffer *)data;
struct channel *chan = shmp(handle, buf->backend.chan);
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
/*
* Only flush buffers periodically if readers are active.
struct shm_handle *handle)
{
struct channel *chan = shmp(handle, buf->backend.chan);
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
if (!chan->switch_timer_interval || buf->switch_timer_enabled)
return;
{
struct lib_ring_buffer *buf = (struct lib_ring_buffer *)data;
struct channel *chan = shmp(handle, buf->backend.chan);
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
CHAN_WARN_ON(chan, !buf->backend.allocated);
struct shm_handle *handle)
{
struct channel *chan = shmp(handle, buf->backend.chan);
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
if (config->wakeup != RING_BUFFER_WAKEUP_BY_TIMER
|| !chan->read_timer_interval
struct shm_handle *handle)
{
struct channel *chan = shmp(handle, buf->backend.chan);
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
if (config->wakeup != RING_BUFFER_WAKEUP_BY_TIMER
|| !chan->read_timer_interval
static void channel_unregister_notifiers(struct channel *chan,
struct shm_handle *handle)
{
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
int cpu;
if (config->alloc == RING_BUFFER_ALLOC_PER_CPU) {
const char *name, void *priv, void *buf_addr,
size_t subbuf_size,
size_t num_subbuf, unsigned int switch_timer_interval,
- unsigned int read_timer_interval)
+ unsigned int read_timer_interval,
+ int *shm_fd, int *wait_fd, uint64_t *memory_map_size)
{
int ret, cpu;
size_t shmsize;
struct channel *chan;
struct shm_handle *handle;
struct shm_object *shmobj;
+ struct shm_ref *ref;
if (lib_ring_buffer_check_config(config, switch_timer_interval,
read_timer_interval))
lib_ring_buffer_start_switch_timer(buf, handle);
lib_ring_buffer_start_read_timer(buf, handle);
}
-
+ ref = &handle->chan._ref;
+ shm_get_object_data(handle, ref, shm_fd, wait_fd, memory_map_size);
return handle;
error_backend_init:
return NULL;
}
+struct shm_handle *channel_handle_create(int shm_fd, int wait_fd,
+ uint64_t memory_map_size)
+{
+ struct shm_handle *handle;
+ struct shm_object *object;
+
+ handle = zmalloc(sizeof(struct shm_handle));
+ if (!handle)
+ return NULL;
+
+ /* Allocate table for channel + per-cpu buffers */
+ handle->table = shm_object_table_create(1 + num_possible_cpus());
+ if (!handle->table)
+ goto error_table_alloc;
+ /* Add channel object */
+ object = shm_object_table_append_shadow(handle->table,
+ shm_fd, wait_fd, memory_map_size);
+ if (!object)
+ goto error_table_object;
+
+ return handle;
+
+error_table_object:
+ shm_object_table_destroy(handle->table);
+error_table_alloc:
+ free(handle);
+ return NULL;
+}
+
+int channel_handle_add_stream(struct shm_handle *handle,
+ int shm_fd, int wait_fd, uint64_t memory_map_size)
+{
+ struct shm_object *object;
+
+ /* Add stream object */
+ object = shm_object_table_append_shadow(handle->table,
+ shm_fd, wait_fd, memory_map_size);
+ if (!object)
+ return -1;
+ return 0;
+}
+
static
void channel_release(struct channel *chan, struct shm_handle *handle)
{
*/
void *channel_destroy(struct channel *chan, struct shm_handle *handle)
{
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
void *priv;
int cpu;
struct shm_handle *handle)
{
struct channel *chan = shmp(handle, buf->backend.chan);
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
unsigned long consumed_cur, write_offset;
int finalized;
struct shm_handle *handle)
{
struct channel *chan = shmp(handle, buf->backend.chan);
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
unsigned long consumed_cur, consumed_idx, commit_count, write_offset;
int ret;
int finalized;
{
struct lib_ring_buffer_backend *bufb = &buf->backend;
struct channel *chan = shmp(handle, bufb->chan);
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
unsigned long read_sb_bindex, consumed_idx, consumed;
CHAN_WARN_ON(chan, uatomic_read(&buf->active_readers) != 1);
int cpu,
struct shm_handle *handle)
{
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
unsigned long cons_idx, commit_count, commit_count_sb;
cons_idx = subbuf_index(cons_offset, chan);
void *priv, int cpu,
struct shm_handle *handle)
{
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
unsigned long write_offset, cons_offset;
/*
struct lib_ring_buffer *buf, int cpu,
struct shm_handle *handle)
{
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
void *priv = chan->backend.priv;
ERRMSG("ring buffer %s, cpu %d: %lu records written, "
u64 tsc,
struct shm_handle *handle)
{
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
unsigned long oldidx = subbuf_index(offsets->old, chan);
unsigned long commit_count;
u64 tsc,
struct shm_handle *handle)
{
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
unsigned long oldidx = subbuf_index(offsets->old - 1, chan);
unsigned long commit_count, padding_size, data_size;
u64 tsc,
struct shm_handle *handle)
{
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
unsigned long beginidx = subbuf_index(offsets->begin, chan);
unsigned long commit_count;
u64 tsc,
struct shm_handle *handle)
{
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
unsigned long endidx = subbuf_index(offsets->end - 1, chan);
unsigned long commit_count, padding_size, data_size;
struct switch_offsets *offsets,
u64 *tsc)
{
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
unsigned long off;
offsets->begin = v_read(config, &buf->offset);
struct shm_handle *handle)
{
struct channel *chan = shmp(handle, buf->backend.chan);
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
struct switch_offsets offsets;
unsigned long oldidx;
u64 tsc;
struct switch_offsets *offsets,
struct lib_ring_buffer_ctx *ctx)
{
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
struct shm_handle *handle = ctx->handle;
unsigned long reserve_commit_diff;
{
struct channel *chan = ctx->chan;
struct shm_handle *handle = ctx->handle;
- const struct lib_ring_buffer_config *config = chan->backend.config;
+ const struct lib_ring_buffer_config *config = &chan->backend.config;
struct lib_ring_buffer *buf;
struct switch_offsets offsets;
int ret;
}
+struct shm_object *shm_object_table_append_shadow(struct shm_object_table *table,
+ int shm_fd, int wait_fd, size_t memory_map_size)
+{
+ struct shm_object *obj;
+ char *memory_map;
+
+ if (table->allocated_len >= table->size)
+ return NULL;
+ obj = &table->objects[table->allocated_len];
+
+ /* wait_fd: set read end of the pipe. */
+ obj->wait_fd[0] = wait_fd;
+ obj->wait_fd[1] = -1; /* write end is unset. */
+ obj->shm_fd = shm_fd;
+
+ /* memory_map: mmap */
+ memory_map = mmap(NULL, memory_map_size, PROT_READ | PROT_WRITE,
+ MAP_SHARED, shm_fd, 0);
+ if (memory_map == MAP_FAILED) {
+ PERROR("mmap");
+ goto error_mmap;
+ }
+ obj->memory_map = memory_map;
+ obj->memory_map_size = memory_map_size;
+ obj->allocated_len = memory_map_size;
+ obj->index = table->allocated_len++;
+
+ return obj;
+
+error_mmap:
+ return NULL;
+}
+
static
void shmp_object_destroy(struct shm_object *obj)
{
#define set_shmp(ref, src) _set_shmp(&(ref)._ref, src)
struct shm_object_table *shm_object_table_create(size_t max_nb_obj);
+struct shm_object *shm_object_table_append_shadow(struct shm_object_table *table,
+ int shm_fd, int wait_fd, size_t memory_map_size);
void shm_object_table_destroy(struct shm_object_table *table);
struct shm_object *shm_object_table_append(struct shm_object_table *table,
size_t memory_map_size);
obj = &table->objects[index];
*shm_fd = obj->shm_fd;
*wait_fd = obj->wait_fd[0];
- *memory_map_size = obj->memory_map_size;
+ *memory_map_size = obj->allocated_len;
return 0;
}
void *buf_addr,
size_t subbuf_size, size_t num_subbuf,
unsigned int switch_timer_interval,
- unsigned int read_timer_interval)
+ unsigned int read_timer_interval,
+ int *shm_fd, int *wait_fd,
+ uint64_t *memory_map_size)
{
struct ltt_channel *chan;
struct ltt_transport *transport;
*/
transport->ops.channel_create("[lttng]", chan, buf_addr,
subbuf_size, num_subbuf, switch_timer_interval,
- read_timer_interval);
+ read_timer_interval, shm_fd, wait_fd,
+ memory_map_size);
if (!chan->chan)
goto create_error;
chan->enabled = 1;
struct ltt_channel *ltt_chan, void *buf_addr,
size_t subbuf_size, size_t num_subbuf,
unsigned int switch_timer_interval,
- unsigned int read_timer_interval)
+ unsigned int read_timer_interval,
+ int *shm_fd, int *wait_fd,
+ uint64_t *memory_map_size)
{
ltt_chan->handle = channel_create(&client_config, name, ltt_chan, buf_addr,
subbuf_size, num_subbuf, switch_timer_interval,
- read_timer_interval);
+ read_timer_interval, shm_fd, wait_fd,
+ memory_map_size);
if (!ltt_chan->handle)
return NULL;
ltt_chan->chan = shmp(ltt_chan->handle, ltt_chan->handle->chan);
struct ltt_channel *ltt_chan, void *buf_addr,
size_t subbuf_size, size_t num_subbuf,
unsigned int switch_timer_interval,
- unsigned int read_timer_interval)
+ unsigned int read_timer_interval,
+ int *shm_fd, int *wait_fd,
+ uint64_t *memory_map_size)
{
ltt_chan->handle = channel_create(&client_config, name, ltt_chan, buf_addr,
subbuf_size, num_subbuf, switch_timer_interval,
- read_timer_interval);
+ read_timer_interval, shm_fd, wait_fd,
+ memory_map_size);
if (!ltt_chan->handle)
return NULL;
ltt_chan->chan = shmp(ltt_chan->handle, ltt_chan->handle->chan);
chan_param->subbuf_size,
chan_param->num_subbuf,
chan_param->switch_timer_interval,
- chan_param->read_timer_interval);
+ chan_param->read_timer_interval,
+ &chan_param->shm_fd,
+ &chan_param->wait_fd,
+ &chan_param->memory_map_size);
if (!chan) {
ret = -EINVAL;
goto chan_error;
int ret = 0;
const struct objd_ops *ops;
struct lttcomm_ust_reply lur;
+ int shm_fd, wait_fd;
ust_lock();
if (ret >= 0) {
lur.ret_code = LTTCOMM_OK;
} else {
- lur.ret_code = LTTCOMM_SESSION_FAIL;
+ //lur.ret_code = LTTCOMM_SESSION_FAIL;
+ lur.ret_code = ret;
}
- if (lum->cmd == LTTNG_UST_STREAM) {
+ switch (lum->cmd) {
+ case LTTNG_UST_STREAM:
/*
* Special-case reply to send stream info.
* Use lum.u output.
*/
lur.u.stream.memory_map_size = lum->u.stream.memory_map_size;
+ shm_fd = lum->u.stream.shm_fd;
+ wait_fd = lum->u.stream.wait_fd;
+ break;
+ case LTTNG_UST_CHANNEL:
+ lur.u.channel.memory_map_size = lum->u.channel.memory_map_size;
+ shm_fd = lum->u.channel.shm_fd;
+ wait_fd = lum->u.channel.wait_fd;
+ break;
}
ret = send_reply(sock, &lur);
+ if (ret < 0) {
+ perror("error sending reply");
+ goto error;
+ }
- if (lum->cmd == LTTNG_UST_STREAM && ret >= 0) {
+ if ((lum->cmd == LTTNG_UST_STREAM || lum->cmd == LTTNG_UST_CHANNEL)
+ && lur.ret_code == LTTCOMM_OK) {
/* we also need to send the file descriptors. */
ret = lttcomm_send_fds_unix_sock(sock,
- &lum->u.stream.shm_fd, &lum->u.stream.shm_fd,
+ &shm_fd, &shm_fd,
1, sizeof(int));
if (ret < 0) {
perror("send shm_fd");
goto error;
}
ret = lttcomm_send_fds_unix_sock(sock,
- &lum->u.stream.wait_fd, &lum->u.stream.wait_fd,
+ &wait_fd, &wait_fd,
1, sizeof(int));
if (ret < 0) {
perror("send wait_fd");
printf("Hello, World!\n");
- sleep(1);
+ sleep(10);
//for (i = 0; i < 50; i++) {
for (i = 0; i < 1000000; i++) {