mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
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>
This commit is contained in:
committed by
Arnaldo Carvalho de Melo
parent
6ec9503f45
commit
0cd1ca4650
@@ -10,6 +10,7 @@ perf-y += evlist.o
|
|||||||
perf-y += mem-events.o
|
perf-y += mem-events.o
|
||||||
perf-y += evsel.o
|
perf-y += evsel.o
|
||||||
perf-y += iostat.o
|
perf-y += iostat.o
|
||||||
|
perf-y += env.o
|
||||||
|
|
||||||
perf-$(CONFIG_DWARF) += dwarf-regs.o
|
perf-$(CONFIG_DWARF) += dwarf-regs.o
|
||||||
perf-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o
|
perf-$(CONFIG_BPF_PROLOGUE) += dwarf-regs.o
|
||||||
|
19
tools/perf/arch/x86/util/env.c
Normal file
19
tools/perf/arch/x86/util/env.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0
|
||||||
|
#include "linux/string.h"
|
||||||
|
#include "util/env.h"
|
||||||
|
#include "env.h"
|
||||||
|
|
||||||
|
bool x86__is_amd_cpu(void)
|
||||||
|
{
|
||||||
|
struct perf_env env = { .total_mem = 0, };
|
||||||
|
static int is_amd; /* 0: Uninitialized, 1: Yes, -1: No */
|
||||||
|
|
||||||
|
if (is_amd)
|
||||||
|
goto ret;
|
||||||
|
|
||||||
|
perf_env__cpuid(&env);
|
||||||
|
is_amd = env.cpuid && strstarts(env.cpuid, "AuthenticAMD") ? 1 : -1;
|
||||||
|
|
||||||
|
ret:
|
||||||
|
return is_amd >= 1 ? true : false;
|
||||||
|
}
|
7
tools/perf/arch/x86/util/env.h
Normal file
7
tools/perf/arch/x86/util/env.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/* SPDX-License-Identifier: GPL-2.0 */
|
||||||
|
#ifndef _X86_ENV_H
|
||||||
|
#define _X86_ENV_H
|
||||||
|
|
||||||
|
bool x86__is_amd_cpu(void);
|
||||||
|
|
||||||
|
#endif /* _X86_ENV_H */
|
@@ -8,6 +8,7 @@
|
|||||||
#include "linux/string.h"
|
#include "linux/string.h"
|
||||||
#include "evsel.h"
|
#include "evsel.h"
|
||||||
#include "util/debug.h"
|
#include "util/debug.h"
|
||||||
|
#include "env.h"
|
||||||
|
|
||||||
#define IBS_FETCH_L3MISSONLY (1ULL << 59)
|
#define IBS_FETCH_L3MISSONLY (1ULL << 59)
|
||||||
#define IBS_OP_L3MISSONLY (1ULL << 16)
|
#define IBS_OP_L3MISSONLY (1ULL << 16)
|
||||||
@@ -78,23 +79,10 @@ void arch__post_evsel_config(struct evsel *evsel, struct perf_event_attr *attr)
|
|||||||
{
|
{
|
||||||
struct perf_pmu *evsel_pmu, *ibs_fetch_pmu, *ibs_op_pmu;
|
struct perf_pmu *evsel_pmu, *ibs_fetch_pmu, *ibs_op_pmu;
|
||||||
static int warned_once;
|
static int warned_once;
|
||||||
/* 0: Uninitialized, 1: Yes, -1: No */
|
|
||||||
static int is_amd;
|
|
||||||
|
|
||||||
if (warned_once || is_amd == -1)
|
if (warned_once || !x86__is_amd_cpu())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!is_amd) {
|
|
||||||
struct perf_env *env = evsel__env(evsel);
|
|
||||||
|
|
||||||
if (!perf_env__cpuid(env) || !env->cpuid ||
|
|
||||||
!strstarts(env->cpuid, "AuthenticAMD")) {
|
|
||||||
is_amd = -1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
is_amd = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
evsel_pmu = evsel__find_pmu(evsel);
|
evsel_pmu = evsel__find_pmu(evsel);
|
||||||
if (!evsel_pmu)
|
if (!evsel_pmu)
|
||||||
return;
|
return;
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
#include "map_symbol.h"
|
#include "map_symbol.h"
|
||||||
#include "mem-events.h"
|
#include "mem-events.h"
|
||||||
#include "linux/string.h"
|
#include "linux/string.h"
|
||||||
|
#include "env.h"
|
||||||
|
|
||||||
static char mem_loads_name[100];
|
static char mem_loads_name[100];
|
||||||
static bool mem_loads_name__init;
|
static bool mem_loads_name__init;
|
||||||
@@ -27,28 +28,12 @@ static struct perf_mem_event perf_mem_events_amd[PERF_MEM_EVENTS__MAX] = {
|
|||||||
E("mem-ldst", "ibs_op//", "ibs_op"),
|
E("mem-ldst", "ibs_op//", "ibs_op"),
|
||||||
};
|
};
|
||||||
|
|
||||||
static int perf_mem_is_amd_cpu(void)
|
|
||||||
{
|
|
||||||
struct perf_env env = { .total_mem = 0, };
|
|
||||||
|
|
||||||
perf_env__cpuid(&env);
|
|
||||||
if (env.cpuid && strstarts(env.cpuid, "AuthenticAMD"))
|
|
||||||
return 1;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct perf_mem_event *perf_mem_events__ptr(int i)
|
struct perf_mem_event *perf_mem_events__ptr(int i)
|
||||||
{
|
{
|
||||||
/* 0: Uninitialized, 1: Yes, -1: No */
|
|
||||||
static int is_amd;
|
|
||||||
|
|
||||||
if (i >= PERF_MEM_EVENTS__MAX)
|
if (i >= PERF_MEM_EVENTS__MAX)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!is_amd)
|
if (x86__is_amd_cpu())
|
||||||
is_amd = perf_mem_is_amd_cpu();
|
|
||||||
|
|
||||||
if (is_amd == 1)
|
|
||||||
return &perf_mem_events_amd[i];
|
return &perf_mem_events_amd[i];
|
||||||
|
|
||||||
return &perf_mem_events_intel[i];
|
return &perf_mem_events_intel[i];
|
||||||
|
Reference in New Issue
Block a user