Move headers under include/
[lttng-modules.git] / lttng-context-ppid.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
886d51a3 3 * lttng-context-ppid.c
b64bc438
MD
4 *
5 * LTTng PPID 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 ppid_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 ppid_record(struct lttng_ctx_field *field,
30 struct lib_ring_buffer_ctx *ctx,
a90917c3 31 struct lttng_channel *chan)
b64bc438
MD
32{
33 pid_t ppid;
34
1638c9b4
MD
35 /*
36 * TODO: when we eventually add RCU subsystem instrumentation,
37 * taking the rcu read lock here will trigger RCU tracing
38 * recursively. We should modify the kernel synchronization so
39 * it synchronizes both for RCU and RCU sched, and rely on
40 * rcu_read_lock_sched_notrace.
41 */
b64bc438
MD
42 rcu_read_lock();
43 ppid = task_tgid_nr(current->real_parent);
44 rcu_read_unlock();
a90917c3 45 lib_ring_buffer_align_ctx(ctx, lttng_alignof(ppid));
b64bc438
MD
46 chan->ops->event_write(ctx, &ppid, sizeof(ppid));
47}
48
f127e61e
MD
49static
50void ppid_get_value(struct lttng_ctx_field *field,
79150a49 51 struct lttng_probe_ctx *lttng_probe_ctx,
f127e61e
MD
52 union lttng_ctx_value *value)
53{
54 pid_t ppid;
55
56 /*
57 * TODO: when we eventually add RCU subsystem instrumentation,
58 * taking the rcu read lock here will trigger RCU tracing
59 * recursively. We should modify the kernel synchronization so
60 * it synchronizes both for RCU and RCU sched, and rely on
61 * rcu_read_lock_sched_notrace.
62 */
63 rcu_read_lock();
64 ppid = task_tgid_nr(current->real_parent);
65 rcu_read_unlock();
66 value->s64 = ppid;
67}
68
b64bc438
MD
69int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx)
70{
71 struct lttng_ctx_field *field;
b64bc438
MD
72
73 field = lttng_append_context(ctx);
74 if (!field)
09fec6b4 75 return -ENOMEM;
44252f0f
MD
76 if (lttng_find_context(*ctx, "ppid")) {
77 lttng_remove_context_field(ctx, field);
78 return -EEXIST;
79 }
b64bc438
MD
80 field->event_field.name = "ppid";
81 field->event_field.type.atype = atype_integer;
ceabb767
MD
82 field->event_field.type.u.integer.size = sizeof(pid_t) * CHAR_BIT;
83 field->event_field.type.u.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT;
84 field->event_field.type.u.integer.signedness = lttng_is_signed_type(pid_t);
85 field->event_field.type.u.integer.reverse_byte_order = 0;
86 field->event_field.type.u.integer.base = 10;
87 field->event_field.type.u.integer.encoding = lttng_encode_none;
b64bc438
MD
88 field->get_size = ppid_get_size;
89 field->record = ppid_record;
f127e61e 90 field->get_value = ppid_get_value;
a9dd15da 91 lttng_context_update(*ctx);
b64bc438
MD
92 return 0;
93}
94EXPORT_SYMBOL_GPL(lttng_add_ppid_to_ctx);
This page took 0.038572 seconds and 4 git commands to generate.