Refactoring: type description structures
[lttng-modules.git] / src / 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>
2df37e95 14#include <lttng/events.h>
437d5aa5 15#include <lttng/events-internal.h>
24591303 16#include <ringbuffer/frontend_types.h>
241ae9a8 17#include <wrapper/vmalloc.h>
2df37e95 18#include <lttng/tracer.h>
b64bc438
MD
19
20static
21size_t vppid_get_size(size_t offset)
22{
23 size_t size = 0;
24
a90917c3 25 size += lib_ring_buffer_align(offset, lttng_alignof(pid_t));
b64bc438
MD
26 size += sizeof(pid_t);
27 return size;
28}
29
30static
437d5aa5 31void vppid_record(struct lttng_kernel_ctx_field *field,
b64bc438 32 struct lib_ring_buffer_ctx *ctx,
a90917c3 33 struct lttng_channel *chan)
b64bc438 34{
90f96adf 35 struct task_struct *parent;
b64bc438
MD
36 pid_t vppid;
37
90f96adf 38 /*
de544ea5
MD
39 * current nsproxy can be NULL when scheduled out of exit. pid_vnr uses
40 * the current thread nsproxy to perform the lookup.
90f96adf 41 */
1638c9b4
MD
42
43 /*
44 * TODO: when we eventually add RCU subsystem instrumentation,
45 * taking the rcu read lock here will trigger RCU tracing
46 * recursively. We should modify the kernel synchronization so
47 * it synchronizes both for RCU and RCU sched, and rely on
48 * rcu_read_lock_sched_notrace.
49 */
50
b64bc438 51 rcu_read_lock();
90f96adf 52 parent = rcu_dereference(current->real_parent);
de544ea5 53 if (!current->nsproxy)
90f96adf
MD
54 vppid = 0;
55 else
56 vppid = task_tgid_vnr(parent);
b64bc438 57 rcu_read_unlock();
a90917c3 58 lib_ring_buffer_align_ctx(ctx, lttng_alignof(vppid));
b64bc438
MD
59 chan->ops->event_write(ctx, &vppid, sizeof(vppid));
60}
61
f127e61e 62static
437d5aa5 63void vppid_get_value(struct lttng_kernel_ctx_field *field,
79150a49 64 struct lttng_probe_ctx *lttng_probe_ctx,
f127e61e
MD
65 union lttng_ctx_value *value)
66{
67 struct task_struct *parent;
68 pid_t vppid;
69
70 /*
71 * current nsproxy can be NULL when scheduled out of exit. pid_vnr uses
72 * the current thread nsproxy to perform the lookup.
73 */
74
75 /*
76 * TODO: when we eventually add RCU subsystem instrumentation,
77 * taking the rcu read lock here will trigger RCU tracing
78 * recursively. We should modify the kernel synchronization so
79 * it synchronizes both for RCU and RCU sched, and rely on
80 * rcu_read_lock_sched_notrace.
81 */
82
83 rcu_read_lock();
84 parent = rcu_dereference(current->real_parent);
85 if (!current->nsproxy)
86 vppid = 0;
87 else
88 vppid = task_tgid_vnr(parent);
89 rcu_read_unlock();
90 value->s64 = vppid;
91}
92
437d5aa5
MD
93static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field(
94 lttng_kernel_static_event_field("vppid",
95 lttng_kernel_static_type_integer_from_type(pid_t, __BYTE_ORDER, 10),
96 false, false, false),
97 vppid_get_size,
98 NULL,
99 vppid_record,
100 vppid_get_value,
101 NULL, NULL);
102
103int lttng_add_vppid_to_ctx(struct lttng_kernel_ctx **ctx)
b64bc438 104{
437d5aa5 105 int ret;
b64bc438 106
437d5aa5 107 if (lttng_kernel_find_context(*ctx, ctx_field->event_field->name))
44252f0f 108 return -EEXIST;
437d5aa5 109 ret = lttng_kernel_context_append(ctx, ctx_field);
263b6c88 110 wrapper_vmalloc_sync_mappings();
437d5aa5 111 return ret;
b64bc438
MD
112}
113EXPORT_SYMBOL_GPL(lttng_add_vppid_to_ctx);
This page took 0.047563 seconds and 4 git commands to generate.