Skip to content

Commit

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

Pull perf/core improvements and fixes from  Arnaldo Carvalho de Melo:

New features:

  - Add option in 'perf sched' to merge like comms to lat output (Josef Bacik)

  - Improve 'perf probe' error messages when not finding a
    suitable vmlinux (Masami Hiramatsu)

Infrastructure changes:

  - Use atomic.h for various pre-existing reference counts (Arnaldo Carvalho de Melo)

  - Leg work for refcounting 'struct map' (Arnaldo Carvalho de Melo)

  - Assign default value for some pointers (Martin Liška)

  - Improve setting of gcc debug option (Martin Liška)

  - Separate the tests and tools in installation (Nam T. Nguyen)

  - Reduce number of arguments of hist_entry_iter__add() (Namhyung Kim)

  - DSO data cache fixes (Namhyung Kim)

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 27, 2015
2 parents a82d24e + dddc7ee commit 6632c4b
Show file tree
Hide file tree
Showing 33 changed files with 332 additions and 204 deletions.
6 changes: 5 additions & 1 deletion tools/perf/Makefile.perf
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ check: $(OUTPUT)common-cmds.h

install-gtk:

install-bin: all install-gtk
install-tools: all install-gtk
$(call QUIET_INSTALL, binaries) \
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'; \
$(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)'; \
Expand Down Expand Up @@ -502,12 +502,16 @@ endif
$(call QUIET_INSTALL, perf_completion-script) \
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d'; \
$(INSTALL) perf-completion.sh '$(DESTDIR_SQ)$(sysconfdir_SQ)/bash_completion.d/perf'

install-tests: all install-gtk
$(call QUIET_INSTALL, tests) \
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \
$(INSTALL) tests/attr.py '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests'; \
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'; \
$(INSTALL) tests/attr/* '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/tests/attr'

install-bin: install-tools install-tests

install: install-bin try-install-man install-traceevent-plugins

install-python_ext:
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/arch/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const char *const mips_triplets[] = {
static bool lookup_path(char *name)
{
bool found = false;
char *path, *tmp;
char *path, *tmp = NULL;
char buf[PATH_MAX];
char *env = getenv("PATH");

Expand Down
9 changes: 5 additions & 4 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ static int process_sample_event(struct perf_tool *tool,
struct report *rep = container_of(tool, struct report, tool);
struct addr_location al;
struct hist_entry_iter iter = {
.hide_unresolved = rep->hide_unresolved,
.add_entry_cb = hist_iter__report_callback,
.evsel = evsel,
.sample = sample,
.hide_unresolved = rep->hide_unresolved,
.add_entry_cb = hist_iter__report_callback,
};
int ret = 0;

Expand Down Expand Up @@ -168,8 +170,7 @@ static int process_sample_event(struct perf_tool *tool,
if (al.map != NULL)
al.map->dso->hit = 1;

ret = hist_entry_iter__add(&iter, &al, evsel, sample, rep->max_stack,
rep);
ret = hist_entry_iter__add(&iter, &al, rep->max_stack, rep);
if (ret < 0)
pr_debug("problem adding hist entry, skipping event\n");
out_put:
Expand Down
77 changes: 72 additions & 5 deletions tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ struct work_atoms {
u64 total_lat;
u64 nb_atoms;
u64 total_runtime;
int num_merged;
};

typedef int (*sort_fn_t)(struct work_atoms *, struct work_atoms *);
Expand Down Expand Up @@ -168,9 +169,10 @@ struct perf_sched {
u64 all_runtime;
u64 all_count;
u64 cpu_last_switched[MAX_CPUS];
struct rb_root atom_root, sorted_atom_root;
struct rb_root atom_root, sorted_atom_root, merged_atom_root;
struct list_head sort_list, cmp_pid;
bool force;
bool skip_merge;
};

static u64 get_nsecs(void)
Expand Down Expand Up @@ -1182,7 +1184,10 @@ static void output_lat_thread(struct perf_sched *sched, struct work_atoms *work_
sched->all_runtime += work_list->total_runtime;
sched->all_count += work_list->nb_atoms;

ret = printf(" %s:%d ", thread__comm_str(work_list->thread), work_list->thread->tid);
if (work_list->num_merged > 1)
ret = printf(" %s:(%d) ", thread__comm_str(work_list->thread), work_list->num_merged);
else
ret = printf(" %s:%d ", thread__comm_str(work_list->thread), work_list->thread->tid);

for (i = 0; i < 24 - ret; i++)
printf(" ");
Expand Down Expand Up @@ -1302,17 +1307,22 @@ static int sort_dimension__add(const char *tok, struct list_head *list)
static void perf_sched__sort_lat(struct perf_sched *sched)
{
struct rb_node *node;

struct rb_root *root = &sched->atom_root;
again:
for (;;) {
struct work_atoms *data;
node = rb_first(&sched->atom_root);
node = rb_first(root);
if (!node)
break;

rb_erase(node, &sched->atom_root);
rb_erase(node, root);
data = rb_entry(node, struct work_atoms, node);
__thread_latency_insert(&sched->sorted_atom_root, data, &sched->sort_list);
}
if (root == &sched->atom_root) {
root = &sched->merged_atom_root;
goto again;
}
}

static int process_sched_wakeup_event(struct perf_tool *tool,
Expand Down Expand Up @@ -1572,6 +1582,59 @@ static void print_bad_events(struct perf_sched *sched)
}
}

static void __merge_work_atoms(struct rb_root *root, struct work_atoms *data)
{
struct rb_node **new = &(root->rb_node), *parent = NULL;
struct work_atoms *this;
const char *comm = thread__comm_str(data->thread), *this_comm;

while (*new) {
int cmp;

this = container_of(*new, struct work_atoms, node);
parent = *new;

this_comm = thread__comm_str(this->thread);
cmp = strcmp(comm, this_comm);
if (cmp > 0) {
new = &((*new)->rb_left);
} else if (cmp < 0) {
new = &((*new)->rb_right);
} else {
this->num_merged++;
this->total_runtime += data->total_runtime;
this->nb_atoms += data->nb_atoms;
this->total_lat += data->total_lat;
list_splice(&data->work_list, &this->work_list);
if (this->max_lat < data->max_lat) {
this->max_lat = data->max_lat;
this->max_lat_at = data->max_lat_at;
}
zfree(&data);
return;
}
}

data->num_merged++;
rb_link_node(&data->node, parent, new);
rb_insert_color(&data->node, root);
}

static void perf_sched__merge_lat(struct perf_sched *sched)
{
struct work_atoms *data;
struct rb_node *node;

if (sched->skip_merge)
return;

while ((node = rb_first(&sched->atom_root))) {
rb_erase(node, &sched->atom_root);
data = rb_entry(node, struct work_atoms, node);
__merge_work_atoms(&sched->merged_atom_root, data);
}
}

static int perf_sched__lat(struct perf_sched *sched)
{
struct rb_node *next;
Expand All @@ -1581,6 +1644,7 @@ static int perf_sched__lat(struct perf_sched *sched)
if (perf_sched__read_events(sched))
return -1;

perf_sched__merge_lat(sched);
perf_sched__sort_lat(sched);

printf("\n -----------------------------------------------------------------------------------------------------------------\n");
Expand Down Expand Up @@ -1732,6 +1796,7 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
.profile_cpu = -1,
.next_shortname1 = 'A',
.next_shortname2 = '0',
.skip_merge = 0,
};
const struct option latency_options[] = {
OPT_STRING('s', "sort", &sched.sort_order, "key[,key2...]",
Expand All @@ -1742,6 +1807,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
"CPU to profile on"),
OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
"dump raw trace in ASCII"),
OPT_BOOLEAN('p', "pids", &sched.skip_merge,
"latency stats per pid instead of per comm"),
OPT_END()
};
const struct option replay_options[] = {
Expand Down
7 changes: 4 additions & 3 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,9 @@ static void perf_event__process_sample(struct perf_tool *tool,
if (al.sym == NULL || !al.sym->ignore) {
struct hists *hists = evsel__hists(evsel);
struct hist_entry_iter iter = {
.add_entry_cb = hist_iter__top_callback,
.evsel = evsel,
.sample = sample,
.add_entry_cb = hist_iter__top_callback,
};

if (symbol_conf.cumulate_callchain)
Expand All @@ -785,8 +787,7 @@ static void perf_event__process_sample(struct perf_tool *tool,

pthread_mutex_lock(&hists->lock);

err = hist_entry_iter__add(&iter, &al, evsel, sample,
top->max_stack, top);
err = hist_entry_iter__add(&iter, &al, top->max_stack, top);
if (err < 0)
pr_err("Problem incrementing symbol period, skipping event\n");

Expand Down
4 changes: 3 additions & 1 deletion tools/perf/config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ifeq ($(ARCH),x86)
LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
$(call detected,CONFIG_X86_64)
else
LIBUNWIND_LIBS = -lunwind -lunwind-x86
LIBUNWIND_LIBS = -lunwind-x86 -llzma -lunwind
endif
NO_PERF_REGS := 0
endif
Expand Down Expand Up @@ -130,6 +130,8 @@ endif

ifeq ($(DEBUG),0)
CFLAGS += -O6
else
CFLAGS += $(call cc-option,-Og,-O0)
endif

ifdef PARSER_DEBUG
Expand Down
19 changes: 19 additions & 0 deletions tools/perf/config/utilities.mak
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,22 @@ $(if $($(1)),$(call _ge_attempt,$($(1)),$(1)),$(call _ge_attempt,$(2)))
endef
_ge_attempt = $(if $(get-executable),$(get-executable),$(call _gea_err,$(2)))
_gea_err = $(if $(1),$(error Please set '$(1)' appropriately))

# try-run
# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
# Exit code chooses option. "$$TMP" is can be used as temporary file and
# is automatically cleaned up.
try-run = $(shell set -e; \
TMP="$(TMPOUT).$$$$.tmp"; \
TMPO="$(TMPOUT).$$$$.o"; \
if ($(1)) >/dev/null 2>&1; \
then echo "$(2)"; \
else echo "$(3)"; \
fi; \
rm -f "$$TMP" "$$TMPO")

# cc-option
# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586)

cc-option = $(call try-run,\
$(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2))
11 changes: 11 additions & 0 deletions tools/perf/tests/dso-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ struct test_data_offset offsets[] = {
},
};

/* move it from util/dso.c for compatibility */
static int dso__data_fd(struct dso *dso, struct machine *machine)
{
int fd = dso__data_get_fd(dso, machine);

if (fd >= 0)
dso__data_put_fd(dso);

return fd;
}

int test__dso_data(void)
{
struct machine machine;
Expand Down
6 changes: 4 additions & 2 deletions tools/perf/tests/hists_cumulate.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
},
};
struct hist_entry_iter iter = {
.evsel = evsel,
.sample = &sample,
.hide_unresolved = false,
};

Expand All @@ -104,8 +106,8 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
&sample) < 0)
goto out;

if (hist_entry_iter__add(&iter, &al, evsel, &sample,
PERF_MAX_STACK_DEPTH, NULL) < 0) {
if (hist_entry_iter__add(&iter, &al, PERF_MAX_STACK_DEPTH,
NULL) < 0) {
addr_location__put(&al);
goto out;
}
Expand Down
4 changes: 3 additions & 1 deletion tools/perf/tests/hists_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static int add_hist_entries(struct perf_evlist *evlist,
},
};
struct hist_entry_iter iter = {
.evsel = evsel,
.sample = &sample,
.ops = &hist_iter_normal,
.hide_unresolved = false,
};
Expand All @@ -81,7 +83,7 @@ static int add_hist_entries(struct perf_evlist *evlist,
&sample) < 0)
goto out;

if (hist_entry_iter__add(&iter, &al, evsel, &sample,
if (hist_entry_iter__add(&iter, &al,
PERF_MAX_STACK_DEPTH, NULL) < 0) {
addr_location__put(&al);
goto out;
Expand Down
6 changes: 4 additions & 2 deletions tools/perf/tests/hists_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
},
};
struct hist_entry_iter iter = {
.evsel = evsel,
.sample = &sample,
.ops = &hist_iter_normal,
.hide_unresolved = false,
};
Expand All @@ -70,8 +72,8 @@ static int add_hist_entries(struct hists *hists, struct machine *machine)
&sample) < 0)
goto out;

if (hist_entry_iter__add(&iter, &al, evsel, &sample,
PERF_MAX_STACK_DEPTH, NULL) < 0) {
if (hist_entry_iter__add(&iter, &al, PERF_MAX_STACK_DEPTH,
NULL) < 0) {
addr_location__put(&al);
goto out;
}
Expand Down
Loading

0 comments on commit 6632c4b

Please sign in to comment.