Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp366619ybe; Wed, 4 Sep 2019 00:36:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcGPjboWn1KX3MQImyX0lTM4WsinfxebqZcGYQfYyL2fodZT+JI5XjkOQchVYTUXuJdb74 X-Received: by 2002:a17:902:7892:: with SMTP id q18mr37430047pll.206.1567582577255; Wed, 04 Sep 2019 00:36:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567582577; cv=none; d=google.com; s=arc-20160816; b=VoEk1bL4p1ZeXAC2GrX2irpwa1rJbFU/TPlrBoRllADpMRb3yJNTKtR0wknwS4wwdV wZOkGT5dwr+sWdIFi6bE7mdht7lCNeSUAmx8uyp1R1Hd5dte7fTNPpLur3Vn6DWaIWTA 7Vsjd7OzyuDQov6pj936YvSC4PMvvHBVyX6326/Z7LUtmL48Frr2v84fCTZVGJCUHK4C lS0gf7NBOcHYRI6hEu8GPg6a1h28cexMSpq+IhCFWk62PGRyV3ozzr37LPRNuXRH9BiN 4L+LFsV8MDMShPAuaIzz7MK16HvCTqT1ahO2hmVsTnvtZLSUGoJBY5nvxgFgUcxFTTWL 09Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=u9Pd3Si3M8Lx5w+Qj7Yh0CvHAJfkr5vh+lBEMM82uqA=; b=BCbAf7nHtQO27YswAkg9FI6NftLoNJZNcW5PrHj9dQPSwLUviCw8AWEClZGYrTKGmv 3PPM/J/psos2yos/ztoi160IlUi+CwRnhW3SUHPWHBp7Nif3gzOT8EFiV7MdI+Cu9NdR dzY3hk7nC53hToF7xHyT2Cmvo6NjN3L34Yox++LiLayFqiWFjcJmbrX43L6PgSJVrs4x qkdk3AZomwb/l+mWL1lfTGCYAH2RMFoOA95LkKHEX9h/FnAokwCIoeT9WWTKzV9hhDMq TJmG6NoqbHX+thbrTF1jaZyZlIEFM0TrKp+tbRLJ36gauMvcBoxCQR/twhUk/3RM7kN4 yxgw== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b9si8338691pfo.273.2019.09.04.00.36.02; Wed, 04 Sep 2019 00:36:17 -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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729235AbfIDHeZ (ORCPT + 99 others); Wed, 4 Sep 2019 03:34:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34054 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728259AbfIDHeZ (ORCPT ); Wed, 4 Sep 2019 03:34:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C8D0A10A8126; Wed, 4 Sep 2019 07:34:24 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5C2FA60126; Wed, 4 Sep 2019 07:34:22 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , Joe Mario , Kan Liang , Andi Kleen , Alexey Budankov Subject: [PATCH 2/3] perf tools: Add perf_env__numa_node function Date: Wed, 4 Sep 2019 09:34:14 +0200 Message-Id: <20190904073415.723-3-jolsa@kernel.org> In-Reply-To: <20190904073415.723-1-jolsa@kernel.org> References: <20190904073415.723-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Wed, 04 Sep 2019 07:34:25 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 40 ++++++++++++++++++++++++++++++++++++++++ tools/perf/util/env.h | 6 ++++++ 2 files changed, 46 insertions(+) diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index 3baca06786fb..ee53e89a9535 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,42 @@ 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++; + + /* + * We initialize the numa_map array to prepare + * it for missing cpus, which return node -1. + */ + env->numa_map = malloc(nr * sizeof(int)); + if (!env->numa_map) + return -1; + + 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