Warn on event registration/unregistration failure
[lttng-modules.git] / src / lttng-context-preemptible.c
1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng-context-preemptible.c
4 *
5 * LTTng preemptible context.
6 *
7 * Copyright (C) 2009-2015 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 <linux/irqflags.h>
14 #include <lttng/events.h>
15 #include <lttng/events-internal.h>
16 #include <ringbuffer/frontend_types.h>
17 #include <wrapper/vmalloc.h>
18 #include <lttng/tracer.h>
19
20 /*
21 * We nest twice in preempt disabling within LTTng: one nesting is done
22 * by the instrumentation (tracepoint, kprobes, kretprobes, syscall
23 * tracepoint), and the second is within the lib ring buffer
24 * lib_ring_buffer_get_cpu().
25 */
26 #define LTTNG_PREEMPT_DISABLE_NESTING 2
27
28 static
29 size_t preemptible_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset)
30 {
31 size_t size = 0;
32
33 size += lib_ring_buffer_align(offset, lttng_alignof(uint8_t));
34 size += sizeof(uint8_t);
35 return size;
36 }
37
38 static
39 void preemptible_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
40 struct lttng_kernel_ring_buffer_ctx *ctx,
41 struct lttng_kernel_channel_buffer *chan)
42 {
43 int pc = preempt_count();
44 uint8_t preemptible = 0;
45
46 WARN_ON_ONCE(pc < LTTNG_PREEMPT_DISABLE_NESTING);
47 if (pc == LTTNG_PREEMPT_DISABLE_NESTING)
48 preemptible = 1;
49 chan->ops->event_write(ctx, &preemptible, sizeof(preemptible), lttng_alignof(preemptible));
50 }
51
52 static
53 void preemptible_get_value(void *priv,
54 struct lttng_kernel_probe_ctx *lttng_probe_ctx,
55 struct lttng_ctx_value *value)
56 {
57 int pc = preempt_count();
58
59 WARN_ON_ONCE(pc < LTTNG_PREEMPT_DISABLE_NESTING);
60 if (pc == LTTNG_PREEMPT_DISABLE_NESTING)
61 value->u.s64 = 1;
62 else
63 value->u.s64 = 0;
64 }
65
66 static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field(
67 lttng_kernel_static_event_field("preemptible",
68 lttng_kernel_static_type_integer_from_type(uint8_t, __BYTE_ORDER, 10),
69 false, false, false),
70 preemptible_get_size,
71 preemptible_record,
72 preemptible_get_value,
73 NULL, NULL);
74
75 int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx)
76 {
77 int ret;
78
79 if (lttng_kernel_find_context(*ctx, ctx_field->event_field->name))
80 return -EEXIST;
81 ret = lttng_kernel_context_append(ctx, ctx_field);
82 wrapper_vmalloc_sync_mappings();
83 return ret;
84 }
85 EXPORT_SYMBOL_GPL(lttng_add_preemptible_to_ctx);
This page took 0.046792 seconds and 4 git commands to generate.