On Wed, 13 Mar 2024 13:45:50 -0400 Steven Rostedt <rost...@goodmis.org> wrote:
> Let me test to make sure that when src is a string "like this" that it does > the strcmp(). Otherwise, we may have to always do the strcmp(), which I > really would like to avoid. I added the below patch and enabled sched_switch and it triggered the warning (expected if it went the strcmp() path). I then changed it to be: #define __assign_str(dst, src) \ do { \ char *__str__ = __get_str(dst); \ int __len__ = __get_dynamic_array_len(dst) - 1; \ WARN_ON_ONCE(__builtin_constant_p(src) ? \ strcmp((src), __data_offsets.dst##_ptr_) : \ - (src) != __data_offsets.dst##_ptr_); \ + (src) == __data_offsets.dst##_ptr_); \ memcpy(__str__, __data_offsets.dst##_ptr_ ? : \ EVENT_NULL_STR, __len__); \ __str__[__len__] = '\0'; \ } while (0) And the sched_switch did not trigger (expected). So it seems that it should not be a problem. Note, I only tested this with gcc and not clang. But I guess there's also the case where we have: __assign_str(str, field ? field : "NULL") But hopefully that's not an issue. -- Steve diff --git a/include/trace/events/sched.h b/include/trace/events/sched.h index dbb01b4b7451..eaacd0c4e899 100644 --- a/include/trace/events/sched.h +++ b/include/trace/events/sched.h @@ -236,6 +236,7 @@ TRACE_EVENT(sched_switch, __array( char, next_comm, TASK_COMM_LEN ) __field( pid_t, next_pid ) __field( int, next_prio ) + __string( test, "this") ), TP_fast_assign( @@ -246,6 +247,7 @@ TRACE_EVENT(sched_switch, memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN); __entry->next_pid = next->pid; __entry->next_prio = next->prio; + __assign_str(test, "this"); /* XXX SCHED_DEADLINE */ ), diff --git a/include/trace/stages/stage6_event_callback.h b/include/trace/stages/stage6_event_callback.h index 83da83a0c14f..cf301c723fd0 100644 --- a/include/trace/stages/stage6_event_callback.h +++ b/include/trace/stages/stage6_event_callback.h @@ -36,7 +36,7 @@ char *__str__ = __get_str(dst); \ int __len__ = __get_dynamic_array_len(dst) - 1; \ WARN_ON_ONCE(__builtin_constant_p(src) ? \ - strcmp((src), __data_offsets.dst##_ptr_) : \ + !strcmp((src), __data_offsets.dst##_ptr_) : \ (src) != __data_offsets.dst##_ptr_); \ memcpy(__str__, __data_offsets.dst##_ptr_ ? : \ EVENT_NULL_STR, __len__); \