4 * LTTng trace/channel/event context management.
6 * Copyright (C) 2011-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <linux/module.h>
24 #include <linux/list.h>
25 #include <linux/mutex.h>
26 #include <linux/slab.h>
27 #include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
28 #include "lttng-events.h"
29 #include "lttng-tracer.h"
31 int lttng_find_context(struct lttng_ctx
*ctx
, const char *name
)
35 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
36 /* Skip allocated (but non-initialized) contexts */
37 if (!ctx
->fields
[i
].event_field
.name
)
39 if (!strcmp(ctx
->fields
[i
].event_field
.name
, name
))
44 EXPORT_SYMBOL_GPL(lttng_find_context
);
47 * Note: as we append context information, the pointer location may change.
49 struct lttng_ctx_field
*lttng_append_context(struct lttng_ctx
**ctx_p
)
51 struct lttng_ctx_field
*field
;
52 struct lttng_ctx
*ctx
;
55 *ctx_p
= kzalloc(sizeof(struct lttng_ctx
), GFP_KERNEL
);
58 (*ctx_p
)->largest_align
= 1;
61 if (ctx
->nr_fields
+ 1 > ctx
->allocated_fields
) {
62 struct lttng_ctx_field
*new_fields
;
64 ctx
->allocated_fields
= max_t(size_t, 1, 2 * ctx
->allocated_fields
);
65 new_fields
= kzalloc(ctx
->allocated_fields
* sizeof(struct lttng_ctx_field
), GFP_KERNEL
);
69 memcpy(new_fields
, ctx
->fields
, sizeof(*ctx
->fields
) * ctx
->nr_fields
);
71 ctx
->fields
= new_fields
;
73 field
= &ctx
->fields
[ctx
->nr_fields
];
77 EXPORT_SYMBOL_GPL(lttng_append_context
);
80 * lttng_context_update() should be called at least once between context
81 * modification and trace start.
83 void lttng_context_update(struct lttng_ctx
*ctx
)
86 size_t largest_align
= 8; /* in bits */
88 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
89 struct lttng_type
*type
;
90 size_t field_align
= 8;
92 type
= &ctx
->fields
[i
].event_field
.type
;
93 switch (type
->atype
) {
95 field_align
= type
->u
.basic
.integer
.alignment
;
99 struct lttng_basic_type
*btype
;
101 btype
= &type
->u
.array
.elem_type
;
102 switch (btype
->atype
) {
104 field_align
= btype
->u
.basic
.integer
.alignment
;
119 struct lttng_basic_type
*btype
;
121 btype
= &type
->u
.sequence
.length_type
;
122 switch (btype
->atype
) {
124 field_align
= btype
->u
.basic
.integer
.alignment
;
135 btype
= &type
->u
.sequence
.elem_type
;
136 switch (btype
->atype
) {
138 field_align
= max_t(size_t,
140 btype
->u
.basic
.integer
.alignment
);
162 largest_align
= max_t(size_t, largest_align
, field_align
);
164 ctx
->largest_align
= largest_align
>> 3; /* bits to bytes */
168 * Remove last context field.
170 void lttng_remove_context_field(struct lttng_ctx
**ctx_p
,
171 struct lttng_ctx_field
*field
)
173 struct lttng_ctx
*ctx
;
177 WARN_ON_ONCE(&ctx
->fields
[ctx
->nr_fields
] != field
);
178 memset(&ctx
->fields
[ctx
->nr_fields
], 0, sizeof(struct lttng_ctx_field
));
180 EXPORT_SYMBOL_GPL(lttng_remove_context_field
);
182 void lttng_destroy_context(struct lttng_ctx
*ctx
)
188 for (i
= 0; i
< ctx
->nr_fields
; i
++) {
189 if (ctx
->fields
[i
].destroy
)
190 ctx
->fields
[i
].destroy(&ctx
->fields
[i
]);