Rename struct lib_ring_buffer_ctx to struct lttng_kernel_ring_buffer_ctx
[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>
0fe45627 15#include <lttng/events-internal.h>
24591303 16#include <ringbuffer/frontend_types.h>
241ae9a8 17#include <wrapper/vmalloc.h>
2df37e95 18#include <lttng/tracer.h>
79150a49
JD
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
28static
a92e844e 29size_t preemptible_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset)
79150a49
JD
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
38static
a92e844e 39void preemptible_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx,
8a57ec02 40 struct lttng_kernel_ring_buffer_ctx *ctx,
79150a49
JD
41 struct lttng_channel *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 lib_ring_buffer_align_ctx(ctx, lttng_alignof(preemptible));
50 chan->ops->event_write(ctx, &preemptible, sizeof(preemptible));
51}
52
53static
bf99c737 54void preemptible_get_value(void *priv,
a92e844e 55 struct lttng_kernel_probe_ctx *lttng_probe_ctx,
bf99c737 56 struct lttng_ctx_value *value)
79150a49
JD
57{
58 int pc = preempt_count();
59
60 WARN_ON_ONCE(pc < LTTNG_PREEMPT_DISABLE_NESTING);
61 if (pc == LTTNG_PREEMPT_DISABLE_NESTING)
bf99c737 62 value->u.s64 = 1;
79150a49 63 else
bf99c737 64 value->u.s64 = 0;
79150a49
JD
65}
66
087e3f1b
MJ
67static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field(
68 lttng_kernel_static_event_field("preemptible",
69 lttng_kernel_static_type_integer_from_type(uint8_t, __BYTE_ORDER, 10),
70 false, false, false),
71 preemptible_get_size,
087e3f1b
MJ
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.043061 seconds and 4 git commands to generate.