Fix: missing define when not building with gcc
[lttng-modules.git] / lttng-context-preemptible.c
1 /*
2 * lttng-context-preemptible.c
3 *
4 * LTTng preemptible context.
5 *
6 * Copyright (C) 2009-2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/sched.h>
26 #include <linux/irqflags.h>
27 #include <lttng-events.h>
28 #include <wrapper/ringbuffer/frontend_types.h>
29 #include <wrapper/vmalloc.h>
30 #include <lttng-tracer.h>
31
32 /*
33 * We nest twice in preempt disabling within LTTng: one nesting is done
34 * by the instrumentation (tracepoint, kprobes, kretprobes, syscall
35 * tracepoint), and the second is within the lib ring buffer
36 * lib_ring_buffer_get_cpu().
37 */
38 #define LTTNG_PREEMPT_DISABLE_NESTING 2
39
40 static
41 size_t preemptible_get_size(size_t offset)
42 {
43 size_t size = 0;
44
45 size += lib_ring_buffer_align(offset, lttng_alignof(uint8_t));
46 size += sizeof(uint8_t);
47 return size;
48 }
49
50 static
51 void preemptible_record(struct lttng_ctx_field *field,
52 struct lib_ring_buffer_ctx *ctx,
53 struct lttng_channel *chan)
54 {
55 int pc = preempt_count();
56 uint8_t preemptible = 0;
57
58 WARN_ON_ONCE(pc < LTTNG_PREEMPT_DISABLE_NESTING);
59 if (pc == LTTNG_PREEMPT_DISABLE_NESTING)
60 preemptible = 1;
61 lib_ring_buffer_align_ctx(ctx, lttng_alignof(preemptible));
62 chan->ops->event_write(ctx, &preemptible, sizeof(preemptible));
63 }
64
65 static
66 void preemptible_get_value(struct lttng_ctx_field *field,
67 struct lttng_probe_ctx *lttng_probe_ctx,
68 union lttng_ctx_value *value)
69 {
70 int pc = preempt_count();
71
72 WARN_ON_ONCE(pc < LTTNG_PREEMPT_DISABLE_NESTING);
73 if (pc == LTTNG_PREEMPT_DISABLE_NESTING)
74 value->s64 = 1;
75 else
76 value->s64 = 0;
77 }
78
79 int lttng_add_preemptible_to_ctx(struct lttng_ctx **ctx)
80 {
81 struct lttng_ctx_field *field;
82
83 field = lttng_append_context(ctx);
84 if (!field)
85 return -ENOMEM;
86 if (lttng_find_context(*ctx, "preemptible")) {
87 lttng_remove_context_field(ctx, field);
88 return -EEXIST;
89 }
90 field->event_field.name = "preemptible";
91 field->event_field.type.atype = atype_integer;
92 field->event_field.type.u.basic.integer.size = sizeof(uint8_t) * CHAR_BIT;
93 field->event_field.type.u.basic.integer.alignment = lttng_alignof(uint8_t) * CHAR_BIT;
94 field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(uint8_t);
95 field->event_field.type.u.basic.integer.reverse_byte_order = 0;
96 field->event_field.type.u.basic.integer.base = 10;
97 field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
98 field->get_size = preemptible_get_size;
99 field->record = preemptible_record;
100 field->get_value = preemptible_get_value;
101 lttng_context_update(*ctx);
102 wrapper_vmalloc_sync_all();
103 return 0;
104 }
105 EXPORT_SYMBOL_GPL(lttng_add_preemptible_to_ctx);
This page took 0.043748 seconds and 4 git commands to generate.