Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp406814ybc; Tue, 12 Nov 2019 03:23:47 -0800 (PST) X-Google-Smtp-Source: APXvYqy0k7300wdVd4q6rGTTq1t8zNbow82Lb0lYG2hUbXoraT/X5O2x8VXmaH0CrQscQN9QC/6O X-Received: by 2002:a50:8a88:: with SMTP id j8mr33300326edj.35.1573557827857; Tue, 12 Nov 2019 03:23:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573557827; cv=none; d=google.com; s=arc-20160816; b=P/U7AqOw+6nS6vu1821DeeVm3LLqmjIXzoxpPZg1RKLjJat3dnK9ajuBOSqDJgYeUi DI9PHFJxst8SyEMCGWMihWL81oVAI0vlKgB9BnpFsOSnUg81zDWQkJtd9u1IRxGMUBG5 ZZNV6TLFbpxkv806ka/ICWnJQ9cLqgcnHLm8A0o2DOU7k8xqLkGWB/w3OLHfZM3hMFus +zX6MOczRbm3R6u5xB7+jX94uIKVIKhrXCWSlwF29A2OG6k7kVhawI0JWT4EJDAf3Q9C nWqdyRz3BcmJfo7R8wQP2B3lYWTdwAvkweotVnmEGPI1j7Npy5tWloFIXtEig/pmJ9U0 24OQ== 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 :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=04YKcK7AmNeTpmwKcffvM6In5pA9VRuIKrqaSGAYDAQ=; b=Z0H4gcVTqvofhQAD/ndpHVBMbQhSaH13sMkGx7DFGsnSqs3wK8hKNsy2sI6G+lyS9b 9myxYhFD6VXxiwXPLKr3jVhOBgy8RpycvXTc4dsJTpDM2JpDYLMBlCSJu8ggZ9OMbFsb bBcrtlyrohxPcEaHoIyWnacOXfWnLOMwdy/eqZm+FwmCuXY06Ci5viaZkejKYA1iOtMb BI7J/eOXaTrtL3q5/5knXPczoMMqD3Xx/qmCnHQ0AX/V4QcLoUwG7yeUaTvS6whg4ODu AWIqGxOPMtLr+2Uzgyh5wiFO/EulZ9VqwDqytEBuBr8Qfs2E8G5VDQLOtD4R6Hxvvtv6 IK+w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ck15si11349473ejb.358.2019.11.12.03.23.23; Tue, 12 Nov 2019 03:23:47 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727478AbfKLLVd (ORCPT + 99 others); Tue, 12 Nov 2019 06:21:33 -0500 Received: from Galois.linutronix.de ([193.142.43.55]:33729 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727394AbfKLLSQ (ORCPT ); Tue, 12 Nov 2019 06:18:16 -0500 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1iUUBQ-0000Qp-Rd; Tue, 12 Nov 2019 12:18:04 +0100 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id B7B9E1C04CB; Tue, 12 Nov 2019 12:18:00 +0100 (CET) Date: Tue, 12 Nov 2019 11:18:00 -0000 From: "tip-bot2 for Jiri Olsa" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf env: Add perf_env__numa_node() Cc: Jiri Olsa , Alexander Shishkin , Alexey Budankov , Andi Kleen , Joe Mario , Kan Liang , Michael Petlan , Namhyung Kim , Peter Zijlstra , Arnaldo Carvalho de Melo , Ingo Molnar , Borislav Petkov , linux-kernel@vger.kernel.org In-Reply-To: <20190904073415.723-3-jolsa@kernel.org> References: <20190904073415.723-3-jolsa@kernel.org> MIME-Version: 1.0 Message-ID: <157355748043.29376.17683018661132241456.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the perf/core branch of tip: Commit-ID: 389799a7a1e86c55f38897e679762efadcc9dedd Gitweb: https://git.kernel.org/tip/389799a7a1e86c55f38897e679762efadcc9dedd Author: Jiri Olsa AuthorDate: Thu, 29 Aug 2019 13:31:48 +02:00 Committer: Arnaldo Carvalho de Melo CommitterDate: Wed, 06 Nov 2019 15:49:39 -03:00 perf env: Add perf_env__numa_node() To speed up cpu to node lookup, add perf_env__numa_node(), that creates cpu array on the first lookup, that holds numa nodes for each stored cpu. Signed-off-by: Jiri Olsa Cc: Alexander Shishkin Cc: Alexey Budankov Cc: Andi Kleen Cc: Joe Mario Cc: Kan Liang Cc: Michael Petlan Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20190904073415.723-3-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- 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 2a91a10..6242a92 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -180,6 +180,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); @@ -354,3 +355,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 a3059dc..11d05ae 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -87,6 +87,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 { @@ -120,4 +124,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 */