Skip to content

Commit 0cd1ca4

Browse files
Ravi Bangoriaacmel
authored andcommitted
perf tool x86: Consolidate is_amd check into single function
There are multiple places where x86 specific code determines AMD vs Intel arch and acts based on that. Consolidate those checks into a single function. Signed-off-by: Ravi Bangoria <ravi.bangoria@amd.com> Acked-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ali Saidi <alisaidi@amazon.com> Cc: Ananth Narayan <ananth.narayan@amd.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sandipan Das <sandipan.das@amd.com> Cc: Santosh Shukla <santosh.shukla@amd.com> Link: https://lore.kernel.org/r/20230613095506.547-3-ravi.bangoria@amd.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 6ec9503 commit 0cd1ca4

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

tools/perf/arch/x86/util/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ perf-y += evlist.o
1010
perf-y += mem-events.o
1111
perf-y += evsel.o
1212
perf-y += iostat.o
13+
perf-y += env.o
1314

1415
perf-$(CONFIG_DWARF) += dwarf-regs.o
1516
perf-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o

tools/perf/arch/x86/util/env.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include "linux/string.h"
3+
#include "util/env.h"
4+
#include "env.h"
5+
6+
bool x86__is_amd_cpu(void)
7+
{
8+
struct perf_env env = { .total_mem = 0, };
9+
static int is_amd; /* 0: Uninitialized, 1: Yes, -1: No */
10+
11+
if (is_amd)
12+
goto ret;
13+
14+
perf_env__cpuid(&env);
15+
is_amd = env.cpuid && strstarts(env.cpuid, "AuthenticAMD") ? 1 : -1;
16+
17+
ret:
18+
return is_amd >= 1 ? true : false;
19+
}

tools/perf/arch/x86/util/env.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _X86_ENV_H
3+
#define _X86_ENV_H
4+
5+
bool x86__is_amd_cpu(void);
6+
7+
#endif /* _X86_ENV_H */

tools/perf/arch/x86/util/evsel.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "linux/string.h"
99
#include "evsel.h"
1010
#include "util/debug.h"
11+
#include "env.h"
1112

1213
#define IBS_FETCH_L3MISSONLY (1ULL << 59)
1314
#define IBS_OP_L3MISSONLY (1ULL << 16)
@@ -78,23 +79,10 @@ void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr)
7879
{
7980
struct perf_pmu *evsel_pmu, *ibs_fetch_pmu, *ibs_op_pmu;
8081
static int warned_once;
81-
/* 0: Uninitialized, 1: Yes, -1: No */
82-
static int is_amd;
8382

84-
if (warned_once || is_amd == -1)
83+
if (warned_once || !x86__is_amd_cpu())
8584
return;
8685

87-
if (!is_amd) {
88-
struct perf_env *env = evsel__env(evsel);
89-
90-
if (!perf_env__cpuid(env) || !env->cpuid ||
91-
!strstarts(env->cpuid, "AuthenticAMD")) {
92-
is_amd = -1;
93-
return;
94-
}
95-
is_amd = 1;
96-
}
97-
9886
evsel_pmu = evsel__find_pmu(evsel);
9987
if (!evsel_pmu)
10088
return;

tools/perf/arch/x86/util/mem-events.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "map_symbol.h"
66
#include "mem-events.h"
77
#include "linux/string.h"
8+
#include "env.h"
89

910
static char mem_loads_name[100];
1011
static bool mem_loads_name__init;
@@ -27,28 +28,12 @@ static struct perf_mem_event perf_mem_events_amd[PERF_MEM_EVENTS__MAX] = {
2728
E("mem-ldst", "ibs_op//", "ibs_op"),
2829
};
2930

30-
static int perf_mem_is_amd_cpu(void)
31-
{
32-
struct perf_env env = { .total_mem = 0, };
33-
34-
perf_env__cpuid(&env);
35-
if (env.cpuid && strstarts(env.cpuid, "AuthenticAMD"))
36-
return 1;
37-
return -1;
38-
}
39-
4031
struct perf_mem_event *perf_mem_events__ptr(int i)
4132
{
42-
/* 0: Uninitialized, 1: Yes, -1: No */
43-
static int is_amd;
44-
4533
if (i >= PERF_MEM_EVENTS__MAX)
4634
return NULL;
4735

48-
if (!is_amd)
49-
is_amd = perf_mem_is_amd_cpu();
50-
51-
if (is_amd == 1)
36+
if (x86__is_amd_cpu())
5237
return &perf_mem_events_amd[i];
5338

5439
return &perf_mem_events_intel[i];

0 commit comments

Comments
 (0)