Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp630088ybe; Mon, 2 Sep 2019 06:58:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzjphp/bQIzmceqW3xp0p2HXoL+Lewq4j32UWNoXQ930wzW2PIBkrAjrqwDXQGYVmVDWJDM X-Received: by 2002:a17:90a:cf0b:: with SMTP id h11mr7661943pju.95.1567432710025; Mon, 02 Sep 2019 06:58:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567432710; cv=none; d=google.com; s=arc-20160816; b=uwTHMAJEefMVmGJMA7IsfJQUarCd4DjT5eFZmu89oTef8HqT7tdkpDAofmJu2eKOJZ xdTPJWjuDeSbj7ay+IImr7B4ymwPXVWT1dOf+RTanBkveLSrDutUmRB/cp1Z4YCiFKCP mFk2LCjfCOghL6umuFfvBesY7tAfAzjL+rsAISuiXcGHoK9eUXNn3KHuTT8da8dMB5Zx +KxC2WxnrBF91uNtRncpvtZNpoYzafRfLdkQ7+Xozm/uLx343ttSh7MIKdBS/K60WW+F r6RlhayJfGD0JjnVvrwF5NN9KrflF9VGeBaValI0+Ej7FIoJhNlOrA22JBgKianu5MGm 6CPQ== 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:date:from:dkim-signature; bh=+Vai56wCT38arG0bdhrBZmoeSGAh3JX1kMMqznwuIqw=; b=DnDK6YgO9SLZKwKgRvytiKR76CXO1513A91T3mOob9YIo5QkZzMXuPO6AytTM9tB5L 6gOuSY7RNUSySoVLhYswBKOI10uuZqb1l2naz9Qtnjpg9mL+JtWq89oQeQqK/pNlWUFQ WJPXd6v3qeHrkKKQKmLoXhr7iLDjjAKbS7R1QxHQksEub0nx7gazLL7wcgDUfi5XhQe2 TtyXJCCG0K7bjH0RtH9+5IwqIasH68mNOd+DfVg7Cg1lLkf0hDZ+VcgfOPsjHDDAasxw 3M/Qt3sQgi9q4+E+xYQVX/ybnNAP4jfpwjycVul9aih/aeXDA4b9uTFzbpqR7uQ8Ku4A vzmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Qd52Fp9b; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g10si11876859plt.119.2019.09.02.06.58.11; Mon, 02 Sep 2019 06:58:30 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Qd52Fp9b; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730724AbfIBN5P (ORCPT + 99 others); Mon, 2 Sep 2019 09:57:15 -0400 Received: from mail-qt1-f195.google.com ([209.85.160.195]:33235 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730136AbfIBN5P (ORCPT ); Mon, 2 Sep 2019 09:57:15 -0400 Received: by mail-qt1-f195.google.com with SMTP id r5so10432949qtd.0 for ; Mon, 02 Sep 2019 06:57:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=+Vai56wCT38arG0bdhrBZmoeSGAh3JX1kMMqznwuIqw=; b=Qd52Fp9b4ropwqmh7oip0W1m/V/IWuEn76hNId70SaBGEsr9rduL5Aw4LcM4LJ4Ggt JBjn7WhGgMdGveWKo025PnAYfps/Ol9jcAcUTx38fJYz5vhuM0Bnu/nguxjGXPraVLcT mRYYGN216HlNebcY8Ox4jVHgy0Uq2rzvt4kQI3vMjbsjXP+fI7/+eyFKhO9JXy++9LyL slhU2E1Bo7kgwKPnxC8h4v/nG9Qu8Xewd0hHUZpDoDbzS1fLb02X4b+4AjwWUI+E4aoj SewuOXmbP6oufBYwTCxp8XnQwdza1TBWcqKyhtoAk2dtuvCXQFCYLatKtipkyVX1A9Pe IBcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+Vai56wCT38arG0bdhrBZmoeSGAh3JX1kMMqznwuIqw=; b=Cmr8cNNOSECSWWF7IsBDXq7dU19DpCX8wUxJwT5Bf33Loh1BHrcybxV7nH1fL7CI6p Se2fxuthCfswBl9v9kOH1H6TDXZM2TioyI+BvAnmRvQ4Ul28aGKtSzaVEbFMx7jI4LRa sQDQ0x7owDczlr6S4mNOntTuEGPyUJg38KqMGDDoz941qEMyzK7a4Pyd/GPQUsokFLPR n0chTCzcGxze6SB6fHkM5Fwy9Sqg7GlTqPnM1Xl422OikKO5JBMM8fGFSvcicxBTyIEV CeeD4wzGudI+3/wEqQV8OU5fYQbQpLtpKtDGW8m838TaV1U1yUHXUcwL6R+9ofSbkvyf qIoQ== X-Gm-Message-State: APjAAAVWa0iPkwta6ER6KFurni5+CocNg7H+YJ3Ts0FFOUKzlgcVYZWZ HPmA4SAKRXGAr2W05aWK6pg= X-Received: by 2002:ac8:71cb:: with SMTP id i11mr9181051qtp.32.1567432634194; Mon, 02 Sep 2019 06:57:14 -0700 (PDT) Received: from quaco.ghostprotocols.net ([179.97.35.50]) by smtp.gmail.com with ESMTPSA id d9sm6482428qko.20.2019.09.02.06.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2019 06:57:13 -0700 (PDT) From: Arnaldo Carvalho de Melo X-Google-Original-From: Arnaldo Carvalho de Melo Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id B82A241146; Mon, 2 Sep 2019 10:57:10 -0300 (-03) Date: Mon, 2 Sep 2019 10:57:10 -0300 To: Jiri Olsa Cc: 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: <20190902135710.GB8396@kernel.org> References: <20190902121255.536-1-jolsa@kernel.org> <20190902121255.536-3-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190902121255.536-3-jolsa@kernel.org> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > + for (i = 0; i < nr; i++) > + env->numa_map[i] = -1; > + > + env->nr_numa_map = nr; > + > + for (i = 0; i < env->nr_numa_nodes; i++) { > + int tmp, j; > + > + nn = &env->numa_nodes[i]; > + perf_cpu_map__for_each_cpu(j, tmp, nn->map) > + env->numa_map[j] = i; > + } > + } > + > + return cpu >= 0 && cpu < env->nr_numa_map ? env->numa_map[cpu] : -1; > +} > diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h > index d8e083d42610..777008f8007a 100644 > --- a/tools/perf/util/env.h > +++ b/tools/perf/util/env.h > @@ -86,6 +86,10 @@ struct perf_env { > struct rb_root btfs; > u32 btfs_cnt; > } bpf_progs; > + > + /* For fast cpu to numa node lookup via perf_env__numa_node */ > + int *numa_map; > + int nr_numa_map; > }; > > enum perf_compress_type { > @@ -118,4 +122,6 @@ struct bpf_prog_info_node *perf_env__find_bpf_prog_info(struct perf_env *env, > __u32 prog_id); > void perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node); > struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id); > + > +int perf_env__numa_node(struct perf_env *env, int cpu); > #endif /* __PERF_ENV_H */ > -- > 2.21.0 -- - Arnaldo