Skip to content

Commit

Permalink
Merge tag 'perf-core-for-mingo-20160523' of git://git.kernel.org/pub/…
Browse files Browse the repository at this point in the history
…scm/linux/kernel/git/acme/linux into perf/urgent

Pull perf/core improvements from Arnaldo Carvalho de Melo:

User visible changes:

- Add "srcline_from" and "srcline_to" branch sort keys to 'perf top' and
  'perf report' (Andi Kleen)

Infrastructure changes:

- Make 'perf trace' auto-attach fd->name and ptr->name beautifiers based
  on the name of syscall arguments, this way new syscalls that have
  'const char * (path,pathname,filename)' will use the fd->name beautifier
  (vfs_getname perf probe, if in place) and the 'fd->name' (vfs_getname
  or via /proc/PID/fd/) (Arnaldo Carvalho de Melo)

- Infrastructure to read from a ring buffer in backward write mode (Wang Nan)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Ingo Molnar committed May 24, 2016
2 parents 408cf67 + 3a62a7b commit 0c9f790
Show file tree
Hide file tree
Showing 12 changed files with 319 additions and 164 deletions.
3 changes: 2 additions & 1 deletion tools/perf/Documentation/perf-report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ OPTIONS

If --branch-stack option is used, following sort keys are also
available:
dso_from, dso_to, symbol_from, symbol_to, mispredict.

- dso_from: name of library or module branched from
- dso_to: name of library or module branched to
- symbol_from: name of function branched from
- symbol_to: name of function branched to
- srcline_from: source file and line branched from
- srcline_to: source file and line branched to
- mispredict: "N" for predicted branch, "Y" for mispredicted branch
- in_tx: branch in TSX transaction
- abort: TSX transaction abort.
Expand Down
81 changes: 71 additions & 10 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <unistd.h>
#include <sched.h>
#include <sys/mman.h>
#include <asm/bug.h>


struct record {
Expand Down Expand Up @@ -82,44 +83,104 @@ static int process_synthesized_event(struct perf_tool *tool,
return record__write(rec, event, event->header.size);
}

static int
backward_rb_find_range(void *buf, int mask, u64 head, u64 *start, u64 *end)
{
struct perf_event_header *pheader;
u64 evt_head = head;
int size = mask + 1;

pr_debug2("backward_rb_find_range: buf=%p, head=%"PRIx64"\n", buf, head);
pheader = (struct perf_event_header *)(buf + (head & mask));
*start = head;
while (true) {
if (evt_head - head >= (unsigned int)size) {
pr_debug("Finshed reading backward ring buffer: rewind\n");
if (evt_head - head > (unsigned int)size)
evt_head -= pheader->size;
*end = evt_head;
return 0;
}

pheader = (struct perf_event_header *)(buf + (evt_head & mask));

if (pheader->size == 0) {
pr_debug("Finshed reading backward ring buffer: get start\n");
*end = evt_head;
return 0;
}

evt_head += pheader->size;
pr_debug3("move evt_head: %"PRIx64"\n", evt_head);
}
WARN_ONCE(1, "Shouldn't get here\n");
return -1;
}

static int
rb_find_range(struct perf_evlist *evlist,
void *data, int mask, u64 head, u64 old,
u64 *start, u64 *end)
{
if (!evlist->backward) {
*start = old;
*end = head;
return 0;
}

return backward_rb_find_range(data, mask, head, start, end);
}

static int record__mmap_read(struct record *rec, int idx)
{
struct perf_mmap *md = &rec->evlist->mmap[idx];
u64 head = perf_mmap__read_head(md);
u64 old = md->prev;
u64 end = head, start = old;
unsigned char *data = md->base + page_size;
unsigned long size;
void *buf;
int rc = 0;

if (old == head)
if (rb_find_range(rec->evlist, data, md->mask, head,
old, &start, &end))
return -1;

if (start == end)
return 0;

rec->samples++;

size = head - old;
size = end - start;
if (size > (unsigned long)(md->mask) + 1) {
WARN_ONCE(1, "failed to keep up with mmap data. (warn only once)\n");

md->prev = head;
perf_evlist__mmap_consume(rec->evlist, idx);
return 0;
}

if ((old & md->mask) + size != (head & md->mask)) {
buf = &data[old & md->mask];
size = md->mask + 1 - (old & md->mask);
old += size;
if ((start & md->mask) + size != (end & md->mask)) {
buf = &data[start & md->mask];
size = md->mask + 1 - (start & md->mask);
start += size;

if (record__write(rec, buf, size) < 0) {
rc = -1;
goto out;
}
}

buf = &data[old & md->mask];
size = head - old;
old += size;
buf = &data[start & md->mask];
size = end - start;
start += size;

if (record__write(rec, buf, size) < 0) {
rc = -1;
goto out;
}

md->prev = old;
md->prev = head;
perf_evlist__mmap_consume(rec->evlist, idx);
out:
return rc;
Expand Down
Loading

0 comments on commit 0c9f790

Please sign in to comment.