fix: refactor contexts for type description structures
[lttng-modules.git] / src / lttng-context-preemptible.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
79150a49
JD
3 * lttng-context-preemptible.c
4 *
5 * LTTng preemptible context.
6 *
7 * Copyright (C) 2009-2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
79150a49
JD
8 */
9
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/sched.h>
13#include <linux/irqflags.h>
2df37e95 14#include <lttng/events.h>
24591303 15#include <ringbuffer/frontend_types.h>
241ae9a8 16#include <wrapper/vmalloc.h>
2df37e95 17#include <lttng/tracer.h>
79150a49
JD
18
19/*
20 * We nest twice in preempt disabling within LTTng: one nesting is done
21 * by the instrumentation (tracepoint, kprobes, kretprobes, syscall
22 * tracepoint), and the second is within the lib ring buffer
23 * lib_ring_buffer_get_cpu().
24 */
25#define LTTNG_PREEMPT_DISABLE_NESTING 2
26
27static
28size_t preemptible_get_size(size_t offset)
29{
30 size_t size = 0;
31
32 size += lib_ring_buffer_align(offset, lttng_alignof(uint8_t));
33 size += sizeof(uint8_t);
34 return size;
35}
36
37static
437d5aa5 38void preemptible_record(struct lttng_kernel_ctx_field *field,
79150a49
JD
39 struct lib_ring_buffer_ctx *ctx,
40 struct lttng_channel *chan)
41{
42 int pc = preempt_count();
43 uint8_t preemptible = 0;
44
45 WARN_ON_ONCE(pc < LTTNG_PREEMPT_DISABLE_NESTING);
46 if (pc == LTTNG_PREEMPT_DISABLE_NESTING)
47 preemptible = 1;
48 lib_ring_buffer_align_ctx(ctx, lttng_alignof(preemptible));
49 chan->ops->event_write(ctx, &preemptible, sizeof(preemptible));
50}
51
52static
437d5aa5 53void preemptible_get_value(struct lttng_kernel_ctx_field *field,
79150a49
JD
54 struct lttng_probe_ctx *lttng_probe_ctx,
55 union 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->s64 = 1;
62 else
63 value->s64 = 0;
64}
65
087e3f1b
MJ
66static 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 NULL,
72 preemptible_record,
73 preemptible_get_value,
74 NULL, NULL);
75
437d5aa5 76int lttng_add_preemptible_to_ctx(struct lttng_kernel_ctx **ctx)
79150a49 77{
087e3f1b 78 int ret;
79150a49 79
087e3f1b 80 if (lttng_kernel_find_context(*ctx, ctx_field->event_field->name))
79150a49 81 return -EEXIST;
087e3f1b 82 ret = lttng_kernel_context_append(ctx, ctx_field);
263b6c88 83 wrapper_vmalloc_sync_mappings();
087e3f1b 84 return ret;
79150a49
JD
85}
86EXPORT_SYMBOL_GPL(lttng_add_preemptible_to_ctx);
This page took 0.040734 seconds and 4 git commands to generate.