Move headers under include/
[lttng-modules.git] / lttng-context-prio.c
CommitLineData
b7cdc182 1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
9f36eaed 2 *
886d51a3 3 * lttng-context-prio.c
a8ad3613
MD
4 *
5 * LTTng priority context.
6 *
886d51a3 7 * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
a8ad3613
MD
8 */
9
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/sched.h>
b5304713
MD
13#include <lttng/lttng-events.h>
14#include <ringbuffer/frontend_types.h>
15#include <lttng/lttng-tracer.h>
a8ad3613
MD
16
17static
18size_t prio_get_size(size_t offset)
19{
20 size_t size = 0;
21
a90917c3 22 size += lib_ring_buffer_align(offset, lttng_alignof(int));
a8ad3613
MD
23 size += sizeof(int);
24 return size;
25}
26
27static
28void prio_record(struct lttng_ctx_field *field,
29 struct lib_ring_buffer_ctx *ctx,
a90917c3 30 struct lttng_channel *chan)
a8ad3613
MD
31{
32 int prio;
33
f0588da3 34 prio = task_prio(current);
a90917c3 35 lib_ring_buffer_align_ctx(ctx, lttng_alignof(prio));
53f1f0ca 36 chan->ops->event_write(ctx, &prio, sizeof(prio));
a8ad3613
MD
37}
38
f127e61e
MD
39static
40void prio_get_value(struct lttng_ctx_field *field,
79150a49 41 struct lttng_probe_ctx *lttng_probe_ctx,
f127e61e
MD
42 union lttng_ctx_value *value)
43{
f0588da3 44 value->s64 = task_prio(current);
f127e61e
MD
45}
46
a8ad3613
MD
47int lttng_add_prio_to_ctx(struct lttng_ctx **ctx)
48{
49 struct lttng_ctx_field *field;
979133c5 50
a8ad3613
MD
51 field = lttng_append_context(ctx);
52 if (!field)
09fec6b4 53 return -ENOMEM;
44252f0f
MD
54 if (lttng_find_context(*ctx, "prio")) {
55 lttng_remove_context_field(ctx, field);
56 return -EEXIST;
57 }
a8ad3613
MD
58 field->event_field.name = "prio";
59 field->event_field.type.atype = atype_integer;
ceabb767
MD
60 field->event_field.type.u.integer.size = sizeof(int) * CHAR_BIT;
61 field->event_field.type.u.integer.alignment = lttng_alignof(int) * CHAR_BIT;
62 field->event_field.type.u.integer.signedness = lttng_is_signed_type(int);
63 field->event_field.type.u.integer.reverse_byte_order = 0;
64 field->event_field.type.u.integer.base = 10;
65 field->event_field.type.u.integer.encoding = lttng_encode_none;
a8ad3613
MD
66 field->get_size = prio_get_size;
67 field->record = prio_record;
f127e61e 68 field->get_value = prio_get_value;
a9dd15da 69 lttng_context_update(*ctx);
a8ad3613
MD
70 return 0;
71}
72EXPORT_SYMBOL_GPL(lttng_add_prio_to_ctx);
This page took 0.039415 seconds and 4 git commands to generate.