Fix: Include linux/sched/rt.h for kernels v3.9 to v3.14
[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 <lttng/tracer.h>
18 #include <lttng/kernel-version.h>
19
20 /*
21 * From kernel v3.0 to v3.8, MAX_RT_PRIO is defined in linux/sched.h.
22 * From kernel v3.9 to v3.14, MAX_RT_PRIO is defined in linux/sched/rt.h,
23 * which is not included by linux/sched.h (hence this work-around).
24 * From kernel v3.15 onwards, MAX_RT_PRIO is defined in linux/sched/prio.h,
25 * which is included by linux/sched.h.
26 */
27 #if LTTNG_KERNEL_RANGE(3,9,0, 3,15,0)
28 # include <linux/sched/rt.h>
29 #endif
30
31 /*
32 * task_prio() has been implemented as p->prio - MAX_RT_PRIO since at
33 * least kernel v3.0.
34 */
35 static
36 int wrapper_task_prio(struct task_struct *p)
37 {
38 return p->prio - MAX_RT_PRIO;
39 }
40
41 static
42 size_t prio_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset)
43 {
44 size_t size = 0;
45
46 size += lib_ring_buffer_align(offset, lttng_alignof(int));
47 size += sizeof(int);
48 return size;
49 }
50
51 static
52 void prio_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
53 struct lttng_kernel_ring_buffer_ctx *ctx,
54 struct lttng_kernel_channel_buffer *chan)
55 {
56 int prio;
57
58 prio = wrapper_task_prio(current);
59 chan->ops->event_write(ctx, &prio, sizeof(prio), lttng_alignof(prio));
60 }
61
62 static
63 void prio_get_value(void *priv,
64 struct lttng_kernel_probe_ctx *lttng_probe_ctx,
65 struct lttng_ctx_value *value)
66 {
67 value->u.s64 = wrapper_task_prio(current);
68 }
69
70 static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field(
71 lttng_kernel_static_event_field("prio",
72 lttng_kernel_static_type_integer_from_type(int, __BYTE_ORDER, 10),
73 false, false),
74 prio_get_size,
75 prio_record,
76 prio_get_value,
77 NULL, NULL);
78
79 int lttng_add_prio_to_ctx(struct lttng_kernel_ctx **ctx)
80 {
81 int ret;
82
83 if (lttng_kernel_find_context(*ctx, ctx_field->event_field->name))
84 return -EEXIST;
85 ret = lttng_kernel_context_append(ctx, ctx_field);
86 wrapper_vmalloc_sync_mappings();
87 return ret;
88 }
89 EXPORT_SYMBOL_GPL(lttng_add_prio_to_ctx);
This page took 0.035314 seconds and 4 git commands to generate.