* Add kernel context to all channel.
*/
static int add_kctx_all_channels(struct ltt_kernel_session *ksession,
- struct lttng_kernel_context *kctx)
+ struct ltt_kernel_context *kctx)
{
int ret;
struct ltt_kernel_channel *kchan;
/*
* Add kernel context to a specific channel.
*/
-static int add_kctx_to_channel(struct lttng_kernel_context *kctx,
+static int add_kctx_to_channel(struct ltt_kernel_context *kctx,
struct ltt_kernel_channel *kchan)
{
int ret;
{
int ret;
struct ltt_kernel_channel *kchan;
- struct lttng_kernel_context kctx;
+ struct ltt_kernel_context *kctx;
assert(ksession);
assert(ctx);
assert(channel_name);
+ kctx = trace_kernel_create_context(NULL);
+ if (!kctx) {
+ ret = LTTNG_ERR_NOMEM;
+ goto error;
+ }
+
/* Setup kernel context structure */
switch (ctx->ctx) {
case LTTNG_EVENT_CONTEXT_PID:
- kctx.ctx = LTTNG_KERNEL_CONTEXT_PID;
+ kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_PID;
break;
case LTTNG_EVENT_CONTEXT_PROCNAME:
- kctx.ctx = LTTNG_KERNEL_CONTEXT_PROCNAME;
+ kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_PROCNAME;
break;
case LTTNG_EVENT_CONTEXT_PRIO:
- kctx.ctx = LTTNG_KERNEL_CONTEXT_PRIO;
+ kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_PRIO;
break;
case LTTNG_EVENT_CONTEXT_NICE:
- kctx.ctx = LTTNG_KERNEL_CONTEXT_NICE;
+ kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_NICE;
break;
case LTTNG_EVENT_CONTEXT_VPID:
- kctx.ctx = LTTNG_KERNEL_CONTEXT_VPID;
+ kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_VPID;
break;
case LTTNG_EVENT_CONTEXT_TID:
- kctx.ctx = LTTNG_KERNEL_CONTEXT_TID;
+ kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_TID;
break;
case LTTNG_EVENT_CONTEXT_VTID:
- kctx.ctx = LTTNG_KERNEL_CONTEXT_VTID;
+ kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_VTID;
break;
case LTTNG_EVENT_CONTEXT_PPID:
- kctx.ctx = LTTNG_KERNEL_CONTEXT_PPID;
+ kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_PPID;
break;
case LTTNG_EVENT_CONTEXT_VPPID:
- kctx.ctx = LTTNG_KERNEL_CONTEXT_VPPID;
+ kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_VPPID;
break;
case LTTNG_EVENT_CONTEXT_HOSTNAME:
- kctx.ctx = LTTNG_KERNEL_CONTEXT_HOSTNAME;
+ kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_HOSTNAME;
break;
case LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER:
case LTTNG_EVENT_CONTEXT_PERF_COUNTER:
- kctx.ctx = LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER;
+ kctx->ctx.ctx = LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER;
break;
default:
return LTTNG_ERR_KERN_CONTEXT_FAIL;
}
- kctx.u.perf_counter.type = ctx->u.perf_counter.type;
- kctx.u.perf_counter.config = ctx->u.perf_counter.config;
- strncpy(kctx.u.perf_counter.name, ctx->u.perf_counter.name,
+ kctx->ctx.u.perf_counter.type = ctx->u.perf_counter.type;
+ kctx->ctx.u.perf_counter.config = ctx->u.perf_counter.config;
+ strncpy(kctx->ctx.u.perf_counter.name, ctx->u.perf_counter.name,
LTTNG_SYMBOL_NAME_LEN);
- kctx.u.perf_counter.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
+ kctx->ctx.u.perf_counter.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
if (*channel_name == '\0') {
- ret = add_kctx_all_channels(ksession, &kctx);
+ ret = add_kctx_all_channels(ksession, kctx);
if (ret != LTTNG_OK) {
goto error;
}
goto error;
}
- ret = add_kctx_to_channel(&kctx, kchan);
+ ret = add_kctx_to_channel(kctx, kchan);
if (ret != LTTNG_OK) {
goto error;
}
* Add context on a kernel channel.
*/
int kernel_add_channel_context(struct ltt_kernel_channel *chan,
- struct lttng_kernel_context *ctx)
+ struct ltt_kernel_context *ctx)
{
int ret;
assert(ctx);
DBG("Adding context to channel %s", chan->channel->name);
- ret = kernctl_add_context(chan->fd, ctx);
+ ret = kernctl_add_context(chan->fd, &ctx->ctx);
if (ret < 0) {
if (errno != EEXIST) {
PERROR("add context ioctl");
goto error;
}
- chan->ctx = zmalloc(sizeof(struct lttng_kernel_context));
- if (chan->ctx == NULL) {
- PERROR("zmalloc event context");
- goto error;
- }
-
- memcpy(chan->ctx, ctx, sizeof(struct lttng_kernel_context));
+ cds_list_add_tail(&ctx->list, &chan->ctx_list);
return 0;
#define KERNEL_EVENT_INIT_LIST_SIZE 64
int kernel_add_channel_context(struct ltt_kernel_channel *chan,
- struct lttng_kernel_context *ctx);
+ struct ltt_kernel_context *ctx);
int kernel_create_session(struct ltt_session *session, int tracer_fd);
int kernel_create_channel(struct ltt_kernel_session *session,
struct lttng_channel *chan);
goto end;
}
- ret = config_writer_open_element(writer, config_element_contexts);
- if (ret) {
- ret = LTTNG_ERR_SAVE_IO_FAIL;
- goto end;
- }
-
ret = config_writer_open_element(writer, config_element_context);
if (ret) {
ret = LTTNG_ERR_SAVE_IO_FAIL;
goto end;
}
+end:
+ return ret;
+}
+
+static
+int save_kernel_contexts(struct config_writer *writer,
+ struct ltt_kernel_channel *kchan)
+{
+ int ret;
+ struct ltt_kernel_context *ctx;
+
+ ret = config_writer_open_element(writer, config_element_contexts);
+ if (ret) {
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ goto end;
+ }
+
+ cds_list_for_each_entry(ctx, &kchan->ctx_list, list) {
+ ret = save_kernel_context(writer, &ctx->ctx);
+ if (ret) {
+ goto end;
+ }
+ }
+
/* /contexts */
ret = config_writer_close_element(writer);
if (ret) {
goto end;
}
- ret = save_kernel_context(writer, kchan->ctx);
+ ret = save_kernel_contexts(writer, kchan);
if (ret) {
goto end;
}
lkc->stream_count = 0;
lkc->event_count = 0;
lkc->enabled = 1;
- lkc->ctx = NULL;
/* Init linked list */
CDS_INIT_LIST_HEAD(&lkc->events_list.head);
CDS_INIT_LIST_HEAD(&lkc->stream_list.head);
+ CDS_INIT_LIST_HEAD(&lkc->ctx_list);
return lkc;
return NULL;
}
+/*
+ * Allocate and init a kernel context object.
+ *
+ * Return the allocated object or NULL on error.
+ */
+struct ltt_kernel_context *trace_kernel_create_context(
+ struct lttng_kernel_context *ctx)
+{
+ struct ltt_kernel_context *kctx;
+
+ kctx = zmalloc(sizeof(*kctx));
+ if (!kctx) {
+ PERROR("zmalloc kernel context");
+ goto error;
+ }
+
+ if (ctx) {
+ memcpy(&kctx->ctx, ctx, sizeof(kctx->ctx));
+ }
+
+error:
+ return kctx;
+}
+
/*
* Allocate and initialize a kernel event. Set name and event type.
*
free(event);
}
+/*
+ * Cleanup kernel context structure.
+ */
+void trace_kernel_destroy_context(struct ltt_kernel_context *ctx)
+{
+ assert(ctx);
+
+ cds_list_del(&ctx->list);
+ free(ctx);
+}
+
/*
* Cleanup kernel channel structure.
*/
{
struct ltt_kernel_stream *stream, *stmp;
struct ltt_kernel_event *event, *etmp;
+ struct ltt_kernel_context *ctx, *ctmp;
int ret;
assert(channel);
trace_kernel_destroy_event(event);
}
+ /* For each context in the channel list */
+ cds_list_for_each_entry_safe(ctx, ctmp, &channel->ctx_list, list) {
+ trace_kernel_destroy_context(ctx);
+ }
+
/* Remove from channel list */
cds_list_del(&channel->list);
free(channel->channel);
- free(channel->ctx);
free(channel);
}
struct cds_list_head head;
};
+struct ltt_kernel_context {
+ struct lttng_kernel_context ctx;
+ struct cds_list_head list;
+};
+
/* Kernel event */
struct ltt_kernel_event {
int fd;
int enabled;
unsigned int stream_count;
unsigned int event_count;
- /*
- * TODO: need internal representation to support more than a
- * single context.
- */
- struct lttng_kernel_context *ctx;
+ struct cds_list_head ctx_list;
struct lttng_channel *channel;
struct ltt_kernel_event_list events_list;
struct ltt_kernel_stream_list stream_list;
struct ltt_kernel_metadata *trace_kernel_create_metadata(void);
struct ltt_kernel_stream *trace_kernel_create_stream(const char *name,
unsigned int count);
+struct ltt_kernel_context *trace_kernel_create_context(
+ struct lttng_kernel_context *ctx);
/*
* Destroy functions free() the data structure and remove from linked list if
void trace_kernel_destroy_channel(struct ltt_kernel_channel *channel);
void trace_kernel_destroy_event(struct ltt_kernel_event *event);
void trace_kernel_destroy_stream(struct ltt_kernel_stream *stream);
+void trace_kernel_destroy_context(struct ltt_kernel_context *ctx);
#endif /* _LTT_TRACE_KERNEL_H */
ok(chan->fd == -1 &&
chan->enabled == 1 &&
chan->stream_count == 0 &&
- chan->ctx == NULL &&
chan->channel->attr.overwrite == attr.attr.overwrite,
"Validate kernel channel");