diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-02-14 08:59:04 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-02-14 13:56:54 -0500 |
commit | c24ae6d96112b10ef703a58d7d74583716d2ce69 (patch) | |
tree | cb96268f56ef91a5616ddfe70cda1da998cfac11 /tools/perf | |
parent | 8a2efd6dd586ef0ff532180e6335ec21310c2cd5 (diff) |
perf evsel: Do not put a variable sized type not at the end of a struct
As this is a GNU extension and while harmless in this case, we can do
the same thing in a more clearer way by using a existing thread_map and
cpu_map constructors:
With this we avoid this while compiling with clang:
util/evsel.c:1659:17: error: field 'map' with variable sized type 'struct cpu_map' not at the end of a struct or class is a GNU extension
[-Werror,-Wgnu-variable-sized-type-not-at-end]
struct cpu_map map;
^
util/evsel.c:1667:20: error: field 'map' with variable sized type 'struct thread_map' not at the end of a struct or class is a GNU extension
[-Werror,-Wgnu-variable-sized-type-not-at-end]
struct thread_map map;
^
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-207juvrqjiar7uvas2s83v5i@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/evsel.c | 62 |
1 files changed, 28 insertions, 34 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index cd2fb42e5dd4..ac59710b79e0 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -1448,8 +1448,8 @@ static bool ignore_missing_thread(struct perf_evsel *evsel, | |||
1448 | return true; | 1448 | return true; |
1449 | } | 1449 | } |
1450 | 1450 | ||
1451 | static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, | 1451 | int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, |
1452 | struct thread_map *threads) | 1452 | struct thread_map *threads) |
1453 | { | 1453 | { |
1454 | int cpu, thread, nthreads; | 1454 | int cpu, thread, nthreads; |
1455 | unsigned long flags = PERF_FLAG_FD_CLOEXEC; | 1455 | unsigned long flags = PERF_FLAG_FD_CLOEXEC; |
@@ -1459,6 +1459,30 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, | |||
1459 | if (perf_missing_features.write_backward && evsel->attr.write_backward) | 1459 | if (perf_missing_features.write_backward && evsel->attr.write_backward) |
1460 | return -EINVAL; | 1460 | return -EINVAL; |
1461 | 1461 | ||
1462 | if (cpus == NULL) { | ||
1463 | static struct cpu_map *empty_cpu_map; | ||
1464 | |||
1465 | if (empty_cpu_map == NULL) { | ||
1466 | empty_cpu_map = cpu_map__dummy_new(); | ||
1467 | if (empty_cpu_map == NULL) | ||
1468 | return -ENOMEM; | ||
1469 | } | ||
1470 | |||
1471 | cpus = empty_cpu_map; | ||
1472 | } | ||
1473 | |||
1474 | if (threads == NULL) { | ||
1475 | static struct thread_map *empty_thread_map; | ||
1476 | |||
1477 | if (empty_thread_map == NULL) { | ||
1478 | empty_thread_map = thread_map__new_by_tid(-1); | ||
1479 | if (empty_thread_map == NULL) | ||
1480 | return -ENOMEM; | ||
1481 | } | ||
1482 | |||
1483 | threads = empty_thread_map; | ||
1484 | } | ||
1485 | |||
1462 | if (evsel->system_wide) | 1486 | if (evsel->system_wide) |
1463 | nthreads = 1; | 1487 | nthreads = 1; |
1464 | else | 1488 | else |
@@ -1655,46 +1679,16 @@ void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads) | |||
1655 | perf_evsel__free_fd(evsel); | 1679 | perf_evsel__free_fd(evsel); |
1656 | } | 1680 | } |
1657 | 1681 | ||
1658 | static struct { | ||
1659 | struct cpu_map map; | ||
1660 | int cpus[1]; | ||
1661 | } empty_cpu_map = { | ||
1662 | .map.nr = 1, | ||
1663 | .cpus = { -1, }, | ||
1664 | }; | ||
1665 | |||
1666 | static struct { | ||
1667 | struct thread_map map; | ||
1668 | int threads[1]; | ||
1669 | } empty_thread_map = { | ||
1670 | .map.nr = 1, | ||
1671 | .threads = { -1, }, | ||
1672 | }; | ||
1673 | |||
1674 | int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, | ||
1675 | struct thread_map *threads) | ||
1676 | { | ||
1677 | if (cpus == NULL) { | ||
1678 | /* Work around old compiler warnings about strict aliasing */ | ||
1679 | cpus = &empty_cpu_map.map; | ||
1680 | } | ||
1681 | |||
1682 | if (threads == NULL) | ||
1683 | threads = &empty_thread_map.map; | ||
1684 | |||
1685 | return __perf_evsel__open(evsel, cpus, threads); | ||
1686 | } | ||
1687 | |||
1688 | int perf_evsel__open_per_cpu(struct perf_evsel *evsel, | 1682 | int perf_evsel__open_per_cpu(struct perf_evsel *evsel, |
1689 | struct cpu_map *cpus) | 1683 | struct cpu_map *cpus) |
1690 | { | 1684 | { |
1691 | return __perf_evsel__open(evsel, cpus, &empty_thread_map.map); | 1685 | return perf_evsel__open(evsel, cpus, NULL); |
1692 | } | 1686 | } |
1693 | 1687 | ||
1694 | int perf_evsel__open_per_thread(struct perf_evsel *evsel, | 1688 | int perf_evsel__open_per_thread(struct perf_evsel *evsel, |
1695 | struct thread_map *threads) | 1689 | struct thread_map *threads) |
1696 | { | 1690 | { |
1697 | return __perf_evsel__open(evsel, &empty_cpu_map.map, threads); | 1691 | return perf_evsel__open(evsel, NULL, threads); |
1698 | } | 1692 | } |
1699 | 1693 | ||
1700 | static int perf_evsel__parse_id_sample(const struct perf_evsel *evsel, | 1694 | static int perf_evsel__parse_id_sample(const struct perf_evsel *evsel, |