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 MD |
16 | #include <wrapper/vmalloc.h> |
17 | #include <wrapper/kallsyms.h> | |
2df37e95 | 18 | #include <lttng/tracer.h> |
a8ad3613 | 19 | |
979133c5 MD |
20 | static |
21 | int (*wrapper_task_prio_sym)(struct task_struct *t); | |
22 | ||
23 | int wrapper_task_prio_init(void) | |
24 | { | |
c539a324 | 25 | wrapper_task_prio_sym = (void *) kallsyms_lookup_funcptr("task_prio"); |
979133c5 MD |
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 | ||
3dfec228 MJ |
33 | /* |
34 | * Canary function to check for 'task_prio()' at compile time. | |
35 | * | |
36 | * From 'include/linux/sched.h': | |
37 | * | |
38 | * extern int task_prio(const struct task_struct *p); | |
39 | */ | |
40 | __attribute__((unused)) static | |
41 | int __canary__task_prio(const struct task_struct *p) | |
42 | { | |
43 | return task_prio(p); | |
44 | } | |
45 | ||
a8ad3613 | 46 | static |
346cb5ee | 47 | size_t prio_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) |
a8ad3613 MD |
48 | { |
49 | size_t size = 0; | |
50 | ||
a90917c3 | 51 | size += lib_ring_buffer_align(offset, lttng_alignof(int)); |
a8ad3613 MD |
52 | size += sizeof(int); |
53 | return size; | |
54 | } | |
55 | ||
56 | static | |
346cb5ee | 57 | void prio_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, |
e27e4381 | 58 | struct lttng_kernel_ring_buffer_ctx *ctx, |
ac847066 | 59 | struct lttng_kernel_channel_buffer *chan) |
a8ad3613 MD |
60 | { |
61 | int prio; | |
62 | ||
8fefc8a2 | 63 | prio = wrapper_task_prio_sym(current); |
77fcffef | 64 | chan->ops->event_write(ctx, &prio, sizeof(prio), lttng_alignof(prio)); |
a8ad3613 MD |
65 | } |
66 | ||
f127e61e | 67 | static |
ea2d95e4 | 68 | void prio_get_value(void *priv, |
346cb5ee | 69 | struct lttng_kernel_probe_ctx *lttng_probe_ctx, |
ea2d95e4 | 70 | struct lttng_ctx_value *value) |
f127e61e | 71 | { |
ea2d95e4 | 72 | value->u.s64 = wrapper_task_prio_sym(current); |
f127e61e MD |
73 | } |
74 | ||
437d5aa5 MD |
75 | static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( |
76 | lttng_kernel_static_event_field("prio", | |
77 | lttng_kernel_static_type_integer_from_type(int, __BYTE_ORDER, 10), | |
78 | false, false, false), | |
79 | prio_get_size, | |
437d5aa5 MD |
80 | prio_record, |
81 | prio_get_value, | |
82 | NULL, NULL); | |
83 | ||
84 | int lttng_add_prio_to_ctx(struct lttng_kernel_ctx **ctx) | |
a8ad3613 | 85 | { |
a8ad3613 MD |
86 | int ret; |
87 | ||
437d5aa5 | 88 | if (lttng_kernel_find_context(*ctx, ctx_field->event_field->name)) |
44252f0f | 89 | return -EEXIST; |
437d5aa5 | 90 | ret = lttng_kernel_context_append(ctx, ctx_field); |
263b6c88 | 91 | wrapper_vmalloc_sync_mappings(); |
437d5aa5 | 92 | return ret; |
a8ad3613 MD |
93 | } |
94 | EXPORT_SYMBOL_GPL(lttng_add_prio_to_ctx); |