fix: tracepoint: Optimize using static_call() (v5.10)
[lttng-modules.git] / tests / probes / lttng-test.c
CommitLineData
9f36eaed
MJ
1/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
89406ecd
MD
3 * lttng-test.c
4 *
5 * Linux Trace Toolkit Next Generation Test Module
6 *
7 * Copyright 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
89406ecd
MD
8 */
9
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/proc_fs.h>
13#include <linux/byteorder/generic.h>
3834b99f 14#include <asm/byteorder.h>
89406ecd 15
156a3977
MD
16#include <lttng-events.h>
17#include <lttng-tracer.h>
18#include <wrapper/tracepoint.h>
19#include <wrapper/kstrtox.h>
89406ecd
MD
20
21#define TP_MODULE_NOAUTOLOAD
22#define LTTNG_PACKAGE_BUILD
23#define CREATE_TRACE_POINTS
156a3977 24#define TRACE_INCLUDE_PATH instrumentation/events/lttng-module
89406ecd
MD
25#define TRACE_INCLUDE_FILE lttng-test
26#define LTTNG_INSTRUMENTATION
156a3977 27#include <instrumentation/events/lttng-module/lttng-test.h>
89406ecd 28
c6b31b34
MJ
29LTTNG_DEFINE_TRACE(lttng_test_filter_event,
30 PARAMS(int anint, int netint, long *values,
31 char *text, size_t textlen,
32 char *etext, uint32_t * net_values),
33 PARAMS(anint, netint, values, text, textlen, etext, net_values)
34);
89406ecd
MD
35
36#define LTTNG_TEST_FILTER_EVENT_FILE "lttng-test-filter-event"
37
38#define LTTNG_WRITE_COUNT_MAX 64
39
40static struct proc_dir_entry *lttng_test_filter_event_dentry;
41
42static
43void trace_test_event(unsigned int nr_iter)
44{
45 int i, netint;
46 long values[] = { 1, 2, 3 };
3834b99f 47 uint32_t net_values[] = { 1, 2, 3 };
89406ecd
MD
48 char text[10] = "test";
49 char escape[10] = "\\*";
50
3834b99f
MD
51 for (i = 0; i < 3; i++) {
52 net_values[i] = htonl(net_values[i]);
53 }
89406ecd
MD
54 for (i = 0; i < nr_iter; i++) {
55 netint = htonl(i);
3834b99f 56 trace_lttng_test_filter_event(i, netint, values, text, strlen(text), escape, net_values);
89406ecd
MD
57 }
58}
59
60/**
61 * lttng_filter_event_write - trigger a lttng_test_filter_event
62 * @file: file pointer
63 * @user_buf: user string
64 * @count: length to copy
65 *
66 * Return -1 on error, with EFAULT errno. Returns count on success.
67 */
68static
69ssize_t lttng_test_filter_event_write(struct file *file, const char __user *user_buf,
70 size_t count, loff_t *ppos)
71{
72 unsigned int nr_iter;
73 ssize_t written;
74 int ret;
75
76 /* Get the number of iterations */
5a18f28d 77 ret = lttng_kstrtouint_from_user(user_buf, count, 10, &nr_iter);
89406ecd
MD
78 if (ret) {
79 written = ret;
80 goto end;
81 }
82 /* Trace the event */
83 trace_test_event(nr_iter);
84 written = count;
85 *ppos += written;
86end:
87 return written;
88}
89
858dfdca
MJ
90#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0))
91static const struct proc_ops lttng_test_filter_event_proc_ops = {
92 .proc_write = lttng_test_filter_event_write,
93};
94#else
95static const struct file_operations lttng_test_filter_event_proc_ops = {
89406ecd
MD
96 .write = lttng_test_filter_event_write,
97};
858dfdca 98#endif
89406ecd
MD
99
100static
101int __init lttng_test_init(void)
102{
103 int ret = 0;
104
105 (void) wrapper_lttng_fixup_sig(THIS_MODULE);
da0fcb14 106 wrapper_vmalloc_sync_mappings();
89406ecd
MD
107 lttng_test_filter_event_dentry =
108 proc_create_data(LTTNG_TEST_FILTER_EVENT_FILE,
109 S_IRUGO | S_IWUGO, NULL,
858dfdca 110 &lttng_test_filter_event_proc_ops, NULL);
89406ecd
MD
111 if (!lttng_test_filter_event_dentry) {
112 printk(KERN_ERR "Error creating LTTng test filter file\n");
113 ret = -ENOMEM;
114 goto error;
115 }
116 ret = __lttng_events_init__lttng_test();
117 if (ret)
118 goto error_events;
119 return ret;
120
121error_events:
122 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL);
123error:
124 return ret;
125}
126
127module_init(lttng_test_init);
128
129static
130void __exit lttng_test_exit(void)
131{
132 __lttng_events_exit__lttng_test();
133 if (lttng_test_filter_event_dentry)
134 remove_proc_entry(LTTNG_TEST_FILTER_EVENT_FILE, NULL);
135}
136
137module_exit(lttng_test_exit);
138
139MODULE_LICENSE("GPL and additional rights");
140MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
141MODULE_DESCRIPTION("LTTng Test");
142MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
143 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
144 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
145 LTTNG_MODULES_EXTRAVERSION);
This page took 0.038354 seconds and 4 git commands to generate.