From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933506AbdBPUDq (ORCPT ); Thu, 16 Feb 2017 15:03:46 -0500 Received: from terminus.zytor.com ([65.50.211.136]:49078 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933083AbdBPUDp (ORCPT ); Thu, 16 Feb 2017 15:03:45 -0500 Date: Thu, 16 Feb 2017 12:03:29 -0800 From: tip-bot for Arnaldo Carvalho de Melo Message-ID: Cc: dsahern@gmail.com, namhyung@kernel.org, wangnan0@huawei.com, jolsa@kernel.org, mingo@kernel.org, adrian.hunter@intel.com, tglx@linutronix.de, hpa@zytor.com, acme@redhat.com, linux-kernel@vger.kernel.org Reply-To: namhyung@kernel.org, dsahern@gmail.com, wangnan0@huawei.com, jolsa@kernel.org, mingo@kernel.org, acme@redhat.com, linux-kernel@vger.kernel.org, adrian.hunter@intel.com, tglx@linutronix.de, hpa@zytor.com To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf evsel: Do not put a variable sized type not at the end of a struct Git-Commit-ID: c24ae6d96112b10ef703a58d7d74583716d2ce69 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: c24ae6d96112b10ef703a58d7d74583716d2ce69 Gitweb: http://git.kernel.org/tip/c24ae6d96112b10ef703a58d7d74583716d2ce69 Author: Arnaldo Carvalho de Melo AuthorDate: Tue, 14 Feb 2017 10:59:04 -0300 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 14 Feb 2017 15:56:54 -0300 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 Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: http://lkml.kernel.org/n/tip-207juvrqjiar7uvas2s83v5i@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/evsel.c | 62 ++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index cd2fb42..ac59710 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, return true; } -static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, - struct thread_map *threads) +int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, + struct thread_map *threads) { int cpu, thread, nthreads; unsigned long flags = PERF_FLAG_FD_CLOEXEC; @@ -1459,6 +1459,30 @@ static int __perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, if (perf_missing_features.write_backward && evsel->attr.write_backward) return -EINVAL; + if (cpus == NULL) { + static struct cpu_map *empty_cpu_map; + + if (empty_cpu_map == NULL) { + empty_cpu_map = cpu_map__dummy_new(); + if (empty_cpu_map == NULL) + return -ENOMEM; + } + + cpus = empty_cpu_map; + } + + if (threads == NULL) { + static struct thread_map *empty_thread_map; + + if (empty_thread_map == NULL) { + empty_thread_map = thread_map__new_by_tid(-1); + if (empty_thread_map == NULL) + return -ENOMEM; + } + + threads = empty_thread_map; + } + if (evsel->system_wide) nthreads = 1; else @@ -1655,46 +1679,16 @@ void perf_evsel__close(struct perf_evsel *evsel, int ncpus, int nthreads) perf_evsel__free_fd(evsel); } -static struct { - struct cpu_map map; - int cpus[1]; -} empty_cpu_map = { - .map.nr = 1, - .cpus = { -1, }, -}; - -static struct { - struct thread_map map; - int threads[1]; -} empty_thread_map = { - .map.nr = 1, - .threads = { -1, }, -}; - -int perf_evsel__open(struct perf_evsel *evsel, struct cpu_map *cpus, - struct thread_map *threads) -{ - if (cpus == NULL) { - /* Work around old compiler warnings about strict aliasing */ - cpus = &empty_cpu_map.map; - } - - if (threads == NULL) - threads = &empty_thread_map.map; - - return __perf_evsel__open(evsel, cpus, threads); -} - int perf_evsel__open_per_cpu(struct perf_evsel *evsel, struct cpu_map *cpus) { - return __perf_evsel__open(evsel, cpus, &empty_thread_map.map); + return perf_evsel__open(evsel, cpus, NULL); } int perf_evsel__open_per_thread(struct perf_evsel *evsel, struct thread_map *threads) { - return __perf_evsel__open(evsel, &empty_cpu_map.map, threads); + return perf_evsel__open(evsel, NULL, threads); } static int perf_evsel__parse_id_sample(const struct perf_evsel *evsel,