Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
9f36eaed | 2 | * |
886d51a3 | 3 | * lttng-context-prio.c |
a8ad3613 MD |
4 | * |
5 | * LTTng priority context. | |
6 | * | |
886d51a3 | 7 | * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
a8ad3613 MD |
8 | */ |
9 | ||
10 | #include <linux/module.h> | |
11 | #include <linux/slab.h> | |
12 | #include <linux/sched.h> | |
2df37e95 | 13 | #include <lttng/events.h> |
437d5aa5 | 14 | #include <lttng/events-internal.h> |
24591303 | 15 | #include <ringbuffer/frontend_types.h> |
241ae9a8 | 16 | #include <wrapper/vmalloc.h> |
2df37e95 | 17 | #include <lttng/tracer.h> |
c63b1067 MD |
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 | |
a8ad3613 | 30 | |
3dfec228 | 31 | /* |
7f1fa632 MD |
32 | * task_prio() has been implemented as p->prio - MAX_RT_PRIO since at |
33 | * least kernel v3.0. | |
3dfec228 | 34 | */ |
7f1fa632 MD |
35 | static |
36 | int wrapper_task_prio(struct task_struct *p) | |
3dfec228 | 37 | { |
7f1fa632 | 38 | return p->prio - MAX_RT_PRIO; |
3dfec228 MJ |
39 | } |
40 | ||
a8ad3613 | 41 | static |
346cb5ee | 42 | size_t prio_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) |
a8ad3613 MD |
43 | { |
44 | size_t size = 0; | |
45 | ||
a90917c3 | 46 | size += lib_ring_buffer_align(offset, lttng_alignof(int)); |
a8ad3613 MD |
47 | size += sizeof(int); |
48 | return size; | |
49 | } | |
50 | ||
51 | static | |
346cb5ee | 52 | void prio_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, |
e27e4381 | 53 | struct lttng_kernel_ring_buffer_ctx *ctx, |
ac847066 | 54 | struct lttng_kernel_channel_buffer *chan) |
a8ad3613 MD |
55 | { |
56 | int prio; | |
57 | ||
7f1fa632 | 58 | prio = wrapper_task_prio(current); |
77fcffef | 59 | chan->ops->event_write(ctx, &prio, sizeof(prio), lttng_alignof(prio)); |
a8ad3613 MD |
60 | } |
61 | ||
f127e61e | 62 | static |
ea2d95e4 | 63 | void prio_get_value(void *priv, |
346cb5ee | 64 | struct lttng_kernel_probe_ctx *lttng_probe_ctx, |
ea2d95e4 | 65 | struct lttng_ctx_value *value) |
f127e61e | 66 | { |
7f1fa632 | 67 | value->u.s64 = wrapper_task_prio(current); |
f127e61e MD |
68 | } |
69 | ||
437d5aa5 MD |
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), | |
07aafa15 | 73 | false, false), |
437d5aa5 | 74 | prio_get_size, |
437d5aa5 MD |
75 | prio_record, |
76 | prio_get_value, | |
77 | NULL, NULL); | |
78 | ||
79 | int lttng_add_prio_to_ctx(struct lttng_kernel_ctx **ctx) | |
a8ad3613 | 80 | { |
a8ad3613 MD |
81 | int ret; |
82 | ||
437d5aa5 | 83 | if (lttng_kernel_find_context(*ctx, ctx_field->event_field->name)) |
44252f0f | 84 | return -EEXIST; |
437d5aa5 | 85 | ret = lttng_kernel_context_append(ctx, ctx_field); |
263b6c88 | 86 | wrapper_vmalloc_sync_mappings(); |
437d5aa5 | 87 | return ret; |
a8ad3613 MD |
88 | } |
89 | EXPORT_SYMBOL_GPL(lttng_add_prio_to_ctx); |