Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp658068ybe; Mon, 2 Sep 2019 07:18:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyzK7nJJ6gEI12Y4GUr+E4M6WEAHq/BsTY3AtpcigMZWgGkH1R24c5hjnS9ZcSAO4tTkQdh X-Received: by 2002:a17:902:1024:: with SMTP id b33mr30675154pla.325.1567433894383; Mon, 02 Sep 2019 07:18:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567433894; cv=none; d=google.com; s=arc-20160816; b=APRGGShDujLSVfktSGiTEO7WBV4PzUGEdEJryrK9LV7mInEJujPSdXM1sFpBZ9Cae6 +U8kfnPMeZkue+aEpdzdUelnb7UEsWlW5Dmw4B+DYYHMxjvGlHjvce5z5nwHMx5HKaqL Z9pBBeQKFVsHBfgVgjl0xiJ4w/ypWafFKmYiHQyxb3SXext6+1foMHx4jTyqxyMFEVtC s32I1BjtXbGo33LJAbYmoKaibTb8SAazqOI3CzQGAXxC0XUZGh6zzM3I4XeDK0gYIQgQ TI8JzuHqvuVLhqaXbeZ5/8dw7Z7xHLyR28re2iHaZSsVRqnO2ibbzAUQKNNhUB8+dG0b dx/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=93Wi9Xa8oqNJSvyMDAeVQzCvTG0arjiI+BInCOPpbno=; b=XKhWyQPy+kUWdutt7H6UULJdaMVHGk70bC2tohtGE+Ak0eg+KFnP493c9ZgKVvy8o+ Du0r7TG0U5x1RV/WkV8zj9NCnuceprjhWTFl4mNu/4wXQoa/rXhG0MdOrBzYc+OyodYR pQsXOztmgEsZKlNn8G+taXhsba0sg0hDXvJXl2GCt/HpIk7y2vXFX+uN+Q5AMAXEQFzy oalraLVBZbXcySUJLHyP18+E9K0M6UYKwpmETyMxJ8rWp+sKz9BYWq9re1oz/488yF0X UhwsSw+32/APTczcXJZTU8u3TzyhipA2VadnJ2RKXAjr+5/K04bkdb4aSezsVFxwhFaC XDBQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j33si7485519pgi.181.2019.09.02.07.17.58; Mon, 02 Sep 2019 07:18:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731141AbfIBOQu (ORCPT + 99 others); Mon, 2 Sep 2019 10:16:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35320 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726438AbfIBOQu (ORCPT ); Mon, 2 Sep 2019 10:16:50 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0ECEB3084288; Mon, 2 Sep 2019 14:16:50 +0000 (UTC) Received: from krava (unknown [10.43.17.103]) by smtp.corp.redhat.com (Postfix) with SMTP id DA1975D6A7; Mon, 2 Sep 2019 14:16:47 +0000 (UTC) Date: Mon, 2 Sep 2019 16:16:47 +0200 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Joe Mario , Kan Liang , Andi Kleen Subject: Re: [PATCH 2/3] perf tools: Add perf_env__numa_node function Message-ID: <20190902141647.GC19702@krava> References: <20190902121255.536-1-jolsa@kernel.org> <20190902121255.536-3-jolsa@kernel.org> <20190902135710.GB8396@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190902135710.GB8396@kernel.org> User-Agent: Mutt/1.12.1 (2019-06-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 02 Sep 2019 14:16:50 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 02, 2019 at 10:57:10AM -0300, Arnaldo Carvalho de Melo wrote: > Em Mon, Sep 02, 2019 at 02:12:54PM +0200, Jiri Olsa escreveu: > > To speed up cpu to node lookup, adding perf_env__numa_node > > function, that creates cpu array on the first lookup, that > > holds numa nodes for each stored cpu. > > > > Link: http://lkml.kernel.org/n/tip-qqwxklhissf3yjyuaszh6480@git.kernel.org > > Signed-off-by: Jiri Olsa > > --- > > tools/perf/util/env.c | 35 +++++++++++++++++++++++++++++++++++ > > tools/perf/util/env.h | 6 ++++++ > > 2 files changed, 41 insertions(+) > > > > diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c > > index 3baca06786fb..6385961e45df 100644 > > --- a/tools/perf/util/env.c > > +++ b/tools/perf/util/env.c > > @@ -179,6 +179,7 @@ void perf_env__exit(struct perf_env *env) > > zfree(&env->sibling_threads); > > zfree(&env->pmu_mappings); > > zfree(&env->cpu); > > + zfree(&env->numa_map); > > > > for (i = 0; i < env->nr_numa_nodes; i++) > > perf_cpu_map__put(env->numa_nodes[i].map); > > @@ -338,3 +339,37 @@ const char *perf_env__arch(struct perf_env *env) > > > > return normalize_arch(arch_name); > > } > > + > > + > > +int perf_env__numa_node(struct perf_env *env, int cpu) > > +{ > > + if (!env->nr_numa_map) { > > + struct numa_node *nn; > > + int i, nr = 0; > > + > > + for (i = 0; i < env->nr_numa_nodes; i++) { > > + nn = &env->numa_nodes[i]; > > + nr = max(nr, perf_cpu_map__max(nn->map)); > > + } > > + > > + nr++; > > + env->numa_map = zalloc(nr * sizeof(int)); > > Why do you use zalloc()... > > > + if (!env->numa_map) > > + return -1; > > Only to right after allocating it set all entries to -1? > > That zalloc() should be downgraded to a plain malloc(), right? > > The setting to -1 is because we may have holes in the array, right? I > think this deserves a comment here as well. yea, I added that later on and missed the zalloc above ;-) I'll send new version thanks, jirka