lttng-abi: Document ioctl numbers reserved by lttng-abi-old.h
[lttng-modules.git] / lttng-context-ppid.c
CommitLineData
9f36eaed
MJ
1/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
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>
241ae9a8
MD
14#include <lttng-events.h>
15#include <wrapper/ringbuffer/frontend_types.h>
16#include <wrapper/vmalloc.h>
17#include <lttng-tracer.h>
b64bc438
MD
18
19static
20size_t ppid_get_size(size_t offset)
21{
22 size_t size = 0;
23
a90917c3 24 size += lib_ring_buffer_align(offset, lttng_alignof(pid_t));
b64bc438
MD
25 size += sizeof(pid_t);
26 return size;
27}
28
29static
30void ppid_record(struct lttng_ctx_field *field,
31 struct lib_ring_buffer_ctx *ctx,
a90917c3 32 struct lttng_channel *chan)
b64bc438
MD
33{
34 pid_t ppid;
35
1638c9b4
MD
36 /*
37 * TODO: when we eventually add RCU subsystem instrumentation,
38 * taking the rcu read lock here will trigger RCU tracing
39 * recursively. We should modify the kernel synchronization so
40 * it synchronizes both for RCU and RCU sched, and rely on
41 * rcu_read_lock_sched_notrace.
42 */
b64bc438
MD
43 rcu_read_lock();
44 ppid = task_tgid_nr(current->real_parent);
45 rcu_read_unlock();
a90917c3 46 lib_ring_buffer_align_ctx(ctx, lttng_alignof(ppid));
b64bc438
MD
47 chan->ops->event_write(ctx, &ppid, sizeof(ppid));
48}
49
f127e61e
MD
50static
51void ppid_get_value(struct lttng_ctx_field *field,
79150a49 52 struct lttng_probe_ctx *lttng_probe_ctx,
f127e61e
MD
53 union lttng_ctx_value *value)
54{
55 pid_t ppid;
56
57 /*
58 * TODO: when we eventually add RCU subsystem instrumentation,
59 * taking the rcu read lock here will trigger RCU tracing
60 * recursively. We should modify the kernel synchronization so
61 * it synchronizes both for RCU and RCU sched, and rely on
62 * rcu_read_lock_sched_notrace.
63 */
64 rcu_read_lock();
65 ppid = task_tgid_nr(current->real_parent);
66 rcu_read_unlock();
67 value->s64 = ppid;
68}
69
b64bc438
MD
70int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx)
71{
72 struct lttng_ctx_field *field;
b64bc438
MD
73
74 field = lttng_append_context(ctx);
75 if (!field)
09fec6b4 76 return -ENOMEM;
44252f0f
MD
77 if (lttng_find_context(*ctx, "ppid")) {
78 lttng_remove_context_field(ctx, field);
79 return -EEXIST;
80 }
b64bc438
MD
81 field->event_field.name = "ppid";
82 field->event_field.type.atype = atype_integer;
83 field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
a90917c3 84 field->event_field.type.u.basic.integer.alignment = lttng_alignof(pid_t) * CHAR_BIT;
06254b0f 85 field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(pid_t);
b64bc438
MD
86 field->event_field.type.u.basic.integer.reverse_byte_order = 0;
87 field->event_field.type.u.basic.integer.base = 10;
88 field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
89 field->get_size = ppid_get_size;
90 field->record = ppid_record;
f127e61e 91 field->get_value = ppid_get_value;
a9dd15da 92 lttng_context_update(*ctx);
b64bc438
MD
93 wrapper_vmalloc_sync_all();
94 return 0;
95}
96EXPORT_SYMBOL_GPL(lttng_add_ppid_to_ctx);
This page took 0.036339 seconds and 4 git commands to generate.