numatop/0005-x86-zen-Add-initial-su...

323 lines
9.5 KiB
Diff

From fdf9b3ce90d1f435fe837added7373e25e6045b2 Mon Sep 17 00:00:00 2001
From: Sandipan Das <sandipan.das@amd.com>
Date: Wed, 16 Feb 2022 18:05:27 +0530
Subject: [PATCH 05/15] x86/zen: Add initial support
Add vendor and family identification as well as the relevant
events to count per-process memory accesseses and CPU usage
on AMD Zen and Zen 2 family of processors.
Signed-off-by: Sandipan Das <sandipan.das@amd.com>
---
Makefile.am | 4 ++-
README.md | 2 +-
x86/include/types.h | 5 ++--
x86/include/util.h | 3 ++
x86/include/zen.h | 50 ++++++++++++++++++++++++++++++++
x86/plat.c | 29 +++++++++++++------
x86/zen.c | 70 +++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 151 insertions(+), 12 deletions(-)
create mode 100644 x86/include/zen.h
create mode 100644 x86/zen.c
diff --git a/Makefile.am b/Makefile.am
index 438a9fc..ae11522 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -67,6 +67,7 @@ libnumatop_la_SOURCES += \
x86/include/types.h \
x86/include/util.h \
x86/include/wsm.h \
+ x86/include/zen.h \
x86/bdw.c \
x86/nhm.c \
x86/plat.c \
@@ -74,7 +75,8 @@ libnumatop_la_SOURCES += \
x86/snb.c \
x86/ui_perf_map.c \
x86/util.c \
- x86/wsm.c
+ x86/wsm.c \
+ x86/zen.c
endif
if CPU_PPC
diff --git a/README.md b/README.md
index e96f0a8..9908e92 100644
--- a/README.md
+++ b/README.md
@@ -58,7 +58,7 @@ http://www.gossamer-threads.com/lists/linux/kernel/1964864
common: common code for all platforms.
-x86 : Intel platform-specific code.
+x86 : Intel and AMD platform-specific code.
powerpc: PowerPC platform-specific code.
diff --git a/x86/include/types.h b/x86/include/types.h
index 1a15b3a..0843bd1 100644
--- a/x86/include/types.h
+++ b/x86/include/types.h
@@ -46,10 +46,11 @@ typedef enum {
CPU_BDX,
CPU_SKX,
CPU_ICX,
- CPU_SPR
+ CPU_SPR,
+ CPU_ZEN
} cpu_type_t;
-#define CPU_TYPE_NUM 12
+#define CPU_TYPE_NUM 13
typedef enum {
PERF_COUNT_INVALID = -1,
diff --git a/x86/include/util.h b/x86/include/util.h
index 37a6300..4d2534b 100644
--- a/x86/include/util.h
+++ b/x86/include/util.h
@@ -36,6 +36,9 @@
#define CPU_MODEL(eax) \
(((eax) & 0x00F0) >> 4)
+#define CPU_EXT_FAMILY(eax) \
+ (((eax) & 0x0FF00000) >> 20)
+
#define CPU_EXT_MODEL(eax) \
(((eax) & 0xF0000) >> 16)
diff --git a/x86/include/zen.h b/x86/include/zen.h
new file mode 100644
index 0000000..be61324
--- /dev/null
+++ b/x86/include/zen.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2023, AMD Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _NUMATOP_AMD_ZEN_H
+#define _NUMATOP_AMD_ZEN_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <sys/types.h>
+#include <inttypes.h>
+#include "../../common/include/types.h"
+
+struct _plat_event_config;
+
+extern void zen_profiling_config(perf_count_id_t, struct _plat_event_config *);
+extern void zen_ll_config(struct _plat_event_config *);
+extern int zen_offcore_num(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _NUMATOP_AMD_ZEN_H */
diff --git a/x86/plat.c b/x86/plat.c
index abf3766..f79837a 100644
--- a/x86/plat.c
+++ b/x86/plat.c
@@ -36,6 +36,7 @@
#include "include/snb.h"
#include "include/bdw.h"
#include "include/skl.h"
+#include "include/zen.h"
pfn_plat_profiling_config_t
s_plat_profiling_config[CPU_TYPE_NUM] = {
@@ -50,7 +51,8 @@ s_plat_profiling_config[CPU_TYPE_NUM] = {
bdw_profiling_config,
skl_profiling_config,
icx_profiling_config,
- spr_profiling_config
+ spr_profiling_config,
+ zen_profiling_config
};
pfn_plat_ll_config_t
@@ -66,7 +68,8 @@ s_plat_ll_config[CPU_TYPE_NUM] = {
bdw_ll_config,
skl_ll_config,
icx_ll_config,
- spr_ll_config
+ spr_ll_config,
+ zen_ll_config
};
pfn_plat_offcore_num_t
@@ -82,7 +85,8 @@ s_plat_offcore_num[CPU_TYPE_NUM] = {
bdw_offcore_num,
skl_offcore_num,
icx_offcore_num,
- spr_offcore_num
+ spr_offcore_num,
+ zen_offcore_num
};
/* ARGSUSED */
@@ -117,7 +121,7 @@ static cpu_type_t
cpu_type_get(void)
{
unsigned int eax, ebx, ecx, edx;
- int family, model, ext_model;
+ int family, model;
cpu_type_t type = CPU_UNSUP;
char vendor[16];
@@ -129,7 +133,8 @@ cpu_type_get(void)
(void) strncpy(&vendor[8], (char *)(&edx), 4);
vendor[12] = 0;
- if (strncmp(vendor, "Genu" "ntel" "ineI", 12) != 0) {
+ if (strncmp(vendor, "Genu" "ntel" "ineI", 12) != 0 &&
+ strncmp(vendor, "Auth" "cAMD" "enti", 12) != 0) {
return (CPU_UNSUP);
}
@@ -138,11 +143,16 @@ cpu_type_get(void)
family = CPU_FAMILY(eax);
model = CPU_MODEL(eax);
- ext_model = CPU_EXT_MODEL(eax);
- if (family == 6) {
- model = (ext_model << 4) + model;
+ /* Extended Model ID is considered only when Family ID is either 6 or 15 */
+ if (family == 6 || family == 15)
+ model += CPU_EXT_MODEL(eax) << 4;
+
+ /* Extended Family ID is considered only when Family ID is 15 */
+ if (family == 15)
+ family += CPU_EXT_FAMILY(eax);
+ if (family == 6) {
switch (model) {
case 26:
type = CPU_NHM_EP;
@@ -178,6 +188,8 @@ cpu_type_get(void)
type = CPU_SPR;
break;
}
+ } else if (family == 23) {
+ type = CPU_ZEN;
}
return (type);
@@ -217,6 +229,7 @@ plat_detect(void)
case CPU_SKX:
case CPU_ICX:
case CPU_SPR:
+ case CPU_ZEN:
ret = 0;
s_cpu_type = cpu_type;
break;
diff --git a/x86/zen.c b/x86/zen.c
new file mode 100644
index 0000000..abf603a
--- /dev/null
+++ b/x86/zen.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2023, AMD Corporation
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Intel Corporation nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* This file contains the Zen platform specific functions. */
+
+#include <inttypes.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <strings.h>
+#include "../common/include/os/linux/perf_event.h"
+#include "../common/include/os/plat.h"
+#include "include/zen.h"
+
+static plat_event_config_t s_zen_config[PERF_COUNT_NUM] = {
+ { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0, 0, 0, "LsNotHaltedCyc" },
+ { PERF_TYPE_RAW, 0x0000000000004043, 0, 0, 0, "LsDmndFillsFromSys.DRAM_IO_Far" },
+ { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0, 0, 0, "LsNotHaltedCyc" },
+ { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, "ExRetOps" },
+ { PERF_TYPE_RAW, 0x0000000000000843, 0, 0, 0, "LsDmndFillsFromSys.DRAM_IO_Near" },
+};
+
+static plat_event_config_t s_zen_ll = {
+ PERF_TYPE_RAW, 0, 0, 0, "Unsupported"
+};
+
+void
+zen_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg)
+{
+ plat_config_get(perf_count_id, cfg, s_zen_config);
+}
+
+void
+zen_ll_config(plat_event_config_t *cfg)
+{
+ memcpy(cfg, &s_zen_ll, sizeof (plat_event_config_t));
+}
+
+int
+zen_offcore_num(void)
+{
+ return (2);
+}
--
2.31.1