From bea0340582dc47b447a014f5bf9f460925afdaf4 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Thu, 26 Apr 2012 14:15:15 +0900 Subject: perf tools: Introduce struct perf_target The perf_target struct will be used for taking care of cpu/thread maps based on user's input. Since it is used on various subcommands it'd better factoring it out. Thanks to Arnaldo for suggesting the better name. Signed-off-by: Namhyung Kim Reviewed-by: David Ahern Cc: David Ahern Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1335417327-11796-2-git-send-email-namhyung.kim@lge.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/perf/util/evlist.c') diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 1986d8051bd1..7080901a2717 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -827,7 +827,7 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, exit(-1); } - if (!opts->system_wide && !opts->target_tid && !opts->target_pid) + if (!opts->target.system_wide && !opts->target.tid && !opts->target.pid) evlist->threads->map[0] = evlist->workload.pid; close(child_ready_pipe[1]); -- cgit v1.2.3-59-g8ed1b From b809ac100e2f12ebf1b58ff522dba15651a77d27 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Thu, 26 Apr 2012 14:15:19 +0900 Subject: perf evlist: Make create_maps() take struct perf_target Now we have all information that needed to create cpu/thread maps in struct perf_target, it'd be better using it as an argument. Signed-off-by: Namhyung Kim Reviewed-by: David Ahern Cc: David Ahern Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1335417327-11796-6-git-send-email-namhyung.kim@lge.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-record.c | 4 +--- tools/perf/builtin-test.c | 7 ++++--- tools/perf/builtin-top.c | 4 +--- tools/perf/util/evlist.c | 12 +++++++----- tools/perf/util/evlist.h | 4 ++-- 5 files changed, 15 insertions(+), 16 deletions(-) (limited to 'tools/perf/util/evlist.c') diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 3596ccab6d3b..d16590942cec 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -891,9 +891,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) rec->opts.target.uid == UINT_MAX - 1) goto out_free_fd; - if (perf_evlist__create_maps(evsel_list, rec->opts.target.pid, - rec->opts.target.tid, rec->opts.target.uid, - rec->opts.target.cpu_list) < 0) + if (perf_evlist__create_maps(evsel_list, &rec->opts.target) < 0) usage_with_options(record_usage, record_options); list_for_each_entry(pos, &evsel_list->entries, node) { diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c index 27882d86e9ab..9d9abbbe23be 100644 --- a/tools/perf/builtin-test.c +++ b/tools/perf/builtin-test.c @@ -1165,6 +1165,9 @@ realloc: static int test__PERF_RECORD(void) { struct perf_record_opts opts = { + .target = { + .uid = UINT_MAX, + }, .no_delay = true, .freq = 10, .mmap_pages = 256, @@ -1207,9 +1210,7 @@ static int test__PERF_RECORD(void) * perf_evlist__prepare_workload we'll fill in the only thread * we're monitoring, the one forked there. */ - err = perf_evlist__create_maps(evlist, opts.target.pid, - opts.target.tid, UINT_MAX, - opts.target.cpu_list); + err = perf_evlist__create_maps(evlist, &opts.target); if (err < 0) { pr_debug("Not enough memory to create thread/cpu maps\n"); goto out_delete_evlist; diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 4f47952eddbd..2a0ec09b9b77 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1258,9 +1258,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) if (top.target.uid_str != NULL && top.target.uid == UINT_MAX - 1) goto out_delete_evlist; - if (perf_evlist__create_maps(top.evlist, top.target.pid, - top.target.tid, top.target.uid, - top.target.cpu_list) < 0) + if (perf_evlist__create_maps(top.evlist, &top.target) < 0) usage_with_options(top_usage, options); if (!top.evlist->nr_entries && diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 7080901a2717..a43e2c56d1c6 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -599,18 +599,20 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages, return perf_evlist__mmap_per_cpu(evlist, prot, mask); } -int perf_evlist__create_maps(struct perf_evlist *evlist, const char *target_pid, - const char *target_tid, uid_t uid, const char *cpu_list) +int perf_evlist__create_maps(struct perf_evlist *evlist, + struct perf_target *target) { - evlist->threads = thread_map__new_str(target_pid, target_tid, uid); + evlist->threads = thread_map__new_str(target->pid, target->tid, + target->uid); if (evlist->threads == NULL) return -1; - if (uid != UINT_MAX || (cpu_list == NULL && target_tid)) + if (target->uid != UINT_MAX || + (target->cpu_list == NULL && target->tid)) evlist->cpus = cpu_map__dummy_new(); else - evlist->cpus = cpu_map__new(cpu_list); + evlist->cpus = cpu_map__new(target->cpu_list); if (evlist->cpus == NULL) goto out_delete_threads; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 21f1c9e57f13..58abb63ac13a 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -106,8 +106,8 @@ static inline void perf_evlist__set_maps(struct perf_evlist *evlist, evlist->threads = threads; } -int perf_evlist__create_maps(struct perf_evlist *evlist, const char *target_pid, - const char *tid, uid_t uid, const char *cpu_list); +int perf_evlist__create_maps(struct perf_evlist *evlist, + struct perf_target *target); void perf_evlist__delete_maps(struct perf_evlist *evlist); int perf_evlist__set_filters(struct perf_evlist *evlist); -- cgit v1.2.3-59-g8ed1b From 12864b31583bcbd26789ebe68c612688f9ee2e30 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Thu, 26 Apr 2012 14:15:22 +0900 Subject: perf target: Split out perf_target handling code For further work on perf_target, it'd be better off splitting the code into a separate file. Signed-off-by: Namhyung Kim Reviewed-by: David Ahern Cc: David Ahern Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1335417327-11796-9-git-send-email-namhyung.kim@lge.com [ committer note: Fixed perl build by using stdbool and types.h in target.h ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile | 2 ++ tools/perf/perf.h | 9 +-------- tools/perf/util/evlist.c | 1 + tools/perf/util/evsel.c | 1 + tools/perf/util/target.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/target.h | 18 ++++++++++++++++++ tools/perf/util/usage.c | 34 ---------------------------------- tools/perf/util/util.h | 2 -- 8 files changed, 68 insertions(+), 44 deletions(-) create mode 100644 tools/perf/util/target.c create mode 100644 tools/perf/util/target.h (limited to 'tools/perf/util/evlist.c') diff --git a/tools/perf/Makefile b/tools/perf/Makefile index e98e14c88532..4122a668952e 100644 --- a/tools/perf/Makefile +++ b/tools/perf/Makefile @@ -300,6 +300,7 @@ LIB_H += util/cpumap.h LIB_H += util/top.h LIB_H += $(ARCH_INCLUDE) LIB_H += util/cgroup.h +LIB_H += util/target.h LIB_OBJS += $(OUTPUT)util/abspath.o LIB_OBJS += $(OUTPUT)util/alias.o @@ -361,6 +362,7 @@ LIB_OBJS += $(OUTPUT)util/util.o LIB_OBJS += $(OUTPUT)util/xyarray.o LIB_OBJS += $(OUTPUT)util/cpumap.o LIB_OBJS += $(OUTPUT)util/cgroup.o +LIB_OBJS += $(OUTPUT)util/target.o BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o diff --git a/tools/perf/perf.h b/tools/perf/perf.h index 7e226c0e0e31..14f1034f14f9 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h @@ -207,14 +207,7 @@ extern const char perf_version_string[]; void pthread__unblock_sigwinch(void); -struct perf_target { - const char *pid; - const char *tid; - const char *cpu_list; - const char *uid_str; - uid_t uid; - bool system_wide; -}; +#include "util/target.h" struct perf_record_opts { struct perf_target target; diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index a43e2c56d1c6..30328623cae6 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -11,6 +11,7 @@ #include #include "cpumap.h" #include "thread_map.h" +#include "target.h" #include "evlist.h" #include "evsel.h" #include diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index d90598edcf1d..bb785a098ced 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -14,6 +14,7 @@ #include "util.h" #include "cpumap.h" #include "thread_map.h" +#include "target.h" #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) #define GROUP_FD(group_fd, cpu) (*(int *)xyarray__entry(group_fd, cpu, 0)) diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c new file mode 100644 index 000000000000..3fadf85dd7e3 --- /dev/null +++ b/tools/perf/util/target.c @@ -0,0 +1,45 @@ +/* + * Helper functions for handling target threads/cpus + * + * Copyright (C) 2012, LG Electronics, Namhyung Kim + * + * Released under the GPL v2. + */ + +#include "target.h" +#include "debug.h" + + +void perf_target__validate(struct perf_target *target) +{ + if (target->pid) + target->tid = target->pid; + + /* CPU and PID are mutually exclusive */ + if (target->tid && target->cpu_list) { + ui__warning("WARNING: PID switch overriding CPU\n"); + sleep(1); + target->cpu_list = NULL; + } + + /* UID and PID are mutually exclusive */ + if (target->tid && target->uid_str) { + ui__warning("PID/TID switch overriding UID\n"); + sleep(1); + target->uid_str = NULL; + } + + /* UID and CPU are mutually exclusive */ + if (target->uid_str && target->cpu_list) { + ui__warning("UID switch overriding CPU\n"); + sleep(1); + target->cpu_list = NULL; + } + + /* PID/UID and SYSTEM are mutually exclusive */ + if ((target->tid || target->uid_str) && target->system_wide) { + ui__warning("PID/TID/UID switch overriding CPU\n"); + sleep(1); + target->system_wide = false; + } +} diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h new file mode 100644 index 000000000000..218291f921ed --- /dev/null +++ b/tools/perf/util/target.h @@ -0,0 +1,18 @@ +#ifndef _PERF_TARGET_H +#define _PERF_TARGET_H + +#include +#include + +struct perf_target { + const char *pid; + const char *tid; + const char *cpu_list; + const char *uid_str; + uid_t uid; + bool system_wide; +}; + +void perf_target__validate(struct perf_target *target); + +#endif /* _PERF_TARGET_H */ diff --git a/tools/perf/util/usage.c b/tools/perf/util/usage.c index 228f0a558872..e851abc22ccc 100644 --- a/tools/perf/util/usage.c +++ b/tools/perf/util/usage.c @@ -113,37 +113,3 @@ uid_t parse_target_uid(const char *str) return result->pw_uid; } - -void perf_target__validate(struct perf_target *target) -{ - if (target->pid) - target->tid = target->pid; - - /* CPU and PID are mutually exclusive */ - if (target->tid && target->cpu_list) { - ui__warning("WARNING: PID switch overriding CPU\n"); - sleep(1); - target->cpu_list = NULL; - } - - /* UID and PID are mutually exclusive */ - if (target->tid && target->uid_str) { - ui__warning("PID/TID switch overriding UID\n"); - sleep(1); - target->uid_str = NULL; - } - - /* UID and CPU are mutually exclusive */ - if (target->uid_str && target->cpu_list) { - ui__warning("UID switch overriding CPU\n"); - sleep(1); - target->cpu_list = NULL; - } - - /* PID/UID and SYSTEM are mutually exclusive */ - if ((target->tid || target->uid_str) && target->system_wide) { - ui__warning("PID/TID/UID switch overriding CPU\n"); - sleep(1); - target->system_wide = false; - } -} diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 3f05d6264dab..52be74c359d3 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -246,12 +246,10 @@ unsigned long convert_unit(unsigned long value, char *unit); int readn(int fd, void *buf, size_t size); struct perf_event_attr; -struct perf_target; void event_attr_init(struct perf_event_attr *attr); uid_t parse_target_uid(const char *str); -void perf_target__validate(struct perf_target *target); #define _STR(x) #x #define STR(x) _STR(x) -- cgit v1.2.3-59-g8ed1b From 55261f46702cec96911a81aacfb3cba13434d304 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Mon, 7 May 2012 14:08:59 +0900 Subject: perf evlist: Fix creation of cpu map Currently, 'perf record -- sleep 1' creates a cpu map for all online cpus since it turns out calling cpu_map__new(NULL). Fix it. Also it is guaranteed that cpu_list is NULL if PID/TID is given by calling perf_target__validate(), so we can make the conditional bit simpler. This also fixes perf test 7 (Validate) failure on my 6 core machine: $ cat /sys/devices/system/cpu/online 0-11 $ ./perf test -v 7 7: Validate PERF_RECORD_* events & perf_sample fields: --- start --- perf_evlist__mmap: Operation not permitted ---- end ---- Validate PERF_RECORD_* events & perf_sample fields: FAILED! Signed-off-by: Namhyung Kim Reviewed-by: David Ahern Cc: David Ahern Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1336367344-28071-3-git-send-email-namhyung.kim@lge.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evlist.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'tools/perf/util/evlist.c') diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 30328623cae6..183b199b0d09 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -609,8 +609,9 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, if (evlist->threads == NULL) return -1; - if (target->uid != UINT_MAX || - (target->cpu_list == NULL && target->tid)) + if (target->uid != UINT_MAX || target->tid) + evlist->cpus = cpu_map__dummy_new(); + else if (!target->system_wide && target->cpu_list == NULL) evlist->cpus = cpu_map__dummy_new(); else evlist->cpus = cpu_map__new(target->cpu_list); -- cgit v1.2.3-59-g8ed1b From d67356e7f80f5c2ef487bedc11a91d5fe18c5a15 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Mon, 7 May 2012 14:09:03 +0900 Subject: perf target: Consolidate target task/cpu checking There are places that check whether target task/cpu is given or not and some of them didn't check newly introduced uid or cpu list. Add and use three of helper functions to treat them properly. Signed-off-by: Namhyung Kim Reviewed-by: David Ahern Cc: David Ahern Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1336367344-28071-7-git-send-email-namhyung.kim@lge.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-record.c | 4 +--- tools/perf/builtin-stat.c | 12 ++++++------ tools/perf/builtin-top.c | 2 +- tools/perf/util/evlist.c | 10 ++++------ tools/perf/util/evsel.c | 8 ++++---- tools/perf/util/target.h | 15 +++++++++++++++ 6 files changed, 31 insertions(+), 20 deletions(-) (limited to 'tools/perf/util/evlist.c') diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index c8bf6ea000da..42e24149c791 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -843,9 +843,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) argc = parse_options(argc, argv, record_options, record_usage, PARSE_OPT_STOP_AT_NON_OPTION); - if (!argc && !rec->opts.target.pid && !rec->opts.target.tid && - !rec->opts.target.system_wide && !rec->opts.target.cpu_list && - !rec->opts.target.uid_str) + if (!argc && perf_target__none(&rec->opts.target)) usage_with_options(record_usage, record_options); if (rec->force && rec->append_file) { diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index bb7723221c0d..d9ff24637eeb 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -290,10 +290,10 @@ static int create_perf_stat_counter(struct perf_evsel *evsel, attr->inherit = !no_inherit; - if (target.system_wide) + if (!perf_target__no_cpu(&target)) return perf_evsel__open_per_cpu(evsel, evsel_list->cpus, group, group_fd); - if (!target.pid && !target.tid && (!group || evsel == first)) { + if (perf_target__no_task(&target) && (!group || evsel == first)) { attr->disabled = 1; attr->enable_on_exec = 1; } @@ -443,7 +443,7 @@ static int run_perf_stat(int argc __used, const char **argv) exit(-1); } - if (!target.tid && !target.pid && !target.system_wide) + if (perf_target__none(&target)) evsel_list->threads->map[0] = child_pid; /* @@ -965,7 +965,7 @@ static void print_stat(int argc, const char **argv) if (!csv_output) { fprintf(output, "\n"); fprintf(output, " Performance counter stats for "); - if (!target.pid && !target.tid) { + if (perf_target__no_task(&target)) { fprintf(output, "\'%s", argv[0]); for (i = 1; i < argc; i++) fprintf(output, " %s", argv[i]); @@ -1187,13 +1187,13 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) } else if (big_num_opt == 0) /* User passed --no-big-num */ big_num = false; - if (!argc && !target.pid && !target.tid) + if (!argc && perf_target__no_task(&target)) usage_with_options(stat_usage, options); if (run_count <= 0) usage_with_options(stat_usage, options); /* no_aggr, cgroup are for system-wide only */ - if ((no_aggr || nr_cgroups) && !target.system_wide) { + if ((no_aggr || nr_cgroups) && perf_target__no_cpu(&target)) { fprintf(stderr, "both cgroup and no-aggregation " "modes only available in system-wide mode\n"); diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 7ba0f03c0132..e4ca827f6879 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1016,7 +1016,7 @@ static int __cmd_top(struct perf_top *top) if (ret) goto out_delete; - if (top->target.tid || top->target.uid != UINT_MAX) + if (!perf_target__no_task(&top->target)) perf_event__synthesize_thread_map(&top->tool, top->evlist->threads, perf_event__process, &top->session->host_machine); diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 183b199b0d09..1201daf71719 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -609,12 +609,10 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, if (evlist->threads == NULL) return -1; - if (target->uid != UINT_MAX || target->tid) - evlist->cpus = cpu_map__dummy_new(); - else if (!target->system_wide && target->cpu_list == NULL) - evlist->cpus = cpu_map__dummy_new(); - else + if (!perf_target__no_cpu(target)) evlist->cpus = cpu_map__new(target->cpu_list); + else + evlist->cpus = cpu_map__dummy_new(); if (evlist->cpus == NULL) goto out_delete_threads; @@ -831,7 +829,7 @@ int perf_evlist__prepare_workload(struct perf_evlist *evlist, exit(-1); } - if (!opts->target.system_wide && !opts->target.tid && !opts->target.pid) + if (perf_target__none(&opts->target)) evlist->threads->map[0] = evlist->workload.pid; close(child_ready_pipe[1]); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index bb785a098ced..21eaab240396 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -114,8 +114,8 @@ void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, attr->sample_type |= PERF_SAMPLE_PERIOD; if (!opts->sample_id_all_missing && - (opts->sample_time || opts->target.system_wide || - !opts->no_inherit || opts->target.cpu_list)) + (opts->sample_time || !opts->no_inherit || + !perf_target__no_cpu(&opts->target))) attr->sample_type |= PERF_SAMPLE_TIME; if (opts->raw_samples) { @@ -136,8 +136,8 @@ void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, attr->mmap = track; attr->comm = track; - if (!opts->target.pid && !opts->target.tid && - !opts->target.system_wide && (!opts->group || evsel == first)) { + if (perf_target__none(&opts->target) && + (!opts->group || evsel == first)) { attr->disabled = 1; attr->enable_on_exec = 1; } diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h index 6fcd01c440a9..127cff3f8ced 100644 --- a/tools/perf/util/target.h +++ b/tools/perf/util/target.h @@ -46,4 +46,19 @@ enum perf_target_errno perf_target__parse_uid(struct perf_target *target); int perf_target__strerror(struct perf_target *target, int errnum, char *buf, size_t buflen); +static inline bool perf_target__no_task(struct perf_target *target) +{ + return !target->pid && !target->tid && !target->uid_str; +} + +static inline bool perf_target__no_cpu(struct perf_target *target) +{ + return !target->system_wide && !target->cpu_list; +} + +static inline bool perf_target__none(struct perf_target *target) +{ + return perf_target__no_task(target) && perf_target__no_cpu(target); +} + #endif /* _PERF_TARGET_H */ -- cgit v1.2.3-59-g8ed1b From aa22dd4990e38700b1855555aa0def5215859abb Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Wed, 16 May 2012 18:45:47 +0900 Subject: perf target: Rename functions to avoid double negation Rename perf_target__no_{cpu,task} to perf_target__has_{cpu,task} because it's more intuitive and easy to parse (for human beings) when used with negation. The names are came out from David Ahern. It is intended to be a mechanical substitution without any functional change. The perf_target__none remains unchanged since I couldn't find a right name and it is hardly used with negation. Signed-off-by: Namhyung Kim Suggested-by: David Ahern Suggested-by: Ingo Molnar Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1337161549-9870-1-git-send-email-namhyung.kim@lge.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-stat.c | 14 +++++++------- tools/perf/builtin-top.c | 2 +- tools/perf/util/evlist.c | 2 +- tools/perf/util/evsel.c | 2 +- tools/perf/util/target.h | 10 +++++----- 5 files changed, 15 insertions(+), 15 deletions(-) (limited to 'tools/perf/util/evlist.c') diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d0605689bad9..0f4b51ae4be7 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -292,10 +292,10 @@ static int create_perf_stat_counter(struct perf_evsel *evsel, attr->inherit = !no_inherit; - if (!perf_target__no_cpu(&target)) + if (perf_target__has_cpu(&target)) return perf_evsel__open_per_cpu(evsel, evsel_list->cpus, group, group_fd); - if (perf_target__no_task(&target) && (!group || evsel == first)) { + if (!perf_target__has_task(&target) && (!group || evsel == first)) { attr->disabled = 1; attr->enable_on_exec = 1; } @@ -972,7 +972,7 @@ static void print_stat(int argc, const char **argv) if (!csv_output) { fprintf(output, "\n"); fprintf(output, " Performance counter stats for "); - if (perf_target__no_task(&target)) { + if (!perf_target__has_task(&target)) { fprintf(output, "\'%s", argv[0]); for (i = 1; i < argc; i++) fprintf(output, " %s", argv[i]); @@ -1194,13 +1194,13 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) } else if (big_num_opt == 0) /* User passed --no-big-num */ big_num = false; - if (!argc && perf_target__no_task(&target)) + if (!argc && !perf_target__has_task(&target)) usage_with_options(stat_usage, options); if (run_count <= 0) usage_with_options(stat_usage, options); /* no_aggr, cgroup are for system-wide only */ - if ((no_aggr || nr_cgroups) && perf_target__no_cpu(&target)) { + if ((no_aggr || nr_cgroups) && !perf_target__has_cpu(&target)) { fprintf(stderr, "both cgroup and no-aggregation " "modes only available in system-wide mode\n"); @@ -1213,9 +1213,9 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used) perf_target__validate(&target); if (perf_evlist__create_maps(evsel_list, &target) < 0) { - if (!perf_target__no_task(&target)) + if (perf_target__has_task(&target)) pr_err("Problems finding threads of monitor\n"); - if (!perf_target__no_cpu(&target)) + if (perf_target__has_cpu(&target)) perror("failed to parse CPUs map"); usage_with_options(stat_usage, options); diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 4eb6171e143b..553560a8b1be 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1020,7 +1020,7 @@ static int __cmd_top(struct perf_top *top) if (ret) goto out_delete; - if (!perf_target__no_task(&top->target)) + if (perf_target__has_task(&top->target)) perf_event__synthesize_thread_map(&top->tool, top->evlist->threads, perf_event__process, &top->session->host_machine); diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 1201daf71719..80bef281eee0 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -609,7 +609,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, if (evlist->threads == NULL) return -1; - if (!perf_target__no_cpu(target)) + if (perf_target__has_cpu(target)) evlist->cpus = cpu_map__new(target->cpu_list); else evlist->cpus = cpu_map__dummy_new(); diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 21eaab240396..d7a2b4b9801d 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -115,7 +115,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct perf_record_opts *opts, if (!opts->sample_id_all_missing && (opts->sample_time || !opts->no_inherit || - !perf_target__no_cpu(&opts->target))) + perf_target__has_cpu(&opts->target))) attr->sample_type |= PERF_SAMPLE_TIME; if (opts->raw_samples) { diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h index 127cff3f8ced..c43f632955fa 100644 --- a/tools/perf/util/target.h +++ b/tools/perf/util/target.h @@ -46,19 +46,19 @@ enum perf_target_errno perf_target__parse_uid(struct perf_target *target); int perf_target__strerror(struct perf_target *target, int errnum, char *buf, size_t buflen); -static inline bool perf_target__no_task(struct perf_target *target) +static inline bool perf_target__has_task(struct perf_target *target) { - return !target->pid && !target->tid && !target->uid_str; + return target->tid || target->pid || target->uid_str; } -static inline bool perf_target__no_cpu(struct perf_target *target) +static inline bool perf_target__has_cpu(struct perf_target *target) { - return !target->system_wide && !target->cpu_list; + return target->system_wide || target->cpu_list; } static inline bool perf_target__none(struct perf_target *target) { - return perf_target__no_task(target) && perf_target__no_cpu(target); + return !perf_target__has_task(target) && !perf_target__has_cpu(target); } #endif /* _PERF_TARGET_H */ -- cgit v1.2.3-59-g8ed1b From 879d77d0cbe20ad1d6099a1e16f03b72c0649828 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Wed, 16 May 2012 18:45:48 +0900 Subject: Revert 'perf evlist: Fix creation of cpu map' The commit 55261f46702c ("perf evlist: Fix creation of cpu map") changed to create a per-task event when no cpu target is specified. However it caused a problem since perf-task do not allow event inheritance due to scalability issues so that the result will contain samples only from parent, not from its children. So we should use perf-task-per-cpu events anyway to get the right result. Revert it. Reported-by: Linus Torvalds Analysed-by: Ingo Molnar Acked-and-tested-by: Peter Zijlstra Signed-off-by: Namhyung Kim Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1337161549-9870-2-git-send-email-namhyung.kim@lge.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evlist.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/perf/util/evlist.c') diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 80bef281eee0..87889f325678 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -609,10 +609,10 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, if (evlist->threads == NULL) return -1; - if (perf_target__has_cpu(target)) - evlist->cpus = cpu_map__new(target->cpu_list); - else + if (perf_target__has_task(target)) evlist->cpus = cpu_map__dummy_new(); + else + evlist->cpus = cpu_map__new(target->cpu_list); if (evlist->cpus == NULL) goto out_delete_threads; -- cgit v1.2.3-59-g8ed1b From d1cb9fce92c41454bd594fb0920575fc63301878 Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Wed, 16 May 2012 18:45:49 +0900 Subject: perf target: Add uses_mmap field If perf doesn't mmap on event (like perf stat), it should not create per-task-per-cpu events. So just use a dummy cpu map to create a per-task event for this case. Signed-off-by: Namhyung Kim Cc: Ingo Molnar Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1337161549-9870-3-git-send-email-namhyung.kim@lge.com [ committer note: renamed .need_mmap to .uses_mmap ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-record.c | 3 +++ tools/perf/builtin-test.c | 1 + tools/perf/builtin-top.c | 3 +++ tools/perf/util/evlist.c | 2 ++ tools/perf/util/target.h | 1 + 5 files changed, 10 insertions(+) (limited to 'tools/perf/util/evlist.c') diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index d19058a7b84c..8a3dfac161e2 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -754,6 +754,9 @@ static struct perf_record record = { .user_freq = UINT_MAX, .user_interval = ULLONG_MAX, .freq = 1000, + .target = { + .uses_mmap = true, + }, }, .write_mode = WRITE_FORCE, .file_new = true, diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c index 9d9abbbe23be..4eaa665fd32b 100644 --- a/tools/perf/builtin-test.c +++ b/tools/perf/builtin-test.c @@ -1167,6 +1167,7 @@ static int test__PERF_RECORD(void) struct perf_record_opts opts = { .target = { .uid = UINT_MAX, + .uses_mmap = true, }, .no_delay = true, .freq = 10, diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 553560a8b1be..3e981a710c4d 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1162,6 +1162,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __used) .freq = 1000, /* 1 KHz */ .mmap_pages = 128, .sym_pcnt_filter = 5, + .target = { + .uses_mmap = true, + }, }; char callchain_default_opt[] = "fractal,0.5,callee"; const struct option options[] = { diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 87889f325678..4ac5f5ae4ce9 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -611,6 +611,8 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, if (perf_target__has_task(target)) evlist->cpus = cpu_map__dummy_new(); + else if (!perf_target__has_cpu(target) && !target->uses_mmap) + evlist->cpus = cpu_map__dummy_new(); else evlist->cpus = cpu_map__new(target->cpu_list); diff --git a/tools/perf/util/target.h b/tools/perf/util/target.h index c43f632955fa..a4be8575fda5 100644 --- a/tools/perf/util/target.h +++ b/tools/perf/util/target.h @@ -11,6 +11,7 @@ struct perf_target { const char *uid_str; uid_t uid; bool system_wide; + bool uses_mmap; }; enum perf_target_errno { -- cgit v1.2.3-59-g8ed1b From 79695e1bb65ba0e21488c360a1bed6e358354aaa Mon Sep 17 00:00:00 2001 From: Arnaldo Carvalho de Melo Date: Wed, 30 May 2012 13:53:54 -0300 Subject: perf stat: Initialize default events wrt exclude_{guest,host} When no event is specified the tools use perf_evlist__add_default(), that will call event_attr_init to initialize the KVM exclusion bits. When the change was made to the tools so that by default guest samples would be excluded, the changes were made just to the parsing routines and to perf_evlist__add_default(), not to perf_evlist__add_attrs, that is used so far just by perf stat to add multiple events, according to the level of detail specified. Recently the tools were changed to reconstruct the event name from all the details in perf_event_attr, not just from .type and .config, but taking into account all the feature bits (.exclude_{guest,host,user,kernel,etc}, .precise_ip, etc). That is when we noticed that the default for perf stat wasn't the one for the rest of the tools, i.e. the .exclude_guest bit wasn't being set. I.e. the default, that doesn't call event_attr_init was showing the :HG modifier: $ perf stat usleep 1 Performance counter stats for 'usleep 1': 0.942119 task-clock # 0.454 CPUs utilized 1 context-switches # 0.001 M/sec 0 CPU-migrations # 0.000 K/sec 126 page-faults # 0.134 M/sec 693,193 cycles:HG # 0.736 GHz [40.11%] 407,461 stalled-cycles-frontend:HG # 58.78% frontend cycles idle [72.29%] 365,403 stalled-cycles-backend:HG # 52.71% backend cycles idle 465,982 instructions:HG # 0.67 insns per cycle # 0.87 stalled cycles per insn 89,760 branches:HG # 95.275 M/sec 6,178 branch-misses:HG # 6.88% of all branches 0.002077228 seconds time elapsed While if one explicitely specifies the same events, which will make the parsing code to be called and thus event_attr_init is called: $ perf stat -e task-clock,context-switches,migrations,page-faults,cycles,stalled-cycles-frontend,stalled-cycles-backend,instructions,branches,branch-misses usleep 1 Performance counter stats for 'usleep 1': 1.040349 task-clock # 0.500 CPUs utilized 2 context-switches # 0.002 M/sec 0 CPU-migrations # 0.000 K/sec 127 page-faults # 0.122 M/sec 587,966 cycles # 0.565 GHz [13.18%] 459,167 stalled-cycles-frontend # 78.09% frontend cycles idle 390,249 stalled-cycles-backend # 66.37% backend cycles idle 504,006 instructions # 0.86 insns per cycle # 0.91 stalled cycles per insn 96,455 branches # 92.714 M/sec 6,522 branch-misses # 6.76% of all branches [96.12%] 0.002078681 seconds time elapsed Fix it by introducing a perf_evlist__add_default_attrs method that will call evlist_attr_init in all the perf_event_attr entries before adding the events. Reported-by: Ingo Molnar Cc: David Ahern Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Mike Galbraith Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/n/tip-4eysr236r0pgiyum9epwxw7s@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-stat.c | 8 ++++---- tools/perf/util/evlist.c | 11 +++++++++++ tools/perf/util/evlist.h | 4 ++++ 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'tools/perf/util/evlist.c') diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 62ae30d34fa6..262589991ea4 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1129,7 +1129,7 @@ static int add_default_attributes(void) return 0; if (!evsel_list->nr_entries) { - if (perf_evlist__add_attrs_array(evsel_list, default_attrs) < 0) + if (perf_evlist__add_default_attrs(evsel_list, default_attrs) < 0) return -1; } @@ -1139,21 +1139,21 @@ static int add_default_attributes(void) return 0; /* Append detailed run extra attributes: */ - if (perf_evlist__add_attrs_array(evsel_list, detailed_attrs) < 0) + if (perf_evlist__add_default_attrs(evsel_list, detailed_attrs) < 0) return -1; if (detailed_run < 2) return 0; /* Append very detailed run extra attributes: */ - if (perf_evlist__add_attrs_array(evsel_list, very_detailed_attrs) < 0) + if (perf_evlist__add_default_attrs(evsel_list, very_detailed_attrs) < 0) return -1; if (detailed_run < 3) return 0; /* Append very, very detailed run extra attributes: */ - return perf_evlist__add_attrs_array(evsel_list, very_very_detailed_attrs); + return perf_evlist__add_default_attrs(evsel_list, very_very_detailed_attrs); } int cmd_stat(int argc, const char **argv, const char *prefix __used) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 4ac5f5ae4ce9..ed277e5627cf 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -159,6 +159,17 @@ out_delete_partial_list: return -1; } +int __perf_evlist__add_default_attrs(struct perf_evlist *evlist, + struct perf_event_attr *attrs, size_t nr_attrs) +{ + size_t i; + + for (i = 0; i < nr_attrs; i++) + event_attr_init(attrs + i); + + return perf_evlist__add_attrs(evlist, attrs, nr_attrs); +} + static int trace_event__id(const char *evname) { char *filename, *colon; diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 58abb63ac13a..989bee9624c2 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -54,6 +54,8 @@ void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); int perf_evlist__add_default(struct perf_evlist *evlist); int perf_evlist__add_attrs(struct perf_evlist *evlist, struct perf_event_attr *attrs, size_t nr_attrs); +int __perf_evlist__add_default_attrs(struct perf_evlist *evlist, + struct perf_event_attr *attrs, size_t nr_attrs); int perf_evlist__add_tracepoints(struct perf_evlist *evlist, const char *tracepoints[], size_t nr_tracepoints); int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist, @@ -62,6 +64,8 @@ int perf_evlist__set_tracepoints_handlers(struct perf_evlist *evlist, #define perf_evlist__add_attrs_array(evlist, array) \ perf_evlist__add_attrs(evlist, array, ARRAY_SIZE(array)) +#define perf_evlist__add_default_attrs(evlist, array) \ + __perf_evlist__add_default_attrs(evlist, array, ARRAY_SIZE(array)) #define perf_evlist__add_tracepoints_array(evlist, array) \ perf_evlist__add_tracepoints(evlist, array, ARRAY_SIZE(array)) -- cgit v1.2.3-59-g8ed1b From 55da80059de6c7533724fcd95f16c5d5618ecf4d Mon Sep 17 00:00:00 2001 From: Namhyung Kim Date: Thu, 31 May 2012 14:51:46 +0900 Subject: perf evlist: Pass third argument to ioctl explicitly The ioctl on perf event fd wants 3 arguments but we only passed 2. As the only user of the functions is perf record and it calls them for every event (regardless of group setting), just pass 0 for now. Signed-off-by: Namhyung Kim Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1338443506-25009-3-git-send-email-namhyung.kim@lge.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evlist.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tools/perf/util/evlist.c') diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index ed277e5627cf..7400fb3fc50c 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -274,7 +274,8 @@ void perf_evlist__disable(struct perf_evlist *evlist) for (cpu = 0; cpu < evlist->cpus->nr; cpu++) { list_for_each_entry(pos, &evlist->entries, node) { for (thread = 0; thread < evlist->threads->nr; thread++) - ioctl(FD(pos, cpu, thread), PERF_EVENT_IOC_DISABLE); + ioctl(FD(pos, cpu, thread), + PERF_EVENT_IOC_DISABLE, 0); } } } @@ -287,7 +288,8 @@ void perf_evlist__enable(struct perf_evlist *evlist) for (cpu = 0; cpu < evlist->cpus->nr; cpu++) { list_for_each_entry(pos, &evlist->entries, node) { for (thread = 0; thread < evlist->threads->nr; thread++) - ioctl(FD(pos, cpu, thread), PERF_EVENT_IOC_ENABLE); + ioctl(FD(pos, cpu, thread), + PERF_EVENT_IOC_ENABLE, 0); } } } -- cgit v1.2.3-59-g8ed1b