Skip to content

Commit 5dafd7c

Browse files
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 improvements and fixes from Arnaldo Carvalho de Melo: New user visible features: - Support multiple probes on different binaries on the same command line (Masami Hiramatsu) User visible changes: - Fix synthesizing fork_event.ppid for non-main thread (David Ahern) - Fix cross-endian analysis (David Ahern) - Fix segfault in 'perf buildid-list' when show DSOs with hits (He Kuang) Infrastructure changes: - Fix type for references to data_head/tail (David Ahern) - Fix error path to do closedir() when synthesizing threads (Arnaldo Carvalho de Melo) Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@kernel.org>
2 parents 51ab715 + 7b8283b commit 5dafd7c

11 files changed

Lines changed: 61 additions & 37 deletions

File tree

‎tools/perf/builtin-probe.c‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ static struct {
5656
bool mod_events;
5757
bool uprobes;
5858
bool quiet;
59+
bool target_used;
5960
int nevents;
6061
struct perf_probe_event events[MAX_PROBES];
6162
struct strlist *dellist;
@@ -78,6 +79,12 @@ static int parse_probe_event(const char *str)
7879
}
7980

8081
pev->uprobes = params.uprobes;
82+
if (params.target) {
83+
pev->target = strdup(params.target);
84+
if (!pev->target)
85+
return -ENOMEM;
86+
params.target_used = true;
87+
}
8188

8289
/* Parse a perf-probe command into event */
8390
ret = parse_perf_probe_command(str, pev);
@@ -102,6 +109,7 @@ static int set_target(const char *ptr)
102109
params.target = strdup(ptr);
103110
if (!params.target)
104111
return -ENOMEM;
112+
params.target_used = false;
105113

106114
found = 1;
107115
buf = ptr + (strlen(ptr) - 3);
@@ -178,7 +186,7 @@ static int opt_set_target(const struct option *opt, const char *str,
178186
int ret = -ENOENT;
179187
char *tmp;
180188

181-
if (str && !params.target) {
189+
if (str) {
182190
if (!strcmp(opt->long_name, "exec"))
183191
params.uprobes = true;
184192
#ifdef HAVE_DWARF_SUPPORT
@@ -200,7 +208,9 @@ static int opt_set_target(const struct option *opt, const char *str,
200208
if (!tmp)
201209
return -ENOMEM;
202210
}
211+
free(params.target);
203212
params.target = tmp;
213+
params.target_used = false;
204214
ret = 0;
205215
}
206216

@@ -485,9 +495,14 @@ __cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
485495
}
486496

487497
if (params.nevents) {
498+
/* Ensure the last given target is used */
499+
if (params.target && !params.target_used) {
500+
pr_warning(" Error: -x/-m must follow the probe definitions.\n");
501+
usage_with_options(probe_usage, options);
502+
}
503+
488504
ret = add_perf_probe_events(params.events, params.nevents,
489505
params.max_probe_points,
490-
params.target,
491506
params.force_add);
492507
if (ret < 0) {
493508
pr_err_with_code(" Error: Failed to add events.", ret);

‎tools/perf/builtin-record.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ static int process_synthesized_event(struct perf_tool *tool,
7070
static int record__mmap_read(struct record *rec, int idx)
7171
{
7272
struct perf_mmap *md = &rec->evlist->mmap[idx];
73-
unsigned int head = perf_mmap__read_head(md);
74-
unsigned int old = md->prev;
73+
u64 head = perf_mmap__read_head(md);
74+
u64 old = md->prev;
7575
unsigned char *data = md->base + page_size;
7676
unsigned long size;
7777
void *buf;

‎tools/perf/util/build-id.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,8 @@ static int perf_event__exit_del_thread(struct perf_tool *tool __maybe_unused,
5959
dump_printf("(%d:%d):(%d:%d)\n", event->fork.pid, event->fork.tid,
6060
event->fork.ppid, event->fork.ptid);
6161

62-
if (thread) {
63-
rb_erase(&thread->rb_node, &machine->threads);
64-
if (machine->last_match == thread)
65-
thread__zput(machine->last_match);
66-
thread__put(thread);
67-
}
62+
if (thread)
63+
machine__remove_thread(machine, thread);
6864

6965
return 0;
7066
}

‎tools/perf/util/event.c‎

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,18 @@ static int perf_event__synthesize_fork(struct perf_tool *tool,
183183
{
184184
memset(&event->fork, 0, sizeof(event->fork) + machine->id_hdr_size);
185185

186-
event->fork.ppid = ppid;
187-
event->fork.ptid = ppid;
186+
/*
187+
* for main thread set parent to ppid from status file. For other
188+
* threads set parent pid to main thread. ie., assume main thread
189+
* spawns all threads in a process
190+
*/
191+
if (tgid == pid) {
192+
event->fork.ppid = ppid;
193+
event->fork.ptid = ppid;
194+
} else {
195+
event->fork.ppid = tgid;
196+
event->fork.ptid = tgid;
197+
}
188198
event->fork.pid = tgid;
189199
event->fork.tid = pid;
190200
event->fork.header.type = PERF_RECORD_FORK;
@@ -377,6 +387,7 @@ static int __event__synthesize_thread(union perf_event *comm_event,
377387
DIR *tasks;
378388
struct dirent dirent, *next;
379389
pid_t tgid, ppid;
390+
int rc = 0;
380391

381392
/* special case: only send one comm event using passed in pid */
382393
if (!full) {
@@ -404,38 +415,38 @@ static int __event__synthesize_thread(union perf_event *comm_event,
404415

405416
while (!readdir_r(tasks, &dirent, &next) && next) {
406417
char *end;
407-
int rc = 0;
408418
pid_t _pid;
409419

410420
_pid = strtol(dirent.d_name, &end, 10);
411421
if (*end)
412422
continue;
413423

424+
rc = -1;
414425
if (perf_event__prepare_comm(comm_event, _pid, machine,
415426
&tgid, &ppid) != 0)
416-
return -1;
427+
break;
417428

418429
if (perf_event__synthesize_fork(tool, fork_event, _pid, tgid,
419430
ppid, process, machine) < 0)
420-
return -1;
431+
break;
421432
/*
422433
* Send the prepared comm event
423434
*/
424435
if (process(tool, comm_event, &synth_sample, machine) != 0)
425-
return -1;
436+
break;
426437

438+
rc = 0;
427439
if (_pid == pid) {
428440
/* process the parent's maps too */
429441
rc = perf_event__synthesize_mmap_events(tool, mmap_event, pid, tgid,
430442
process, machine, mmap_data);
443+
if (rc)
444+
break;
431445
}
432-
433-
if (rc)
434-
return rc;
435446
}
436447

437448
closedir(tasks);
438-
return 0;
449+
return rc;
439450
}
440451

441452
int perf_event__synthesize_thread_map(struct perf_tool *tool,

‎tools/perf/util/evlist.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ static struct perf_evsel *perf_evlist__event2evsel(struct perf_evlist *evlist,
634634
union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
635635
{
636636
struct perf_mmap *md = &evlist->mmap[idx];
637-
unsigned int head = perf_mmap__read_head(md);
638-
unsigned int old = md->prev;
637+
u64 head = perf_mmap__read_head(md);
638+
u64 old = md->prev;
639639
unsigned char *data = md->base + page_size;
640640
union perf_event *event = NULL;
641641

@@ -716,7 +716,7 @@ void perf_evlist__mmap_consume(struct perf_evlist *evlist, int idx)
716716
struct perf_mmap *md = &evlist->mmap[idx];
717717

718718
if (!evlist->overwrite) {
719-
unsigned int old = md->prev;
719+
u64 old = md->prev;
720720

721721
perf_mmap__write_tail(md, old);
722722
}

‎tools/perf/util/evlist.h‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct perf_mmap {
2727
void *base;
2828
int mask;
2929
int refcnt;
30-
unsigned int prev;
30+
u64 prev;
3131
char event_copy[PERF_SAMPLE_MAX_SIZE] __attribute__((aligned(8)));
3232
};
3333

@@ -189,16 +189,15 @@ size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp);
189189
int perf_evlist__strerror_open(struct perf_evlist *evlist, int err, char *buf, size_t size);
190190
int perf_evlist__strerror_mmap(struct perf_evlist *evlist, int err, char *buf, size_t size);
191191

192-
static inline unsigned int perf_mmap__read_head(struct perf_mmap *mm)
192+
static inline u64 perf_mmap__read_head(struct perf_mmap *mm)
193193
{
194194
struct perf_event_mmap_page *pc = mm->base;
195-
int head = ACCESS_ONCE(pc->data_head);
195+
u64 head = ACCESS_ONCE(pc->data_head);
196196
rmb();
197197
return head;
198198
}
199199

200-
static inline void perf_mmap__write_tail(struct perf_mmap *md,
201-
unsigned long tail)
200+
static inline void perf_mmap__write_tail(struct perf_mmap *md, u64 tail)
202201
{
203202
struct perf_event_mmap_page *pc = md->base;
204203

‎tools/perf/util/header.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2504,8 +2504,11 @@ int perf_session__read_header(struct perf_session *session)
25042504
if (read_attr(fd, header, &f_attr) < 0)
25052505
goto out_errno;
25062506

2507-
if (header->needs_swap)
2507+
if (header->needs_swap) {
2508+
f_attr.ids.size = bswap_64(f_attr.ids.size);
2509+
f_attr.ids.offset = bswap_64(f_attr.ids.offset);
25082510
perf_event__attr_swap(&f_attr.attr);
2511+
}
25092512

25102513
tmp = lseek(fd, 0, SEEK_CUR);
25112514
evsel = perf_evsel__new(&f_attr.attr);

‎tools/perf/util/machine.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include "unwind.h"
1515
#include "linux/hash.h"
1616

17-
static void machine__remove_thread(struct machine *machine, struct thread *th);
18-
1917
static void dsos__init(struct dsos *dsos)
2018
{
2119
INIT_LIST_HEAD(&dsos->head);
@@ -1256,7 +1254,7 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
12561254
return 0;
12571255
}
12581256

1259-
static void machine__remove_thread(struct machine *machine, struct thread *th)
1257+
void machine__remove_thread(struct machine *machine, struct thread *th)
12601258
{
12611259
if (machine->last_match == th)
12621260
thread__zput(machine->last_match);

‎tools/perf/util/machine.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid);
120120
void machine__exit(struct machine *machine);
121121
void machine__delete_threads(struct machine *machine);
122122
void machine__delete(struct machine *machine);
123+
void machine__remove_thread(struct machine *machine, struct thread *th);
123124

124125
struct branch_info *sample__resolve_bstack(struct perf_sample *sample,
125126
struct addr_location *al);

‎tools/perf/util/probe-event.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,7 @@ void clear_perf_probe_event(struct perf_probe_event *pev)
19061906

19071907
free(pev->event);
19081908
free(pev->group);
1909+
free(pev->target);
19091910
clear_perf_probe_point(&pev->point);
19101911

19111912
for (i = 0; i < pev->nargs; i++) {
@@ -2654,7 +2655,7 @@ struct __event_package {
26542655
};
26552656

26562657
int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
2657-
int max_tevs, const char *target, bool force_add)
2658+
int max_tevs, bool force_add)
26582659
{
26592660
int i, j, ret;
26602661
struct __event_package *pkgs;
@@ -2678,7 +2679,7 @@ int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
26782679
ret = convert_to_probe_trace_events(pkgs[i].pev,
26792680
&pkgs[i].tevs,
26802681
max_tevs,
2681-
target);
2682+
pkgs[i].pev->target);
26822683
if (ret < 0)
26832684
goto end;
26842685
pkgs[i].ntevs = ret;

0 commit comments

Comments
 (0)