1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_TRACE_H
3 #define _LINUX_TRACE_H
4 
5 #define TRACE_EXPORT_FUNCTION	BIT(0)
6 #define TRACE_EXPORT_EVENT	BIT(1)
7 #define TRACE_EXPORT_MARKER	BIT(2)
8 
9 /*
10  * The trace export - an export of Ftrace output. The trace_export
11  * can process traces and export them to a registered destination as
12  * an addition to the current only output of Ftrace - i.e. ring buffer.
13  *
14  * If you want traces to be sent to some other place rather than ring
15  * buffer only, just need to register a new trace_export and implement
16  * its own .write() function for writing traces to the storage.
17  *
18  * next		- pointer to the next trace_export
19  * write	- copy traces which have been delt with ->commit() to
20  *		  the destination
21  * flags	- which ftrace to be exported
22  */
23 struct trace_export {
24 	struct trace_export __rcu	*next;
25 	void (*write)(struct trace_export *, const void *, unsigned int);
26 	int flags;
27 };
28 
29 struct trace_array;
30 
31 #ifdef CONFIG_TRACING
32 
33 int register_ftrace_export(struct trace_export *export);
34 int unregister_ftrace_export(struct trace_export *export);
35 
36 void trace_printk_init_buffers(void);
37 __printf(3, 4)
38 int trace_array_printk(struct trace_array *tr, unsigned long ip,
39 		       const char *fmt, ...);
40 int trace_array_init_printk(struct trace_array *tr);
41 void trace_array_put(struct trace_array *tr);
42 struct trace_array *trace_array_get_by_name(const char *name);
43 int trace_array_destroy(struct trace_array *tr);
44 
45 /* For osnoise tracer */
46 int osnoise_arch_register(void);
47 void osnoise_arch_unregister(void);
48 void osnoise_trace_irq_entry(int id);
49 void osnoise_trace_irq_exit(int id, const char *desc);
50 
51 #else /* CONFIG_TRACING */
register_ftrace_export(struct trace_export * export)52 static inline int register_ftrace_export(struct trace_export *export)
53 {
54 	return -EINVAL;
55 }
unregister_ftrace_export(struct trace_export * export)56 static inline int unregister_ftrace_export(struct trace_export *export)
57 {
58 	return 0;
59 }
trace_printk_init_buffers(void)60 static inline void trace_printk_init_buffers(void)
61 {
62 }
trace_array_printk(struct trace_array * tr,unsigned long ip,const char * fmt,...)63 static inline int trace_array_printk(struct trace_array *tr, unsigned long ip,
64 				     const char *fmt, ...)
65 {
66 	return 0;
67 }
trace_array_init_printk(struct trace_array * tr)68 static inline int trace_array_init_printk(struct trace_array *tr)
69 {
70 	return -EINVAL;
71 }
trace_array_put(struct trace_array * tr)72 static inline void trace_array_put(struct trace_array *tr)
73 {
74 }
trace_array_get_by_name(const char * name)75 static inline struct trace_array *trace_array_get_by_name(const char *name)
76 {
77 	return NULL;
78 }
trace_array_destroy(struct trace_array * tr)79 static inline int trace_array_destroy(struct trace_array *tr)
80 {
81 	return 0;
82 }
83 #endif	/* CONFIG_TRACING */
84 
85 #endif	/* _LINUX_TRACE_H */
86