From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753474AbdBNLBk (ORCPT ); Tue, 14 Feb 2017 06:01:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47768 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753433AbdBNLBN (ORCPT ); Tue, 14 Feb 2017 06:01:13 -0500 Date: Tue, 14 Feb 2017 12:01:10 +0100 From: Jiri Olsa To: Jan Stancek Cc: linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, mhiramat@kernel.org Subject: Re: [PATCH v2 2/3] perf: make build_cpu_topology skip offline/absent CPUs Message-ID: <20170214110110.GB18546@krava> References: <8ea4601b5cacc49927235b4ebac424bd6eeccb06.1486999090.git.jstancek@redhat.com> <1e819d91d89ddbd5e526bd216951b167233e74db.1486999090.git.jstancek@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1e819d91d89ddbd5e526bd216951b167233e74db.1486999090.git.jstancek@redhat.com> User-Agent: Mutt/1.7.1 (2016-10-04) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 14 Feb 2017 11:01:13 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 13, 2017 at 04:34:35PM +0100, Jan Stancek wrote: SNIP > This patch makes build_cpu_topology() skip offline/absent CPUs, > by checking their presence against cpu_map built from online CPUs. > > Signed-off-by: Jan Stancek > --- > tools/perf/util/header.c | 21 +++++++++++++++++---- > 1 file changed, 17 insertions(+), 4 deletions(-) > > Changes in v2: > - drop out label, use return NULL where possible > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c > index d89c9c7ef4e5..4b0ea4e92e9d 100644 > --- a/tools/perf/util/header.c > +++ b/tools/perf/util/header.c > @@ -503,24 +503,31 @@ static void free_cpu_topo(struct cpu_topo *tp) > > static struct cpu_topo *build_cpu_topology(void) > { > - struct cpu_topo *tp; > + struct cpu_topo *tp = NULL; > void *addr; > u32 nr, i; > size_t sz; > long ncpus; > - int ret = -1; > + int ret = 0; hum, shoudn't we fail if we dont find any online cpu? jirka > + struct cpu_map *map; > > ncpus = sysconf(_SC_NPROCESSORS_CONF); > if (ncpus < 0) > return NULL; > > + /* build online CPU map */ > + map = cpu_map__new(NULL); > + if (map == NULL) { > + pr_debug("failed to get system cpumap\n"); > + return NULL; > + } > + > nr = (u32)(ncpus & UINT_MAX); > > sz = nr * sizeof(char *); > - > addr = calloc(1, sizeof(*tp) + 2 * sz); > if (!addr) > - return NULL; > + goto out_free; > > tp = addr; > tp->cpu_nr = nr; > @@ -530,10 +537,16 @@ static struct cpu_topo *build_cpu_topology(void) > tp->thread_siblings = addr; > > for (i = 0; i < nr; i++) { > + if (!cpu_map__has(map, i)) > + continue; > + > ret = build_cpu_topo(tp, i); > if (ret < 0) > break; > } > + > +out_free: > + cpu_map__put(map); > if (ret) { > free_cpu_topo(tp); > tp = NULL; > -- > 1.8.3.1 >