Skip to content

Commit 26a5074

Browse files
zanussiIngo Molnar
authored andcommitted
tracing/events: Add 'signed' field to format files
The sign info used for filters in the kernel is also useful to applications that process the trace stream. Add it to the format files and make it available to userspace. Signed-off-by: Tom Zanussi <tzanussi@gmail.com> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: rostedt@goodmis.org Cc: lizf@cn.fujitsu.com Cc: hch@infradead.org Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> LKML-Reference: <1254809398-8078-2-git-send-email-tzanussi@gmail.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent d9b2002 commit 26a5074

7 files changed

Lines changed: 82 additions & 42 deletions

File tree

‎include/trace/ftrace.h‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,10 @@
120120
#undef __field
121121
#define __field(type, item) \
122122
ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
123-
"offset:%u;\tsize:%u;\n", \
123+
"offset:%u;\tsize:%u;\tsigned:%u;\n", \
124124
(unsigned int)offsetof(typeof(field), item), \
125-
(unsigned int)sizeof(field.item)); \
125+
(unsigned int)sizeof(field.item), \
126+
(unsigned int)is_signed_type(type)); \
126127
if (!ret) \
127128
return 0;
128129

@@ -132,19 +133,21 @@
132133
#undef __array
133134
#define __array(type, item, len) \
134135
ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
135-
"offset:%u;\tsize:%u;\n", \
136+
"offset:%u;\tsize:%u;\tsigned:%u;\n", \
136137
(unsigned int)offsetof(typeof(field), item), \
137-
(unsigned int)sizeof(field.item)); \
138+
(unsigned int)sizeof(field.item), \
139+
(unsigned int)is_signed_type(type)); \
138140
if (!ret) \
139141
return 0;
140142

141143
#undef __dynamic_array
142144
#define __dynamic_array(type, item, len) \
143145
ret = trace_seq_printf(s, "\tfield:__data_loc " #type "[] " #item ";\t"\
144-
"offset:%u;\tsize:%u;\n", \
146+
"offset:%u;\tsize:%u;\tsigned:%u;\n", \
145147
(unsigned int)offsetof(typeof(field), \
146148
__data_loc_##item), \
147-
(unsigned int)sizeof(field.__data_loc_##item)); \
149+
(unsigned int)sizeof(field.__data_loc_##item), \
150+
(unsigned int)is_signed_type(type)); \
148151
if (!ret) \
149152
return 0;
150153

‎kernel/trace/ring_buffer.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,18 +397,21 @@ int ring_buffer_print_page_header(struct trace_seq *s)
397397
int ret;
398398

399399
ret = trace_seq_printf(s, "\tfield: u64 timestamp;\t"
400-
"offset:0;\tsize:%u;\n",
401-
(unsigned int)sizeof(field.time_stamp));
400+
"offset:0;\tsize:%u;\tsigned:%u;\n",
401+
(unsigned int)sizeof(field.time_stamp),
402+
(unsigned int)is_signed_type(u64));
402403

403404
ret = trace_seq_printf(s, "\tfield: local_t commit;\t"
404-
"offset:%u;\tsize:%u;\n",
405+
"offset:%u;\tsize:%u;\tsigned:%u;\n",
405406
(unsigned int)offsetof(typeof(field), commit),
406-
(unsigned int)sizeof(field.commit));
407+
(unsigned int)sizeof(field.commit),
408+
(unsigned int)is_signed_type(long));
407409

408410
ret = trace_seq_printf(s, "\tfield: char data;\t"
409-
"offset:%u;\tsize:%u;\n",
411+
"offset:%u;\tsize:%u;\tsigned:%u;\n",
410412
(unsigned int)offsetof(typeof(field), data),
411-
(unsigned int)BUF_PAGE_SIZE);
413+
(unsigned int)BUF_PAGE_SIZE,
414+
(unsigned int)is_signed_type(char));
412415

413416
return ret;
414417
}

‎kernel/trace/trace_events.c‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -507,25 +507,25 @@ extern char *__bad_type_size(void);
507507
#define FIELD(type, name) \
508508
sizeof(type) != sizeof(field.name) ? __bad_type_size() : \
509509
#type, "common_" #name, offsetof(typeof(field), name), \
510-
sizeof(field.name)
510+
sizeof(field.name), is_signed_type(type)
511511

512512
static int trace_write_header(struct trace_seq *s)
513513
{
514514
struct trace_entry field;
515515

516516
/* struct trace_entry */
517517
return trace_seq_printf(s,
518-
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
519-
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
520-
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
521-
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
522-
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
523-
"\n",
524-
FIELD(unsigned short, type),
525-
FIELD(unsigned char, flags),
526-
FIELD(unsigned char, preempt_count),
527-
FIELD(int, pid),
528-
FIELD(int, lock_depth));
518+
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\tsigned:%u;\n"
519+
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\tsigned:%u;\n"
520+
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\tsigned:%u;\n"
521+
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\tsigned:%u;\n"
522+
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\tsigned:%u;\n"
523+
"\n",
524+
FIELD(unsigned short, type),
525+
FIELD(unsigned char, flags),
526+
FIELD(unsigned char, preempt_count),
527+
FIELD(int, pid),
528+
FIELD(int, lock_depth));
529529
}
530530

531531
static ssize_t

‎kernel/trace/trace_export.c‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,44 +66,47 @@ static void __used ____ftrace_check_##name(void) \
6666
#undef __field
6767
#define __field(type, item) \
6868
ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
69-
"offset:%zu;\tsize:%zu;\n", \
69+
"offset:%zu;\tsize:%zu;\tsigned:%u;\n", \
7070
offsetof(typeof(field), item), \
71-
sizeof(field.item)); \
71+
sizeof(field.item), is_signed_type(type)); \
7272
if (!ret) \
7373
return 0;
7474

7575
#undef __field_desc
7676
#define __field_desc(type, container, item) \
7777
ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
78-
"offset:%zu;\tsize:%zu;\n", \
78+
"offset:%zu;\tsize:%zu;\tsigned:%u;\n", \
7979
offsetof(typeof(field), container.item), \
80-
sizeof(field.container.item)); \
80+
sizeof(field.container.item), \
81+
is_signed_type(type)); \
8182
if (!ret) \
8283
return 0;
8384

8485
#undef __array
8586
#define __array(type, item, len) \
8687
ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
87-
"offset:%zu;\tsize:%zu;\n", \
88-
offsetof(typeof(field), item), \
89-
sizeof(field.item)); \
88+
"offset:%zu;\tsize:%zu;\tsigned:%u;\n", \
89+
offsetof(typeof(field), item), \
90+
sizeof(field.item), is_signed_type(type)); \
9091
if (!ret) \
9192
return 0;
9293

9394
#undef __array_desc
9495
#define __array_desc(type, container, item, len) \
9596
ret = trace_seq_printf(s, "\tfield:" #type " " #item "[" #len "];\t" \
96-
"offset:%zu;\tsize:%zu;\n", \
97+
"offset:%zu;\tsize:%zu;\tsigned:%u;\n", \
9798
offsetof(typeof(field), container.item), \
98-
sizeof(field.container.item)); \
99+
sizeof(field.container.item), \
100+
is_signed_type(type)); \
99101
if (!ret) \
100102
return 0;
101103

102104
#undef __dynamic_array
103105
#define __dynamic_array(type, item) \
104106
ret = trace_seq_printf(s, "\tfield:" #type " " #item ";\t" \
105-
"offset:%zu;\tsize:0;\n", \
106-
offsetof(typeof(field), item)); \
107+
"offset:%zu;\tsize:0;\tsigned:%u;\n", \
108+
offsetof(typeof(field), item), \
109+
is_signed_type(type)); \
107110
if (!ret) \
108111
return 0;
109112

‎kernel/trace/trace_syscalls.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ extern char *__bad_type_size(void);
103103
#define SYSCALL_FIELD(type, name) \
104104
sizeof(type) != sizeof(trace.name) ? \
105105
__bad_type_size() : \
106-
#type, #name, offsetof(typeof(trace), name), sizeof(trace.name)
106+
#type, #name, offsetof(typeof(trace), name), \
107+
sizeof(trace.name), is_signed_type(type)
107108

108109
int syscall_enter_format(struct ftrace_event_call *call, struct trace_seq *s)
109110
{
@@ -120,7 +121,8 @@ int syscall_enter_format(struct ftrace_event_call *call, struct trace_seq *s)
120121
if (!entry)
121122
return 0;
122123

123-
ret = trace_seq_printf(s, "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n",
124+
ret = trace_seq_printf(s, "\tfield:%s %s;\toffset:%zu;\tsize:%zu;"
125+
"\tsigned:%u;\n",
124126
SYSCALL_FIELD(int, nr));
125127
if (!ret)
126128
return 0;
@@ -130,8 +132,10 @@ int syscall_enter_format(struct ftrace_event_call *call, struct trace_seq *s)
130132
entry->args[i]);
131133
if (!ret)
132134
return 0;
133-
ret = trace_seq_printf(s, "\toffset:%d;\tsize:%zu;\n", offset,
134-
sizeof(unsigned long));
135+
ret = trace_seq_printf(s, "\toffset:%d;\tsize:%zu;"
136+
"\tsigned:%u;\n", offset,
137+
sizeof(unsigned long),
138+
is_signed_type(unsigned long));
135139
if (!ret)
136140
return 0;
137141
offset += sizeof(unsigned long);
@@ -163,8 +167,10 @@ int syscall_exit_format(struct ftrace_event_call *call, struct trace_seq *s)
163167
struct syscall_trace_exit trace;
164168

165169
ret = trace_seq_printf(s,
166-
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n"
167-
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n",
170+
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;"
171+
"\tsigned:%u;\n"
172+
"\tfield:%s %s;\toffset:%zu;\tsize:%zu;"
173+
"\tsigned:%u;\n",
168174
SYSCALL_FIELD(int, nr),
169175
SYSCALL_FIELD(long, ret));
170176
if (!ret)
@@ -212,7 +218,7 @@ int syscall_exit_define_fields(struct ftrace_event_call *call)
212218
if (ret)
213219
return ret;
214220

215-
ret = trace_define_field(call, SYSCALL_FIELD(long, ret), 0,
221+
ret = trace_define_field(call, SYSCALL_FIELD(long, ret),
216222
FILTER_OTHER);
217223

218224
return ret;

‎tools/perf/util/trace-event-parse.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,21 @@ static int event_read_fields(struct event *event, struct format_field **fields)
894894
field->size = strtoul(token, NULL, 0);
895895
free_token(token);
896896

897+
if (read_expected(EVENT_OP, (char *)";") < 0)
898+
goto fail_expect;
899+
900+
if (read_expected(EVENT_ITEM, (char *)"signed") < 0)
901+
goto fail_expect;
902+
903+
if (read_expected(EVENT_OP, (char *)":") < 0)
904+
goto fail_expect;
905+
906+
if (read_expect_type(EVENT_ITEM, &token))
907+
goto fail;
908+
if (strtoul(token, NULL, 0))
909+
field->flags |= FIELD_IS_SIGNED;
910+
free_token(token);
911+
897912
if (read_expected(EVENT_OP, (char *)";") < 0)
898913
goto fail_expect;
899914

@@ -2843,6 +2858,15 @@ static void parse_header_field(char *type,
28432858
return;
28442859
*size = atoi(token);
28452860
free_token(token);
2861+
if (read_expected(EVENT_OP, (char *)";") < 0)
2862+
return;
2863+
if (read_expected(EVENT_ITEM, (char *)"signed") < 0)
2864+
return;
2865+
if (read_expected(EVENT_OP, (char *)":") < 0)
2866+
return;
2867+
if (read_expect_type(EVENT_ITEM, &token) < 0)
2868+
return;
2869+
free_token(token);
28462870
if (read_expected(EVENT_OP, (char *)";") < 0)
28472871
return;
28482872
if (read_expect_type(EVENT_NEWLINE, &token) < 0)

‎tools/perf/util/trace-event.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum {
2626
enum format_flags {
2727
FIELD_IS_ARRAY = 1,
2828
FIELD_IS_POINTER = 2,
29+
FIELD_IS_SIGNED = 4,
2930
};
3031

3132
struct format_field {

0 commit comments

Comments
 (0)