aac10a6399ac8618a42e23c299edd8d41a0c7ee7
[lttng-modules.git] / src / lttng-context-prio.c
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng-context-prio.c
4 *
5 * LTTng priority context.
6 *
7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 #include <linux/module.h>
11 #include <linux/slab.h>
12 #include <linux/sched.h>
13 #include <lttng/events.h>
14 #include <lttng/events-internal.h>
15 #include <ringbuffer/frontend_types.h>
16 #include <wrapper/vmalloc.h>
17 #include <wrapper/kallsyms.h>
18 #include <lttng/tracer.h>
19
20 static
21 int (*wrapper_task_prio_sym)(struct task_struct *t);
22
23 int wrapper_task_prio_init(void)
24 {
25 wrapper_task_prio_sym = (void *) kallsyms_lookup_funcptr("task_prio");
26 if (!wrapper_task_prio_sym) {
27 printk(KERN_WARNING "LTTng: task_prio symbol lookup failed.\n");
28 return -EINVAL;
29 }
30 return 0;
31 }
32 EXPORT_SYMBOL_GPL(wrapper_task_prio_init);
33
34 /*
35 * Canary function to check for 'task_prio()' at compile time.
36 *
37 * From 'include/linux/sched.h':
38 *
39 * extern int task_prio(const struct task_struct *p);
40 */
41 __attribute__((unused)) static
42 int __canary__task_prio(const struct task_struct *p)
43 {
44 return task_prio(p);
45 }
46
47 static
48 size_t prio_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset)
49 {
50 size_t size = 0;
51
52 size += lib_ring_buffer_align(offset, lttng_alignof(int));
53 size += sizeof(int);
54 return size;
55 }
56
57 static
58 void prio_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
59 struct lttng_kernel_ring_buffer_ctx *ctx,
60 struct lttng_kernel_channel_buffer *chan)
61 {
62 int prio;
63
64 prio = wrapper_task_prio_sym(current);
65 chan->ops->event_write(ctx, &prio, sizeof(prio), lttng_alignof(prio));
66 }
67
68 static
69 void prio_get_value(void *priv,
70 struct lttng_kernel_probe_ctx *lttng_probe_ctx,
71 struct lttng_ctx_value *value)
72 {
73 value->u.s64 = wrapper_task_prio_sym(current);
74 }
75
76 static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field(
77 lttng_kernel_static_event_field("prio",
78 lttng_kernel_static_type_integer_from_type(int, __BYTE_ORDER, 10),
79 false, false),
80 prio_get_size,
81 prio_record,
82 prio_get_value,
83 NULL, NULL);
84
85 int lttng_add_prio_to_ctx(struct lttng_kernel_ctx **ctx)
86 {
87 int ret;
88
89 if (lttng_kernel_find_context(*ctx, ctx_field->event_field->name))
90 return -EEXIST;
91 ret = lttng_kernel_context_append(ctx, ctx_field);
92 wrapper_vmalloc_sync_mappings();
93 return ret;
94 }
95 EXPORT_SYMBOL_GPL(lttng_add_prio_to_ctx);
This page took 0.030435 seconds and 3 git commands to generate.