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:

  * Check maximum frequency rate for record/top, emitting better error
    messages, from Jiri Olsa.

  * Disable live kvm command if timerfd is not supported, from David Ahern.

  * Add usage to 'perf list', from David Ahern.

  * Fix detection of non-core features, from David Ahern.

  * Consolidate __hists__add_*entry(), cleanup from 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 Nov 6, 2013
2 parents 87968f9 + 316c713 commit 83bf970
Show file tree
Hide file tree
Showing 45 changed files with 591 additions and 497 deletions.
4 changes: 2 additions & 2 deletions tools/perf/Makefile.perf
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ LIB_H += util/cache.h
LIB_H += util/callchain.h
LIB_H += util/build-id.h
LIB_H += util/debug.h
LIB_H += util/sysfs.h
LIB_H += util/fs.h
LIB_H += util/pmu.h
LIB_H += util/event.h
LIB_H += util/evsel.h
Expand Down Expand Up @@ -304,7 +304,7 @@ LIB_OBJS += $(OUTPUT)util/annotate.o
LIB_OBJS += $(OUTPUT)util/build-id.o
LIB_OBJS += $(OUTPUT)util/config.o
LIB_OBJS += $(OUTPUT)util/ctype.o
LIB_OBJS += $(OUTPUT)util/sysfs.o
LIB_OBJS += $(OUTPUT)util/fs.o
LIB_OBJS += $(OUTPUT)util/pmu.o
LIB_OBJS += $(OUTPUT)util/environment.o
LIB_OBJS += $(OUTPUT)util/event.o
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static int perf_evsel__add_sample(struct perf_evsel *evsel,
return 0;
}

he = __hists__add_entry(&evsel->hists, al, NULL, 1, 1, 0);
he = __hists__add_entry(&evsel->hists, al, NULL, NULL, NULL, 1, 1, 0);
if (he == NULL)
return -ENOMEM;

Expand Down
3 changes: 2 additions & 1 deletion tools/perf/builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ static int hists__add_entry(struct hists *hists,
struct addr_location *al, u64 period,
u64 weight, u64 transaction)
{
if (__hists__add_entry(hists, al, NULL, period, weight, transaction) != NULL)
if (__hists__add_entry(hists, al, NULL, NULL, NULL, period, weight,
transaction) != NULL)
return 0;
return -ENOMEM;
}
Expand Down
12 changes: 12 additions & 0 deletions tools/perf/builtin-kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include "util/data.h"

#include <sys/prctl.h>
#ifdef HAVE_TIMERFD_SUPPORT
#include <sys/timerfd.h>
#endif

#include <termios.h>
#include <semaphore.h>
Expand Down Expand Up @@ -337,6 +339,7 @@ static void init_kvm_event_record(struct perf_kvm_stat *kvm)
INIT_LIST_HEAD(&kvm->kvm_events_cache[i]);
}

#ifdef HAVE_TIMERFD_SUPPORT
static void clear_events_cache_stats(struct list_head *kvm_events_cache)
{
struct list_head *head;
Expand All @@ -358,6 +361,7 @@ static void clear_events_cache_stats(struct list_head *kvm_events_cache)
}
}
}
#endif

static int kvm_events_hash_fn(u64 key)
{
Expand Down Expand Up @@ -783,6 +787,7 @@ static void print_result(struct perf_kvm_stat *kvm)
pr_info("\nLost events: %" PRIu64 "\n\n", kvm->lost_events);
}

#ifdef HAVE_TIMERFD_SUPPORT
static int process_lost_event(struct perf_tool *tool,
union perf_event *event __maybe_unused,
struct perf_sample *sample __maybe_unused,
Expand All @@ -793,6 +798,7 @@ static int process_lost_event(struct perf_tool *tool,
kvm->lost_events++;
return 0;
}
#endif

static bool skip_sample(struct perf_kvm_stat *kvm,
struct perf_sample *sample)
Expand Down Expand Up @@ -872,6 +878,7 @@ static bool verify_vcpu(int vcpu)
return true;
}

#ifdef HAVE_TIMERFD_SUPPORT
/* keeping the max events to a modest level to keep
* the processing of samples per mmap smooth.
*/
Expand Down Expand Up @@ -1213,6 +1220,7 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)
out:
return rc;
}
#endif

static int read_events(struct perf_kvm_stat *kvm)
{
Expand Down Expand Up @@ -1379,6 +1387,7 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)
return kvm_events_report_vcpu(kvm);
}

#ifdef HAVE_TIMERFD_SUPPORT
static struct perf_evlist *kvm_live_event_list(void)
{
struct perf_evlist *evlist;
Expand Down Expand Up @@ -1566,6 +1575,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,

return err;
}
#endif

static void print_kvm_stat_usage(void)
{
Expand Down Expand Up @@ -1604,8 +1614,10 @@ static int kvm_cmd_stat(const char *file_name, int argc, const char **argv)
if (!strncmp(argv[1], "rep", 3))
return kvm_events_report(&kvm, argc - 1 , argv + 1);

#ifdef HAVE_TIMERFD_SUPPORT
if (!strncmp(argv[1], "live", 4))
return kvm_events_live(&kvm, argc - 1 , argv + 1);
#endif

perf_stat:
return cmd_stat(argc, argv, NULL);
Expand Down
84 changes: 48 additions & 36 deletions tools/perf/builtin-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,51 +14,63 @@
#include "util/parse-events.h"
#include "util/cache.h"
#include "util/pmu.h"
#include "util/parse-options.h"

int cmd_list(int argc, const char **argv, const char *prefix __maybe_unused)
{
int i;
const struct option list_options[] = {
OPT_END()
};
const char * const list_usage[] = {
"perf list [hw|sw|cache|tracepoint|pmu|event_glob]",
NULL
};

argc = parse_options(argc, argv, list_options, list_usage,
PARSE_OPT_STOP_AT_NON_OPTION);

setup_pager();

if (argc == 1)
if (argc == 0) {
print_events(NULL, false);
else {
int i;

for (i = 1; i < argc; ++i) {
if (i > 2)
putchar('\n');
if (strncmp(argv[i], "tracepoint", 10) == 0)
print_tracepoint_events(NULL, NULL, false);
else if (strcmp(argv[i], "hw") == 0 ||
strcmp(argv[i], "hardware") == 0)
print_events_type(PERF_TYPE_HARDWARE);
else if (strcmp(argv[i], "sw") == 0 ||
strcmp(argv[i], "software") == 0)
print_events_type(PERF_TYPE_SOFTWARE);
else if (strcmp(argv[i], "cache") == 0 ||
strcmp(argv[i], "hwcache") == 0)
print_hwcache_events(NULL, false);
else if (strcmp(argv[i], "pmu") == 0)
print_pmu_events(NULL, false);
else if (strcmp(argv[i], "--raw-dump") == 0)
print_events(NULL, true);
else {
char *sep = strchr(argv[i], ':'), *s;
int sep_idx;
return 0;
}

if (sep == NULL) {
print_events(argv[i], false);
continue;
}
sep_idx = sep - argv[i];
s = strdup(argv[i]);
if (s == NULL)
return -1;
for (i = 0; i < argc; ++i) {
if (i)
putchar('\n');
if (strncmp(argv[i], "tracepoint", 10) == 0)
print_tracepoint_events(NULL, NULL, false);
else if (strcmp(argv[i], "hw") == 0 ||
strcmp(argv[i], "hardware") == 0)
print_events_type(PERF_TYPE_HARDWARE);
else if (strcmp(argv[i], "sw") == 0 ||
strcmp(argv[i], "software") == 0)
print_events_type(PERF_TYPE_SOFTWARE);
else if (strcmp(argv[i], "cache") == 0 ||
strcmp(argv[i], "hwcache") == 0)
print_hwcache_events(NULL, false);
else if (strcmp(argv[i], "pmu") == 0)
print_pmu_events(NULL, false);
else if (strcmp(argv[i], "--raw-dump") == 0)
print_events(NULL, true);
else {
char *sep = strchr(argv[i], ':'), *s;
int sep_idx;

s[sep_idx] = '\0';
print_tracepoint_events(s, s + sep_idx + 1, false);
free(s);
if (sep == NULL) {
print_events(argv[i], false);
continue;
}
sep_idx = sep - argv[i];
s = strdup(argv[i]);
if (s == NULL)
return -1;

s[sep_idx] = '\0';
print_tracepoint_events(s, s + sep_idx + 1, false);
free(s);
}
}
return 0;
Expand Down
15 changes: 1 addition & 14 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,20 +958,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
if (perf_evlist__create_maps(evsel_list, &rec->opts.target) < 0)
usage_with_options(record_usage, record_options);

if (rec->opts.user_interval != ULLONG_MAX)
rec->opts.default_interval = rec->opts.user_interval;
if (rec->opts.user_freq != UINT_MAX)
rec->opts.freq = rec->opts.user_freq;

/*
* User specified count overrides default frequency.
*/
if (rec->opts.default_interval)
rec->opts.freq = 0;
else if (rec->opts.freq) {
rec->opts.default_interval = rec->opts.freq;
} else {
ui__error("frequency and count are zero, aborting\n");
if (perf_record_opts__config(&rec->opts)) {
err = -EINVAL;
goto out_free_fd;
}
Expand Down
16 changes: 11 additions & 5 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ static int perf_report__add_mem_hist_entry(struct perf_tool *tool,
* and this is indirectly achieved by passing period=weight here
* and the he_stat__add_period() function.
*/
he = __hists__add_mem_entry(&evsel->hists, al, parent, mi, cost, cost);
he = __hists__add_entry(&evsel->hists, al, parent, NULL, mi,
cost, cost, 0);
if (!he)
return -ENOMEM;

Expand Down Expand Up @@ -200,12 +201,16 @@ static int perf_report__add_branch_hist_entry(struct perf_tool *tool,

err = -ENOMEM;

/* overwrite the 'al' to branch-to info */
al->map = bi[i].to.map;
al->sym = bi[i].to.sym;
al->addr = bi[i].to.addr;
/*
* The report shows the percentage of total branches captured
* and not events sampled. Thus we use a pseudo period of 1.
*/
he = __hists__add_branch_entry(&evsel->hists, al, parent,
&bi[i], 1, 1);
he = __hists__add_entry(&evsel->hists, al, parent, &bi[i], NULL,
1, 1, 0);
if (he) {
struct annotation *notes;
bx = he->branch_info;
Expand Down Expand Up @@ -266,8 +271,9 @@ static int perf_evsel__add_hist_entry(struct perf_tool *tool,
return err;
}

he = __hists__add_entry(&evsel->hists, al, parent, sample->period,
sample->weight, sample->transaction);
he = __hists__add_entry(&evsel->hists, al, parent, NULL, NULL,
sample->period, sample->weight,
sample->transaction);
if (he == NULL)
return -ENOMEM;

Expand Down
20 changes: 4 additions & 16 deletions tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ static struct hist_entry *perf_evsel__add_hist_entry(struct perf_evsel *evsel,
struct hist_entry *he;

pthread_mutex_lock(&evsel->hists.lock);
he = __hists__add_entry(&evsel->hists, al, NULL, sample->period,
sample->weight, sample->transaction);
he = __hists__add_entry(&evsel->hists, al, NULL, NULL, NULL,
sample->period, sample->weight,
sample->transaction);
pthread_mutex_unlock(&evsel->hists.lock);
if (he == NULL)
return NULL;
Expand Down Expand Up @@ -1208,20 +1209,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
if (top.delay_secs < 1)
top.delay_secs = 1;

if (opts->user_interval != ULLONG_MAX)
opts->default_interval = opts->user_interval;
if (opts->user_freq != UINT_MAX)
opts->freq = opts->user_freq;

/*
* User specified count overrides default frequency.
*/
if (opts->default_interval)
opts->freq = 0;
else if (opts->freq) {
opts->default_interval = opts->freq;
} else {
ui__error("frequency and count are zero, aborting\n");
if (perf_record_opts__config(opts)) {
status = -EINVAL;
goto out_delete_maps;
}
Expand Down
17 changes: 12 additions & 5 deletions tools/perf/config/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ endif

feature_check = $(eval $(feature_check_code))
define feature_check_code
feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) LIBUNWIND_LIBS="$(LIBUNWIND_LIBS)" -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBUNWIND_LIBS="$(LIBUNWIND_LIBS)" -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
endef

feature_set = $(eval $(feature_set_code))
Expand Down Expand Up @@ -235,7 +235,7 @@ CFLAGS += -I$(LIB_INCLUDE)
CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE

ifndef NO_BIONIC
$(feature_check,bionic)
$(call feature_check,bionic)
ifeq ($(feature-bionic), 1)
BIONIC := 1
EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
Expand Down Expand Up @@ -397,6 +397,13 @@ else
endif
endif

$(call feature_check,timerfd)
ifeq ($(feature-timerfd), 1)
CFLAGS += -DHAVE_TIMERFD_SUPPORT
else
msg := $(warning No timerfd support. Disables 'perf kvm stat live');
endif

disable-python = $(eval $(disable-python_code))
define disable-python_code
CFLAGS += -DNO_LIBPYTHON
Expand Down Expand Up @@ -472,15 +479,15 @@ else
CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
else
ifneq ($(feature-libbfd), 1)
$(feature_check,liberty)
$(call feature_check,liberty)
ifeq ($(feature-liberty), 1)
EXTLIBS += -lbfd -liberty
else
$(feature_check,liberty-z)
$(call feature_check,liberty-z)
ifeq ($(feature-liberty-z), 1)
EXTLIBS += -lbfd -liberty -lz
else
$(feature_check,cplus-demangle)
$(call feature_check,cplus-demangle)
ifeq ($(feature-cplus-demangle), 1)
EXTLIBS += -liberty
CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
Expand Down
6 changes: 5 additions & 1 deletion tools/perf/config/feature-checks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ FILES= \
test-libunwind \
test-on-exit \
test-stackprotector-all \
test-stackprotector
test-stackprotector \
test-timerfd

CC := $(CC) -MD

Expand Down Expand Up @@ -136,6 +137,9 @@ test-on-exit:
test-backtrace:
$(BUILD)

test-timerfd:
$(BUILD)

-include *.d

###############################
Expand Down
Loading

0 comments on commit 83bf970

Please sign in to comment.