1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
5 * LTTng priority context.
7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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>
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.
27 #if LTTNG_KERNEL_RANGE(3,9,0, 3,15,0)
28 # include <linux/sched/rt.h>
32 * task_prio() has been implemented as p->prio - MAX_RT_PRIO since at
36 int wrapper_task_prio(struct task_struct
*p
)
38 return p
->prio
- MAX_RT_PRIO
;
42 size_t prio_get_size(void *priv
, struct lttng_kernel_probe_ctx
*probe_ctx
, size_t offset
)
46 size
+= lib_ring_buffer_align(offset
, lttng_alignof(int));
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
)
58 prio
= wrapper_task_prio(current
);
59 chan
->ops
->event_write(ctx
, &prio
, sizeof(prio
), lttng_alignof(prio
));
63 void prio_get_value(void *priv
,
64 struct lttng_kernel_probe_ctx
*lttng_probe_ctx
,
65 struct lttng_ctx_value
*value
)
67 value
->u
.s64
= wrapper_task_prio(current
);
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),
79 int lttng_add_prio_to_ctx(struct lttng_kernel_ctx
**ctx
)
83 if (lttng_kernel_find_context(*ctx
, ctx_field
->event_field
->name
))
85 ret
= lttng_kernel_context_append(ctx
, ctx_field
);
86 wrapper_vmalloc_sync_mappings();
89 EXPORT_SYMBOL_GPL(lttng_add_prio_to_ctx
);