Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
9f36eaed | 2 | * |
13edcd1d MD |
3 | * lttng-context-cpu-id.c |
4 | * | |
5 | * LTTng CPU id context. | |
6 | * | |
7 | * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
13edcd1d MD |
8 | */ |
9 | ||
10 | #include <linux/module.h> | |
11 | #include <linux/slab.h> | |
12 | #include <linux/sched.h> | |
241ae9a8 MD |
13 | #include <lttng-events.h> |
14 | #include <wrapper/ringbuffer/frontend_types.h> | |
241ae9a8 | 15 | #include <lttng-tracer.h> |
13edcd1d MD |
16 | |
17 | static | |
18 | size_t cpu_id_get_size(size_t offset) | |
19 | { | |
20 | size_t size = 0; | |
21 | ||
1c23b886 MD |
22 | size += lib_ring_buffer_align(offset, lttng_alignof(int)); |
23 | size += sizeof(int); | |
13edcd1d MD |
24 | return size; |
25 | } | |
26 | ||
27 | static | |
28 | void cpu_id_record(struct lttng_ctx_field *field, | |
29 | struct lib_ring_buffer_ctx *ctx, | |
30 | struct lttng_channel *chan) | |
31 | { | |
1c23b886 | 32 | int cpu; |
13edcd1d MD |
33 | |
34 | cpu = ctx->cpu; | |
35 | lib_ring_buffer_align_ctx(ctx, lttng_alignof(cpu)); | |
36 | chan->ops->event_write(ctx, &cpu, sizeof(cpu)); | |
37 | } | |
38 | ||
39 | static | |
40 | void cpu_id_get_value(struct lttng_ctx_field *field, | |
79150a49 | 41 | struct lttng_probe_ctx *lttng_probe_ctx, |
13edcd1d MD |
42 | union lttng_ctx_value *value) |
43 | { | |
44 | value->s64 = smp_processor_id(); | |
45 | } | |
46 | ||
47 | int lttng_add_cpu_id_to_ctx(struct lttng_ctx **ctx) | |
48 | { | |
49 | struct lttng_ctx_field *field; | |
50 | ||
51 | field = lttng_append_context(ctx); | |
52 | if (!field) | |
53 | return -ENOMEM; | |
54 | if (lttng_find_context(*ctx, "cpu_id")) { | |
55 | lttng_remove_context_field(ctx, field); | |
56 | return -EEXIST; | |
57 | } | |
58 | field->event_field.name = "cpu_id"; | |
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; | |
13edcd1d MD |
66 | field->get_size = cpu_id_get_size; |
67 | field->record = cpu_id_record; | |
68 | field->get_value = cpu_id_get_value; | |
69 | lttng_context_update(*ctx); | |
13edcd1d MD |
70 | return 0; |
71 | } | |
72 | EXPORT_SYMBOL_GPL(lttng_add_cpu_id_to_ctx); |