Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Chunyan Zhang | 478409d | 2016-11-21 15:57:18 +0800 | [diff] [blame] | 2 | #ifndef _LINUX_TRACE_H |
| 3 | #define _LINUX_TRACE_H |
| 4 | |
Tingwei Zhang | 8438f52 | 2020-10-05 10:13:13 +0300 | [diff] [blame] | 5 | #define TRACE_EXPORT_FUNCTION BIT(0) |
Tingwei Zhang | 8ab7a2b | 2020-10-05 10:13:14 +0300 | [diff] [blame] | 6 | #define TRACE_EXPORT_EVENT BIT(1) |
Tingwei Zhang | 458999c | 2020-10-05 10:13:15 +0300 | [diff] [blame] | 7 | #define TRACE_EXPORT_MARKER BIT(2) |
Tingwei Zhang | 8438f52 | 2020-10-05 10:13:13 +0300 | [diff] [blame] | 8 | |
Chunyan Zhang | 478409d | 2016-11-21 15:57:18 +0800 | [diff] [blame] | 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 |
Tingwei Zhang | 8438f52 | 2020-10-05 10:13:13 +0300 | [diff] [blame] | 21 | * flags - which ftrace to be exported |
Chunyan Zhang | 478409d | 2016-11-21 15:57:18 +0800 | [diff] [blame] | 22 | */ |
| 23 | struct trace_export { |
| 24 | struct trace_export __rcu *next; |
Felipe Balbi | a773d41 | 2017-06-02 13:20:25 +0300 | [diff] [blame] | 25 | void (*write)(struct trace_export *, const void *, unsigned int); |
Tingwei Zhang | 8438f52 | 2020-10-05 10:13:13 +0300 | [diff] [blame] | 26 | int flags; |
Chunyan Zhang | 478409d | 2016-11-21 15:57:18 +0800 | [diff] [blame] | 27 | }; |
| 28 | |
Aashish Sharma | bedf0683 | 2022-11-07 21:35:56 +0530 | [diff] [blame] | 29 | struct trace_array; |
| 30 | |
Arun Easi | 1a77dd1 | 2022-09-07 16:33:08 -0700 | [diff] [blame] | 31 | #ifdef CONFIG_TRACING |
| 32 | |
Chunyan Zhang | 478409d | 2016-11-21 15:57:18 +0800 | [diff] [blame] | 33 | int register_ftrace_export(struct trace_export *export); |
| 34 | int unregister_ftrace_export(struct trace_export *export); |
| 35 | |
Steven Rostedt (Google) | d503b8f | 2023-02-07 12:28:52 -0500 | [diff] [blame] | 36 | /** |
| 37 | * trace_array_puts - write a constant string into the trace buffer. |
| 38 | * @tr: The trace array to write to |
| 39 | * @str: The constant string to write |
| 40 | */ |
| 41 | #define trace_array_puts(tr, str) \ |
| 42 | ({ \ |
| 43 | str ? __trace_array_puts(tr, _THIS_IP_, str, strlen(str)) : -1; \ |
| 44 | }) |
| 45 | int __trace_array_puts(struct trace_array *tr, unsigned long ip, |
| 46 | const char *str, int size); |
| 47 | |
Divya Indi | 2d6425a | 2019-08-14 10:55:23 -0700 | [diff] [blame] | 48 | void trace_printk_init_buffers(void); |
Tom Rix | bd0c970 | 2020-12-21 08:27:15 -0800 | [diff] [blame] | 49 | __printf(3, 4) |
Divya Indi | 2d6425a | 2019-08-14 10:55:23 -0700 | [diff] [blame] | 50 | int trace_array_printk(struct trace_array *tr, unsigned long ip, |
Tom Rix | bd0c970 | 2020-12-21 08:27:15 -0800 | [diff] [blame] | 51 | const char *fmt, ...); |
Steven Rostedt (VMware) | 38ce2a9 | 2020-08-06 12:46:49 -0400 | [diff] [blame] | 52 | int trace_array_init_printk(struct trace_array *tr); |
Divya Indi | 2887978 | 2019-11-20 11:08:38 -0800 | [diff] [blame] | 53 | void trace_array_put(struct trace_array *tr); |
Steven Rostedt (Google) | f568fbe | 2023-12-13 09:37:01 -0500 | [diff] [blame] | 54 | struct trace_array *trace_array_get_by_name(const char *name, const char *systems); |
Divya Indi | 2d6425a | 2019-08-14 10:55:23 -0700 | [diff] [blame] | 55 | int trace_array_destroy(struct trace_array *tr); |
Daniel Bristot de Oliveira | bce29ac | 2021-06-22 16:42:27 +0200 | [diff] [blame] | 56 | |
| 57 | /* For osnoise tracer */ |
| 58 | int osnoise_arch_register(void); |
| 59 | void osnoise_arch_unregister(void); |
Daniel Bristot de Oliveira | f7d9f63 | 2021-06-28 11:45:47 +0200 | [diff] [blame] | 60 | void osnoise_trace_irq_entry(int id); |
| 61 | void osnoise_trace_irq_exit(int id, const char *desc); |
Daniel Bristot de Oliveira | bce29ac | 2021-06-22 16:42:27 +0200 | [diff] [blame] | 62 | |
Arun Easi | 1a77dd1 | 2022-09-07 16:33:08 -0700 | [diff] [blame] | 63 | #else /* CONFIG_TRACING */ |
| 64 | static inline int register_ftrace_export(struct trace_export *export) |
| 65 | { |
| 66 | return -EINVAL; |
| 67 | } |
| 68 | static inline int unregister_ftrace_export(struct trace_export *export) |
| 69 | { |
| 70 | return 0; |
| 71 | } |
| 72 | static inline void trace_printk_init_buffers(void) |
| 73 | { |
| 74 | } |
Andy Shevchenko | c1ab9f0 | 2025-03-21 16:40:49 +0200 | [diff] [blame] | 75 | static inline __printf(3, 4) |
| 76 | int trace_array_printk(struct trace_array *tr, unsigned long ip, const char *fmt, ...) |
Arun Easi | 1a77dd1 | 2022-09-07 16:33:08 -0700 | [diff] [blame] | 77 | { |
| 78 | return 0; |
| 79 | } |
| 80 | static inline int trace_array_init_printk(struct trace_array *tr) |
| 81 | { |
| 82 | return -EINVAL; |
| 83 | } |
| 84 | static inline void trace_array_put(struct trace_array *tr) |
| 85 | { |
| 86 | } |
Steven Rostedt (Google) | f568fbe | 2023-12-13 09:37:01 -0500 | [diff] [blame] | 87 | static inline struct trace_array *trace_array_get_by_name(const char *name, const char *systems) |
Arun Easi | 1a77dd1 | 2022-09-07 16:33:08 -0700 | [diff] [blame] | 88 | { |
| 89 | return NULL; |
| 90 | } |
| 91 | static inline int trace_array_destroy(struct trace_array *tr) |
| 92 | { |
| 93 | return 0; |
| 94 | } |
Chunyan Zhang | 478409d | 2016-11-21 15:57:18 +0800 | [diff] [blame] | 95 | #endif /* CONFIG_TRACING */ |
| 96 | |
| 97 | #endif /* _LINUX_TRACE_H */ |