Skip to content

Commit 3e7e09d

Browse files
author
Ingo Molnar
committed
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core
Pull perf/core updates from Arnaldo Carvalho de Melo: Changes in user visible interfaces: * Rename 'record's --no-delay option to --no-buffering, better reflecting its purpose and freeing up '--delay' to take the place of '--initial-delay', so that 'record' and 'stat' are consistent. Refactorings: * Get rid of die() and friends (good riddance!) in libtraceevent (Namhyung Kim) Infrastructure enhancements: * Fix cross build problems related to pkgconfig and CROSS_COMPILE not being propagated to the feature tests, leading to features being tested in the host and then being enabled on the target. (Mark Rutland) * Fix pointer-integer size mismatch in some libtraceevent plugins (Mark Rutland) * Fix build error due to zfree() cast (Namhyung Kim) Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
2 parents 860fc2f + 0e9e79a commit 3e7e09d

28 files changed

+147
-147
lines changed

tools/lib/traceevent/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export Q VERBOSE
136136

137137
EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
138138

139-
INCLUDES = -I. $(CONFIG_INCLUDES)
139+
INCLUDES = -I. -I $(srctree)/../../include $(CONFIG_INCLUDES)
140140

141141
# Set compile option CFLAGS if not set elsewhere
142142
CFLAGS ?= -g -Wall

tools/lib/traceevent/event-parse.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ struct pevent_record {
5858
#endif
5959
};
6060

61+
enum trace_seq_fail {
62+
TRACE_SEQ__GOOD,
63+
TRACE_SEQ__BUFFER_POISONED,
64+
TRACE_SEQ__MEM_ALLOC_FAILED,
65+
};
66+
6167
/*
6268
* Trace sequences are used to allow a function to call several other functions
6369
* to create a string of data to use (up to a max of PAGE_SIZE).
@@ -68,6 +74,7 @@ struct trace_seq {
6874
unsigned int buffer_size;
6975
unsigned int len;
7076
unsigned int readpos;
77+
enum trace_seq_fail state;
7178
};
7279

7380
void trace_seq_init(struct trace_seq *s);
@@ -98,7 +105,7 @@ typedef int (*pevent_event_handler_func)(struct trace_seq *s,
98105
void *context);
99106

100107
typedef int (*pevent_plugin_load_func)(struct pevent *pevent);
101-
typedef int (*pevent_plugin_unload_func)(void);
108+
typedef int (*pevent_plugin_unload_func)(struct pevent *pevent);
102109

103110
struct plugin_option {
104111
struct plugin_option *next;
@@ -123,7 +130,7 @@ struct plugin_option {
123130
* PEVENT_PLUGIN_UNLOADER: (optional)
124131
* The function called just before unloading
125132
*
126-
* int PEVENT_PLUGIN_UNLOADER(void)
133+
* int PEVENT_PLUGIN_UNLOADER(struct pevent *pevent)
127134
*
128135
* PEVENT_PLUGIN_OPTIONS: (optional)
129136
* Plugin options that can be set before loading
@@ -404,7 +411,8 @@ enum pevent_errno {
404411
struct plugin_list;
405412

406413
struct plugin_list *traceevent_load_plugins(struct pevent *pevent);
407-
void traceevent_unload_plugins(struct plugin_list *plugin_list);
414+
void traceevent_unload_plugins(struct plugin_list *plugin_list,
415+
struct pevent *pevent);
408416

409417
struct cmdline;
410418
struct cmdline_list;

tools/lib/traceevent/event-plugin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ traceevent_load_plugins(struct pevent *pevent)
197197
}
198198

199199
void
200-
traceevent_unload_plugins(struct plugin_list *plugin_list)
200+
traceevent_unload_plugins(struct plugin_list *plugin_list, struct pevent *pevent)
201201
{
202202
pevent_plugin_unload_func func;
203203
struct plugin_list *list;
@@ -207,7 +207,7 @@ traceevent_unload_plugins(struct plugin_list *plugin_list)
207207
plugin_list = list->next;
208208
func = dlsym(list->handle, PEVENT_PLUGIN_UNLOADER_NAME);
209209
if (func)
210-
func();
210+
func(pevent);
211211
dlclose(list->handle);
212212
free(list->name);
213213
free(list);

tools/lib/traceevent/event-utils.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,14 @@
2323
#include <ctype.h>
2424

2525
/* Can be overridden */
26-
void die(const char *fmt, ...);
27-
void *malloc_or_die(unsigned int size);
2826
void warning(const char *fmt, ...);
2927
void pr_stat(const char *fmt, ...);
3028
void vpr_stat(const char *fmt, va_list ap);
3129

3230
/* Always available */
33-
void __die(const char *fmt, ...);
3431
void __warning(const char *fmt, ...);
3532
void __pr_stat(const char *fmt, ...);
3633

37-
void __vdie(const char *fmt, ...);
3834
void __vwarning(const char *fmt, ...);
3935
void __vpr_stat(const char *fmt, ...);
4036

tools/lib/traceevent/parse-utils.c

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,6 @@
2525

2626
#define __weak __attribute__((weak))
2727

28-
void __vdie(const char *fmt, va_list ap)
29-
{
30-
int ret = errno;
31-
32-
if (errno)
33-
perror("trace-cmd");
34-
else
35-
ret = -1;
36-
37-
fprintf(stderr, " ");
38-
vfprintf(stderr, fmt, ap);
39-
40-
fprintf(stderr, "\n");
41-
exit(ret);
42-
}
43-
44-
void __die(const char *fmt, ...)
45-
{
46-
va_list ap;
47-
48-
va_start(ap, fmt);
49-
__vdie(fmt, ap);
50-
va_end(ap);
51-
}
52-
53-
void __weak die(const char *fmt, ...)
54-
{
55-
va_list ap;
56-
57-
va_start(ap, fmt);
58-
__vdie(fmt, ap);
59-
va_end(ap);
60-
}
61-
6228
void __vwarning(const char *fmt, va_list ap)
6329
{
6430
if (errno)
@@ -117,13 +83,3 @@ void __weak pr_stat(const char *fmt, ...)
11783
__vpr_stat(fmt, ap);
11884
va_end(ap);
11985
}
120-
121-
void __weak *malloc_or_die(unsigned int size)
122-
{
123-
void *data;
124-
125-
data = malloc(size);
126-
if (!data)
127-
die("malloc");
128-
return data;
129-
}

tools/lib/traceevent/plugin_cfg80211.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ static unsigned long long
88
process___le16_to_cpup(struct trace_seq *s,
99
unsigned long long *args)
1010
{
11-
uint16_t *val = (uint16_t *) args[0];
11+
uint16_t *val = (uint16_t *) (unsigned long) args[0];
1212
return val ? (long long) le16toh(*val) : 0;
1313
}
1414

tools/lib/traceevent/plugin_function.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ int PEVENT_PLUGIN_LOADER(struct pevent *pevent)
144144
return 0;
145145
}
146146

147-
void PEVENT_PLUGIN_UNLOADER(void)
147+
void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent)
148148
{
149149
int i, x;
150150

tools/lib/traceevent/plugin_scsi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
405405
unsigned long long process_scsi_trace_parse_cdb(struct trace_seq *s,
406406
unsigned long long *args)
407407
{
408-
scsi_trace_parse_cdb(s, (unsigned char *) args[1], args[2]);
408+
scsi_trace_parse_cdb(s, (unsigned char *) (unsigned long) args[1], args[2]);
409409
return 0;
410410
}
411411

tools/lib/traceevent/trace-seq.c

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <string.h>
2323
#include <stdarg.h>
2424

25+
#include <asm/bug.h>
2526
#include "event-parse.h"
2627
#include "event-utils.h"
2728

@@ -32,10 +33,21 @@
3233
#define TRACE_SEQ_POISON ((void *)0xdeadbeef)
3334
#define TRACE_SEQ_CHECK(s) \
3435
do { \
35-
if ((s)->buffer == TRACE_SEQ_POISON) \
36-
die("Usage of trace_seq after it was destroyed"); \
36+
if (WARN_ONCE((s)->buffer == TRACE_SEQ_POISON, \
37+
"Usage of trace_seq after it was destroyed")) \
38+
(s)->state = TRACE_SEQ__BUFFER_POISONED; \
3739
} while (0)
3840

41+
#define TRACE_SEQ_CHECK_RET_N(s, n) \
42+
do { \
43+
TRACE_SEQ_CHECK(s); \
44+
if ((s)->state != TRACE_SEQ__GOOD) \
45+
return n; \
46+
} while (0)
47+
48+
#define TRACE_SEQ_CHECK_RET(s) TRACE_SEQ_CHECK_RET_N(s, )
49+
#define TRACE_SEQ_CHECK_RET0(s) TRACE_SEQ_CHECK_RET_N(s, 0)
50+
3951
/**
4052
* trace_seq_init - initialize the trace_seq structure
4153
* @s: a pointer to the trace_seq structure to initialize
@@ -45,7 +57,11 @@ void trace_seq_init(struct trace_seq *s)
4557
s->len = 0;
4658
s->readpos = 0;
4759
s->buffer_size = TRACE_SEQ_BUF_SIZE;
48-
s->buffer = malloc_or_die(s->buffer_size);
60+
s->buffer = malloc(s->buffer_size);
61+
if (s->buffer != NULL)
62+
s->state = TRACE_SEQ__GOOD;
63+
else
64+
s->state = TRACE_SEQ__MEM_ALLOC_FAILED;
4965
}
5066

5167
/**
@@ -71,17 +87,23 @@ void trace_seq_destroy(struct trace_seq *s)
7187
{
7288
if (!s)
7389
return;
74-
TRACE_SEQ_CHECK(s);
90+
TRACE_SEQ_CHECK_RET(s);
7591
free(s->buffer);
7692
s->buffer = TRACE_SEQ_POISON;
7793
}
7894

7995
static void expand_buffer(struct trace_seq *s)
8096
{
97+
char *buf;
98+
99+
buf = realloc(s->buffer, s->buffer_size + TRACE_SEQ_BUF_SIZE);
100+
if (WARN_ONCE(!buf, "Can't allocate trace_seq buffer memory")) {
101+
s->state = TRACE_SEQ__MEM_ALLOC_FAILED;
102+
return;
103+
}
104+
105+
s->buffer = buf;
81106
s->buffer_size += TRACE_SEQ_BUF_SIZE;
82-
s->buffer = realloc(s->buffer, s->buffer_size);
83-
if (!s->buffer)
84-
die("Can't allocate trace_seq buffer memory");
85107
}
86108

87109
/**
@@ -105,9 +127,9 @@ trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
105127
int len;
106128
int ret;
107129

108-
TRACE_SEQ_CHECK(s);
109-
110130
try_again:
131+
TRACE_SEQ_CHECK_RET0(s);
132+
111133
len = (s->buffer_size - 1) - s->len;
112134

113135
va_start(ap, fmt);
@@ -141,9 +163,9 @@ trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
141163
int len;
142164
int ret;
143165

144-
TRACE_SEQ_CHECK(s);
145-
146166
try_again:
167+
TRACE_SEQ_CHECK_RET0(s);
168+
147169
len = (s->buffer_size - 1) - s->len;
148170

149171
ret = vsnprintf(s->buffer + s->len, len, fmt, args);
@@ -172,13 +194,15 @@ int trace_seq_puts(struct trace_seq *s, const char *str)
172194
{
173195
int len;
174196

175-
TRACE_SEQ_CHECK(s);
197+
TRACE_SEQ_CHECK_RET0(s);
176198

177199
len = strlen(str);
178200

179201
while (len > ((s->buffer_size - 1) - s->len))
180202
expand_buffer(s);
181203

204+
TRACE_SEQ_CHECK_RET0(s);
205+
182206
memcpy(s->buffer + s->len, str, len);
183207
s->len += len;
184208

@@ -187,19 +211,21 @@ int trace_seq_puts(struct trace_seq *s, const char *str)
187211

188212
int trace_seq_putc(struct trace_seq *s, unsigned char c)
189213
{
190-
TRACE_SEQ_CHECK(s);
214+
TRACE_SEQ_CHECK_RET0(s);
191215

192216
while (s->len >= (s->buffer_size - 1))
193217
expand_buffer(s);
194218

219+
TRACE_SEQ_CHECK_RET0(s);
220+
195221
s->buffer[s->len++] = c;
196222

197223
return 1;
198224
}
199225

200226
void trace_seq_terminate(struct trace_seq *s)
201227
{
202-
TRACE_SEQ_CHECK(s);
228+
TRACE_SEQ_CHECK_RET(s);
203229

204230
/* There's always one character left on the buffer */
205231
s->buffer[s->len] = 0;
@@ -208,5 +234,16 @@ void trace_seq_terminate(struct trace_seq *s)
208234
int trace_seq_do_printf(struct trace_seq *s)
209235
{
210236
TRACE_SEQ_CHECK(s);
211-
return printf("%.*s", s->len, s->buffer);
237+
238+
switch (s->state) {
239+
case TRACE_SEQ__GOOD:
240+
return printf("%.*s", s->len, s->buffer);
241+
case TRACE_SEQ__BUFFER_POISONED:
242+
puts("Usage of trace_seq after it was destroyed");
243+
break;
244+
case TRACE_SEQ__MEM_ALLOC_FAILED:
245+
puts("Can't allocate trace_seq buffer memory");
246+
break;
247+
}
248+
return -1;
212249
}

tools/perf/Documentation/perf-record.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ OPTIONS
6868
--realtime=::
6969
Collect data with this RT SCHED_FIFO priority.
7070

71-
-D::
72-
--no-delay::
71+
--no-buffering::
7372
Collect data without buffering.
7473

7574
-c::
@@ -209,7 +208,8 @@ overrides that and uses per-thread mmaps. A side-effect of that is that
209208
inheritance is automatically disabled. --per-thread is ignored with a warning
210209
if combined with -a or -C options.
211210

212-
--initial-delay msecs::
211+
-D::
212+
--delay=::
213213
After starting the program, wait msecs before measuring. This is useful to
214214
filter out the startup phase of the program, which is often very different.
215215

tools/perf/Makefile.perf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ $(OUTPUT)PERF-VERSION-FILE: ../../.git/HEAD
7676

7777
CC = $(CROSS_COMPILE)gcc
7878
AR = $(CROSS_COMPILE)ar
79+
PKG_CONFIG = $(CROSS_COMPILE)pkg-config
7980

8081
RM = rm -f
8182
LN = ln -f

tools/perf/builtin-record.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ const struct option record_options[] = {
838838
"record events on existing thread id"),
839839
OPT_INTEGER('r', "realtime", &record.realtime_prio,
840840
"collect data with this RT SCHED_FIFO priority"),
841-
OPT_BOOLEAN('D', "no-delay", &record.opts.no_delay,
841+
OPT_BOOLEAN(0, "no-buffering", &record.opts.no_buffering,
842842
"collect data without buffering"),
843843
OPT_BOOLEAN('R', "raw-samples", &record.opts.raw_samples,
844844
"collect raw sample records from all opened counters"),
@@ -882,7 +882,7 @@ const struct option record_options[] = {
882882
OPT_CALLBACK('G', "cgroup", &record.evlist, "name",
883883
"monitor event in cgroup name only",
884884
parse_cgroups),
885-
OPT_UINTEGER(0, "initial-delay", &record.opts.initial_delay,
885+
OPT_UINTEGER('D', "delay", &record.opts.initial_delay,
886886
"ms to wait before starting measurement after program start"),
887887
OPT_STRING('u', "uid", &record.opts.target.uid_str, "user",
888888
"user to profile"),

0 commit comments

Comments
 (0)