diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/builtin-record.c | 15 | ||||
-rw-r--r-- | tools/perf/util/cpumap.c | 10 | ||||
-rw-r--r-- | tools/perf/util/cpumap.h | 1 | ||||
-rw-r--r-- | tools/perf/util/mmap.c | 28 |
4 files changed, 53 insertions, 1 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 7ced5f3e8100..3fdfbaebd95e 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include "util/bpf-loader.h" | 38 | #include "util/bpf-loader.h" |
39 | #include "util/trigger.h" | 39 | #include "util/trigger.h" |
40 | #include "util/perf-hooks.h" | 40 | #include "util/perf-hooks.h" |
41 | #include "util/cpu-set-sched.h" | ||
41 | #include "util/time-utils.h" | 42 | #include "util/time-utils.h" |
42 | #include "util/units.h" | 43 | #include "util/units.h" |
43 | #include "util/bpf-event.h" | 44 | #include "util/bpf-event.h" |
@@ -536,6 +537,9 @@ static int record__mmap_evlist(struct record *rec, | |||
536 | struct record_opts *opts = &rec->opts; | 537 | struct record_opts *opts = &rec->opts; |
537 | char msg[512]; | 538 | char msg[512]; |
538 | 539 | ||
540 | if (opts->affinity != PERF_AFFINITY_SYS) | ||
541 | cpu__setup_cpunode_map(); | ||
542 | |||
539 | if (perf_evlist__mmap_ex(evlist, opts->mmap_pages, | 543 | if (perf_evlist__mmap_ex(evlist, opts->mmap_pages, |
540 | opts->auxtrace_mmap_pages, | 544 | opts->auxtrace_mmap_pages, |
541 | opts->auxtrace_snapshot_mode, | 545 | opts->auxtrace_snapshot_mode, |
@@ -719,6 +723,16 @@ static struct perf_event_header finished_round_event = { | |||
719 | .type = PERF_RECORD_FINISHED_ROUND, | 723 | .type = PERF_RECORD_FINISHED_ROUND, |
720 | }; | 724 | }; |
721 | 725 | ||
726 | static void record__adjust_affinity(struct record *rec, struct perf_mmap *map) | ||
727 | { | ||
728 | if (rec->opts.affinity != PERF_AFFINITY_SYS && | ||
729 | !CPU_EQUAL(&rec->affinity_mask, &map->affinity_mask)) { | ||
730 | CPU_ZERO(&rec->affinity_mask); | ||
731 | CPU_OR(&rec->affinity_mask, &rec->affinity_mask, &map->affinity_mask); | ||
732 | sched_setaffinity(0, sizeof(rec->affinity_mask), &rec->affinity_mask); | ||
733 | } | ||
734 | } | ||
735 | |||
722 | static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evlist, | 736 | static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evlist, |
723 | bool overwrite) | 737 | bool overwrite) |
724 | { | 738 | { |
@@ -746,6 +760,7 @@ static int record__mmap_read_evlist(struct record *rec, struct perf_evlist *evli | |||
746 | struct perf_mmap *map = &maps[i]; | 760 | struct perf_mmap *map = &maps[i]; |
747 | 761 | ||
748 | if (map->base) { | 762 | if (map->base) { |
763 | record__adjust_affinity(rec, map); | ||
749 | if (!record__aio_enabled(rec)) { | 764 | if (!record__aio_enabled(rec)) { |
750 | if (perf_mmap__push(map, rec, record__pushfn) != 0) { | 765 | if (perf_mmap__push(map, rec, record__pushfn) != 0) { |
751 | rc = -1; | 766 | rc = -1; |
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 383674f448fc..0bbc3feb0894 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c | |||
@@ -730,3 +730,13 @@ size_t cpu_map__snprint_mask(struct cpu_map *map, char *buf, size_t size) | |||
730 | buf[size - 1] = '\0'; | 730 | buf[size - 1] = '\0'; |
731 | return ptr - buf; | 731 | return ptr - buf; |
732 | } | 732 | } |
733 | |||
734 | const struct cpu_map *cpu_map__online(void) /* thread unsafe */ | ||
735 | { | ||
736 | static const struct cpu_map *online = NULL; | ||
737 | |||
738 | if (!online) | ||
739 | online = cpu_map__new(NULL); /* from /sys/devices/system/cpu/online */ | ||
740 | |||
741 | return online; | ||
742 | } | ||
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index ed8999d1a640..f00ce624b9f7 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h | |||
@@ -29,6 +29,7 @@ int cpu_map__get_core_id(int cpu); | |||
29 | int cpu_map__get_core(struct cpu_map *map, int idx, void *data); | 29 | int cpu_map__get_core(struct cpu_map *map, int idx, void *data); |
30 | int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp); | 30 | int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp); |
31 | int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep); | 31 | int cpu_map__build_core_map(struct cpu_map *cpus, struct cpu_map **corep); |
32 | const struct cpu_map *cpu_map__online(void); /* thread unsafe */ | ||
32 | 33 | ||
33 | struct cpu_map *cpu_map__get(struct cpu_map *map); | 34 | struct cpu_map *cpu_map__get(struct cpu_map *map); |
34 | void cpu_map__put(struct cpu_map *map); | 35 | void cpu_map__put(struct cpu_map *map); |
diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index d882f43148c3..cdc7740fc181 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c | |||
@@ -383,6 +383,32 @@ void perf_mmap__munmap(struct perf_mmap *map) | |||
383 | auxtrace_mmap__munmap(&map->auxtrace_mmap); | 383 | auxtrace_mmap__munmap(&map->auxtrace_mmap); |
384 | } | 384 | } |
385 | 385 | ||
386 | static void build_node_mask(int node, cpu_set_t *mask) | ||
387 | { | ||
388 | int c, cpu, nr_cpus; | ||
389 | const struct cpu_map *cpu_map = NULL; | ||
390 | |||
391 | cpu_map = cpu_map__online(); | ||
392 | if (!cpu_map) | ||
393 | return; | ||
394 | |||
395 | nr_cpus = cpu_map__nr(cpu_map); | ||
396 | for (c = 0; c < nr_cpus; c++) { | ||
397 | cpu = cpu_map->map[c]; /* map c index to online cpu index */ | ||
398 | if (cpu__get_node(cpu) == node) | ||
399 | CPU_SET(cpu, mask); | ||
400 | } | ||
401 | } | ||
402 | |||
403 | static void perf_mmap__setup_affinity_mask(struct perf_mmap *map, struct mmap_params *mp) | ||
404 | { | ||
405 | CPU_ZERO(&map->affinity_mask); | ||
406 | if (mp->affinity == PERF_AFFINITY_NODE && cpu__max_node() > 1) | ||
407 | build_node_mask(cpu__get_node(map->cpu), &map->affinity_mask); | ||
408 | else if (mp->affinity == PERF_AFFINITY_CPU) | ||
409 | CPU_SET(map->cpu, &map->affinity_mask); | ||
410 | } | ||
411 | |||
386 | int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int cpu) | 412 | int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int cpu) |
387 | { | 413 | { |
388 | /* | 414 | /* |
@@ -412,7 +438,7 @@ int perf_mmap__mmap(struct perf_mmap *map, struct mmap_params *mp, int fd, int c | |||
412 | map->fd = fd; | 438 | map->fd = fd; |
413 | map->cpu = cpu; | 439 | map->cpu = cpu; |
414 | 440 | ||
415 | CPU_ZERO(&map->affinity_mask); | 441 | perf_mmap__setup_affinity_mask(map, mp); |
416 | 442 | ||
417 | if (auxtrace_mmap__mmap(&map->auxtrace_mmap, | 443 | if (auxtrace_mmap__mmap(&map->auxtrace_mmap, |
418 | &mp->auxtrace_mp, map->base, fd)) | 444 | &mp->auxtrace_mp, map->base, fd)) |