Move headers under include/
[lttng-modules.git] / lttng-context-vtid.c
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng-context-vtid.c
4 *
5 * LTTng vTID 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 vtid_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 vtid_record(struct lttng_ctx_field *field,
29 struct lib_ring_buffer_ctx *ctx,
30 struct lttng_channel *chan)
31 {
32 pid_t vtid;
33
34 /*
35 * nsproxy can be NULL when scheduled out of exit.
36 */
37 if (!current->nsproxy)
38 vtid = 0;
39 else
40 vtid = task_pid_vnr(current);
41 lib_ring_buffer_align_ctx(ctx, lttng_alignof(vtid));
42 chan->ops->event_write(ctx, &vtid, sizeof(vtid));
43 }
44
45 static
46 void vtid_get_value(struct lttng_ctx_field *field,
47 struct lttng_probe_ctx *lttng_probe_ctx,
48 union lttng_ctx_value *value)
49 {
50 pid_t vtid;
51
52 /*
53 * nsproxy can be NULL when scheduled out of exit.
54 */
55 if (!current->nsproxy)
56 vtid = 0;
57 else
58 vtid = task_pid_vnr(current);
59 value->s64 = vtid;
60 }
61
62 int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx)
63 {
64 struct lttng_ctx_field *field;
65
66 field = lttng_append_context(ctx);
67 if (!field)
68 return -ENOMEM;
69 if (lttng_find_context(*ctx, "vtid")) {
70 lttng_remove_context_field(ctx, field);
71 return -EEXIST;
72 }
73 field->event_field.name = "vtid";
74 field->event_field.type.atype = atype_integer;
75 field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT;
76 field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT;
77 field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t);
78 field->event_field.type.u.integer.reverse_byte_order = 0;
79 field->event_field.type.u.integer.base = 10;
80 field->event_field.type.u.integer.encoding = lttng_encode_none;
81 field->get_size = vtid_get_size;
82 field->record = vtid_record;
83 field->get_value = vtid_get_value;
84 lttng_context_update(*ctx);
85 return 0;
86 }
87 EXPORT_SYMBOL_GPL(lttng_add_vtid_to_ctx);
This page took 0.03025 seconds and 4 git commands to generate.