Commit | Line | Data |
---|---|---|
79150a49 JD |
1 | /* |
2 | * lttng-context-interruptible.c | |
3 | * | |
4 | * LTTng interruptible 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> | |
241ae9a8 MD |
27 | #include <lttng-events.h> |
28 | #include <wrapper/ringbuffer/frontend_types.h> | |
29 | #include <wrapper/vmalloc.h> | |
30 | #include <lttng-tracer.h> | |
79150a49 JD |
31 | |
32 | /* | |
33 | * Interruptible at value -1 means "unknown". | |
34 | */ | |
35 | ||
36 | static | |
37 | size_t interruptible_get_size(size_t offset) | |
38 | { | |
39 | size_t size = 0; | |
40 | ||
41 | size += lib_ring_buffer_align(offset, lttng_alignof(int8_t)); | |
42 | size += sizeof(int8_t); | |
43 | return size; | |
44 | } | |
45 | ||
46 | static | |
47 | void interruptible_record(struct lttng_ctx_field *field, | |
48 | struct lib_ring_buffer_ctx *ctx, | |
49 | struct lttng_channel *chan) | |
50 | { | |
51 | struct lttng_probe_ctx *lttng_probe_ctx = ctx->priv; | |
52 | int8_t interruptible = lttng_probe_ctx->interruptible; | |
53 | ||
54 | lib_ring_buffer_align_ctx(ctx, lttng_alignof(interruptible)); | |
55 | chan->ops->event_write(ctx, &interruptible, sizeof(interruptible)); | |
56 | } | |
57 | ||
58 | static | |
59 | void interruptible_get_value(struct lttng_ctx_field *field, | |
60 | struct lttng_probe_ctx *lttng_probe_ctx, | |
61 | union lttng_ctx_value *value) | |
62 | { | |
63 | int8_t interruptible = lttng_probe_ctx->interruptible; | |
64 | ||
65 | value->s64 = interruptible; | |
66 | } | |
67 | ||
68 | int lttng_add_interruptible_to_ctx(struct lttng_ctx **ctx) | |
69 | { | |
70 | struct lttng_ctx_field *field; | |
71 | ||
72 | field = lttng_append_context(ctx); | |
73 | if (!field) | |
74 | return -ENOMEM; | |
75 | if (lttng_find_context(*ctx, "interruptible")) { | |
76 | lttng_remove_context_field(ctx, field); | |
77 | return -EEXIST; | |
78 | } | |
79 | field->event_field.name = "interruptible"; | |
80 | field->event_field.type.atype = atype_integer; | |
81 | field->event_field.type.u.basic.integer.size = sizeof(int8_t) * CHAR_BIT; | |
82 | field->event_field.type.u.basic.integer.alignment = lttng_alignof(int8_t) * CHAR_BIT; | |
83 | field->event_field.type.u.basic.integer.signedness = lttng_is_signed_type(int8_t); | |
84 | field->event_field.type.u.basic.integer.reverse_byte_order = 0; | |
85 | field->event_field.type.u.basic.integer.base = 10; | |
86 | field->event_field.type.u.basic.integer.encoding = lttng_encode_none; | |
87 | field->get_size = interruptible_get_size; | |
88 | field->record = interruptible_record; | |
89 | field->get_value = interruptible_get_value; | |
90 | lttng_context_update(*ctx); | |
91 | wrapper_vmalloc_sync_all(); | |
92 | return 0; | |
93 | } | |
94 | EXPORT_SYMBOL_GPL(lttng_add_interruptible_to_ctx); |