Move headers under include/
[lttng-modules.git] / lttng-context-vppid.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
886d51a3 3 * lttng-context-vppid.c
b64bc438
MD
4 *
5 * LTTng vPPID 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>
13#include <linux/syscalls.h>
b5304713
MD
14#include <lttng/lttng-events.h>
15#include <ringbuffer/frontend_types.h>
16#include <lttng/lttng-tracer.h>
b64bc438
MD
17
18static
19size_t vppid_get_size(size_t offset)
20{
21 size_t size = 0;
22
a90917c3 23 size += lib_ring_buffer_align(offset, lttng_alignof(pid_t));
b64bc438
MD
24 size += sizeof(pid_t);
25 return size;
26}
27
28static
29void vppid_record(struct lttng_ctx_field *field,
30 struct lib_ring_buffer_ctx *ctx,
a90917c3 31 struct lttng_channel *chan)
b64bc438 32{
90f96adf 33 struct task_struct *parent;
b64bc438
MD
34 pid_t vppid;
35
90f96adf 36 /*
de544ea5
MD
37 * current nsproxy can be NULL when scheduled out of exit. pid_vnr uses
38 * the current thread nsproxy to perform the lookup.
90f96adf 39 */
1638c9b4
MD
40
41 /*
42 * TODO: when we eventually add RCU subsystem instrumentation,
43 * taking the rcu read lock here will trigger RCU tracing
44 * recursively. We should modify the kernel synchronization so
45 * it synchronizes both for RCU and RCU sched, and rely on
46 * rcu_read_lock_sched_notrace.
47 */
48
b64bc438 49 rcu_read_lock();
90f96adf 50 parent = rcu_dereference(current->real_parent);
de544ea5 51 if (!current->nsproxy)
90f96adf
MD
52 vppid = 0;
53 else
54 vppid = task_tgid_vnr(parent);
b64bc438 55 rcu_read_unlock();
a90917c3 56 lib_ring_buffer_align_ctx(ctx, lttng_alignof(vppid));
b64bc438
MD
57 chan->ops->event_write(ctx, &vppid, sizeof(vppid));
58}
59
f127e61e
MD
60static
61void vppid_get_value(struct lttng_ctx_field *field,
79150a49 62 struct lttng_probe_ctx *lttng_probe_ctx,
f127e61e
MD
63 union lttng_ctx_value *value)
64{
65 struct task_struct *parent;
66 pid_t vppid;
67
68 /*
69 * current nsproxy can be NULL when scheduled out of exit. pid_vnr uses
70 * the current thread nsproxy to perform the lookup.
71 */
72
73 /*
74 * TODO: when we eventually add RCU subsystem instrumentation,
75 * taking the rcu read lock here will trigger RCU tracing
76 * recursively. We should modify the kernel synchronization so
77 * it synchronizes both for RCU and RCU sched, and rely on
78 * rcu_read_lock_sched_notrace.
79 */
80
81 rcu_read_lock();
82 parent = rcu_dereference(current->real_parent);
83 if (!current->nsproxy)
84 vppid = 0;
85 else
86 vppid = task_tgid_vnr(parent);
87 rcu_read_unlock();
88 value->s64 = vppid;
89}
90
b64bc438
MD
91int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx)
92{
93 struct lttng_ctx_field *field;
b64bc438
MD
94
95 field = lttng_append_context(ctx);
96 if (!field)
09fec6b4 97 return -ENOMEM;
44252f0f
MD
98 if (lttng_find_context(*ctx, "vppid")) {
99 lttng_remove_context_field(ctx, field);
100 return -EEXIST;
101 }
b64bc438
MD
102 field->event_field.name = "vppid";
103 field->event_field.type.atype = atype_integer;
ceabb767
MD
104 field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT;
105 field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT;
106 field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t);
107 field->event_field.type.u.integer.reverse_byte_order = 0;
108 field->event_field.type.u.integer.base = 10;
109 field->event_field.type.u.integer.encoding = lttng_encode_none;
b64bc438
MD
110 field->get_size = vppid_get_size;
111 field->record = vppid_record;
f127e61e 112 field->get_value = vppid_get_value;
a9dd15da 113 lttng_context_update(*ctx);
b64bc438
MD
114 return 0;
115}
116EXPORT_SYMBOL_GPL(lttng_add_vppid_to_ctx);
This page took 0.045668 seconds and 4 git commands to generate.