perf record: Allocate affinity masks
authorAlexey Budankov <alexey.budankov@linux.intel.com>
Tue, 22 Jan 2019 17:47:43 +0000 (20:47 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 6 Feb 2019 13:00:39 +0000 (10:00 -0300)
Allocate affinity option and masks for mmap data buffers and record
thread as well as initialize allocated objects.

Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/526fa2b0-07de-6dbd-a7e9-26ba875593c9@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-record.c
tools/perf/perf.h
tools/perf/util/evlist.c
tools/perf/util/evlist.h
tools/perf/util/mmap.c
tools/perf/util/mmap.h

index 56e9d9e8c174bedd49d6e4564af94b3c19f53ce1..7ced5f3e81006bc93a56821b67738705347129a0 100644 (file)
@@ -81,12 +81,17 @@ struct record {
        bool                    timestamp_boundary;
        struct switch_output    switch_output;
        unsigned long long      samples;
+       cpu_set_t               affinity_mask;
 };
 
 static volatile int auxtrace_record__snapshot_started;
 static DEFINE_TRIGGER(auxtrace_snapshot_trigger);
 static DEFINE_TRIGGER(switch_output_trigger);
 
+static const char *affinity_tags[PERF_AFFINITY_MAX] = {
+       "SYS", "NODE", "CPU"
+};
+
 static bool switch_output_signal(struct record *rec)
 {
        return rec->switch_output.signal &&
@@ -533,7 +538,8 @@ static int record__mmap_evlist(struct record *rec,
 
        if (perf_evlist__mmap_ex(evlist, opts->mmap_pages,
                                 opts->auxtrace_mmap_pages,
-                                opts->auxtrace_snapshot_mode, opts->nr_cblocks) < 0) {
+                                opts->auxtrace_snapshot_mode,
+                                opts->nr_cblocks, opts->affinity) < 0) {
                if (errno == EPERM) {
                        pr_err("Permission error mapping pages.\n"
                               "Consider increasing "
@@ -1977,6 +1983,9 @@ int cmd_record(int argc, const char **argv)
 # undef REASON
 #endif
 
+       CPU_ZERO(&rec->affinity_mask);
+       rec->opts.affinity = PERF_AFFINITY_SYS;
+
        rec->evlist = perf_evlist__new();
        if (rec->evlist == NULL)
                return -ENOMEM;
@@ -2140,6 +2149,8 @@ int cmd_record(int argc, const char **argv)
        if (verbose > 0)
                pr_info("nr_cblocks: %d\n", rec->opts.nr_cblocks);
 
+       pr_debug("affinity: %s\n", affinity_tags[rec->opts.affinity]);
+
        err = __cmd_record(&record, argc, argv);
 out:
        perf_evlist__delete(rec->evlist);
index 5941fb6eccfcd3bc528fa7de618ace9aa5ae88e8..b120e547ddc7b7fd9b4a03c8723a797f010b9511 100644 (file)
@@ -84,6 +84,14 @@ struct record_opts {
        clockid_t    clockid;
        u64          clockid_res_ns;
        int          nr_cblocks;
+       int          affinity;
+};
+
+enum perf_affinity {
+       PERF_AFFINITY_SYS = 0,
+       PERF_AFFINITY_NODE,
+       PERF_AFFINITY_CPU,
+       PERF_AFFINITY_MAX
 };
 
 struct option;
index 8c902276d4b4ceab5c205ae6ab9a60fa69680bb2..08cedb643ea6ec3d7ec8255895bdc45ec9880f68 100644 (file)
@@ -1022,7 +1022,7 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
  */
 int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
                         unsigned int auxtrace_pages,
-                        bool auxtrace_overwrite, int nr_cblocks)
+                        bool auxtrace_overwrite, int nr_cblocks, int affinity)
 {
        struct perf_evsel *evsel;
        const struct cpu_map *cpus = evlist->cpus;
@@ -1032,7 +1032,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
         * Its value is decided by evsel's write_backward.
         * So &mp should not be passed through const pointer.
         */
-       struct mmap_params mp = { .nr_cblocks = nr_cblocks };
+       struct mmap_params mp = { .nr_cblocks = nr_cblocks, .affinity = affinity };
 
        if (!evlist->mmap)
                evlist->mmap = perf_evlist__alloc_mmap(evlist, false);
@@ -1064,7 +1064,7 @@ int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
 
 int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages)
 {
-       return perf_evlist__mmap_ex(evlist, pages, 0, false, 0);
+       return perf_evlist__mmap_ex(evlist, pages, 0, false, 0, PERF_AFFINITY_SYS);
 }
 
 int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
index 00ab43c6dd157d5654796d6704ab786c3d18b699..744906dd488732a46801fcc50588a32c190b7a45 100644 (file)
@@ -165,7 +165,7 @@ unsigned long perf_event_mlock_kb_in_pages(void);
 
 int perf_evlist__mmap_ex(struct perf_evlist *evlist, unsigned int pages,
                         unsigned int auxtrace_pages,
-                        bool auxtrace_overwrite, int nr_cblocks);
+                        bool auxtrace_overwrite, int nr_cblocks, int affinity);
 int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages);
 void perf_evlist__munmap(struct perf_evlist *evlist);
 
index 8fc39311a30dc8e480f36ba933e57b8150b6af77..e68ba754a8e2138792c1d466a0a09adf7e7980fd 100644 (file)
@@ -343,6 +343,8 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int c
        map->fd = fd;
        map->cpu = cpu;
 
+       CPU_ZERO(&map->affinity_mask);
+
        if (auxtrace_mmap__mmap(&map->auxtrace_mmap,
                                &mp->auxtrace_mp, map->base, fd))
                return -1;
index aeb6942fdb00ca8daccb0f5a6acc34fea72fb2b1..e566c19b242b61d4490e2899f11ac38ac971ce5b 100644 (file)
@@ -38,6 +38,7 @@ struct perf_mmap {
                int              nr_cblocks;
        } aio;
 #endif
+       cpu_set_t       affinity_mask;
 };
 
 /*
@@ -69,7 +70,7 @@ enum bkw_mmap_state {
 };
 
 struct mmap_params {
-       int                         prot, mask, nr_cblocks;
+       int                         prot, mask, nr_cblocks, affinity;
        struct auxtrace_mmap_params auxtrace_mp;
 };