Skip to content

Commit 8729134

Browse files
vnagarnaikrostedt
authored andcommitted
tracing: Fix array size mismatch in format string
In event format strings, the array size is reported in two locations. One in array subscript and then via the "size:" attribute. The values reported there have a mismatch. For e.g., in sched:sched_switch the prev_comm and next_comm character arrays have subscript values as [32] where as the actual field size is 16. name: sched_switch ID: 301 format: field:unsigned short common_type; offset:0; size:2; signed:0; field:unsigned char common_flags; offset:2; size:1; signed:0; field:unsigned char common_preempt_count; offset:3; size:1;signed:0; field:int common_pid; offset:4; size:4; signed:1; field:char prev_comm[32]; offset:8; size:16; signed:1; field:pid_t prev_pid; offset:24; size:4; signed:1; field:int prev_prio; offset:28; size:4; signed:1; field:long prev_state; offset:32; size:8; signed:1; field:char next_comm[32]; offset:40; size:16; signed:1; field:pid_t next_pid; offset:56; size:4; signed:1; field:int next_prio; offset:60; size:4; signed:1; After bisection, the following commit was blamed: 92edca0 tracing: Use direct field, type and system names This commit removes the duplication of strings for field->name and field->type assuming that all the strings passed in __trace_define_field() are immutable. This is not true for arrays, where the type string is created in event_storage variable and field->type for all array fields points to event_storage. Use __stringify() to create a string constant for the type string. Also, get rid of event_storage and event_storage_mutex that are not needed anymore. also, an added benefit is that this reduces the overhead of events a bit more: text data bss dec hex filename 8424787 2036472 1302528 11763787 b3804b vmlinux 8420814 2036408 1302528 11759750 b37086 vmlinux.patched Link: http://lkml.kernel.org/r/1392349908-29685-1-git-send-email-vnagarnaik@google.com Cc: Laurent Chavey <chavey@google.com> Cc: stable@vger.kernel.org # 3.10+ Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@google.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent dcb99fd commit 8729134

File tree

4 files changed

+4
-20
lines changed

4 files changed

+4
-20
lines changed

include/linux/ftrace_event.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,6 @@ enum {
495495
FILTER_TRACE_FN,
496496
};
497497

498-
#define EVENT_STORAGE_SIZE 128
499-
extern struct mutex event_storage_mutex;
500-
extern char event_storage[EVENT_STORAGE_SIZE];
501-
502498
extern int trace_event_raw_init(struct ftrace_event_call *call);
503499
extern int trace_define_field(struct ftrace_event_call *call, const char *type,
504500
const char *name, int offset, int size,

include/trace/ftrace.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,12 @@ static struct trace_event_functions ftrace_event_type_funcs_##call = { \
310310
#undef __array
311311
#define __array(type, item, len) \
312312
do { \
313-
mutex_lock(&event_storage_mutex); \
313+
char *type_str = #type"["__stringify(len)"]"; \
314314
BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
315-
snprintf(event_storage, sizeof(event_storage), \
316-
"%s[%d]", #type, len); \
317-
ret = trace_define_field(event_call, event_storage, #item, \
315+
ret = trace_define_field(event_call, type_str, #item, \
318316
offsetof(typeof(field), item), \
319317
sizeof(field.item), \
320318
is_signed_type(type), FILTER_OTHER); \
321-
mutex_unlock(&event_storage_mutex); \
322319
if (ret) \
323320
return ret; \
324321
} while (0);

kernel/trace/trace_events.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@
2727

2828
DEFINE_MUTEX(event_mutex);
2929

30-
DEFINE_MUTEX(event_storage_mutex);
31-
EXPORT_SYMBOL_GPL(event_storage_mutex);
32-
33-
char event_storage[EVENT_STORAGE_SIZE];
34-
EXPORT_SYMBOL_GPL(event_storage);
35-
3630
LIST_HEAD(ftrace_events);
3731
static LIST_HEAD(ftrace_common_fields);
3832

kernel/trace/trace_export.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,12 @@ static void __always_unused ____ftrace_check_##name(void) \
9595
#undef __array
9696
#define __array(type, item, len) \
9797
do { \
98+
char *type_str = #type"["__stringify(len)"]"; \
9899
BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
99-
mutex_lock(&event_storage_mutex); \
100-
snprintf(event_storage, sizeof(event_storage), \
101-
"%s[%d]", #type, len); \
102-
ret = trace_define_field(event_call, event_storage, #item, \
100+
ret = trace_define_field(event_call, type_str, #item, \
103101
offsetof(typeof(field), item), \
104102
sizeof(field.item), \
105103
is_signed_type(type), filter_type); \
106-
mutex_unlock(&event_storage_mutex); \
107104
if (ret) \
108105
return ret; \
109106
} while (0);

0 commit comments

Comments
 (0)