perf record: Make per-cpu mmaps the default.
authorAdrian Hunter <adrian.hunter@intel.com>
Fri, 15 Nov 2013 13:52:29 +0000 (15:52 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 27 Nov 2013 17:58:36 +0000 (14:58 -0300)
This affects the -p, -t and -u options that previously defaulted to
per-thread mmaps.

Consequently add an option to select per-thread mmaps to support the old
behaviour.

Note that per-thread can be used with a workload-only (i.e. none of -p,
-t, -u, -a or -C is selected) to get a per-thread mmap with no
inheritance.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/5286271D.3020808@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-record.txt
tools/perf/builtin-record.c
tools/perf/tests/attr/test-record-no-inherit
tools/perf/util/evlist.c
tools/perf/util/evsel.c
tools/perf/util/target.c
tools/perf/util/target.h

index 43b42c4f4a915ad96be76c737b63feee12925de2..6ac867e7667f4251875ac0fc90e60b16b5f2fbd6 100644 (file)
@@ -201,11 +201,11 @@ abort events and some memory events in precise mode on modern Intel CPUs.
 --transaction::
 Record transaction flags for transaction related events.
 
---force-per-cpu::
-Force the use of per-cpu mmaps.  By default, when tasks are specified (i.e. -p,
--t or -u options) per-thread mmaps are created.  This option overrides that and
-forces per-cpu mmaps.  A side-effect of that is that inheritance is
-automatically enabled.  Add the -i option also to disable inheritance.
+--per-thread::
+Use per-thread mmaps.  By default per-cpu mmaps are created.  This option
+overrides that and uses per-thread mmaps.  A side-effect of that is that
+inheritance is automatically disabled.  --per-thread is ignored with a warning
+if combined with -a or -C options.
 
 SEE ALSO
 --------
index 7c8020a32784abcd6d44223dc3a5586f7ba7f3f0..f5b18b8fe8c98020e0d90506fd12fb31be4cfbc1 100644 (file)
@@ -800,6 +800,7 @@ static struct perf_record record = {
                .freq                = 4000,
                .target              = {
                        .uses_mmap   = true,
+                       .default_per_cpu = true,
                },
        },
 };
@@ -888,8 +889,8 @@ const struct option record_options[] = {
                    "sample by weight (on special events only)"),
        OPT_BOOLEAN(0, "transaction", &record.opts.sample_transaction,
                    "sample transaction flags (special events only)"),
-       OPT_BOOLEAN(0, "force-per-cpu", &record.opts.target.force_per_cpu,
-                   "force the use of per-cpu mmaps"),
+       OPT_BOOLEAN(0, "per-thread", &record.opts.target.per_thread,
+                   "use per-thread mmaps"),
        OPT_END()
 };
 
index 9079a25cd643cdabaf570d19131e4cc0e4fef7f6..44edcb2edcd50b7c4696477e88f6e12176555303 100644 (file)
@@ -3,5 +3,5 @@ command = record
 args    = -i kill >/dev/null 2>&1
 
 [event:base-record]
-sample_type=259
+sample_type=263
 inherit=0
index bbc746aa571663d92e989bb5f3f2703c31c9a193..76fa76431329f9b252d15e1b49b43e18d05c6c0a 100644 (file)
@@ -819,8 +819,10 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
        if (evlist->threads == NULL)
                return -1;
 
-       if (target->force_per_cpu)
-               evlist->cpus = cpu_map__new(target->cpu_list);
+       if (target->default_per_cpu)
+               evlist->cpus = target->per_thread ?
+                                       cpu_map__dummy_new() :
+                                       cpu_map__new(target->cpu_list);
        else if (target__has_task(target))
                evlist->cpus = cpu_map__dummy_new();
        else if (!target__has_cpu(target) && !target->uses_mmap)
index dad64926170f492d4dbb21630ea3d57070182d2d..b5fe7f9b2e15091f5d38db1044159177d9c15f27 100644 (file)
@@ -574,6 +574,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
        struct perf_evsel *leader = evsel->leader;
        struct perf_event_attr *attr = &evsel->attr;
        int track = !evsel->idx; /* only the first counter needs these */
+       bool per_cpu = opts->target.default_per_cpu && !opts->target.per_thread;
 
        attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1;
        attr->inherit       = !opts->no_inherit;
@@ -647,7 +648,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
                }
        }
 
-       if (target__has_cpu(&opts->target) || opts->target.force_per_cpu)
+       if (target__has_cpu(&opts->target))
                perf_evsel__set_sample_bit(evsel, CPU);
 
        if (opts->period)
@@ -655,7 +656,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 
        if (!perf_missing_features.sample_id_all &&
            (opts->sample_time || !opts->no_inherit ||
-            target__has_cpu(&opts->target) || opts->target.force_per_cpu))
+            target__has_cpu(&opts->target) || per_cpu))
                perf_evsel__set_sample_bit(evsel, TIME);
 
        if (opts->raw_samples) {
index 3c778a07b7cc78de8d92ec188e9bb446c40798bd..e74c5963dc7a9db7038e4ad3f5f7de1ed490f20f 100644 (file)
@@ -55,6 +55,13 @@ enum target_errno target__validate(struct target *target)
                        ret = TARGET_ERRNO__UID_OVERRIDE_SYSTEM;
        }
 
+       /* THREAD and SYSTEM/CPU are mutually exclusive */
+       if (target->per_thread && (target->system_wide || target->cpu_list)) {
+               target->per_thread = false;
+               if (ret == TARGET_ERRNO__SUCCESS)
+                       ret = TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD;
+       }
+
        return ret;
 }
 
@@ -100,6 +107,7 @@ static const char *target__error_str[] = {
        "UID switch overriding CPU",
        "PID/TID switch overriding SYSTEM",
        "UID switch overriding SYSTEM",
+       "SYSTEM/CPU switch overriding PER-THREAD",
        "Invalid User: %s",
        "Problems obtaining information for user %s",
 };
@@ -131,7 +139,8 @@ int target__strerror(struct target *target, int errnum,
        msg = target__error_str[idx];
 
        switch (errnum) {
-       case TARGET_ERRNO__PID_OVERRIDE_CPU ... TARGET_ERRNO__UID_OVERRIDE_SYSTEM:
+       case TARGET_ERRNO__PID_OVERRIDE_CPU ...
+            TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD:
                snprintf(buf, buflen, "%s", msg);
                break;
 
index 2d0c506908926f6fce822adc45a39e76911edd10..31dd2e9a27d043fd0609bfed57ea6a0f9076c6d9 100644 (file)
@@ -12,7 +12,8 @@ struct target {
        uid_t        uid;
        bool         system_wide;
        bool         uses_mmap;
-       bool         force_per_cpu;
+       bool         default_per_cpu;
+       bool         per_thread;
 };
 
 enum target_errno {
@@ -33,6 +34,7 @@ enum target_errno {
        TARGET_ERRNO__UID_OVERRIDE_CPU,
        TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
        TARGET_ERRNO__UID_OVERRIDE_SYSTEM,
+       TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD,
 
        /* for target__parse_uid() */
        TARGET_ERRNO__INVALID_UID,