Add check for old tracepoint kernel
[lttng-modules.git] / lttng-context-comm.c
CommitLineData
25b2f99a
MD
1/*
2 * (C) Copyright 2009-2011 -
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * LTTng comm name context.
6 *
7 * Dual LGPL v2.1/GPL v2 license.
8 */
9
10#include <linux/module.h>
11#include <linux/slab.h>
12#include <linux/sched.h>
13#include "ltt-events.h"
14#include "wrapper/ringbuffer/frontend_types.h"
15#include "wrapper/vmalloc.h"
16#include "ltt-tracer.h"
17
18static
19size_t comm_get_size(size_t offset)
20{
21 size_t size = 0;
22
23 size += sizeof(current->comm);
24 return size;
25}
26
27/*
28 * Racy read of comm. We simply copy its whole array size.
29 * Races with /proc/<task>/comm write only.
30 * Otherwise having to take a mutex for each event is cumbersome and
31 * could lead to crash in IRQ context and deadlock of the lockdep tracer.
32 */
33static
34void comm_record(struct lttng_ctx_field *field,
35 struct lib_ring_buffer_ctx *ctx,
36 struct ltt_channel *chan)
37{
38 chan->ops->event_write(ctx, current->comm, sizeof(current->comm));
39}
40
41int lttng_add_comm_to_ctx(struct lttng_ctx **ctx)
42{
43 struct lttng_ctx_field *field;
44 int ret;
45
46 field = lttng_append_context(ctx);
47 if (!field)
48 return ret;
49 field->event_field.name = "comm";
50 field->event_field.type.atype = atype_array;
51 field->event_field.type.u.array.elem_type.atype = atype_integer;
52 field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT;
53 field->event_field.type.u.array.elem_type.u.basic.integer.alignment = ltt_alignof(char) * CHAR_BIT;
54 field->event_field.type.u.array.elem_type.u.basic.integer.signedness = is_signed_type(char);
55 field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0;
56 field->event_field.type.u.array.elem_type.u.basic.integer.base = 10;
57 field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8;
58 field->event_field.type.u.array.length = sizeof(current->comm);
59
60 field->get_size = comm_get_size;
61 field->record = comm_record;
62 wrapper_vmalloc_sync_all();
63 return 0;
64}
65EXPORT_SYMBOL_GPL(lttng_add_comm_to_ctx);
66
67MODULE_LICENSE("GPL and additional rights");
68MODULE_AUTHOR("Mathieu Desnoyers");
69MODULE_DESCRIPTION("Linux Trace Toolkit Perf Support");
This page took 0.032613 seconds and 4 git commands to generate.