Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tracing: Add trace_array_puts() to write into instance

Add a generic trace_array_puts() that can be used to "trace_puts()" into
an allocated trace_array instance. This is just another variant of
trace_array_printk().

Link: https://lkml.kernel.org/r/20230207173026.584717290@goodmis.org

Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Ross Zwisler <zwisler@google.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

+29 -10
+12
include/linux/trace.h
··· 33 33 int register_ftrace_export(struct trace_export *export); 34 34 int unregister_ftrace_export(struct trace_export *export); 35 35 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 + 36 48 void trace_printk_init_buffers(void); 37 49 __printf(3, 4) 38 50 int trace_array_printk(struct trace_array *tr, unsigned long ip,
+17 -10
kernel/trace/trace.c
··· 1023 1023 ring_buffer_unlock_commit(buffer); 1024 1024 } 1025 1025 1026 - /** 1027 - * __trace_puts - write a constant string into the trace buffer. 1028 - * @ip: The address of the caller 1029 - * @str: The constant string to write 1030 - * @size: The size of the string. 1031 - */ 1032 - int __trace_puts(unsigned long ip, const char *str, int size) 1026 + int __trace_array_puts(struct trace_array *tr, unsigned long ip, 1027 + const char *str, int size) 1033 1028 { 1034 1029 struct ring_buffer_event *event; 1035 1030 struct trace_buffer *buffer; ··· 1032 1037 unsigned int trace_ctx; 1033 1038 int alloc; 1034 1039 1035 - if (!(global_trace.trace_flags & TRACE_ITER_PRINTK)) 1040 + if (!(tr->trace_flags & TRACE_ITER_PRINTK)) 1036 1041 return 0; 1037 1042 1038 1043 if (unlikely(tracing_selftest_running || tracing_disabled)) ··· 1041 1046 alloc = sizeof(*entry) + size + 2; /* possible \n added */ 1042 1047 1043 1048 trace_ctx = tracing_gen_ctx(); 1044 - buffer = global_trace.array_buffer.buffer; 1049 + buffer = tr->array_buffer.buffer; 1045 1050 ring_buffer_nest_start(buffer); 1046 1051 event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc, 1047 1052 trace_ctx); ··· 1063 1068 entry->buf[size] = '\0'; 1064 1069 1065 1070 __buffer_unlock_commit(buffer, event); 1066 - ftrace_trace_stack(&global_trace, buffer, trace_ctx, 4, NULL); 1071 + ftrace_trace_stack(tr, buffer, trace_ctx, 4, NULL); 1067 1072 out: 1068 1073 ring_buffer_nest_end(buffer); 1069 1074 return size; 1075 + } 1076 + EXPORT_SYMBOL_GPL(__trace_array_puts); 1077 + 1078 + /** 1079 + * __trace_puts - write a constant string into the trace buffer. 1080 + * @ip: The address of the caller 1081 + * @str: The constant string to write 1082 + * @size: The size of the string. 1083 + */ 1084 + int __trace_puts(unsigned long ip, const char *str, int size) 1085 + { 1086 + return __trace_array_puts(&global_trace, ip, str, size); 1070 1087 } 1071 1088 EXPORT_SYMBOL_GPL(__trace_puts); 1072 1089