instrumentation: lttng-test.h: remove unused include version.h
[lttng-modules.git] / lttng-context-vpid.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
886d51a3 3 * lttng-context-vpid.c
b64bc438
MD
4 *
5 * LTTng vPID context.
6 *
886d51a3 7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
b64bc438
MD
8 */
9
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/sched.h>
241ae9a8
MD
13#include <lttng-events.h>
14#include <wrapper/ringbuffer/frontend_types.h>
241ae9a8 15#include <lttng-tracer.h>
b64bc438
MD
16
17static
18size_t vpid_get_size(size_t offset)
19{
20 size_t size = 0;
21
a90917c3 22 size += lib_ring_buffer_align(offset, lttng_alignof(pid_t));
b64bc438
MD
23 size += sizeof(pid_t);
24 return size;
25}
26
27static
28void vpid_record(struct lttng_ctx_field *field,
29 struct lib_ring_buffer_ctx *ctx,
a90917c3 30 struct lttng_channel *chan)
b64bc438
MD
31{
32 pid_t vpid;
33
90f96adf
MD
34 /*
35 * nsproxy can be NULL when scheduled out of exit.
36 */
37 if (!current->nsproxy)
38 vpid = 0;
39 else
40 vpid = task_tgid_vnr(current);
a90917c3 41 lib_ring_buffer_align_ctx(ctx, lttng_alignof(vpid));
b64bc438
MD
42 chan->ops->event_write(ctx, &vpid, sizeof(vpid));
43}
44
07dfc1d0
MD
45static
46void vpid_get_value(struct lttng_ctx_field *field,
79150a49 47 struct lttng_probe_ctx *lttng_probe_ctx,
07dfc1d0
MD
48 union lttng_ctx_value *value)
49{
50 pid_t vpid;
51
52 /*
53 * nsproxy can be NULL when scheduled out of exit.
54 */
55 if (!current->nsproxy)
56 vpid = 0;
57 else
58 vpid = task_tgid_vnr(current);
59 value->s64 = vpid;
60}
61
b64bc438
MD
62int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx)
63{
64 struct lttng_ctx_field *field;
b64bc438
MD
65
66 field = lttng_append_context(ctx);
67 if (!field)
09fec6b4 68 return -ENOMEM;
44252f0f
MD
69 if (lttng_find_context(*ctx, "vpid")) {
70 lttng_remove_context_field(ctx, field);
71 return -EEXIST;
72 }
b64bc438
MD
73 field->event_field.name = "vpid";
74 field->event_field.type.atype = atype_integer;
ceabb767
MD
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;
b64bc438
MD
81 field->get_size = vpid_get_size;
82 field->record = vpid_record;
07dfc1d0 83 field->get_value = vpid_get_value;
a9dd15da 84 lttng_context_update(*ctx);
b64bc438
MD
85 return 0;
86}
87EXPORT_SYMBOL_GPL(lttng_add_vpid_to_ctx);
This page took 0.038755 seconds and 4 git commands to generate.