Move headers under include/
[lttng-modules.git] / lttng-context-tid.c
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng-context-tid.c
4 *
5 * LTTng TID context.
6 *
7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 #include <linux/module.h>
11 #include <linux/slab.h>
12 #include <linux/sched.h>
13 #include <lttng/lttng-events.h>
14 #include <ringbuffer/frontend_types.h>
15 #include <lttng/lttng-tracer.h>
16
17 static
18 size_t tid_get_size(size_t offset)
19 {
20 size_t size = 0;
21
22 size += lib_ring_buffer_align(offset, lttng_alignof(pid_t));
23 size += sizeof(pid_t);
24 return size;
25 }
26
27 static
28 void tid_record(struct lttng_ctx_field *field,
29 struct lib_ring_buffer_ctx *ctx,
30 struct lttng_channel *chan)
31 {
32 pid_t tid;
33
34 tid = task_pid_nr(current);
35 lib_ring_buffer_align_ctx(ctx, lttng_alignof(tid));
36 chan->ops->event_write(ctx, &tid, sizeof(tid));
37 }
38
39 static
40 void tid_get_value(struct lttng_ctx_field *field,
41 struct lttng_probe_ctx *lttng_probe_ctx,
42 union lttng_ctx_value *value)
43 {
44 pid_t tid;
45
46 tid = task_pid_nr(current);
47 value->s64 = tid;
48 }
49
50 int lttng_add_tid_to_ctx(struct lttng_ctx **ctx)
51 {
52 struct lttng_ctx_field *field;
53
54 field = lttng_append_context(ctx);
55 if (!field)
56 return -ENOMEM;
57 if (lttng_find_context(*ctx, "tid")) {
58 lttng_remove_context_field(ctx, field);
59 return -EEXIST;
60 }
61 field->event_field.name = "tid";
62 field->event_field.type.atype = atype_integer;
63 field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT;
64 field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT;
65 field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t);
66 field->event_field.type.u.integer.reverse_byte_order = 0;
67 field->event_field.type.u.integer.base = 10;
68 field->event_field.type.u.integer.encoding = lttng_encode_none;
69 field->get_size = tid_get_size;
70 field->record = tid_record;
71 field->get_value = tid_get_value;
72 lttng_context_update(*ctx);
73 return 0;
74 }
75 EXPORT_SYMBOL_GPL(lttng_add_tid_to_ctx);
This page took 0.030241 seconds and 4 git commands to generate.