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:

User visible changes:

  - Force period term to overload global settings, i.e. previously this
    command line:

     $ perf record -e 'cpu/instructions,period=20000/',cycles -c 1000 sleep 1

    would result in both events having a period equal to 1000, with the fix we
    get something saner:

     $ perf evlist -v | grep period
     cpu/instructions,period=20000/: ... { sample_period, sample_freq }: 20000, ...
     cycles: ... { sample_period, sample_freq }: 1000 ...
     $

   (Jiri Olsa)

Infrastructure changes:

  - Use the dummy software event with freq=0 in the twatch.py python
    binding example, to avoid disabling nohz. (Arnaldo Carvalho de Melo)

  - Add some missing constants to the python binding. (Arnaldo Carvalho de Melo)

  - Fix mismatched declarations for elf_getphdrnum, that happens
    only in the corner case where this function is not found on
    the system.  (Arnaldo Carvalho de Melo)

  - Add build test for having ending double slash. (Jiri Olsa)

  - Introduce callgraph_set for callgraph option. (Kan Liang)

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Ingo Molnar committed Jul 31, 2015
2 parents acd632e + aa53c09 commit 41d279a
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 97 deletions.
2 changes: 1 addition & 1 deletion tools/perf/Documentation/perf-record.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ OPTIONS
/sys/bus/event_sources/devices/<pmu>/format/*

There are also some params which are not defined in .../<pmu>/format/*.
These params can be used to set event defaults.
These params can be used to overload default config values per event.
Here is a list of the params.
- 'period': Set event sampling period

Expand Down
9 changes: 7 additions & 2 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,12 +762,14 @@ static void callchain_debug(void)
callchain_param.dump_size);
}

int record_parse_callchain_opt(const struct option *opt __maybe_unused,
int record_parse_callchain_opt(const struct option *opt,
const char *arg,
int unset)
{
int ret;
struct record_opts *record = (struct record_opts *)opt->value;

record->callgraph_set = true;
callchain_param.enabled = !unset;

/* --no-call-graph */
Expand All @@ -784,10 +786,13 @@ int record_parse_callchain_opt(const struct option *opt __maybe_unused,
return ret;
}

int record_callchain_opt(const struct option *opt __maybe_unused,
int record_callchain_opt(const struct option *opt,
const char *arg __maybe_unused,
int unset __maybe_unused)
{
struct record_opts *record = (struct record_opts *)opt->value;

record->callgraph_set = true;
callchain_param.enabled = true;

if (callchain_param.record_mode == CALLCHAIN_NONE)
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ static int trace__symbols_init(struct trace *trace, struct perf_evlist *evlist)
if (trace->host == NULL)
return -ENOMEM;

if (trace_event__register_resolver(trace->host) < 0)
if (trace_event__register_resolver(trace->host, machine__resolve_kernel_addr) < 0)
return -errno;

err = __machine__synthesize_threads(trace->host, &trace->tool, &trace->opts.target,
Expand Down
1 change: 1 addition & 0 deletions tools/perf/perf.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct record_opts {
bool sample_weight;
bool sample_time;
bool sample_time_set;
bool callgraph_set;
bool period;
bool sample_intr_regs;
bool running_time;
Expand Down
12 changes: 11 additions & 1 deletion tools/perf/python/twatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,20 @@
def main():
cpus = perf.cpu_map()
threads = perf.thread_map()
evsel = perf.evsel(task = 1, comm = 1, mmap = 0,
evsel = perf.evsel(type = perf.TYPE_SOFTWARE,
config = perf.COUNT_SW_DUMMY,
task = 1, comm = 1, mmap = 0, freq = 0,
wakeup_events = 1, watermark = 1,
sample_id_all = 1,
sample_type = perf.SAMPLE_PERIOD | perf.SAMPLE_TID | perf.SAMPLE_CPU)

"""What we want are just the PERF_RECORD_ lifetime events for threads,
using the default, PERF_TYPE_HARDWARE + PERF_COUNT_HW_CYCLES & freq=1
(the default), makes perf reenable irq_vectors:local_timer_entry, when
disabling nohz, not good for some use cases where all we want is to get
threads comes and goes... So use (perf.TYPE_SOFTWARE, perf_COUNT_SW_DUMMY,
freq=0) instead."""

evsel.open(cpus = cpus, threads = threads);
evlist = perf.evlist(cpus, threads)
evlist.add(evsel)
Expand Down
13 changes: 9 additions & 4 deletions tools/perf/tests/make
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ make_install_man := install-man
make_install_html := install-html
make_install_info := install-info
make_install_pdf := install-pdf
make_install_prefix := install prefix=/tmp/krava
make_install_prefix := install prefix=/tmp/krava
make_install_prefix_slash := install prefix=/tmp/krava/
make_static := LDFLAGS=-static

# all the NO_* variable combined
Expand Down Expand Up @@ -101,6 +102,7 @@ run += make_util_pmu_bison_o
run += make_install
run += make_install_bin
run += make_install_prefix
run += make_install_prefix_slash
# FIXME 'install-*' commented out till they're fixed
# run += make_install_doc
# run += make_install_man
Expand Down Expand Up @@ -175,11 +177,14 @@ test_make_install_O := $(call test_dest_files,$(installed_files_all))
test_make_install_bin := $(call test_dest_files,$(installed_files_bin))
test_make_install_bin_O := $(call test_dest_files,$(installed_files_bin))

# We prefix all installed files for make_install_prefix
# We prefix all installed files for make_install_prefix(_slash)
# with '/tmp/krava' to match installed/prefix-ed files.
installed_files_all_prefix := $(addprefix /tmp/krava/,$(installed_files_all))
test_make_install_prefix := $(call test_dest_files,$(installed_files_all_prefix))
test_make_install_prefix_O := $(call test_dest_files,$(installed_files_all_prefix))
test_make_install_prefix := $(call test_dest_files,$(installed_files_all_prefix))
test_make_install_prefix_O := $(call test_dest_files,$(installed_files_all_prefix))

test_make_install_prefix_slash := $(test_make_install_prefix)
test_make_install_prefix_slash_O := $(test_make_install_prefix_O)

# FIXME nothing gets installed
test_make_install_man := test -f $$TMP_DEST/share/man/man1/perf.1
Expand Down
12 changes: 10 additions & 2 deletions tools/perf/tests/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ static int test__checkevent_symbolic_name_config(struct perf_evlist *evlist)
TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
TEST_ASSERT_VAL("wrong config",
PERF_COUNT_HW_CPU_CYCLES == evsel->attr.config);
/*
* The period value gets configured within perf_evlist__config,
* while this test executes only parse events method.
*/
TEST_ASSERT_VAL("wrong period",
100000 == evsel->attr.sample_period);
0 == evsel->attr.sample_period);
TEST_ASSERT_VAL("wrong config1",
0 == evsel->attr.config1);
TEST_ASSERT_VAL("wrong config2",
Expand Down Expand Up @@ -406,7 +410,11 @@ static int test__checkevent_pmu(struct perf_evlist *evlist)
TEST_ASSERT_VAL("wrong config", 10 == evsel->attr.config);
TEST_ASSERT_VAL("wrong config1", 1 == evsel->attr.config1);
TEST_ASSERT_VAL("wrong config2", 3 == evsel->attr.config2);
TEST_ASSERT_VAL("wrong period", 1000 == evsel->attr.sample_period);
/*
* The period value gets configured within perf_evlist__config,
* while this test executes only parse events method.
*/
TEST_ASSERT_VAL("wrong period", 0 == evsel->attr.sample_period);

return 0;
}
Expand Down
33 changes: 33 additions & 0 deletions tools/perf/util/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
evsel->unit = "";
evsel->scale = 1.0;
INIT_LIST_HEAD(&evsel->node);
INIT_LIST_HEAD(&evsel->config_terms);
perf_evsel__object.init(evsel);
evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
perf_evsel__calc_id_pos(evsel);
Expand Down Expand Up @@ -586,6 +587,21 @@ perf_evsel__config_callgraph(struct perf_evsel *evsel,
}
}

static void apply_config_terms(struct perf_event_attr *attr __maybe_unused,
struct list_head *config_terms)
{
struct perf_evsel_config_term *term;

list_for_each_entry(term, config_terms, list) {
switch (term->type) {
case PERF_EVSEL__CONFIG_TERM_PERIOD:
attr->sample_period = term->val.period;
default:
break;
}
}
}

/*
* The enable_on_exec/disabled value strategy:
*
Expand Down Expand Up @@ -777,6 +793,12 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)
attr->use_clockid = 1;
attr->clockid = opts->clockid;
}

/*
* Apply event specific term settings,
* it overloads any global configuration.
*/
apply_config_terms(attr, &evsel->config_terms);
}

static int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
Expand Down Expand Up @@ -900,6 +922,16 @@ static void perf_evsel__free_id(struct perf_evsel *evsel)
zfree(&evsel->id);
}

static void perf_evsel__free_config_terms(struct perf_evsel *evsel)
{
struct perf_evsel_config_term *term, *h;

list_for_each_entry_safe(term, h, &evsel->config_terms, list) {
list_del(&term->list);
free(term);
}
}

void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
{
int cpu, thread;
Expand All @@ -919,6 +951,7 @@ void perf_evsel__exit(struct perf_evsel *evsel)
assert(list_empty(&evsel->node));
perf_evsel__free_fd(evsel);
perf_evsel__free_id(evsel);
perf_evsel__free_config_terms(evsel);
close_cgroup(evsel->cgrp);
cpu_map__put(evsel->cpus);
thread_map__put(evsel->threads);
Expand Down
20 changes: 20 additions & 0 deletions tools/perf/util/evsel.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ struct perf_sample_id {

struct cgroup_sel;

/*
* The 'struct perf_evsel_config_term' is used to pass event
* specific configuration data to perf_evsel__config routine.
* It is allocated within event parsing and attached to
* perf_evsel::config_terms list head.
*/
enum {
PERF_EVSEL__CONFIG_TERM_PERIOD,
PERF_EVSEL__CONFIG_TERM_MAX,
};

struct perf_evsel_config_term {
struct list_head list;
int type;
union {
u64 period;
} val;
};

/** struct perf_evsel - event selector
*
* @name - Can be set to retain the original event name passed by the user,
Expand Down Expand Up @@ -87,6 +106,7 @@ struct perf_evsel {
struct perf_evsel *leader;
char *group_name;
bool cmdline_group_boundary;
struct list_head config_terms;
};

union u64_swap {
Expand Down
70 changes: 58 additions & 12 deletions tools/perf/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ const char *event_type(int type)
static struct perf_evsel *
__add_event(struct list_head *list, int *idx,
struct perf_event_attr *attr,
char *name, struct cpu_map *cpus)
char *name, struct cpu_map *cpus,
struct list_head *config_terms)
{
struct perf_evsel *evsel;

Expand All @@ -291,14 +292,19 @@ __add_event(struct list_head *list, int *idx,

if (name)
evsel->name = strdup(name);

if (config_terms)
list_splice(config_terms, &evsel->config_terms);

list_add_tail(&evsel->node, list);
return evsel;
}

static int add_event(struct list_head *list, int *idx,
struct perf_event_attr *attr, char *name)
struct perf_event_attr *attr, char *name,
struct list_head *config_terms)
{
return __add_event(list, idx, attr, name, NULL) ? 0 : -ENOMEM;
return __add_event(list, idx, attr, name, NULL, config_terms) ? 0 : -ENOMEM;
}

static int parse_aliases(char *str, const char *names[][PERF_EVSEL__MAX_ALIASES], int size)
Expand Down Expand Up @@ -377,7 +383,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
memset(&attr, 0, sizeof(attr));
attr.config = cache_type | (cache_op << 8) | (cache_result << 16);
attr.type = PERF_TYPE_HW_CACHE;
return add_event(list, idx, &attr, name);
return add_event(list, idx, &attr, name, NULL);
}

static int add_tracepoint(struct list_head *list, int *idx,
Expand Down Expand Up @@ -539,7 +545,7 @@ int parse_events_add_breakpoint(struct list_head *list, int *idx,
attr.type = PERF_TYPE_BREAKPOINT;
attr.sample_period = 1;

return add_event(list, idx, &attr, NULL);
return add_event(list, idx, &attr, NULL, NULL);
}

static int check_type_val(struct parse_events_term *term,
Expand Down Expand Up @@ -590,7 +596,6 @@ do { \
break;
case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD:
CHECK_TYPE_VAL(NUM);
attr->sample_period = term->val.num;
break;
case PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE:
/*
Expand Down Expand Up @@ -622,22 +627,58 @@ static int config_attr(struct perf_event_attr *attr,
return 0;
}

static int get_config_terms(struct list_head *head_config,
struct list_head *head_terms __maybe_unused)
{
#define ADD_CONFIG_TERM(__type, __name, __val) \
do { \
struct perf_evsel_config_term *__t; \
\
__t = zalloc(sizeof(*__t)); \
if (!__t) \
return -ENOMEM; \
\
INIT_LIST_HEAD(&__t->list); \
__t->type = PERF_EVSEL__CONFIG_TERM_ ## __type; \
__t->val.__name = __val; \
list_add_tail(&__t->list, head_terms); \
} while (0)

struct parse_events_term *term;

list_for_each_entry(term, head_config, list) {
switch (term->type_term) {
case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD:
ADD_CONFIG_TERM(PERIOD, period, term->val.num);
default:
break;
}
}
#undef ADD_EVSEL_CONFIG
return 0;
}

int parse_events_add_numeric(struct parse_events_evlist *data,
struct list_head *list,
u32 type, u64 config,
struct list_head *head_config)
{
struct perf_event_attr attr;
LIST_HEAD(config_terms);

memset(&attr, 0, sizeof(attr));
attr.type = type;
attr.config = config;

if (head_config &&
config_attr(&attr, head_config, data->error))
return -EINVAL;
if (head_config) {
if (config_attr(&attr, head_config, data->error))
return -EINVAL;

if (get_config_terms(head_config, &config_terms))
return -ENOMEM;
}

return add_event(list, &data->idx, &attr, NULL);
return add_event(list, &data->idx, &attr, NULL, &config_terms);
}

static int parse_events__is_name_term(struct parse_events_term *term)
Expand All @@ -664,6 +705,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
struct perf_pmu_info info;
struct perf_pmu *pmu;
struct perf_evsel *evsel;
LIST_HEAD(config_terms);

pmu = perf_pmu__find(name);
if (!pmu)
Expand All @@ -678,7 +720,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,

if (!head_config) {
attr.type = pmu->type;
evsel = __add_event(list, &data->idx, &attr, NULL, pmu->cpus);
evsel = __add_event(list, &data->idx, &attr, NULL, pmu->cpus, NULL);
return evsel ? 0 : -ENOMEM;
}

Expand All @@ -692,11 +734,15 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
if (config_attr(&attr, head_config, data->error))
return -EINVAL;

if (get_config_terms(head_config, &config_terms))
return -ENOMEM;

if (perf_pmu__config(pmu, &attr, head_config, data->error))
return -EINVAL;

evsel = __add_event(list, &data->idx, &attr,
pmu_event_name(head_config), pmu->cpus);
pmu_event_name(head_config), pmu->cpus,
&config_terms);
if (evsel) {
evsel->unit = info.unit;
evsel->scale = info.scale;
Expand Down
Loading

0 comments on commit 41d279a

Please sign in to comment.