linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Andi Kleen <ak@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 06/44] perf pmu: Extract function to get JSON alias map
Date: Fri, 22 Sep 2017 11:41:42 -0300	[thread overview]
Message-ID: <20170922144220.9411-7-acme@kernel.org> (raw)
In-Reply-To: <20170922144220.9411-1-acme@kernel.org>

From: Andi Kleen <ak@linux.intel.com>

Extract the code to get the per cpu JSON alias into a separate function
for reuse. No behavior changes.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/20170831194036.30146-6-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/pmu.c | 49 +++++++++++++++++++++++++++++++++----------------
 tools/perf/util/pmu.h |  2 ++
 2 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index ac16a9db1fb5..ed25d7f88731 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -516,16 +516,8 @@ char * __weak get_cpuid_str(void)
 	return NULL;
 }
 
-/*
- * From the pmu_events_map, find the table of PMU events that corresponds
- * to the current running CPU. Then, add all PMU events from that table
- * as aliases.
- */
-static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
+static char *perf_pmu__getcpuid(void)
 {
-	int i;
-	struct pmu_events_map *map;
-	struct pmu_event *pe;
 	char *cpuid;
 	static bool printed;
 
@@ -535,22 +527,50 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
 	if (!cpuid)
 		cpuid = get_cpuid_str();
 	if (!cpuid)
-		return;
+		return NULL;
 
 	if (!printed) {
 		pr_debug("Using CPUID %s\n", cpuid);
 		printed = true;
 	}
+	return cpuid;
+}
+
+struct pmu_events_map *perf_pmu__find_map(void)
+{
+	struct pmu_events_map *map;
+	char *cpuid = perf_pmu__getcpuid();
+	int i;
 
 	i = 0;
-	while (1) {
+	for (;;) {
 		map = &pmu_events_map[i++];
-		if (!map->table)
-			goto out;
+		if (!map->table) {
+			map = NULL;
+			break;
+		}
 
 		if (!strcmp(map->cpuid, cpuid))
 			break;
 	}
+	free(cpuid);
+	return map;
+}
+
+/*
+ * From the pmu_events_map, find the table of PMU events that corresponds
+ * to the current running CPU. Then, add all PMU events from that table
+ * as aliases.
+ */
+static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
+{
+	int i;
+	struct pmu_events_map *map;
+	struct pmu_event *pe;
+
+	map = perf_pmu__find_map();
+	if (!map)
+		return;
 
 	/*
 	 * Found a matching PMU events table. Create aliases
@@ -575,9 +595,6 @@ static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
 				(char *)pe->metric_expr,
 				(char *)pe->metric_name);
 	}
-
-out:
-	free(cpuid);
 }
 
 struct perf_event_attr * __weak
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 389e9729331f..060f6abba8ed 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -90,4 +90,6 @@ int perf_pmu__test(void);
 
 struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
 
+struct pmu_events_map *perf_pmu__find_map(void);
+
 #endif /* __PMU_H */
-- 
2.13.5

  parent reply	other threads:[~2017-09-22 14:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-22 14:41 [GIT PULL 00/44] perf/core improvements and fixes Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 01/44] perf sched timehist: Add pid and tid options Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 02/44] perf tools: Support weak groups in 'perf stat' Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 03/44] perf vendor events: Support metric_group and no event name in JSON parser Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 04/44] perf stat: Factor out generic metric printing Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 05/44] perf stat: Print generic metric header even for failed expressions Arnaldo Carvalho de Melo
2017-09-22 14:41 ` Arnaldo Carvalho de Melo [this message]
2017-09-22 14:41 ` [PATCH 07/44] perf stat: Support JSON metrics in perf stat Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 08/44] perf list: Add metric groups to perf list Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 09/44] perf stat: Don't use ctx for saved values lookup Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 10/44] perf stat: Support duration_time for metrics Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 11/44] perf stat: Hide internal duration_time counter Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 12/44] perf stat: Update walltime_nsecs_stats in interval mode Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 13/44] perf record: Support direct --user-regs arguments Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 14/44] perf script: Support user regs Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 15/44] perf tools: Add python-clean target Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 16/44] perf ui progress: Add ui specific init function Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 17/44] perf ui progress: Add size info into progress bar Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 18/44] perf tools: Use scandir() to replace readdir() Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 19/44] perf config: Write a config file just once Arnaldo Carvalho de Melo
2017-09-22 14:41 ` [PATCH 20/44] perf config: Allow creating empty config set for config file autogeneration Arnaldo Carvalho de Melo
2017-09-22 16:26 ` [GIT PULL 00/44] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170922144220.9411-7-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ak@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).