Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp533949ybe; Mon, 2 Sep 2019 05:37:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqzO5TZvMUQKxNdEVvit2d24e21TGbRdr3XUgpKosN2CjoxPzsgYi5jg/Dw8dYOvJMHVzb7T X-Received: by 2002:a17:902:1002:: with SMTP id b2mr29111180pla.336.1567427869896; Mon, 02 Sep 2019 05:37:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567427869; cv=none; d=google.com; s=arc-20160816; b=IVqj/awb15soSZ6xW6U9Bh8xnwsmqzqkF/E+rY4l5PhJnG4ejEfqx3ezET3eKfjaL0 /D0uVevBqhRktn1un0TdgNZBXvQpkU12EhJZfUQxX3QRRAB6GRxIuO6v3KCheqejyOBR nfmFa22vprj6A3yiU7xQgQgP5ZWLaAIJ0/zqIdOKf9Yf5+l0I376sdRY46+nzZ0fn2yK mL/NTMwfuYMkR94sV8fb/EhEXveEZLSw87NQJicovF+SydKkFgAoCzYrOm0dlEQGG2ir rDm/rarazeKZv3bN0/IR/S31p/QQVJCVCqiaXlRTH2h9Y/XvHxRWf5mI1MvPfL4z+ON9 7TlQ== 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=DBHTKHmwcE+pdhMBH4rSkVXYSaZavhHUvzZBYZFlNgw=; b=ajxYKUoLiESCAxCMHfHaldDDa8jtSkHVCSs+u2mn/JMjiee5l1LBvsSVovurSlCow5 JGJu+InJO+AReUdwJI2siUhNZo/9jg2Yd08ERco01ulguh8H/6briTGXQbB6Tuq2wQMU j/2DDK34ysTvuY8r9rGzE+MknY7wjqQrI4PMz56Vb1J0aDaaAQOzOcGMLYp9wixo0Mqz 7DZQjo6Kjygw2aMLQrt2fh5C8NnxSXbti6M3LVYNlIqiIq3RoVahnG6pXItCOGIqjTe7 Lefus7/DPq1V5yq/3aWEsn4fKN3BfIeGSz/aWw3A3Annbc7zaPN0jrnyNfQacHNBk7vZ a64g== 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 v10si1428213plg.224.2019.09.02.05.37.34; Mon, 02 Sep 2019 05:37:49 -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 S1731466AbfIBMNJ (ORCPT + 99 others); Mon, 2 Sep 2019 08:13:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48752 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729658AbfIBMNI (ORCPT ); Mon, 2 Sep 2019 08:13:08 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AA2F383BDC; Mon, 2 Sep 2019 12:13:07 +0000 (UTC) Received: from krava.brq.redhat.com (unknown [10.43.17.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89BB360C05; Mon, 2 Sep 2019 12:13:05 +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 Subject: [PATCH 2/3] perf tools: Add perf_env__numa_node function Date: Mon, 2 Sep 2019 14:12:54 +0200 Message-Id: <20190902121255.536-3-jolsa@kernel.org> In-Reply-To: <20190902121255.536-1-jolsa@kernel.org> References: <20190902121255.536-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Mon, 02 Sep 2019 12:13:07 +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 | 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)); + 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