├── .gitignore ├── AUTHORS ├── COPYING ├── Makefile.am ├── README.md ├── SECURITY.md ├── autogen.sh ├── common ├── cmd.c ├── disp.c ├── include │ ├── cmd.h │ ├── disp.h │ ├── lwp.h │ ├── os │ │ ├── linux │ │ │ └── perf_event.h │ │ ├── map.h │ │ ├── node.h │ │ ├── os_cmd.h │ │ ├── os_page.h │ │ ├── os_perf.h │ │ ├── os_types.h │ │ ├── os_util.h │ │ ├── os_win.h │ │ ├── pfwrapper.h │ │ ├── plat.h │ │ └── sym.h │ ├── page.h │ ├── perf.h │ ├── proc.h │ ├── reg.h │ ├── types.h │ ├── ui_perf_map.h │ ├── util.h │ └── win.h ├── lwp.c ├── numatop.c ├── os │ ├── map.c │ ├── node.c │ ├── os_cmd.c │ ├── os_page.c │ ├── os_perf.c │ ├── os_util.c │ ├── os_win.c │ ├── pfwrapper.c │ ├── plat.c │ └── sym.c ├── page.c ├── perf.c ├── proc.c ├── reg.c ├── ui_perf_map.c ├── util.c └── win.c ├── configure.ac ├── kernel_patches └── 0001-perf-x86-Widen-Haswell-OFFCORE-mask.patch ├── numatop.8 ├── powerpc ├── FEATURES ├── include │ ├── power10.h │ ├── power8.h │ ├── power9.h │ └── types.h ├── plat.c ├── power10.c ├── power8.c ├── power9.c ├── ui_perf_map.c └── util.c ├── test ├── mgen.01.sh ├── mgen.02.sh └── mgen │ ├── README │ ├── include │ └── util.h │ ├── mgen.c │ ├── powerpc │ └── util.c │ └── x86 │ └── util.c └── x86 ├── FEATURES ├── bdw.c ├── include ├── bdw.h ├── nhm.h ├── skl.h ├── snb.h ├── srf.h ├── types.h ├── util.h ├── wsm.h └── zen.h ├── nhm.c ├── plat.c ├── skl.c ├── snb.c ├── srf.c ├── ui_perf_map.c ├── util.c ├── wsm.c └── zen.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.lo 2 | *.o 3 | *.log 4 | *.trs 5 | .deps 6 | .dirstamp 7 | .libs 8 | Makefile 9 | Makefile.in 10 | aclocal.m4 11 | autom4te.cache/ 12 | compile 13 | config.* 14 | configure 15 | depcomp 16 | install-sh 17 | libnumatop.la 18 | libtool 19 | ltmain.sh 20 | m4/ 21 | mgen 22 | missing 23 | numatop 24 | numatop-*.tar.* 25 | stamp-h1 26 | test-driver 27 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Jin Yao (yao.jin@intel.com) 2 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Intel Corporation 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of Intel Corporation nor the names of its contributors 12 | may be used to endorse or promote products derived from this software 13 | without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | 27 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | EXTRA_DIST = \ 3 | README.md \ 4 | AUTHORS \ 5 | COPYING \ 6 | kernel_patches/0001-perf-x86-Widen-Haswell-OFFCORE-mask.patch \ 7 | $(TESTS) 8 | 9 | dist_man_MANS = \ 10 | numatop.8 11 | 12 | AM_CFLAGS = -fPIC -O2 -g -Wall -W -Wformat-security -D_FORTIFY_SOURCE=2 -fno-common -std=gnu99 13 | ACLOCAL_AMFLAGS = -I m4 14 | 15 | noinst_LTLIBRARIES = libnumatop.la 16 | libnumatop_la_SOURCES = \ 17 | common/include/os/linux/perf_event.h \ 18 | common/include/os/map.h \ 19 | common/include/os/node.h \ 20 | common/include/os/os_cmd.h \ 21 | common/include/os/os_page.h \ 22 | common/include/os/os_perf.h \ 23 | common/include/os/os_types.h \ 24 | common/include/os/os_util.h \ 25 | common/include/os/os_win.h \ 26 | common/include/os/pfwrapper.h \ 27 | common/include/os/plat.h \ 28 | common/include/os/sym.h \ 29 | common/include/cmd.h \ 30 | common/include/disp.h \ 31 | common/include/lwp.h \ 32 | common/include/page.h \ 33 | common/include/perf.h \ 34 | common/include/proc.h \ 35 | common/include/reg.h \ 36 | common/include/types.h \ 37 | common/include/ui_perf_map.h \ 38 | common/include/util.h \ 39 | common/include/win.h \ 40 | common/os/map.c \ 41 | common/os/node.c \ 42 | common/os/os_cmd.c \ 43 | common/os/os_page.c \ 44 | common/os/os_perf.c \ 45 | common/os/os_util.c \ 46 | common/os/os_win.c \ 47 | common/os/pfwrapper.c \ 48 | common/os/plat.c \ 49 | common/os/sym.c \ 50 | common/cmd.c \ 51 | common/disp.c \ 52 | common/lwp.c \ 53 | common/page.c \ 54 | common/perf.c \ 55 | common/proc.c \ 56 | common/reg.c \ 57 | common/ui_perf_map.c \ 58 | common/util.c \ 59 | common/win.c 60 | 61 | if CPU_X86 62 | libnumatop_la_SOURCES += \ 63 | x86/include/bdw.h \ 64 | x86/include/nhm.h \ 65 | x86/include/skl.h \ 66 | x86/include/snb.h \ 67 | x86/include/srf.h \ 68 | x86/include/types.h \ 69 | x86/include/util.h \ 70 | x86/include/wsm.h \ 71 | x86/include/zen.h \ 72 | x86/bdw.c \ 73 | x86/nhm.c \ 74 | x86/plat.c \ 75 | x86/skl.c \ 76 | x86/snb.c \ 77 | x86/srf.c \ 78 | x86/ui_perf_map.c \ 79 | x86/util.c \ 80 | x86/wsm.c \ 81 | x86/zen.c 82 | endif 83 | 84 | if CPU_PPC 85 | libnumatop_la_SOURCES += \ 86 | powerpc/include/power8.h \ 87 | powerpc/include/power9.h \ 88 | powerpc/include/power10.h \ 89 | powerpc/include/types.h \ 90 | powerpc/plat.c \ 91 | powerpc/power8.c \ 92 | powerpc/power9.c \ 93 | powerpc/power10.c \ 94 | powerpc/ui_perf_map.c \ 95 | powerpc/util.c 96 | endif 97 | 98 | bin_PROGRAMS = numatop 99 | noinst_PROGRAMS = mgen 100 | 101 | numatop_CFLAGS = $(NCURSES_CFLAGS) 102 | numatop_LDADD = libnumatop.la $(NCURSES_LIBS) 103 | numatop_SOURCES = common/numatop.c 104 | 105 | mgen_CFLAGS = $(NCURSES_CFLAGS) 106 | mgen_LDADD = libnumatop.la $(NCURSES_LIBS) 107 | mgen_SOURCES = \ 108 | test/mgen/include/util.h \ 109 | test/mgen/mgen.c 110 | 111 | if CPU_PPC 112 | mgen_SOURCES += \ 113 | test/mgen/powerpc/util.c 114 | endif 115 | if CPU_X86 116 | mgen_SOURCES += \ 117 | test/mgen/x86/util.c 118 | endif 119 | 120 | TESTS = test/mgen.01.sh test/mgen.02.sh 121 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Building & Installing NumaTOP 3 | 4 | Numatop uses autotools. If you're compiling from git, run `autogen.sh` 5 | and then `make`. Otherwise, use `./configure && make`. 6 | 7 | To install, run `sudo make install`. 8 | 9 | To run the test program, run `make check` after compilation or check 10 | the `mgen` program for help information. 11 | 12 | 13 | ## Build Dependencies 14 | 15 | NumaTOP requires following libraries or packages: 16 | 17 | * numactl-devel or libnuma-dev(el) 18 | * libncurses 19 | * libpthread 20 | 21 | * check 22 | 23 | ## Run NumaTOP 24 | 25 | NumaTOP requires running as root. 26 | # ./numatop 27 | 28 | In many systems, the default max open files are 1024, for platforms (like SPR) 29 | that have more CPUs, they require the system with the max open files should 30 | bigger than 1024, otherwise, the error can be "Fail to setup perf": 31 | 32 | # ulimit -n 33 | 1024 <------the max open files are 1024 34 | # ./numatop 35 | NumaTOP is starting ... 36 | Fail to setup perf (probably permission denied)! 37 | 38 | Need to enlarge the max open files: 39 | 40 | # ulimit -n 8192 41 | # ulimit -n 42 | 8192 <------now the max open files are 8192 43 | 44 | ## Supported Kernels 45 | 46 | The recommended kernel version is the latest stable kernel, currently 4.15. 47 | 48 | The minimum kernel version supported is 3.16 49 | 50 | For Haswell supporting, please also apply a perf patch on 3.16. The patch 51 | is `kernel_patches/0001-perf-x86-Widen-Haswell-OFFCORE-mask.patch`. 52 | 53 | The patch can also be found at following link: 54 | http://www.gossamer-threads.com/lists/linux/kernel/1964864 55 | 56 | 57 | ## Directories 58 | 59 | common: common code for all platforms. 60 | 61 | x86 : Intel and AMD platform-specific code. 62 | 63 | powerpc: PowerPC platform-specific code. 64 | 65 | test : mgen source code. mgen is a micro-test application which can 66 | generate memory access with runtime latency value among CPUs. 67 | Note that this application is only used for numatop testing! 68 | 69 | kernel_patches: the required kernel patches. 70 | 71 | 72 | ## Supported Hardware 73 | 74 | numatop is supported on Intel Xeon processors: 5500-series, 6500/7500-series, 75 | 5600 series, E7-x8xx-series, and E5-16xx/24xx/26xx/46xx-series. 76 | 77 | E5-16xx/24xx/26xx/46xx-series had better be updated to latest CPU microcode 78 | (microcode must be 0x618+ or 0x70c+). 79 | 80 | AMD EPYC processors from the 7001, 7002, 7003, 4004, 8004 and 9004 series are 81 | also supported. 82 | 83 | To learn about NumaTOP, please visit http://01.org/numatop 84 | 85 | 86 | ## PowerPC Support 87 | 88 | NumaTOP is also supported on PowerPC. Please check powerpc/FEATURES file 89 | for more details. 90 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. 3 | 4 | ## Reporting a Vulnerability 5 | Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). 6 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | autoreconf --force --install --symlink --warnings=all 6 | 7 | args="\ 8 | --sysconfdir=/etc \ 9 | --localstatedir=/var \ 10 | --prefix=/usr \ 11 | --enable-silent-rules" 12 | 13 | ./configure CFLAGS="-g -O2 $CFLAGS" $args "$@" 14 | make clean 15 | -------------------------------------------------------------------------------- /common/include/cmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_CMD_H 30 | #define _NUMATOP_CMD_H 31 | 32 | #include 33 | #include 34 | #include "types.h" 35 | #include "win.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #define CMD_HOME_CHAR 'h' 42 | #define CMD_REFRESH_CHAR 'r' 43 | #define CMD_QUIT_CHAR 'q' 44 | #define CMD_BACK_CHAR 'b' 45 | #define CMD_LATENCY_CHAR 'l' 46 | #define CMD_IR_NORMALIZE_CHAR 'i' 47 | #define CMD_NODE_OVERVIEW_CHAR 'n' 48 | #define CMD_1_CHAR '1' 49 | #define CMD_2_CHAR '2' 50 | #define CMD_3_CHAR '3' 51 | #define CMD_4_CHAR '4' 52 | #define CMD_5_CHAR '5' 53 | #define CMD_CALLCHAIN_CHAR 'c' 54 | #define CMD_ACCDST_CHAR 'd' 55 | #define CMD_MAP_GET_CHAR 'm' 56 | #define CMD_MAP_STOP_CHAR 's' 57 | #define CMD_PQOS_CMT_CHAR 'o' 58 | #define CMD_PQOS_MBM_CHAR 'p' 59 | 60 | typedef enum { 61 | CMD_INVALID_ID = 0, 62 | CMD_HOME_ID, 63 | CMD_IR_NORMALIZE_ID, 64 | CMD_MONITOR_ID, 65 | CMD_LWP_ID, 66 | CMD_LAT_ID, 67 | CMD_LATNODE_ID, 68 | CMD_NODE_OVERVIEW_ID, 69 | CMD_NODE_DETAIL_ID, 70 | CMD_CALLCHAIN_ID, 71 | CMD_LLCALLCHAIN_ID, 72 | CMD_ACCDST_ID, 73 | CMD_MAP_GET_ID, 74 | CMD_MAP_STOP_ID, 75 | CMD_1_ID, 76 | CMD_2_ID, 77 | CMD_3_ID, 78 | CMD_4_ID, 79 | CMD_5_ID, 80 | CMD_REFRESH_ID, 81 | CMD_QUIT_ID, 82 | CMD_BACK_ID, 83 | CMD_RESIZE_ID, 84 | CMD_PQOS_CMT_ID, 85 | CMD_PQOS_MBM_ID, 86 | } cmd_id_t; 87 | 88 | #define CMD_NUM 25 89 | 90 | typedef struct _cmd_home { 91 | cmd_id_t id; 92 | } cmd_home_t; 93 | 94 | typedef struct _cmd_ir_normalize { 95 | cmd_id_t id; 96 | } cmd_ir_normalize_t; 97 | 98 | typedef struct _cmd_monitor { 99 | cmd_id_t id; 100 | pid_t pid; 101 | int lwpid; 102 | } cmd_monitor_t; 103 | 104 | typedef struct _cmd_lwp { 105 | cmd_id_t id; 106 | pid_t pid; 107 | } cmd_lwp_t; 108 | 109 | typedef struct _cmd_lat { 110 | cmd_id_t id; 111 | pid_t pid; 112 | int lwpid; 113 | } cmd_lat_t; 114 | 115 | typedef struct _cmd_latnode { 116 | cmd_id_t id; 117 | pid_t pid; 118 | int lwpid; 119 | uint64_t addr; 120 | uint64_t size; 121 | } cmd_latnode_t; 122 | 123 | typedef struct _cmd_accdst { 124 | cmd_id_t id; 125 | pid_t pid; 126 | int lwpid; 127 | } cmd_accdst_t; 128 | 129 | typedef struct _cmd_node_overview { 130 | cmd_id_t id; 131 | } cmd_node_overview_t; 132 | 133 | typedef struct _cmd_node_detail { 134 | cmd_id_t id; 135 | int nid; 136 | } cmd_node_detail_t; 137 | 138 | typedef struct _cmd_callchain { 139 | cmd_id_t id; 140 | pid_t pid; 141 | int lwpid; 142 | } cmd_callchain_t; 143 | 144 | typedef struct _cmd_llcallchain { 145 | cmd_id_t id; 146 | pid_t pid; 147 | int lwpid; 148 | uint64_t addr; 149 | uint64_t size; 150 | char desc[WIN_DESCBUF_SIZE]; 151 | } cmd_llcallchain_t; 152 | 153 | typedef struct _cmd_pqos_cmt { 154 | cmd_id_t id; 155 | pid_t pid; 156 | int lwpid; 157 | int flags; 158 | } cmd_pqos_cmt_t; 159 | 160 | typedef struct _cmd_pqos_mbm { 161 | cmd_id_t id; 162 | pid_t pid; 163 | int lwpid; 164 | int flags; 165 | } cmd_pqos_mbm_t; 166 | 167 | typedef union _cmd { 168 | cmd_home_t home; 169 | cmd_ir_normalize_t ir_normalize; 170 | cmd_monitor_t monitor; 171 | cmd_lwp_t lwp; 172 | cmd_lat_t lat; 173 | cmd_latnode_t latnode; 174 | cmd_node_overview_t node_list; 175 | cmd_node_detail_t node_detail; 176 | cmd_callchain_t callchain; 177 | cmd_llcallchain_t llcallchain; 178 | cmd_accdst_t accdst; 179 | cmd_pqos_cmt_t pqos_cmt; 180 | cmd_pqos_mbm_t pqos_mbm; 181 | } cmd_t; 182 | 183 | typedef int (*pfn_switch_preop_t)(cmd_t *, boolean_t *); 184 | typedef int (*pfn_switch_op_t)(cmd_t *, boolean_t); 185 | 186 | typedef struct _switch { 187 | pfn_switch_preop_t preop; 188 | pfn_switch_op_t op; 189 | } switch_t; 190 | 191 | #define CMD_ID_SET(cmd_addr, id) \ 192 | (*(int *)(cmd_addr) = (id)) 193 | 194 | #define CMD_ID(cmd_addr) \ 195 | (*(int *)(cmd_addr)) 196 | 197 | #define CMD_LWP(cmd) \ 198 | ((cmd_lwp_t *)(cmd)) 199 | 200 | #define CMD_LAT(cmd) \ 201 | ((cmd_lat_t *)(cmd)) 202 | 203 | #define CMD_LATNODE(cmd) \ 204 | ((cmd_latnode_t *)(cmd)) 205 | 206 | #define CMD_ACCDST(cmd) \ 207 | ((cmd_accdst_t *)(cmd)) 208 | 209 | #define CMD_MONITOR(cmd) \ 210 | ((cmd_monitor_t *)(cmd)) 211 | 212 | #define CMD_NODE_DETAIL(cmd) \ 213 | ((cmd_node_detail_t *)(cmd)) 214 | 215 | #define CMD_CALLCHAIN(cmd) \ 216 | ((cmd_callchain_t *)(cmd)) 217 | 218 | #define CMD_LLCALLCHAIN(cmd) \ 219 | ((cmd_llcallchain_t *)(cmd)) 220 | 221 | #define CMD_PQOS_CMT(cmd) \ 222 | ((cmd_pqos_cmt_t *)(cmd)) 223 | 224 | #define CMD_PQOS_MBM(cmd) \ 225 | ((cmd_pqos_mbm_t *)(cmd)) 226 | 227 | #define CMD_UNCOREQPI(cmd) \ 228 | ((cmd_uncoreqpi_t *)(cmd)) 229 | 230 | extern void switch_table_init(void); 231 | extern int cmd_id_get(char); 232 | extern void cmd_execute(cmd_t *, boolean_t *); 233 | extern int op_refresh(cmd_t *, boolean_t); 234 | extern int op_page_next(cmd_t *, boolean_t); 235 | 236 | #ifdef __cplusplus 237 | } 238 | #endif 239 | 240 | #endif /* _NUMATOP_CMD_H */ 241 | -------------------------------------------------------------------------------- /common/include/disp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_DISP_H 30 | #define _NUMATOP_DISP_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "types.h" 37 | #include "util.h" 38 | #include "cmd.h" 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | #define DISP_DEFAULT_INTVAL 5 45 | #define PIPE_CHAR_QUIT 'q' 46 | #define PIPE_CHAR_RESIZE 'r' 47 | 48 | typedef enum { 49 | DISP_FLAG_NONE = 0, 50 | DISP_FLAG_ERR, 51 | DISP_FLAG_QUIT, 52 | DISP_FLAG_PROFILING_DATA_READY, 53 | DISP_FLAG_PROFILING_DATA_FAIL, 54 | DISP_FLAG_CALLCHAIN_DATA_READY, 55 | DISP_FLAG_CALLCHAIN_DATA_FAIL, 56 | DISP_FLAG_LL_DATA_READY, 57 | DISP_FLAG_LL_DATA_FAIL, 58 | DISP_FLAG_PQOS_CMT_READY, 59 | DISP_FLAG_PQOS_CMT_FAIL, 60 | DISP_FLAG_CMD, 61 | DISP_FLAG_SCROLLUP, 62 | DISP_FLAG_SCROLLDOWN, 63 | DISP_FLAG_SCROLLENTER, 64 | DISP_FLAG_GETCH 65 | } disp_flag_t; 66 | 67 | typedef struct _disp_ctl { 68 | pthread_mutex_t mutex; 69 | pthread_cond_t cond; 70 | pthread_mutex_t mutex2; 71 | pthread_cond_t cond2; 72 | pthread_t thr; 73 | boolean_t inited; 74 | cmd_t cmd; 75 | disp_flag_t flag; 76 | disp_flag_t flag2; 77 | int intval_ms; 78 | } disp_ctl_t; 79 | 80 | typedef struct _cons_ctl { 81 | fd_set fds; 82 | pthread_t thr; 83 | int pipe[2]; 84 | boolean_t inited; 85 | } cons_ctl_t; 86 | 87 | extern int g_run_secs; 88 | 89 | extern int disp_init(void); 90 | extern void disp_fini(void); 91 | extern int disp_cons_ctl_init(void); 92 | extern void disp_cons_ctl_fini(void); 93 | extern void disp_consthr_quit(void); 94 | extern void disp_profiling_data_ready(int); 95 | extern void disp_profiling_data_fail(void); 96 | extern void disp_callchain_data_ready(int); 97 | extern void disp_callchain_data_fail(void); 98 | extern void disp_ll_data_ready(int); 99 | extern void disp_ll_data_fail(void); 100 | extern void disp_pqos_cmt_data_ready(int); 101 | extern void disp_pqos_cmt_data_fail(void); 102 | extern void disp_on_resize(int); 103 | extern void disp_intval(char *, int); 104 | extern void disp_dispthr_quit_wait(void); 105 | extern void disp_dispthr_quit_start(void); 106 | extern void disp_go_home(void); 107 | extern void disp_flag2_set(disp_flag_t); 108 | extern disp_flag_t disp_flag2_wait(void); 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /* _NUMATOP_DISP_H */ 115 | -------------------------------------------------------------------------------- /common/include/lwp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_LWP_H 30 | #define _NUMATOP_LWP_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "types.h" 37 | #include "perf.h" 38 | #include "./os/node.h" 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | struct _track_proc; 45 | 46 | typedef struct _track_lwp { 47 | pthread_mutex_t mutex; 48 | int ref_count; 49 | int id; 50 | int intval_ms; 51 | int cpuid_max; 52 | uint64_t key; 53 | boolean_t removing; 54 | boolean_t quitting; 55 | boolean_t inited; 56 | struct _track_proc *proc; 57 | count_value_t *countval_arr; 58 | perf_countchain_t count_chain; 59 | perf_llrecgrp_t llrec_grp; 60 | perf_pqos_t pqos; 61 | void *perf_priv; 62 | } track_lwp_t; 63 | 64 | extern int lwp_free(track_lwp_t *); 65 | extern track_lwp_t *lwp_sort_next(struct _track_proc *); 66 | extern void lwp_enum_update(struct _track_proc *); 67 | extern int lwp_refcount_inc(track_lwp_t *); 68 | extern void lwp_refcount_dec(track_lwp_t *); 69 | extern int lwp_key_compute(track_lwp_t *, void *, boolean_t *end); 70 | extern int lwp_countval_update(track_lwp_t *, int, perf_count_id_t, uint64_t); 71 | extern int lwp_intval_get(track_lwp_t *); 72 | extern void lwp_intval_update(struct _track_proc *, int intval_ms); 73 | extern void lwp_quitting_set(track_lwp_t *); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* _NUMATOP_LWP_H */ 80 | -------------------------------------------------------------------------------- /common/include/os/map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_MAP_H 30 | #define _NUMATOP_MAP_H 31 | 32 | #include 33 | #include 34 | #include "../types.h" 35 | #include "sym.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #define MAP_R(attr) \ 42 | (((attr) >> 3) & 0x1) 43 | 44 | #define MAP_W(attr) \ 45 | (((attr) >> 2) & 0x1) 46 | 47 | #define MAP_X(attr) \ 48 | (((attr) >> 1) & 0x1) 49 | 50 | #define MAP_P(attr) \ 51 | (((attr) & 0x1) == 0) 52 | 53 | #define MAP_S(attr) \ 54 | (((attr) & 0x1) == 1) 55 | 56 | #define MAP_R_SET(attr) \ 57 | ((attr) |= (1 << 3)) 58 | 59 | #define MAP_W_SET(attr) \ 60 | ((attr) |= (1 << 2)) 61 | 62 | #define MAP_X_SET(attr) \ 63 | ((attr) |= (1 << 1)) 64 | 65 | #define MAP_P_SET(attr) \ 66 | ((attr) &= (unsigned int)(~1)) 67 | 68 | #define MAP_S_SET(attr) \ 69 | ((attr) |= 1) 70 | 71 | #define MAPFILE_LINE_SIZE (PATH_MAX + 1024) 72 | #define MAP_ENTRY_NUM 64 73 | 74 | typedef struct _numa_entry { 75 | uint64_t start_addr; 76 | uint64_t end_addr; 77 | int nid; 78 | } numa_entry_t; 79 | 80 | typedef struct _numa_map { 81 | numa_entry_t *arr; 82 | int nentry_cur; 83 | int nentry_max; 84 | } numa_map_t; 85 | 86 | typedef struct _map_entry { 87 | uint64_t start_addr; 88 | uint64_t end_addr; 89 | unsigned int attr; 90 | boolean_t need_resolve; 91 | numa_map_t numa_map; 92 | char desc[PATH_MAX]; 93 | } map_entry_t; 94 | 95 | typedef struct _map_proc { 96 | map_entry_t *arr; 97 | int nentry_cur; 98 | int nentry_max; 99 | boolean_t loaded; 100 | } map_proc_t; 101 | 102 | typedef struct _map_nodedst { 103 | int naccess; 104 | unsigned int total_lat; 105 | } map_nodedst_t; 106 | 107 | #define NUMA_MOVE_NPAGES 1024 108 | 109 | struct _track_proc; 110 | 111 | int map_init(void); 112 | void map_fini(void); 113 | int map_proc_load(struct _track_proc *); 114 | int map_proc_fini(struct _track_proc *); 115 | map_entry_t* map_entry_find(struct _track_proc *, uint64_t, uint64_t); 116 | int map_map2numa(struct _track_proc *, map_entry_t *); 117 | int map_addr2nodedst(pid_t pid, void **, int *, int, map_nodedst_t *, 118 | int, int *); 119 | 120 | #ifdef __cplusplus 121 | } 122 | #endif 123 | 124 | #endif /* _NUMATOP_SYM_H */ 125 | 126 | -------------------------------------------------------------------------------- /common/include/os/node.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_NODE_H 30 | #define _NUMATOP_NODE_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include "../types.h" 36 | #include "../perf.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #define NODE_ALL -1 43 | #define INVALID_NID -1 44 | #define INVALID_CPUID -1 45 | #define NODE_VALID(node) ((node)->nid != INVALID_NID) 46 | 47 | #define NODE_QPI_MAX 3 48 | #define NODE_IMC_MAX 8 49 | 50 | /* Number of online CPUs */ 51 | extern int g_ncpus; 52 | 53 | typedef struct _node_meminfo { 54 | uint64_t mem_total; 55 | uint64_t mem_free; 56 | uint64_t active; 57 | uint64_t inactive; 58 | uint64_t dirty; 59 | uint64_t writeback; 60 | uint64_t mapped; 61 | } node_meminfo_t; 62 | 63 | typedef struct _qpi_info { 64 | int id; 65 | int type; 66 | int fd; 67 | unsigned int config; 68 | uint64_t values[3]; 69 | uint64_t value_scaled; 70 | } qpi_info_t; 71 | 72 | typedef struct _node_qpi { 73 | int qpi_num; 74 | qpi_info_t qpi_info[NODE_QPI_MAX]; 75 | } node_qpi_t; 76 | 77 | typedef struct _imc_info { 78 | int id; 79 | int type; 80 | int fd; 81 | uint64_t values[3]; 82 | uint64_t value_scaled; 83 | } imc_info_t; 84 | 85 | typedef struct _node_imc { 86 | int imc_num; 87 | imc_info_t imc_info[NODE_IMC_MAX]; 88 | } node_imc_t; 89 | 90 | typedef struct _node { 91 | int nid; 92 | int ncpus; 93 | perf_cpu_t cpus[NCPUS_NODE_MAX]; 94 | count_value_t countval; 95 | node_meminfo_t meminfo; 96 | node_qpi_t qpi; 97 | node_imc_t imc; 98 | boolean_t hotadd; 99 | boolean_t hotremove; 100 | } node_t; 101 | 102 | typedef struct _node_group { 103 | pthread_mutex_t mutex; 104 | node_t nodes[NNODES_MAX]; 105 | int nnodes; 106 | int cpuid_max; 107 | int intval_ms; 108 | boolean_t inited; 109 | } node_group_t; 110 | 111 | extern int node_group_init(void); 112 | extern void node_group_fini(void); 113 | extern int node_group_refresh(boolean_t); 114 | extern node_t *node_get(int); 115 | extern int node_num(void); 116 | extern void node_group_lock(void); 117 | extern void node_group_unlock(void); 118 | extern node_t *node_by_cpu(int); 119 | extern int node_ncpus(node_t *); 120 | extern int node_intval_get(void); 121 | extern void node_countval_update(node_t *, perf_count_id_t, uint64_t); 122 | extern uint64_t node_countval_get(node_t *, ui_count_id_t); 123 | extern void node_meminfo(int, node_meminfo_t *); 124 | extern int node_cpu_traverse(pfn_perf_cpu_op_t, void *, boolean_t, 125 | pfn_perf_cpu_op_t); 126 | extern uint64_t node_countval_sum(count_value_t *, int, ui_count_id_t); 127 | extern perf_cpu_t* node_cpus(node_t *); 128 | extern void node_intval_update(int); 129 | extern void node_profiling_clear(void); 130 | extern node_t* node_valid_get(int); 131 | extern int node_cpuid_max(void); 132 | extern int node_qpi_init(void); 133 | extern int node_imc_init(void); 134 | 135 | #ifdef __cplusplus 136 | } 137 | #endif 138 | 139 | #endif /* _NODE_H */ 140 | -------------------------------------------------------------------------------- /common/include/os/os_cmd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_OS_CMD_H 30 | #define _NUMATOP_OS_CMD_H 31 | 32 | #include 33 | #include 34 | #include "../types.h" 35 | #include "../cmd.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | extern int os_preop_switch2profiling(cmd_t *, boolean_t *); 42 | extern int os_preop_switch2ll(cmd_t *, boolean_t *); 43 | extern int os_preop_llrefresh(cmd_t *, boolean_t *); 44 | extern int os_preop_llmap_get(cmd_t *, boolean_t *); 45 | extern int os_preop_switch2ln(cmd_t *, boolean_t *); 46 | extern int os_preop_lnrefresh(cmd_t *, boolean_t *); 47 | extern int os_preop_lnmap_get(cmd_t *, boolean_t *); 48 | extern int os_preop_back2ll(cmd_t *, boolean_t *); 49 | extern int os_preop_switch2callchain(cmd_t *, boolean_t *); 50 | extern int os_preop_switch2accdst(cmd_t *, boolean_t *); 51 | extern int os_preop_leavecallchain(cmd_t *, boolean_t *); 52 | extern int os_preop_switch2pqoscmt(cmd_t *, boolean_t *); 53 | extern int os_preop_switch2pqosmbm(cmd_t *, boolean_t *); 54 | extern int os_preop_switch2uncore(cmd_t *, boolean_t *); 55 | 56 | extern int os_op_llmap_stop(cmd_t *, boolean_t); 57 | extern int os_op_lnmap_stop(cmd_t *, boolean_t); 58 | extern int os_op_switch2ll(cmd_t *, boolean_t); 59 | extern int os_op_callchain_count(cmd_t *, boolean_t); 60 | extern int os_op_switch2llcallchain(cmd_t *, boolean_t); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* _NUMATOP_OS_CMD_H */ 67 | -------------------------------------------------------------------------------- /common/include/os/os_page.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_OS_PAGE_H 30 | #define _NUMATOP_OS_PAGE_H 31 | 32 | #include 33 | #include "../types.h" 34 | #include "../page.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | extern boolean_t os_page_smpl_start(page_t *); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif /* _NUMATOP_OS_PAGE_H */ 47 | -------------------------------------------------------------------------------- /common/include/os/os_perf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_OS_PERF_H 30 | #define _NUMATOP_OS_PERF_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include "../types.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | extern precise_type_t g_precise; 42 | 43 | #define PERF_REC_NUM 512 44 | #define PERF_FD_NUM NCPUS_MAX * PERF_COUNT_NUM 45 | #define INVALID_CODE_UMASK (uint64_t)(-1) 46 | #define PERF_PQOS_CMT_MAX 10 47 | 48 | #define PERF_PQOS_FLAG_LLC 1 49 | #define PERF_PQOS_FLAG_TOTAL_BW 2 50 | #define PERF_PQOS_FLAG_LOCAL_BW 4 51 | 52 | typedef struct _os_perf_callchain { 53 | unsigned int ip_num; 54 | uint64_t ips[IP_NUM]; 55 | } os_perf_callchain_t; 56 | 57 | typedef struct _os_perf_llrec { 58 | uint64_t addr; 59 | uint64_t cpu; 60 | uint64_t latency; 61 | os_perf_callchain_t callchain; 62 | } os_perf_llrec_t; 63 | 64 | typedef struct _perf_cpu { 65 | int cpuid; 66 | int fds[PERF_COUNT_NUM]; 67 | int group_idx; 68 | int map_len; 69 | int map_mask; 70 | void *map_base; 71 | boolean_t hit; 72 | boolean_t hotadd; 73 | boolean_t hotremove; 74 | count_value_t countval_last; 75 | } perf_cpu_t; 76 | 77 | typedef struct _perf_pqos { 78 | int task_id; 79 | int flags; 80 | uint64_t occupancy_scaled; 81 | uint64_t totalbw_scaled; 82 | uint64_t localbw_scaled; 83 | uint64_t totalbw; 84 | uint64_t localbw; 85 | } perf_pqos_t; 86 | 87 | typedef int (*pfn_perf_cpu_op_t)(struct _perf_cpu *, void *); 88 | 89 | struct _perf_ctl; 90 | union _perf_task; 91 | struct _perf_countchain; 92 | struct _perf_chainrecgrp; 93 | struct _perf_chainrec; 94 | struct _perf_llrecgrp; 95 | struct _track_proc; 96 | struct _track_lwp; 97 | 98 | extern boolean_t os_profiling_started(struct _perf_ctl *); 99 | extern int os_profiling_start(struct _perf_ctl *, union _perf_task *); 100 | extern int os_profiling_smpl(struct _perf_ctl *, union _perf_task *, int *); 101 | extern int os_profiling_partpause(struct _perf_ctl *, union _perf_task *); 102 | extern int os_profiling_multipause(struct _perf_ctl *, union _perf_task *); 103 | extern int os_profiling_restore(struct _perf_ctl *, union _perf_task *); 104 | extern int os_profiling_multi_restore(struct _perf_ctl *, union _perf_task *); 105 | extern int os_callchain_start(struct _perf_ctl *, union _perf_task *); 106 | extern int os_callchain_smpl(struct _perf_ctl *, union _perf_task *, int *); 107 | extern int os_ll_start(struct _perf_ctl *, union _perf_task *); 108 | extern int os_ll_smpl(struct _perf_ctl *, union _perf_task *, int *); 109 | extern int os_perf_init(void); 110 | extern void os_perf_fini(void); 111 | extern void os_perfthr_quit_wait(void); 112 | extern int os_perf_profiling_partpause(perf_count_id_t); 113 | extern int os_perf_profiling_multipause(perf_count_id_t *); 114 | extern int os_perf_profiling_restore(perf_count_id_t); 115 | extern int os_perf_profiling_multi_restore(perf_count_id_t *); 116 | extern int os_perf_callchain_start(pid_t, int); 117 | extern int os_perf_callchain_smpl(void); 118 | extern int os_perf_ll_smpl(struct _perf_ctl *, pid_t, int); 119 | extern void os_perf_countchain_reset(struct _perf_countchain *); 120 | extern void os_allstop(void); 121 | extern int os_perf_allstop(void); 122 | extern void* os_perf_priv_alloc(boolean_t *); 123 | extern void os_perf_priv_free(void *); 124 | extern int os_perf_chain_nentries( 125 | struct _perf_chainrecgrp *, int *); 126 | extern struct _perf_chainrec* os_perf_chainrec_get( 127 | struct _perf_chainrecgrp *, int); 128 | extern char *os_perf_chain_entryname(void *, int); 129 | extern void os_perf_cpuarr_init(perf_cpu_t *, int, boolean_t); 130 | extern void os_perf_cpuarr_fini(perf_cpu_t *, int, boolean_t); 131 | extern int os_perf_cpuarr_refresh(perf_cpu_t *, int, int *, int, boolean_t); 132 | extern void os_pqos_cmt_init(perf_pqos_t *); 133 | extern int os_pqos_cmt_start(struct _perf_ctl *, union _perf_task *); 134 | extern int os_perf_pqos_cmt_smpl(struct _perf_ctl *, pid_t, int); 135 | extern int os_pqos_cmt_smpl(struct _perf_ctl *, union _perf_task *, int *); 136 | extern void os_perf_pqos_free(perf_pqos_t *); 137 | extern int os_pqos_cmt_proc_smpl(struct _track_proc *, void *, boolean_t *); 138 | extern int os_pqos_cmt_lwp_smpl(struct _track_lwp *, void *, boolean_t *); 139 | extern int os_pqos_cmt_proc_free(struct _track_proc *, void *, boolean_t *); 140 | extern boolean_t os_perf_pqos_cmt_started(struct _perf_ctl *); 141 | extern int os_pqos_proc_stop(struct _perf_ctl *, union _perf_task *); 142 | extern int os_uncore_stop(struct _perf_ctl *, union _perf_task *); 143 | extern int os_uncore_start(struct _perf_ctl *, union _perf_task *); 144 | extern int os_uncore_smpl(struct _perf_ctl *, union _perf_task *, int *); 145 | extern boolean_t os_perf_uncore_started(struct _perf_ctl *); 146 | extern int os_perf_uncore_smpl(struct _perf_ctl *, int); 147 | 148 | #ifdef __cplusplus 149 | } 150 | #endif 151 | 152 | #endif /* _NUMATOP_OS_PERF_H */ 153 | -------------------------------------------------------------------------------- /common/include/os/os_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_OS_TYPES_H 30 | #define _NUMATOP_OS_TYPES_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | typedef enum { 37 | B_FALSE = 0, 38 | B_TRUE 39 | } boolean_t; 40 | 41 | #define IP_NUM 32 42 | #define INVALID_FD -1 43 | #define INVALID_CONFIG (uint64_t)(-1) 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* _NUMATOP_OS_TYPES_H */ 50 | -------------------------------------------------------------------------------- /common/include/os/os_util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_OS_UTIL_H 30 | #define _NUMATOP_OS_UTIL_H 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include "../types.h" 40 | #include "../os/node.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #define DIGIT_LEN_MAX 512 47 | #define CPU0_CPUFREQ_PATH \ 48 | "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" 49 | #define NODE_INFO_ROOT \ 50 | "/sys/devices/system/node/" 51 | #define NODE_NONLINE_PATH \ 52 | "/sys/devices/system/node/online" 53 | #define CPUINFO_PATH \ 54 | "/proc/cpuinfo" 55 | #define CQM_LLC_OCCUPANCY_SCALE_PATH \ 56 | "/sys/devices/intel_cqm/events/llc_occupancy.scale" 57 | #define CQM_LLC_TOTAL_BW_SCALE_PATH \ 58 | "/sys/devices/intel_cqm/events/total_bytes.scale" 59 | #define CQM_LLC_LOCAL_BW_SCALE_PATH \ 60 | "/sys/devices/intel_cqm/events/local_bytes.scale" 61 | 62 | struct _perf_pqos; 63 | 64 | extern boolean_t os_authorized(void); 65 | extern int os_numatop_lock(boolean_t *); 66 | extern void os_numatop_unlock(void); 67 | extern int os_procfs_psinfo_get(pid_t, void *); 68 | extern int os_procfs_pname_get(pid_t, char *, int); 69 | extern int os_procfs_lwp_enum(pid_t, int **lwps, int *); 70 | extern boolean_t os_procfs_lwp_valid(pid_t, int); 71 | extern int processor_bind(int cpu); 72 | extern int processor_unbind(void); 73 | extern void os_calibrate(double *nsofclk, uint64_t *clkofsec); 74 | extern boolean_t os_sysfs_node_enum(int *, int, int *); 75 | extern boolean_t os_sysfs_cpu_enum(int, int *, int, int *); 76 | extern int sysfs_os_online_ncpus(void); 77 | extern boolean_t os_sysfs_meminfo(int, node_meminfo_t *); 78 | extern int os_sysfs_online_ncpus(void); 79 | extern int os_sysfs_cqm_llc_scale(const char*, double *); 80 | extern int os_sysfs_uncore_qpi_init(qpi_info_t *, int); 81 | extern int os_sysfs_uncore_upi_init(qpi_info_t *, int); 82 | extern int os_sysfs_uncore_imc_init(imc_info_t *, int); 83 | extern boolean_t os_cmt_init(void); 84 | extern void os_cmt_fini(void); 85 | extern int os_sysfs_cmt_task_set(int, int, struct _perf_pqos *); 86 | extern int os_sysfs_cmt_task_value(struct _perf_pqos *, int); 87 | 88 | #ifdef __cplusplus 89 | } 90 | #endif 91 | 92 | #endif /* _NUMATOP_OS_UTIL_H */ 93 | -------------------------------------------------------------------------------- /common/include/os/os_win.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_OS_WIN_H 30 | #define _NUMATOP_OS_WIN_H 31 | 32 | #include 33 | #include 34 | #include "../types.h" 35 | #include "../proc.h" 36 | #include "node.h" 37 | #include "os_perf.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | #define NOTE_LAT \ 44 | "Q: Quit; H: Home; B: Back; R: Refresh; " \ 45 | "C: Call-Chain; D: Distribution" 46 | 47 | #define NOTE_LATNODE \ 48 | "Q: Quit; H: Home; B: Back; R: Refresh" 49 | 50 | #define NOTE_LLCALLCHAIN \ 51 | "Q: Quit; H: Home; B: Back; R: Refresh" 52 | 53 | struct _nodeoverview_line; 54 | struct _dyn_nodedetail; 55 | struct _dyn_callchain; 56 | struct _dyn_win; 57 | struct _page; 58 | struct _lat_line; 59 | 60 | extern void os_nodeoverview_caption_build(char *, int); 61 | extern void os_nodeoverview_data_build(char *, int, 62 | struct _nodeoverview_line *, node_t *); 63 | extern void os_nodedetail_data(struct _dyn_nodedetail *, win_reg_t *); 64 | extern int os_callchain_list_show(struct _dyn_callchain *, track_proc_t *, 65 | track_lwp_t *); 66 | extern void os_lat_buf_hit(struct _lat_line *, int, os_perf_llrec_t *, 67 | uint64_t *, uint64_t *); 68 | extern boolean_t os_lat_win_draw(struct _dyn_win *); 69 | extern void* os_llcallchain_dyn_create(struct _page *); 70 | extern void os_llcallchain_win_destroy(struct _dyn_win *); 71 | extern boolean_t os_llcallchain_win_draw(struct _dyn_win *); 72 | extern void os_llcallchain_win_scroll(struct _dyn_win *, int); 73 | extern boolean_t os_latnode_win_draw(struct _dyn_win *); 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif /* _NUMATOP_OS_WIN_H */ 80 | -------------------------------------------------------------------------------- /common/include/os/pfwrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_PFWRAPPER_H 30 | #define _NUMATOP_PFWRAPPER_H 31 | 32 | #include 33 | #include 34 | #include "linux/perf_event.h" 35 | #include "../types.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | #define PF_MAP_NPAGES_MAX 1024 42 | #define PF_MAP_NPAGES_MIN 64 43 | #define PF_MAP_NPAGES_NORMAL 256 44 | 45 | #if defined(__i386__) 46 | #ifndef __NR_perf_event_open 47 | #define __NR_perf_event_open 336 48 | #endif 49 | 50 | #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") 51 | #define wmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") 52 | #define mb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") 53 | #endif 54 | 55 | #if defined(__x86_64__) 56 | #ifndef __NR_perf_event_open 57 | #define __NR_perf_event_open 298 58 | #endif 59 | 60 | #define rmb() asm volatile("lfence" ::: "memory") 61 | #define wmb() asm volatile("sfence" ::: "memory") 62 | #define mb() asm volatile("mfence":::"memory") 63 | #endif 64 | 65 | #if defined(__powerpc64__) 66 | #ifndef __NR_perf_event_open 67 | #define __NR_perf_event_open 319 68 | #endif 69 | 70 | #define rmb() __asm__ __volatile__ ("sync" : : : "memory") 71 | #define wmb() __asm__ __volatile__ ("sync" : : : "memory") 72 | #define mb() __asm__ __volatile__ ("sync" : : : "memory") 73 | #endif 74 | 75 | typedef struct _pf_conf { 76 | perf_count_id_t perf_count_id; 77 | uint32_t type; 78 | uint64_t config; 79 | uint64_t config1; 80 | uint64_t sample_period; 81 | bool exclude_guest; 82 | } pf_conf_t; 83 | 84 | typedef struct _pf_profiling_rec { 85 | unsigned int pid; 86 | unsigned int tid; 87 | uint64_t period; 88 | count_value_t countval; 89 | unsigned int ip_num; 90 | uint64_t ips[IP_NUM]; 91 | } pf_profiling_rec_t; 92 | 93 | typedef struct _pf_profiling_rbrec { 94 | uint32_t pid; 95 | uint32_t tid; 96 | uint64_t time_enabled; 97 | uint64_t time_running; 98 | uint64_t counts[PERF_COUNT_NUM]; 99 | uint64_t ip_num; 100 | } pf_profiling_rbrec_t; 101 | 102 | typedef struct _pf_ll_rec { 103 | unsigned int pid; 104 | unsigned int tid; 105 | uint64_t addr; 106 | uint64_t cpu; 107 | uint64_t latency; 108 | unsigned int ip_num; 109 | uint64_t ips[IP_NUM]; 110 | } pf_ll_rec_t; 111 | 112 | typedef struct _pf_ll_rbrec { 113 | unsigned int pid; 114 | unsigned int tid; 115 | uint64_t addr; 116 | uint64_t cpu; 117 | uint64_t latency; 118 | unsigned int ip_num; 119 | } pf_ll_rbrec_t; 120 | 121 | struct _perf_cpu; 122 | struct _perf_pqos; 123 | struct _node; 124 | 125 | typedef int (*pfn_pf_event_op_t)(struct _perf_cpu *); 126 | 127 | int pf_ringsize_init(void); 128 | int pf_profiling_setup(struct _perf_cpu *, int, pf_conf_t *); 129 | int pf_profiling_start(struct _perf_cpu *, perf_count_id_t); 130 | int pf_profiling_stop(struct _perf_cpu *, perf_count_id_t); 131 | int pf_profiling_allstart(struct _perf_cpu *); 132 | int pf_profiling_allstop(struct _perf_cpu *); 133 | void pf_profiling_record(struct _perf_cpu *, pf_profiling_rec_t *, int *); 134 | int pf_ll_setup(struct _perf_cpu *, pf_conf_t *); 135 | int pf_ll_start(struct _perf_cpu *); 136 | int pf_ll_stop(struct _perf_cpu *); 137 | void pf_ll_record(struct _perf_cpu *, pf_ll_rec_t *, int *); 138 | void pf_resource_free(struct _perf_cpu *); 139 | int pf_pqos_occupancy_setup(struct _perf_pqos *, int pid, int lwpid); 140 | int pf_pqos_totalbw_setup(struct _perf_pqos *, int pid, int lwpid); 141 | int pf_pqos_localbw_setup(struct _perf_pqos *, int pid, int lwpid); 142 | int pf_pqos_start(struct _perf_pqos *); 143 | int pf_pqos_stop(struct _perf_pqos *); 144 | void pf_pqos_record(struct _perf_pqos *); 145 | void pf_pqos_resource_free(struct _perf_pqos *); 146 | void pf_uncoreqpi_free(struct _node *); 147 | int pf_uncoreqpi_setup(struct _node *); 148 | int pf_uncoreqpi_start(struct _node *); 149 | int pf_uncoreqpi_smpl(struct _node *); 150 | void pf_uncoreimc_free(struct _node *); 151 | int pf_uncoreimc_setup(struct _node *); 152 | int pf_uncoreimc_start(struct _node *); 153 | int pf_uncoreimc_smpl(struct _node *); 154 | 155 | #ifdef __cplusplus 156 | } 157 | #endif 158 | 159 | #endif /* _NUMATOP_PFWRAPPER_H */ 160 | -------------------------------------------------------------------------------- /common/include/os/plat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_PLAT_H 30 | #define _NUMATOP_PLAT_H 31 | 32 | #include 33 | #include 34 | #include "../types.h" 35 | #ifdef __powerpc64__ 36 | #include "../../../powerpc/include/types.h" 37 | #else 38 | #include "../../../x86/include/types.h" 39 | #endif 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | #define PLAT_EVENT_DESC_SIZE 64 46 | 47 | typedef struct _plat_event_config { 48 | uint32_t type; 49 | /* 50 | * config = "code + umask" if type is PERF_TYPE_RAW or 51 | * event_id if type is PERF_TYPE_HARDWARE. 52 | */ 53 | uint64_t config; 54 | uint64_t other_attr; 55 | uint64_t extra_value; 56 | uint64_t sample_period; 57 | bool exclude_guest; 58 | char desc[PLAT_EVENT_DESC_SIZE]; 59 | } plat_event_config_t; 60 | 61 | extern uint64_t g_sample_period[PERF_COUNT_NUM][PRECISE_NUM]; 62 | extern cpu_type_t s_cpu_type; 63 | extern boolean_t g_cmt_enabled; 64 | 65 | typedef void (*pfn_plat_profiling_config_t)(perf_count_id_t, 66 | plat_event_config_t *); 67 | typedef void (*pfn_plat_ll_config_t)(plat_event_config_t *); 68 | typedef int (*pfn_plat_offcore_num_t)(void); 69 | 70 | extern pfn_plat_profiling_config_t s_plat_profiling_config[CPU_TYPE_NUM]; 71 | extern pfn_plat_ll_config_t s_plat_ll_config[CPU_TYPE_NUM]; 72 | extern pfn_plat_offcore_num_t s_plat_offcore_num[CPU_TYPE_NUM]; 73 | 74 | extern int plat_detect(void); 75 | extern void plat_profiling_config(perf_count_id_t, plat_event_config_t *); 76 | extern void plat_ll_config(plat_event_config_t *); 77 | extern void plat_config_get(perf_count_id_t, plat_event_config_t *, plat_event_config_t *); 78 | extern int plat_offcore_num(void); 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* _NUMATOP_PLAT_H */ 85 | -------------------------------------------------------------------------------- /common/include/os/sym.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_SYM_H 30 | #define _NUMATOP_SYM_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include "../types.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* 42 | * This symbol type is the same as STT_FUNC except that it always 43 | * points to a function or piece of executable code which takes no 44 | * arguments and which returns a function pointer. 45 | */ 46 | #ifndef STT_IFUNC 47 | #define STT_IFUNC 10 48 | #endif 49 | 50 | #define SYM_ITEM_NUM 1024 51 | #define SYM_NAME_SIZE 32 52 | #define SYM_LIB_NUM 16 53 | #define SYM_CLASS_NUM 2 54 | #define ELF32_LOAD_ADDR 0x08048000 55 | #define ELF64_LOAD_ADDR 0x400000 56 | #define INVALID_LOADADDR (uint64_t)(-1) 57 | 58 | typedef enum { 59 | SYM_CLASS_INVALID = -1, 60 | SYM_CLASS_ELF32 = 0, 61 | SYM_CLASS_ELF64 62 | } sym_class_t; 63 | 64 | typedef enum { 65 | SYM_TYPE_FUNC = 1, 66 | SYM_TYPE_OBJECT 67 | } sym_type_t; 68 | 69 | typedef struct _sym_item { 70 | char name[SYM_NAME_SIZE]; 71 | sym_type_t type; 72 | unsigned int index; 73 | uint64_t off; 74 | uint64_t size; 75 | } sym_item_t; 76 | 77 | typedef struct _sym_binary { 78 | sym_item_t *items; 79 | int nitem_cur; 80 | int nitem_max; 81 | FILE *fp; 82 | char path[PATH_MAX]; 83 | } sym_binary_t; 84 | 85 | typedef struct _sym_lib { 86 | sym_binary_t binary; 87 | struct _sym_lib *next; 88 | } sym_lib_t; 89 | 90 | typedef struct _sym_libref { 91 | sym_lib_t **libs; 92 | uint64_t *lib_loadaddr; 93 | int nlib_cur; 94 | int nlib_max; 95 | } sym_libref_t; 96 | 97 | typedef struct _sym { 98 | sym_binary_t image; 99 | uint64_t image_loadaddr; 100 | sym_libref_t libref; 101 | boolean_t loaded; 102 | } sym_t; 103 | 104 | typedef struct _sym_ops { 105 | int (*pfn_binary_read)(sym_binary_t *, sym_type_t); 106 | } sym_ops_t; 107 | 108 | typedef struct _sym_callentry { 109 | uint64_t addr; 110 | uint64_t size; 111 | char name[SYM_NAME_SIZE]; 112 | } sym_callentry_t; 113 | 114 | typedef struct _sym_callchain { 115 | sym_callentry_t *entry_arr; 116 | int nentry; 117 | int naccess; 118 | struct _sym_callchain *prev; 119 | struct _sym_callchain *next; 120 | } sym_callchain_t; 121 | 122 | typedef struct _sym_chainlist { 123 | sym_callchain_t *head; 124 | sym_callchain_t *tail; 125 | int num; 126 | } sym_chainlist_t; 127 | 128 | #define IP_HIT(ip, addr, size) \ 129 | (((ip) >= (addr)) && ((ip) < (addr) + (size))) 130 | 131 | struct _track_proc; 132 | 133 | void sym_init(void); 134 | void sym_fini(void); 135 | int sym_load(struct _track_proc *, sym_type_t); 136 | void sym_free(sym_t *); 137 | int sym_callchain_add(sym_t *, uint64_t *, int, sym_chainlist_t *); 138 | void sym_callchain_resort(sym_chainlist_t *); 139 | sym_callchain_t* sym_callchain_detach(sym_chainlist_t *); 140 | void sym_callchain_free(sym_callchain_t *); 141 | void sym_chainlist_free(sym_chainlist_t *); 142 | int sym_chainlist_nentry(sym_chainlist_t *, int *); 143 | 144 | #ifdef __cplusplus 145 | } 146 | #endif 147 | 148 | #endif /* _NUMATOP_SYM_H */ 149 | -------------------------------------------------------------------------------- /common/include/page.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_PAGE_H 30 | #define _NUMATOP_PAGE_H 31 | 32 | #include 33 | #include "types.h" 34 | #include "util.h" 35 | #include "win.h" 36 | #include "cmd.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #define PAGE_WIN_TYPE(page) \ 43 | ((page)->dyn_win.type) 44 | 45 | #define PAGE_CMD(page) \ 46 | (&((page)->cmd)) 47 | 48 | typedef struct _page { 49 | cmd_t cmd; 50 | struct _page *prev; 51 | struct _page *next; 52 | dyn_win_t dyn_win; 53 | } page_t; 54 | 55 | typedef struct _page_list { 56 | page_t *head; 57 | page_t *tail; 58 | page_t *cur; 59 | page_t *next_run; 60 | int npages; 61 | } page_list_t; 62 | 63 | extern void page_list_init(void); 64 | extern void page_list_fini(void); 65 | extern page_t *page_create(cmd_t *); 66 | extern boolean_t page_next_execute(boolean_t); 67 | extern page_t *page_current_get(void); 68 | extern void page_next_set(page_t *); 69 | extern page_t *page_current_set(page_t *); 70 | extern void page_drop_next(page_t *); 71 | extern page_t *page_curprev_get(void); 72 | extern void page_win_destroy(void); 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif /* _NUMATOP_PAGE_H */ 79 | -------------------------------------------------------------------------------- /common/include/perf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_PERF_H 30 | #define _NUMATOP_PERF_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include "types.h" 36 | #include "./os/os_perf.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #define PERF_WAIT_NSEC 60 43 | #define PERF_INTVAL_MIN_MS 1000 44 | 45 | typedef enum { 46 | PERF_STATUS_IDLE = 0, 47 | PERF_STATUS_PROFILING_STARTED, 48 | PERF_STATUS_PROFILING_PART_STARTED, 49 | PERF_STATUS_PROFILING_MULTI_STARTED, 50 | PERF_STATUS_PROFILING_FAILED, 51 | PERF_STATUS_CALLCHAIN_STARTED, 52 | PERF_STATUS_CALLCHAIN_FAILED, 53 | PERF_STATUS_LL_STARTED, 54 | PERF_STATUS_LL_FAILED, 55 | PERF_STATUS_PQOS_CMT_STARTED, 56 | PERF_STATUS_PQOS_CMT_FAILED, 57 | PERF_STATUS_UNCORE_STARTED, 58 | PERF_STATUS_UNCORE_FAILED, 59 | } perf_status_t; 60 | 61 | typedef enum { 62 | PERF_INVALID_ID = 0, 63 | PERF_PROFILING_START_ID, 64 | PERF_PROFILING_PARTPAUSE_ID, 65 | PERF_PROFILING_MULTIPAUSE_ID, 66 | PERF_PROFILING_RESTORE_ID, 67 | PERF_PROFILING_MULTI_RESTORE_ID, 68 | PERF_PROFILING_SMPL_ID, 69 | PERF_CALLCHAIN_START_ID, 70 | PERF_CALLCHAIN_SMPL_ID, 71 | PERF_LL_START_ID, 72 | PERF_LL_SMPL_ID, 73 | PERF_STOP_ID, 74 | PERF_QUIT_ID, 75 | PERF_PQOS_CMT_START_ID, 76 | PERF_PQOS_CMT_SMPL_ID, 77 | PERF_PQOS_CMT_STOP_ID, 78 | PERF_UNCORE_START_ID, 79 | PERF_UNCORE_SMPL_ID, 80 | PERF_UNCORE_STOP_ID, 81 | } perf_taskid_t; 82 | 83 | typedef struct _task_quit { 84 | perf_taskid_t task_id; 85 | } task_quit_t; 86 | 87 | typedef struct _task_allstop { 88 | perf_taskid_t task_id; 89 | } task_allstop_t; 90 | 91 | typedef struct _task_profiling { 92 | perf_taskid_t task_id; 93 | boolean_t use_dispflag1; 94 | } task_profiling_t; 95 | 96 | typedef struct _task_partpause { 97 | perf_taskid_t task_id; 98 | perf_count_id_t perf_count_id; 99 | } task_partpause_t; 100 | 101 | typedef struct _task_multipause { 102 | perf_taskid_t task_id; 103 | perf_count_id_t *perf_count_ids; 104 | } task_multipause_t; 105 | 106 | typedef struct _task_restore { 107 | perf_taskid_t task_id; 108 | perf_count_id_t perf_count_id; 109 | } task_restore_t; 110 | 111 | typedef struct _task_multi_restore { 112 | perf_taskid_t task_id; 113 | perf_count_id_t *perf_count_ids; 114 | } task_multi_restore_t; 115 | 116 | typedef struct _task_callchain { 117 | perf_taskid_t task_id; 118 | pid_t pid; 119 | int lwpid; 120 | } task_callchain_t; 121 | 122 | typedef struct _task_ll { 123 | perf_taskid_t task_id; 124 | pid_t pid; 125 | int lwpid; 126 | } task_ll_t; 127 | 128 | typedef struct _task_pqos_cmt { 129 | perf_taskid_t task_id; 130 | pid_t pid; 131 | int lwpid; 132 | int flags; 133 | } task_pqos_cmt_t; 134 | 135 | typedef struct _task_uncore { 136 | perf_taskid_t task_id; 137 | int nid; 138 | } task_uncore_t; 139 | 140 | typedef union _perf_task { 141 | task_quit_t quit; 142 | task_allstop_t allstop; 143 | task_profiling_t profiling; 144 | task_partpause_t partpause; 145 | task_restore_t restore; 146 | task_callchain_t callchain; 147 | task_ll_t ll; 148 | task_pqos_cmt_t pqos_cmt; 149 | task_uncore_t uncore; 150 | } perf_task_t; 151 | 152 | typedef struct _perf_llrecgrp { 153 | os_perf_llrec_t *rec_arr; 154 | int nrec_cur; 155 | int nrec_max; 156 | int cursor; 157 | } perf_llrecgrp_t; 158 | 159 | typedef struct _perf_chainrec { 160 | uint64_t count_value; 161 | os_perf_callchain_t callchain; 162 | } perf_chainrec_t; 163 | 164 | typedef struct _perf_chainrecgrp { 165 | perf_chainrec_t *rec_arr; 166 | int nrec_cur; 167 | int nrec_max; 168 | int cursor; 169 | } perf_chainrecgrp_t; 170 | 171 | typedef struct _perf_countchain { 172 | perf_chainrecgrp_t chaingrps[PERF_COUNT_NUM]; 173 | } perf_countchain_t; 174 | 175 | #define TASKID(task_addr) \ 176 | (*(perf_taskid_t *)(task_addr)) 177 | 178 | #define TASKID_SET(task_addr, task_id) \ 179 | ((*(perf_taskid_t *)(task_addr)) = (task_id)) 180 | 181 | #define PERF_PROFILING_STARTED \ 182 | (s_perf_ctl.status == PERF_STATUS_PROFILING_STARTED) 183 | 184 | typedef struct _perf_ctl { 185 | pthread_mutex_t mutex; 186 | pthread_cond_t cond; 187 | pthread_mutex_t status_mutex; 188 | pthread_cond_t status_cond; 189 | perf_status_t status; 190 | pthread_t thr; 191 | perf_task_t task; 192 | boolean_t inited; 193 | uint64_t last_ms; 194 | uint64_t last_ms_pqos; 195 | } perf_ctl_t; 196 | 197 | extern int perf_init(void); 198 | extern void perf_fini(void); 199 | extern int perf_allstop(void); 200 | extern boolean_t perf_profiling_started(void); 201 | extern int perf_profiling_start(void); 202 | extern int perf_profiling_smpl(boolean_t); 203 | extern int perf_profiling_partpause(ui_count_id_t); 204 | extern int perf_profiling_restore(ui_count_id_t); 205 | extern boolean_t perf_callchain_started(void); 206 | extern int perf_callchain_start(pid_t, int); 207 | extern int perf_callchain_smpl(void); 208 | extern boolean_t perf_ll_started(void); 209 | extern int perf_ll_start(pid_t); 210 | extern int perf_ll_smpl(pid_t, int); 211 | extern void perf_llrecgrp_reset(perf_llrecgrp_t *); 212 | extern void perf_countchain_reset(perf_countchain_t *); 213 | extern void perf_status_set(perf_status_t); 214 | extern void perf_status_set_no_signal(perf_status_t); 215 | extern void* perf_priv_alloc(boolean_t *); 216 | extern void perf_priv_free(void *); 217 | extern void perf_task_set(perf_task_t *); 218 | extern int perf_status_wait(perf_status_t); 219 | extern void perf_smpl_wait(void); 220 | extern void perf_ll_started_set(void); 221 | extern int perf_pqos_cmt_start(int, int, int); 222 | extern int perf_pqos_cmt_smpl(pid_t, int); 223 | extern int perf_pqos_active_proc_setup(int, boolean_t); 224 | extern boolean_t perf_pqos_cmt_started(void); 225 | extern int perf_pqos_cmt_stop(pid_t, int); 226 | extern int perf_pqos_proc_setup(int, int, int); 227 | extern int perf_uncore_stop(int); 228 | extern int perf_uncore_setup(int); 229 | extern int perf_uncore_smpl(int); 230 | extern boolean_t perf_uncore_started(void); 231 | 232 | #ifdef __cplusplus 233 | } 234 | #endif 235 | 236 | #endif /* _NUMATOP_PERF_H */ 237 | -------------------------------------------------------------------------------- /common/include/proc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_PROC_H 30 | #define _NUMATOP_PROC_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "types.h" 37 | #include "lwp.h" 38 | #include "perf.h" 39 | #include "./os/node.h" 40 | #include "./os/map.h" 41 | #include "./os/sym.h" 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | #define PROC_NAME_SIZE 16 48 | #define PROC_HASHTBL_SIZE 128 49 | 50 | #define PROC_HASHTBL_INDEX(pid) \ 51 | ((int)(pid) % PROC_HASHTBL_SIZE) 52 | 53 | typedef struct _proc_lwplist { 54 | int nlwps; 55 | int sort_idx; 56 | track_lwp_t **id_arr; 57 | track_lwp_t **sort_arr; 58 | } proc_lwplist_t; 59 | 60 | typedef struct _track_proc { 61 | pthread_mutex_t mutex; 62 | int ref_count; 63 | boolean_t inited; 64 | boolean_t tagged; 65 | boolean_t removing; 66 | pid_t pid; 67 | int flag; 68 | int idarr_idx; 69 | int cpuid_max; 70 | char name[PROC_NAME_SIZE]; 71 | proc_lwplist_t lwp_list; 72 | int intval_ms; 73 | uint64_t key; 74 | map_proc_t map; 75 | sym_t sym; 76 | count_value_t *countval_arr; 77 | perf_countchain_t count_chain; 78 | perf_llrecgrp_t llrec_grp; 79 | perf_pqos_t pqos; 80 | boolean_t lwp_pqosed; 81 | struct _track_proc *hash_prev; 82 | struct _track_proc *hash_next; 83 | struct _track_proc *sort_prev; 84 | struct _track_proc *sort_next; 85 | } track_proc_t; 86 | 87 | typedef struct _proc_group { 88 | pthread_mutex_t mutex; 89 | pthread_cond_t cond; 90 | int nprocs; 91 | int nlwps; 92 | int sort_idx; 93 | boolean_t inited; 94 | track_proc_t *hashtbl[PROC_HASHTBL_SIZE]; 95 | track_proc_t *latest; 96 | track_proc_t **sort_arr; 97 | } proc_group_t; 98 | 99 | extern int proc_group_init(void); 100 | extern void proc_group_fini(void); 101 | extern track_proc_t *proc_find(pid_t); 102 | extern track_lwp_t *proc_lwp_find(track_proc_t *, id_t); 103 | extern void proc_lwp_count(int *, int *); 104 | extern void proc_lwp_resort(track_proc_t *, sort_key_t); 105 | extern void proc_group_lock(void); 106 | extern void proc_group_unlock(void); 107 | extern void proc_resort(sort_key_t); 108 | extern track_proc_t *proc_sort_next(void); 109 | extern int proc_nlwp(track_proc_t *); 110 | extern void proc_enum_update(pid_t); 111 | extern int proc_refcount_inc(track_proc_t *); 112 | extern void proc_refcount_dec(track_proc_t *); 113 | extern void proc_lwp_traverse(track_proc_t *, 114 | int (*func)(track_lwp_t *, void *, boolean_t *), void *); 115 | extern int proc_countval_update(track_proc_t *, int, perf_count_id_t, uint64_t); 116 | extern void proc_intval_update(int); 117 | extern int proc_intval_get(track_proc_t *); 118 | extern void proc_profiling_clear(void); 119 | extern void proc_callchain_clear(void); 120 | extern void proc_ll_clear(track_proc_t *); 121 | extern void proc_pqos_func(track_proc_t *, 122 | int (*func)(track_proc_t *, void *, boolean_t *)); 123 | 124 | #ifdef __cplusplus 125 | } 126 | #endif 127 | 128 | #endif /* _NUMATOP_PROC_H */ 129 | -------------------------------------------------------------------------------- /common/include/reg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_REG_H 30 | #define _NUMATOP_REG_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include "types.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | typedef enum { 42 | ALIGN_LEFT = 0, 43 | ALIGN_MIDDLE 44 | } reg_align_t; 45 | 46 | typedef enum { 47 | SCROLL_DOWN = 0, 48 | SCROLL_UP 49 | } reg_scroll_t; 50 | 51 | typedef struct _scroll_line { 52 | boolean_t enabled; /* indicate if support "scrolling" */ 53 | int highlight; /* current highlight line. */ 54 | int page_start; 55 | } scroll_line_t; 56 | 57 | typedef struct _win_reg { 58 | void *hdl; 59 | int begin_x; /* offset to stdscr */ 60 | int begin_y; /* offset to stdscr */ 61 | int ncols_scr; 62 | int nlines_scr; 63 | unsigned int mode; 64 | int nlines_total; 65 | void *buf; 66 | void (*line_get)(struct _win_reg *, int, char *, int); 67 | scroll_line_t scroll; 68 | } win_reg_t; 69 | 70 | /* Screen dimension */ 71 | extern int g_scr_height; 72 | extern int g_scr_width; 73 | 74 | extern int reg_init(win_reg_t *, int, int, int, int, unsigned int); 75 | extern void reg_buf_init(win_reg_t *, void *, 76 | void (*line_get)(win_reg_t *, int, char *, int)); 77 | extern void reg_scroll_init(win_reg_t *, boolean_t); 78 | extern void reg_erase(win_reg_t *); 79 | extern void reg_refresh(win_reg_t *); 80 | extern void reg_refresh_nout(win_reg_t *); 81 | extern void reg_update_all(void); 82 | extern void reg_win_destroy(win_reg_t *seg); 83 | extern void reg_line_write(win_reg_t *, int, reg_align_t, char *); 84 | extern void reg_highlight_write(win_reg_t *, int, int, char *); 85 | extern void reg_line_scroll(win_reg_t *, int); 86 | extern void reg_scroll_show(win_reg_t *, void *, int, 87 | void (*str_build_func)(char *, int, int, void *)); 88 | extern boolean_t reg_curses_init(boolean_t); 89 | extern void reg_curses_fini(void); 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif /* _NUMATOP_REG_H */ 96 | -------------------------------------------------------------------------------- /common/include/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_TYPES_H 30 | #define _NUMATOP_TYPES_H 31 | 32 | #include 33 | #include 34 | #include "./os/os_types.h" 35 | #ifdef __powerpc64__ 36 | #include "../../powerpc/include/types.h" 37 | #else 38 | #include "../../x86/include/types.h" 39 | #endif 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | typedef enum { 46 | PRECISE_NORMAL = 0, 47 | PRECISE_HIGH, 48 | PRECISE_LOW 49 | } precise_type_t; 50 | 51 | #define PRECISE_NUM 3 52 | 53 | typedef enum { 54 | SORT_KEY_INVALID = -1, 55 | SORT_KEY_CPU = 0, 56 | SORT_KEY_PID, 57 | SORT_KEY_RPI, 58 | SORT_KEY_LPI, 59 | SORT_KEY_CPI, 60 | SORT_KEY_RMA, 61 | SORT_KEY_LMA, 62 | SORT_KEY_RL 63 | } sort_key_t; 64 | 65 | #define MAX_VALUE 4294967295U 66 | #define NS_SEC 1000000000 67 | #define MS_SEC 1000 68 | #define NS_USEC 1000 69 | #define USEC_MS 1000 70 | #define NS_MS 1000000 71 | #define MICROSEC 1000000 72 | #define GHZ 1000000000 73 | #define MHZ 1000000 74 | #define KHZ 1000 75 | #define GB_BYTES 1024*1024*1024 76 | #define KB_BYTES 1024 77 | #define TIME_NSEC_MAX 2147483647 78 | 79 | #ifndef PATH_MAX 80 | #define PATH_MAX 2048 81 | #endif 82 | 83 | #define SCRIPT_SIZE 4096 84 | 85 | #define SMPL_PERIOD_INFINITE 0XFFFFFFFFFFFFFFULL 86 | #define SMPL_PERIOD_RMA_DEFAULT 10000 87 | #define SMPL_PERIOD_RMA_1_DEFAULT 10000 88 | #define SMPL_PERIOD_LMA_DEFAULT 10000 89 | #define SMPL_PERIOD_CLK_DEFAULT 10000000 90 | #define SMPL_PERIOD_CORECLK_DEFAULT SMPL_PERIOD_INFINITE 91 | #define SMPL_PERIOD_IR_DEFAULT 10000000 92 | 93 | #define SMPL_PERIOD_RMA_MIN 5000 94 | #define SMPL_PERIOD_RMA_1_MIN 5000 95 | #define SMPL_PERIOD_LMA_MIN 5000 96 | #define SMPL_PERIOD_CLK_MIN 1000000 97 | #define SMPL_PERIOD_CORECLK_MIN SMPL_PERIOD_INFINITE 98 | #define SMPL_PERIOD_IR_MIN 1000000 99 | 100 | #define SMPL_PERIOD_RMA_MAX 100000 101 | #define SMPL_PERIOD_RMA_1_MAX 100000 102 | #define SMPL_PERIOD_LMA_MAX 100000 103 | #define SMPL_PERIOD_CLK_MAX 100000000 104 | #define SMPL_PERIOD_CORECLK_MAX SMPL_PERIOD_INFINITE 105 | #define SMPL_PERIOD_IR_MAX 100000000 106 | 107 | typedef enum { 108 | UI_COUNT_INVALID = -1, 109 | UI_COUNT_CORE_CLK = 0, 110 | UI_COUNT_RMA, 111 | UI_COUNT_CLK, 112 | UI_COUNT_IR, 113 | UI_COUNT_LMA 114 | } ui_count_id_t; 115 | 116 | #define UI_COUNT_NUM 5 117 | 118 | #define NNODES_MAX 64 119 | #define NCPUS_NODE_MAX 256 120 | #define NCPUS_MAX (NNODES_MAX * NCPUS_NODE_MAX) 121 | #define NPROCS_NAX 4096 122 | #define LL_THRESH 128 123 | #define LL_PERIOD 1000 124 | 125 | typedef struct _count_value { 126 | uint64_t counts[PERF_COUNT_NUM]; 127 | } count_value_t; 128 | 129 | typedef struct _bufaddr { 130 | uint64_t addr; 131 | uint64_t size; 132 | } bufaddr_t; 133 | 134 | #ifdef __cplusplus 135 | } 136 | #endif 137 | 138 | #endif /* _NUMATOP_TYPES_H */ 139 | -------------------------------------------------------------------------------- /common/include/ui_perf_map.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_UI_PERF_MAP_H 30 | #define _NUMATOP_UI_PERF_MAP_H 31 | 32 | #include "types.h" 33 | 34 | /* 35 | * Hardcoding 2 here because there is only one use case 36 | * for powerpc and it uses 2 perf events to get RMA. If 37 | * there is a case in future where more than 2 events are 38 | * needed, this has to be changed. 39 | */ 40 | #define UI_PERF_MAP_MAX 2 41 | 42 | typedef struct _ui_perf_count_map_t { 43 | ui_count_id_t ui_count_id; 44 | int n_perf_count; 45 | perf_count_id_t perf_count_ids[UI_PERF_MAP_MAX]; 46 | } ui_perf_count_map_t; 47 | 48 | extern ui_perf_count_map_t ui_perf_count_map[UI_COUNT_NUM]; 49 | 50 | extern int get_ui_perf_count_map(ui_count_id_t, perf_count_id_t **); 51 | extern uint64_t ui_perf_count_aggr(ui_count_id_t, uint64_t *); 52 | 53 | #endif /* _NUMATOP_UI_PERF_MAP_H */ 54 | -------------------------------------------------------------------------------- /common/include/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_UTIL_H 30 | #define _NUMATOP_UTIL_H 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "types.h" 39 | #include "./os/map.h" 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | #define EXIT_MSG_SIZE 128 46 | #define LINE_SIZE 512 47 | #define PROCFS_ID_NUM 4096 48 | 49 | #ifndef MIN 50 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) 51 | #endif 52 | 53 | #define ASSERT(expr) assert(expr) 54 | 55 | #define DUMP_CACHE_SIZE 256*1024 56 | #define LOGFILE_PATH "/tmp/numatop.log" 57 | 58 | typedef struct _debug_ctl { 59 | pthread_mutex_t mutex; 60 | boolean_t inited; 61 | } debug_ctl_t; 62 | 63 | typedef struct _dump_ctl { 64 | FILE *fout; 65 | char *cache; 66 | char *pcur; 67 | int rest_size; 68 | boolean_t cache_mode; 69 | } dump_ctl_t; 70 | 71 | extern struct timeval g_tvbase; 72 | extern int g_pagesize; 73 | extern double g_nsofclk; 74 | extern boolean_t g_cmt_enabled; 75 | 76 | extern void *zalloc(size_t n); 77 | extern int debug_init(int, FILE *); 78 | extern void debug_fini(void); 79 | extern void debug_print(FILE *out, int level, const char *fmt, ...); 80 | extern uint64_t current_ms(struct timeval *); 81 | extern double ratio(uint64_t value1, uint64_t value2); 82 | extern int procfs_enum_id(char *, int **, int *); 83 | extern int procfs_proc_enum(pid_t **, int *); 84 | extern void exit_msg_put(const char *fmt, ...); 85 | extern void exit_msg_print(void); 86 | extern uint64_t cyc2ns(uint64_t); 87 | extern int dump_init(FILE *); 88 | extern void dump_fini(void); 89 | extern void dump_write(const char *fmt, ...); 90 | extern void dump_cache_enable(void); 91 | extern void dump_cache_disable(void); 92 | extern void dump_cache_flush(void); 93 | extern void stderr_print(char *format, ...); 94 | extern int array_alloc(void **, int *, int *, int, int); 95 | extern void pagesize_init(void); 96 | extern uint64_t rdtsc(void); 97 | extern int arch__cpuinfo_freq(double *freq, char *unit); 98 | extern int is_userspace(uint64_t); 99 | 100 | #ifdef __cplusplus 101 | } 102 | #endif 103 | 104 | #endif /* _NUMATOP_UTIL_H */ 105 | -------------------------------------------------------------------------------- /common/os/os_page.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "../include/types.h" 37 | #include "../include/cmd.h" 38 | #include "../include/page.h" 39 | #include "../include/perf.h" 40 | #include "../include/disp.h" 41 | #include "../include/os/os_page.h" 42 | 43 | /* 44 | * Start sampling the performance data. 45 | */ 46 | boolean_t 47 | os_page_smpl_start(page_t *page) 48 | { 49 | cmd_t *cmd = PAGE_CMD(page); 50 | win_type_t type = PAGE_WIN_TYPE(page); 51 | 52 | switch (CMD_ID(cmd)) { 53 | case CMD_HOME_ID: 54 | /* fall through */ 55 | case CMD_IR_NORMALIZE_ID: 56 | /* fall through */ 57 | case CMD_MONITOR_ID: 58 | /* fall through */ 59 | case CMD_LWP_ID: 60 | /* fall through */ 61 | case CMD_NODE_OVERVIEW_ID: 62 | /* fall through */ 63 | case CMD_CALLCHAIN_ID: 64 | if (perf_profiling_smpl(B_TRUE) == 0) { 65 | return (B_TRUE); 66 | } 67 | break; 68 | 69 | case CMD_NODE_DETAIL_ID: 70 | if (perf_profiling_smpl(B_FALSE) != 0) 71 | break; 72 | 73 | if (disp_flag2_wait() != DISP_FLAG_PROFILING_DATA_READY) 74 | break; 75 | 76 | if (perf_uncore_smpl(CMD_NODE_DETAIL(cmd)->nid) != 0) 77 | break; 78 | 79 | return B_TRUE; 80 | 81 | case CMD_LAT_ID: 82 | /* fall through */ 83 | case CMD_LLCALLCHAIN_ID: 84 | /* fall through */ 85 | case CMD_LATNODE_ID: 86 | /* fall through */ 87 | case CMD_ACCDST_ID: 88 | if (perf_ll_smpl(0, 0) == 0) { 89 | return (B_TRUE); 90 | } 91 | break; 92 | 93 | case CMD_PQOS_CMT_ID: 94 | if (perf_profiling_smpl(B_FALSE) != 0) 95 | break; 96 | 97 | if (disp_flag2_wait() != DISP_FLAG_PROFILING_DATA_READY) 98 | break; 99 | 100 | if (type == WIN_TYPE_PQOS_CMT_TOPNPROC) { 101 | perf_pqos_active_proc_setup(CMD_PQOS_CMT(cmd)->flags, B_TRUE); 102 | if (perf_pqos_cmt_smpl(0, 0) != 0) 103 | break; 104 | 105 | } else if (type == WIN_TYPE_PQOS_CMT_MONIPROC) { 106 | if (perf_pqos_cmt_smpl(CMD_PQOS_CMT(cmd)->pid, 0) != 0) 107 | break; 108 | } else if (type == WIN_TYPE_PQOS_CMT_MONILWP) { 109 | if (perf_pqos_cmt_smpl(CMD_PQOS_CMT(cmd)->pid, 110 | CMD_PQOS_CMT(cmd)->lwpid) != 0) 111 | break; 112 | } 113 | 114 | return B_TRUE; 115 | 116 | case CMD_PQOS_MBM_ID: 117 | if (perf_profiling_smpl(B_FALSE) != 0) 118 | break; 119 | 120 | if (disp_flag2_wait() != DISP_FLAG_PROFILING_DATA_READY) 121 | break; 122 | 123 | if (perf_pqos_cmt_smpl(CMD_PQOS_CMT(cmd)->pid, 124 | CMD_PQOS_CMT(cmd)->lwpid) != 0) 125 | break; 126 | 127 | return B_TRUE; 128 | 129 | default: 130 | break; 131 | } 132 | 133 | return (B_FALSE); 134 | } 135 | -------------------------------------------------------------------------------- /common/os/plat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* This file contains a general layer of functions. */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "../include/types.h" 39 | #include "../include/util.h" 40 | #include "../include/os/plat.h" 41 | 42 | cpu_type_t s_cpu_type = CPU_UNSUP; 43 | 44 | /* 45 | * Platform-independent function to get the event configuration for profiling. 46 | */ 47 | void 48 | plat_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 49 | { 50 | pfn_plat_profiling_config_t pfn = 51 | s_plat_profiling_config[s_cpu_type]; 52 | 53 | if (pfn != NULL) { 54 | pfn(perf_count_id, cfg); 55 | } 56 | } 57 | 58 | /* 59 | * Platform-independent function to get the event configuration for LL. 60 | */ 61 | void 62 | plat_ll_config(plat_event_config_t *cfg) 63 | { 64 | pfn_plat_ll_config_t pfn = 65 | s_plat_ll_config[s_cpu_type]; 66 | 67 | if (pfn != NULL) { 68 | pfn(cfg); 69 | } 70 | } 71 | 72 | void 73 | plat_config_get(perf_count_id_t perf_count_id, plat_event_config_t *cfg, 74 | plat_event_config_t *cfg_arr) 75 | { 76 | cfg->type = cfg_arr[perf_count_id].type; 77 | cfg->config = cfg_arr[perf_count_id].config; 78 | cfg->other_attr = cfg_arr[perf_count_id].other_attr; 79 | cfg->extra_value = cfg_arr[perf_count_id].extra_value; 80 | strncpy(cfg->desc, cfg_arr[perf_count_id].desc, PLAT_EVENT_DESC_SIZE); 81 | cfg->desc[PLAT_EVENT_DESC_SIZE - 1] = 0; 82 | } 83 | 84 | /* 85 | * Platform-independent function to return the number of offcore counters. 86 | */ 87 | int 88 | plat_offcore_num(void) 89 | { 90 | pfn_plat_offcore_num_t pfn = 91 | s_plat_offcore_num[s_cpu_type]; 92 | 93 | if (pfn != NULL) { 94 | return (pfn()); 95 | } 96 | 97 | return (0); 98 | } 99 | -------------------------------------------------------------------------------- /common/page.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* This file contains code to handle the 'page' which is used in display */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "include/types.h" 39 | #include "include/cmd.h" 40 | #include "include/page.h" 41 | #include "include/win.h" 42 | #include "include/perf.h" 43 | #include "include/os/node.h" 44 | #include "include/os/os_page.h" 45 | 46 | static page_list_t s_page_list; 47 | 48 | /* 49 | * Free the resource of a page. 50 | */ 51 | static void 52 | page_free(page_t *page) 53 | { 54 | if (page != NULL) { 55 | win_dyn_fini(page); 56 | free(page); 57 | } 58 | } 59 | 60 | /* 61 | * Initialization for page list. 62 | */ 63 | void 64 | page_list_init(void) 65 | { 66 | s_page_list.head = NULL; 67 | s_page_list.tail = NULL; 68 | s_page_list.cur = NULL; 69 | s_page_list.next_run = NULL; 70 | s_page_list.npages = 0; 71 | } 72 | 73 | /* 74 | * Clean up the resources of the page list. 75 | */ 76 | void 77 | page_list_fini(void) 78 | { 79 | page_t *p1, *p2; 80 | 81 | p1 = s_page_list.head; 82 | while (p1 != NULL) { 83 | p2 = p1->next; 84 | page_free(p1); 85 | p1 = p2; 86 | } 87 | 88 | s_page_list.head = NULL; 89 | s_page_list.tail = NULL; 90 | s_page_list.cur = NULL; 91 | s_page_list.next_run = NULL; 92 | s_page_list.npages = 0; 93 | } 94 | 95 | /* 96 | * Append a new page to the tail of page list. 97 | */ 98 | static void 99 | page_append(page_t *page) 100 | { 101 | page_t *tail; 102 | 103 | page->prev = page->next = NULL; 104 | if ((tail = s_page_list.tail) != NULL) { 105 | tail->next = page; 106 | page->prev = tail; 107 | } else { 108 | s_page_list.head = page; 109 | } 110 | 111 | s_page_list.tail = page; 112 | s_page_list.npages++; 113 | } 114 | 115 | /* 116 | * Allocate the resource for the new page. 117 | */ 118 | page_t * 119 | page_create(cmd_t *cmd) 120 | { 121 | page_t *page; 122 | 123 | if ((page = zalloc(sizeof (page_t))) == NULL) { 124 | return (NULL); 125 | } 126 | 127 | /* 128 | * Copy the command information in page. 129 | */ 130 | (void) memcpy(&page->cmd, cmd, sizeof (cmd_t)); 131 | 132 | /* 133 | * Drop all the pages after the current one. 134 | */ 135 | page_drop_next(s_page_list.cur); 136 | 137 | /* 138 | * Append the new page after the current one. 139 | */ 140 | page_append(page); 141 | s_page_list.next_run = page; 142 | return (page); 143 | } 144 | 145 | /* 146 | * Show the page on the screen. 147 | */ 148 | static boolean_t 149 | page_show(page_t *page, boolean_t smpl) 150 | { 151 | if (g_scr_height < 24 || g_scr_width < 80) { 152 | dump_write("\n%s\n", "Terminal size is too small."); 153 | dump_write("%s\n", "Please resize it to 80x24 or larger."); 154 | return (B_FALSE); 155 | } 156 | 157 | if (node_group_refresh(B_FALSE) != 0) { 158 | return (B_FALSE); 159 | } 160 | 161 | if ((!page->dyn_win.inited) && 162 | (win_dyn_init(page) != 0)) { 163 | return (B_FALSE); 164 | } 165 | 166 | if (smpl) { 167 | win_warn_msg(WARN_WAIT); 168 | (void) os_page_smpl_start(page); 169 | return (B_TRUE); 170 | } 171 | 172 | return (page->dyn_win.draw(&page->dyn_win)); 173 | } 174 | 175 | /* 176 | * Show the next page in list. 177 | */ 178 | boolean_t 179 | page_next_execute(boolean_t smpl) 180 | { 181 | page_t *next_run; 182 | boolean_t ret; 183 | 184 | if ((next_run = s_page_list.next_run) == NULL) { 185 | return (B_FALSE); 186 | } 187 | 188 | ret = page_show(next_run, smpl); 189 | s_page_list.cur = next_run; 190 | 191 | if (smpl) { 192 | s_page_list.next_run = next_run; 193 | } else { 194 | s_page_list.next_run = NULL; 195 | } 196 | 197 | return (ret); 198 | } 199 | 200 | page_t * 201 | page_current_get(void) 202 | { 203 | return (s_page_list.cur); 204 | } 205 | 206 | page_t * 207 | page_current_set(page_t *page) 208 | { 209 | s_page_list.cur = page; 210 | return (s_page_list.cur); 211 | } 212 | 213 | void 214 | page_next_set(page_t *page) 215 | { 216 | s_page_list.next_run = page; 217 | } 218 | 219 | /* 220 | * Free all the pages which are after the specified page node in list. 221 | */ 222 | void 223 | page_drop_next(page_t *page) 224 | { 225 | page_t *next, *p; 226 | 227 | if (page == NULL) { 228 | return; 229 | } 230 | 231 | next = page->next; 232 | while (next != NULL) { 233 | p = next->next; 234 | page_free(next); 235 | s_page_list.npages--; 236 | next = p; 237 | } 238 | 239 | page->next = NULL; 240 | s_page_list.tail = page; 241 | } 242 | 243 | /* 244 | * Get the previous node of current one in list. 245 | */ 246 | page_t * 247 | page_curprev_get(void) 248 | { 249 | page_t *cur; 250 | 251 | if ((cur = s_page_list.cur) != NULL) { 252 | return (cur->prev); 253 | } 254 | 255 | return (NULL); 256 | } 257 | 258 | /* 259 | * Free the resources of windows which are associated with the pages in list. 260 | */ 261 | void 262 | page_win_destroy(void) 263 | { 264 | page_t *p1; 265 | 266 | p1 = s_page_list.head; 267 | while (p1 != NULL) { 268 | win_dyn_fini(p1); 269 | p1 = p1->next; 270 | } 271 | } 272 | 273 | 274 | -------------------------------------------------------------------------------- /common/ui_perf_map.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include "./include/types.h" 31 | #include "./include/ui_perf_map.h" 32 | 33 | int 34 | get_ui_perf_count_map(ui_count_id_t ui_count_id, perf_count_id_t **perf_count_ids) 35 | { 36 | if (ui_count_id == UI_COUNT_INVALID) { 37 | return PERF_COUNT_INVALID; 38 | } 39 | 40 | *perf_count_ids = ui_perf_count_map[ui_count_id].perf_count_ids; 41 | return ui_perf_count_map[ui_count_id].n_perf_count; 42 | } 43 | 44 | uint64_t 45 | ui_perf_count_aggr(ui_count_id_t ui_count_id, uint64_t *counts) 46 | { 47 | int i = 0; 48 | uint64_t tmp = 0; 49 | int n_perf_count; 50 | perf_count_id_t *perf_count_ids = NULL; 51 | 52 | n_perf_count = get_ui_perf_count_map(ui_count_id, &perf_count_ids); 53 | 54 | for (i = 0; i < n_perf_count; i++) { 55 | tmp += counts[perf_count_ids[i]]; 56 | } 57 | return tmp; 58 | } 59 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.69]) 5 | AC_INIT([numatop], [v2.5.1], [zhengjun.xing@intel.com]) 6 | AM_INIT_AUTOMAKE([-Wno-portability no-dist-gzip dist-xz foreign subdir-objects]) 7 | AC_CONFIG_SRCDIR([common/numatop.c]) 8 | AC_CONFIG_HEADERS([config.h]) 9 | LT_INIT 10 | AC_CONFIG_MACRO_DIRS([m4]) 11 | 12 | AC_CANONICAL_HOST 13 | AM_CONDITIONAL(CPU_X86, test "x$host_cpu" = "xx86_64" -o "x$host_cpu" = "xi686") 14 | AM_CONDITIONAL(CPU_PPC, test "x$host_cpu" = "xpowerpc64" -o "x$host_cpu" = "xpowerpc64le") 15 | 16 | # Checks for programs. 17 | AC_PROG_CC 18 | AC_PROG_INSTALL 19 | 20 | # Checks for libraries. 21 | AC_CHECK_LIB([numa], [numa_free], [], [ AC_MSG_ERROR([numactl-devel or libnuma-dev(el) is required but was not found]) exit -1]) 22 | AC_CHECK_LIB([pthread], [pthread_create]) 23 | 24 | PKG_CHECK_MODULES([CHECK], [check]) 25 | 26 | PKG_CHECK_MODULES([NCURSES], [ncursesw ncurses], [LIBS="$LIBS $ncurses_LIBS"], [ 27 | AC_SEARCH_LIBS([delwin], [ncursesw ncurses], [], [ 28 | AC_MSG_ERROR([ncurses is required but was not found]) 29 | ], []) 30 | ]) 31 | 32 | # Checks for header files. 33 | AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h locale.h stddef.h stdint.h stdlib.h string.h strings.h sys/ioctl.h sys/time.h unistd.h]) 34 | 35 | # Checks for typedefs, structures, and compiler characteristics. 36 | AC_TYPE_INT64_T 37 | AC_TYPE_PID_T 38 | AC_TYPE_SIZE_T 39 | AC_TYPE_UINT32_T 40 | AC_TYPE_UINT64_T 41 | 42 | # Checks for library functions. 43 | AC_FUNC_MALLOC 44 | AC_FUNC_MMAP 45 | AC_FUNC_REALLOC 46 | AC_FUNC_STRTOD 47 | AC_CHECK_FUNCS([getpagesize gettimeofday memset munmap select strcasecmp strchr strcspn strstr strtol strtoull]) 48 | 49 | AC_CONFIG_FILES([Makefile]) 50 | AC_OUTPUT 51 | -------------------------------------------------------------------------------- /kernel_patches/0001-perf-x86-Widen-Haswell-OFFCORE-mask.patch: -------------------------------------------------------------------------------- 1 | From 1124c7b559c86dd9fadee30e635909f19d6b62e6 Mon Sep 17 00:00:00 2001 2 | From: Andi Kleen 3 | Date: Tue, 5 Aug 2014 10:24:18 +0800 4 | Subject: [PATCH] perf, x86: Widen Haswell OFFCORE mask 5 | 6 | Haswell supports more bits in the offcore_rsp_* MSRs than Sandy 7 | Bridge. Previously the Haswell code was using the Sandy Bridge 8 | extra register definitions, which prevented users from setting 9 | all of these bits. This in term did not allow to set some valid 10 | SNOOP_* bits, among others. 11 | 12 | I allowed all bits the CPU does not #GP on. This is ok because 13 | it's protected by a model check. 14 | 15 | Add a new extra_regs table for Haswell and use. Except for the 16 | widened mask it is identical to Sandy Bridge. 17 | 18 | Signed-off-by: Andi Kleen 19 | Signed-off-by: Jin Yao 20 | --- 21 | arch/x86/kernel/cpu/perf_event_intel.c | 10 +++++++++- 22 | 1 file changed, 9 insertions(+), 1 deletion(-) 23 | 24 | diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c 25 | index 2502d0d..4f69013 100644 26 | --- a/arch/x86/kernel/cpu/perf_event_intel.c 27 | +++ b/arch/x86/kernel/cpu/perf_event_intel.c 28 | @@ -189,6 +189,14 @@ static struct extra_reg intel_snbep_extra_regs[] __read_mostly = { 29 | EVENT_EXTRA_END 30 | }; 31 | 32 | +static struct extra_reg intel_hsw_extra_regs[] __read_mostly = { 33 | + /* must define OFFCORE_RSP_X first, see intel_fixup_er() */ 34 | + INTEL_UEVENT_EXTRA_REG(0x01b7, MSR_OFFCORE_RSP_0, 0x3fffff8fffull, RSP_0), 35 | + INTEL_UEVENT_EXTRA_REG(0x01bb, MSR_OFFCORE_RSP_1, 0x3fffff8fffull, RSP_1), 36 | + INTEL_UEVENT_PEBS_LDLAT_EXTRA_REG(0x01cd), 37 | + EVENT_EXTRA_END 38 | +}; 39 | + 40 | EVENT_ATTR_STR(mem-loads, mem_ld_nhm, "event=0x0b,umask=0x10,ldlat=3"); 41 | EVENT_ATTR_STR(mem-loads, mem_ld_snb, "event=0xcd,umask=0x1,ldlat=3"); 42 | EVENT_ATTR_STR(mem-stores, mem_st_snb, "event=0xcd,umask=0x2"); 43 | @@ -2552,7 +2560,7 @@ __init int intel_pmu_init(void) 44 | 45 | x86_pmu.event_constraints = intel_hsw_event_constraints; 46 | x86_pmu.pebs_constraints = intel_hsw_pebs_event_constraints; 47 | - x86_pmu.extra_regs = intel_snb_extra_regs; 48 | + x86_pmu.extra_regs = intel_hsw_extra_regs; 49 | x86_pmu.pebs_aliases = intel_pebs_aliases_snb; 50 | /* all extra regs are per-cpu when HT is on */ 51 | x86_pmu.er_flags |= ERF_HAS_RSP_1; 52 | -- 53 | 1.9.1 54 | 55 | -------------------------------------------------------------------------------- /powerpc/FEATURES: -------------------------------------------------------------------------------- 1 | Features supported on PowerPC: 2 | ------------------------------ 3 | 4 | Per process/thread: 5 | 6 | | Feature | Supported | 7 | |-----------------------------------------------------------|---------------| 8 | | RMA (RMEM + DMEM) | Y | 9 | | LMA (LMEM) | Y | 10 | | CPI | Y | 11 | | CPU% | Y | 12 | | Memory area ADDR | Y | 13 | | Memory area SIZE | Y | 14 | | Memory area ACCESS% | N | 15 | | Memory area LAT(ns) | N | 16 | | Memory area DESC | Y | 17 | | Node ACCESS% | N | 18 | | Node LAT(ns) | N | 19 | | Call-chain when process generates RMA / LMA / CYCLES / IR | Y | 20 | | Call-chain when process accesses the memory area | N | 21 | | PQOS CMT/MBM | N | 22 | 23 | Per Node: 24 | 25 | | Feature | Supported | 26 | |-----------------------------------------------------------|---------------| 27 | | RMA (RMEM + DMEM) | Y | 28 | | LMA (LMEM) | Y | 29 | | CPU | Y | 30 | | CPU% | Y | 31 | | MEM total | Y | 32 | | MEM free | Y | 33 | | MEM active | Y | 34 | | MEM inactive | Y | 35 | | Dirty | Y | 36 | | Writeback | Y | 37 | | Mapped | Y | 38 | | QPI/UPI 0 bandwidth | N | 39 | | QPI/UPI 1 bandwidth | N | 40 | | Memory controller bandwidth | N | 41 | 42 | Other: 43 | 44 | | Feature | Supported | 45 | |-----------------------------------------------------------|---------------| 46 | | mgen testcase | Y | 47 | -------------------------------------------------------------------------------- /powerpc/include/power10.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_POWERPC_POWER10_H 30 | #define _NUMATOP_POWERPC_POWER10_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include 37 | #include 38 | #include "../../common/include/types.h" 39 | 40 | struct _plat_event_config; 41 | 42 | extern void power10_profiling_config(perf_count_id_t, struct _plat_event_config *); 43 | extern void power10_ll_config(plat_event_config_t *cfg); 44 | extern int power10_offcore_num(void); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* _NUMATOP_POWERPC_POWER10_H */ 51 | -------------------------------------------------------------------------------- /powerpc/include/power8.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_POWERPC_POWER8_H 30 | #define _NUMATOP_POWERPC_POWER8_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include 37 | #include 38 | #include "../../common/include/types.h" 39 | 40 | struct _plat_event_config; 41 | 42 | extern void power8_profiling_config(perf_count_id_t, struct _plat_event_config *); 43 | extern void power8_ll_config(plat_event_config_t *cfg); 44 | extern int power8_offcore_num(void); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* _NUMATOP_POWERPC_POWER8_H */ 51 | -------------------------------------------------------------------------------- /powerpc/include/power9.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_POWERPC_POWER9_H 30 | #define _NUMATOP_POWERPC_POWER9_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include 37 | #include 38 | #include "../../common/include/types.h" 39 | 40 | struct _plat_event_config; 41 | 42 | extern void power9_profiling_config(perf_count_id_t, struct _plat_event_config *); 43 | extern void power9_ll_config(plat_event_config_t *cfg); 44 | extern int power9_offcore_num(void); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* _NUMATOP_POWERPC_POWER9_H */ 51 | -------------------------------------------------------------------------------- /powerpc/include/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_POWERPC_TYPES_H 30 | #define _NUMATOP_POWERPC_TYPES_H 31 | 32 | #include "../../common/include/types.h" 33 | 34 | #define CORP "IBM" 35 | 36 | typedef enum { 37 | CPU_UNSUP = 0, 38 | CPU_POWER8, 39 | CPU_POWER9, 40 | CPU_POWER10 41 | } cpu_type_t; 42 | 43 | #define CPU_TYPE_NUM 4 44 | 45 | typedef enum { 46 | PERF_COUNT_INVALID = -1, 47 | PERF_COUNT_CORE_CLK = 0, 48 | PERF_COUNT_RMA, 49 | PERF_COUNT_CLK, 50 | PERF_COUNT_IR, 51 | PERF_COUNT_LMA, 52 | PERF_COUNT_RMA_1 53 | } perf_count_id_t; 54 | 55 | #define PERF_COUNT_NUM 6 56 | 57 | #endif /* _NUMATOP_POWERPC_TYPES_H */ 58 | -------------------------------------------------------------------------------- /powerpc/plat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "../common/include/os/plat.h" 34 | #include "../common/include/os/os_util.h" 35 | #include "include/types.h" 36 | #include "include/power8.h" 37 | #include "include/power9.h" 38 | #include "include/power10.h" 39 | 40 | pfn_plat_profiling_config_t 41 | s_plat_profiling_config[CPU_TYPE_NUM] = { 42 | NULL, 43 | power8_profiling_config, 44 | power9_profiling_config, 45 | power10_profiling_config 46 | }; 47 | 48 | pfn_plat_ll_config_t 49 | s_plat_ll_config[CPU_TYPE_NUM] = { 50 | NULL, 51 | power8_ll_config, 52 | power9_ll_config, 53 | power10_ll_config 54 | }; 55 | 56 | pfn_plat_offcore_num_t 57 | s_plat_offcore_num[CPU_TYPE_NUM] = { 58 | NULL, 59 | power8_offcore_num, 60 | power9_offcore_num, 61 | power10_offcore_num 62 | }; 63 | 64 | #define SPRN_PVR 0x11F 65 | #define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF) 66 | #define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF) 67 | 68 | int 69 | plat_detect(void) 70 | { 71 | int ret = -1; 72 | int pvr = 0; 73 | 74 | asm __volatile__ 75 | ("mfspr %0,%1" : "=r"(pvr) : "i"(SPRN_PVR)); 76 | 77 | switch(PVR_VER(pvr)) { 78 | case 0x4b: 79 | case 0x4c: 80 | case 0x4d: 81 | s_cpu_type = CPU_POWER8; 82 | ret = 0; 83 | break; 84 | case 0x4e: 85 | /* No support for Power9 DD1. */ 86 | if (PVR_REV(pvr) == 0x100) 87 | break; 88 | 89 | s_cpu_type = CPU_POWER9; 90 | ret = 0; 91 | break; 92 | case 0x80: 93 | s_cpu_type = CPU_POWER10; 94 | ret = 0; 95 | break; 96 | 97 | case 0x82: 98 | s_cpu_type = CPU_POWER10; 99 | ret = 0; 100 | break; 101 | } 102 | 103 | return ret; 104 | } 105 | -------------------------------------------------------------------------------- /powerpc/power10.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "../common/include/os/linux/perf_event.h" 37 | #include "../common/include/os/plat.h" 38 | #include "include/power10.h" 39 | 40 | static plat_event_config_t s_power10_profiling[PERF_COUNT_NUM] = { 41 | { PERF_TYPE_RAW, 0x600f4, 0, 0, 0, 0, "PM_RUN_CYC" }, 42 | { PERF_TYPE_RAW, 0x0F4040000004C040, 0, 0, 0, 0, "PM_DATA_FROM_DMEM" }, 43 | { PERF_TYPE_RAW, 0x100f0, 0, 0, 0, 0, "PM_CYC" }, 44 | { PERF_TYPE_RAW, 0x500fa, 0, 0, 0, 0, "PM_RUN_INST_CMPL" }, 45 | { PERF_TYPE_RAW, 0x094040000002C040, 0, 0, 0, 0, "PM_DATA_FROM_LMEM" }, 46 | { PERF_TYPE_RAW, 0x0D4040000003C040, 0, 0, 0, 0, "PM_DATA_FROM_RMEM" }, 47 | }; 48 | 49 | static plat_event_config_t s_power10_ll = { 50 | PERF_TYPE_RAW, 0x0000, 0, 0, 0, 1, "PM_SUSPENDED" 51 | }; 52 | 53 | void 54 | power10_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 55 | { 56 | plat_config_get(perf_count_id, cfg, s_power10_profiling); 57 | } 58 | 59 | void 60 | power10_ll_config(plat_event_config_t *cfg) 61 | { 62 | memcpy(cfg, &s_power10_ll, sizeof (plat_event_config_t)); 63 | } 64 | 65 | int 66 | power10_offcore_num(void) 67 | { 68 | return (3); 69 | } 70 | -------------------------------------------------------------------------------- /powerpc/power8.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "../common/include/os/linux/perf_event.h" 37 | #include "../common/include/os/plat.h" 38 | #include "include/power8.h" 39 | 40 | static plat_event_config_t s_power8_profiling[PERF_COUNT_NUM] = { 41 | { PERF_TYPE_RAW, 0x600f4, 0, 0, 0, 0, "PM_RUN_CYC" }, 42 | { PERF_TYPE_RAW, 0x4c04c, 0, 0, 0, 0, "PM_DATA_FROM_DMEM" }, 43 | { PERF_TYPE_RAW, 0x1001e, 0, 0, 0, 0, "PM_CYC" }, 44 | { PERF_TYPE_RAW, 0x500fa, 0, 0, 0, 0, "PM_RUN_INST_CMPL" }, 45 | { PERF_TYPE_RAW, 0x2c048, 0, 0, 0, 0, "PM_DATA_FROM_LMEM" }, 46 | { PERF_TYPE_RAW, 0x3c04a, 0, 0, 0, 0, "PM_DATA_FROM_RMEM" }, 47 | }; 48 | 49 | static plat_event_config_t s_power8_ll = { 50 | PERF_TYPE_RAW, 0x0000, 0, 0, 0, 1, "PM_SUSPENDED" 51 | }; 52 | 53 | void 54 | power8_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 55 | { 56 | plat_config_get(perf_count_id, cfg, s_power8_profiling); 57 | } 58 | 59 | void 60 | power8_ll_config(plat_event_config_t *cfg) 61 | { 62 | memcpy(cfg, &s_power8_ll, sizeof (plat_event_config_t)); 63 | } 64 | 65 | int 66 | power8_offcore_num(void) 67 | { 68 | return (3); 69 | } 70 | -------------------------------------------------------------------------------- /powerpc/power9.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "../common/include/os/linux/perf_event.h" 37 | #include "../common/include/os/plat.h" 38 | #include "include/power9.h" 39 | 40 | static plat_event_config_t s_power9_profiling[PERF_COUNT_NUM] = { 41 | { PERF_TYPE_RAW, 0x600f4, 0, 0, 0, 0, "PM_RUN_CYC" }, 42 | { PERF_TYPE_RAW, 0x4c04c, 0, 0, 0, 0, "PM_DATA_FROM_DMEM" }, 43 | { PERF_TYPE_RAW, 0x1001e, 0, 0, 0, 0, "PM_CYC" }, 44 | { PERF_TYPE_RAW, 0x500fa, 0, 0, 0, 0, "PM_RUN_INST_CMPL" }, 45 | { PERF_TYPE_RAW, 0x2c048, 0, 0, 0, 0, "PM_DATA_FROM_LMEM" }, 46 | { PERF_TYPE_RAW, 0x3c04a, 0, 0, 0, 0, "PM_DATA_FROM_RMEM" }, 47 | }; 48 | 49 | static plat_event_config_t s_power9_ll = { 50 | PERF_TYPE_RAW, 0x0000, 0, 0, 0, 1, "PM_SUSPENDED" 51 | }; 52 | 53 | void 54 | power9_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 55 | { 56 | plat_config_get(perf_count_id, cfg, s_power9_profiling); 57 | } 58 | 59 | void 60 | power9_ll_config(plat_event_config_t *cfg) 61 | { 62 | memcpy(cfg, &s_power9_ll, sizeof (plat_event_config_t)); 63 | } 64 | 65 | int 66 | power9_offcore_num(void) 67 | { 68 | return (3); 69 | } 70 | -------------------------------------------------------------------------------- /powerpc/ui_perf_map.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "../common/include/ui_perf_map.h" 30 | 31 | ui_perf_count_map_t ui_perf_count_map[UI_COUNT_NUM] = { 32 | { UI_COUNT_CORE_CLK, 0, { PERF_COUNT_INVALID, PERF_COUNT_INVALID } }, 33 | { UI_COUNT_RMA, 2, { PERF_COUNT_RMA, PERF_COUNT_RMA_1 } }, 34 | { UI_COUNT_CLK, 1, { PERF_COUNT_CLK, PERF_COUNT_INVALID } }, 35 | { UI_COUNT_IR, 1, { PERF_COUNT_IR, PERF_COUNT_INVALID } }, 36 | { UI_COUNT_LMA, 1, { PERF_COUNT_LMA, PERF_COUNT_INVALID } } 37 | }; 38 | -------------------------------------------------------------------------------- /powerpc/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "../common/include/os/os_util.h" 34 | 35 | #define KERNEL_ADDR_START 0xc000000000000000 36 | 37 | uint64_t 38 | rdtsc(void) 39 | { 40 | uint64_t tb = 0; 41 | 42 | __asm__ volatile("mftb %0" : "=r"(tb)); 43 | 44 | return (tb); 45 | } 46 | 47 | int 48 | arch__cpuinfo_freq(double *freq, char *unit) 49 | { 50 | FILE *f; 51 | char *line = NULL, *c; 52 | size_t len = 0; 53 | int ret = -1; 54 | 55 | if ((f = fopen(CPUINFO_PATH, "r")) == NULL) { 56 | return -1; 57 | } 58 | 59 | while (getline(&line, &len, f) > 0) { 60 | if (strncmp(line, "clock", sizeof ("clock") -1)) { 61 | continue; 62 | } 63 | 64 | if (sscanf(line + strcspn(line, ":") + 1, "%lf%10s", 65 | freq, unit) == 2) { 66 | if (strcasecmp(unit, "GHz") == 0) { 67 | *freq *= GHZ; 68 | } else if (strcasecmp(unit, "MHz") == 0) { 69 | *freq *= MHZ; 70 | } 71 | break; 72 | } 73 | } 74 | 75 | /* 76 | * Hyperwiser does not expose cpufreq on PowerVMs(pSeries) 77 | * servers. Thus 'clock' field from /proc/cpuinfo shows 78 | * absolute max freq. While in case of PowerNV servers, 79 | * 'clock' field shows current freq for each individual 80 | * processor. 81 | * 82 | * Use 'clock' field to get freq on pSeries and fallback to 83 | * sysfs cpufreq approach for PowerNV. 84 | */ 85 | while (getline(&line, &len, f) > 0) { 86 | if (strncmp(line, "platform", sizeof("sizeof") -1)) { 87 | continue; 88 | } 89 | 90 | c = strchr(line, ':'); 91 | if ((size_t)(c - line + 2) < len && 92 | !strncmp(c + 2, "pSeries", sizeof ("pSeries") - 1)) { 93 | ret = 0; 94 | break; 95 | } 96 | } 97 | 98 | free(line); 99 | fclose(f); 100 | return ret; 101 | } 102 | 103 | int 104 | is_userspace(uint64_t ip) 105 | { 106 | return (ip < KERNEL_ADDR_START && ip != 0x0); 107 | } 108 | -------------------------------------------------------------------------------- /test/mgen.01.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | exec ./mgen -a 1 -c 1 -t 10 3 | -------------------------------------------------------------------------------- /test/mgen.02.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | exec ./mgen -a 0 -c 1 -t 10 4 | -------------------------------------------------------------------------------- /test/mgen/README: -------------------------------------------------------------------------------- 1 | Building 2 | --------- 3 | 1. To build mgen 4 | cd / 5 | make test 6 | 7 | 2. To clean the built objects 8 | cd / 9 | make clean 10 | 11 | Note 12 | ---- 13 | mgen is a micro-test application which can generate memory access with 14 | runtime latency between CPUs. 15 | 16 | Please note the latencies reported by mgen are not the official latencies 17 | from Intel/IBM. It is just a tool to test numatop. 18 | 19 | For example: 20 | 21 | 1. Generate LMA for 1000s (memory allocated on node1, thread runs on cpu1): 22 | (cpu1 is on node1) 23 | ./mgen -a 1 -c 1 -t 1000 24 | 25 | 2. Generate RMA for 1000s (memory allocated on node0, thread runs on cpu10): 26 | (cpu10 is not on node0): 27 | ./mgen -a 0 -c 10 -t 1000 28 | -------------------------------------------------------------------------------- /test/mgen/include/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * Copyright (c) 2017, IBM Corporation 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Intel Corporation nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _NUMATOP_TEST_UTIL_H 31 | #define _NUMATOP_TEST_UTIL_H 32 | 33 | #ifndef PATH_MAX 34 | #define PATH_MAX 4096 35 | #endif 36 | 37 | #define CPU0_CPUFREQ_PATH \ 38 | "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq" 39 | 40 | #define CPUINFO_PATH \ 41 | "/proc/cpuinfo" 42 | 43 | #define MEAS_TIME_DEFAULT 5 44 | #define MAX_VALUE 4294967295U 45 | #define MHZ 1000000 46 | #define GHZ 1000000000 47 | #define KHZ 1000 48 | #define NS_SEC 1000000000 49 | #define NS_MS 1000000 50 | #define MS_SEC 1000 51 | #define MICROSEC 1000000 52 | #define BUF_SIZE 256 * 1024 * 1024 53 | #define RAND_ARRAY_SIZE 8192 54 | #define INVALID_RAND -1 55 | #define BUF_ELE_SIZE 64 56 | #define READ_NUM 10240000 57 | 58 | extern double s_nsofclk; 59 | extern uint64_t s_clkofsec; 60 | extern double s_latest_avglat; 61 | extern struct timeval s_tvbase; 62 | 63 | extern void arch__dependent_read(void *, int); 64 | 65 | #endif /* _NUMATOP_TEST_UTIL_H */ 66 | -------------------------------------------------------------------------------- /test/mgen/powerpc/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * Copyright (c) 2017, IBM Corporation 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Intel Corporation nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include "../include/util.h" 33 | 34 | extern uint64_t current_ms(struct timeval *); 35 | 36 | static 37 | void buf_read(void *buf, int read_num) 38 | { 39 | asm volatile ( 40 | "mtctr %1\n\t" 41 | "LOOP1:\n\t" 42 | "ld %0,0(%0)\n\t" 43 | "bdnz LOOP1\n\t" 44 | "STOP:\n\t" 45 | :: "r"(buf), "r"(read_num) 46 | ); 47 | } 48 | 49 | static void 50 | latency_calculate(uint64_t count, uint64_t dur_ms, uint64_t total_ms) 51 | { 52 | double sec, lat; 53 | 54 | sec = (double)total_ms / (double)MS_SEC; 55 | lat = ((double)dur_ms * NS_MS) / (double)count; 56 | printf("%8.1fs %13.1f\n", sec, lat); 57 | fflush(stdout); 58 | } 59 | 60 | void 61 | arch__dependent_read(void *buf, int meas_sec) 62 | { 63 | uint64_t total_count = 0, dur_count = 0; 64 | uint64_t start_ms, end_ms, prev_ms; 65 | uint64_t run_ms, total_ms, dur_ms; 66 | 67 | printf("\n%9s %13s\n", "Time", "Latency(ns)"); 68 | printf("-------------------------\n"); 69 | 70 | run_ms = (uint64_t)meas_sec * MS_SEC; 71 | 72 | start_ms = current_ms(&s_tvbase); 73 | prev_ms = start_ms; 74 | end_ms = start_ms; 75 | 76 | while (1) { 77 | total_ms = end_ms - start_ms; 78 | dur_ms = end_ms - prev_ms; 79 | 80 | if (dur_ms >= MS_SEC) { 81 | latency_calculate(dur_count, dur_ms, total_ms); 82 | prev_ms = current_ms(&s_tvbase); 83 | dur_count = 0; 84 | } 85 | 86 | if (total_ms >= run_ms) { 87 | break; 88 | } 89 | 90 | if (total_count > 0) { 91 | s_latest_avglat = ((double)total_ms * NS_MS) / 92 | (double)total_count; 93 | } 94 | 95 | buf_read(buf, READ_NUM); 96 | 97 | dur_count += READ_NUM; 98 | total_count += READ_NUM; 99 | end_ms = current_ms(&s_tvbase); 100 | } 101 | 102 | printf("-------------------------\n"); 103 | 104 | if (total_count > 0) { 105 | printf("%9s %13.1f\n\n", "Average", 106 | ((double)total_ms * NS_MS) / (double)total_count); 107 | } else { 108 | printf("%9s %13.1f\n\n", "Average", 0.0); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /test/mgen/x86/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * Copyright (c) 2017, IBM Corporation 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Intel Corporation nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include "../include/util.h" 33 | #include "../../../common/include/util.h" 34 | 35 | static 36 | void buf_read(void *buf, int read_num) 37 | { 38 | asm volatile ( 39 | "xor %0, %0\n\t" 40 | "LOOP1:\n\t" 41 | "mov (%1),%1\n\t" 42 | "inc %0\n\t" 43 | "cmp %2,%0\n\t" 44 | "jb LOOP1\n\t" 45 | "STOP:\n\t" 46 | ::"b"(0), "d"(buf), "r"(read_num) 47 | ); 48 | } 49 | 50 | static void 51 | latency_calculate(uint64_t count, uint64_t dur_cyc, uint64_t total_cyc) 52 | { 53 | double sec, lat; 54 | 55 | sec = (double)total_cyc / (double)s_clkofsec; 56 | lat = ((double)dur_cyc * s_nsofclk) / (double)count; 57 | printf("%8.1fs %13.1f\n", sec, lat); 58 | fflush(stdout); 59 | } 60 | 61 | void 62 | arch__dependent_read(void *buf, int meas_sec) 63 | { 64 | uint64_t total_count = 0, dur_count = 0; 65 | uint64_t start_tsc, end_tsc, prev_tsc; 66 | uint64_t run_cyc, total_cyc, dur_cyc; 67 | 68 | printf("\n%9s %13s\n", "Time", "Latency(ns)"); 69 | printf("-------------------------\n"); 70 | 71 | run_cyc = (uint64_t)((uint64_t)meas_sec * 72 | (uint64_t)((double)(NS_SEC) * (1.0 / s_nsofclk))); 73 | 74 | start_tsc = rdtsc(); 75 | end_tsc = start_tsc; 76 | prev_tsc = start_tsc; 77 | 78 | while (1) { 79 | total_cyc = end_tsc - start_tsc; 80 | dur_cyc = end_tsc - prev_tsc; 81 | 82 | if (dur_cyc >= s_clkofsec) { 83 | latency_calculate(dur_count, dur_cyc, total_cyc); 84 | prev_tsc = rdtsc(); 85 | dur_count = 0; 86 | } 87 | 88 | if (total_cyc >= run_cyc) { 89 | break; 90 | } 91 | 92 | if (total_count > 0) { 93 | s_latest_avglat = ((double)total_cyc * s_nsofclk) / (double)total_count; 94 | } 95 | 96 | buf_read(buf, READ_NUM); 97 | 98 | dur_count += READ_NUM; 99 | total_count += READ_NUM; 100 | end_tsc = rdtsc(); 101 | } 102 | 103 | printf("-------------------------\n"); 104 | 105 | if (total_count > 0) { 106 | printf("%9s %13.1f\n\n", "Average", 107 | ((double)total_cyc * s_nsofclk) / (double)total_count); 108 | } else { 109 | printf("%9s %13.1f\n\n", "Average", 0.0); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /x86/FEATURES: -------------------------------------------------------------------------------- 1 | Features supported on X86: 2 | -------------------------- 3 | 4 | Per process/thread: 5 | 6 | | Feature | Supported | 7 | |-----------------------------------------------------------|---------------| 8 | | | AMD | Intel | 9 | |-----------------------------------------------------------|---------------| 10 | | RMA | Y | Y | 11 | | LMA | Y | Y | 12 | | CPI | Y | Y | 13 | | CPU% | Y | Y | 14 | | Memory area ADDR | Y | Y | 15 | | Memory area SIZE | Y | Y | 16 | | Memory area ACCESS% | Y | Y | 17 | | Memory area LAT(ns) | Y | Y | 18 | | Memory area DESC | Y | Y | 19 | | Node ACCESS% | Y | Y | 20 | | Node LAT(ns) | Y | Y | 21 | | Call-chain when process generates RMA / LMA / CYCLES / IR | Y | Y | 22 | | Call-chain when process accesses the memory area | Y | Y | 23 | | PQOS CMT/MBM | N | Y | 24 | 25 | Per Node: 26 | 27 | | Feature | Supported | 28 | |-----------------------------------------------------------|---------------| 29 | | | AMD | Intel | 30 | |-----------------------------------------------------------|---------------| 31 | | RMA | Y | Y | 32 | | LMA | Y | Y | 33 | | CPU | Y | Y | 34 | | CPU% | Y | Y | 35 | | MEM total | Y | Y | 36 | | MEM free | Y | Y | 37 | | MEM active | Y | Y | 38 | | MEM inactive | Y | Y | 39 | | Dirty | Y | Y | 40 | | Writeback | Y | Y | 41 | | Mapped | Y | Y | 42 | | QPI/UPI 0 bandwidth | N | Y | 43 | | QPI/UPI 1 bandwidth | N | Y | 44 | | Memory controller bandwidth | N | Y | 45 | 46 | Other: 47 | 48 | | Feature | Supported | 49 | |-----------------------------------------------------------|---------------| 50 | | | AMD | Intel | 51 | |-----------------------------------------------------------|---------------| 52 | | mgen testcase | Y | Y | 53 | -------------------------------------------------------------------------------- /x86/bdw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* This file contains the bdw platform specific functions. */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "../common/include/os/linux/perf_event.h" 39 | #include "../common/include/os/plat.h" 40 | #include "include/bdw.h" 41 | 42 | static plat_event_config_t s_bdw_config[PERF_COUNT_NUM] = { 43 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.core" }, 44 | { PERF_TYPE_RAW, 0x01B7, 0x53, 0x638000001, 0, 0, "off_core_response_0" }, 45 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.ref" }, 46 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "instr_retired.any" }, 47 | { PERF_TYPE_RAW, 0x01BB, 0x53, 0x604000001, 0, 0, "off_core_response_1" } 48 | }; 49 | 50 | static plat_event_config_t s_bdw_ll = { 51 | PERF_TYPE_RAW, 0x01CD, 0x53, LL_THRESH, 0, 1, "mem_trans_retired.latency_above_threshold" 52 | }; 53 | 54 | void 55 | bdw_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 56 | { 57 | plat_config_get(perf_count_id, cfg, s_bdw_config); 58 | } 59 | 60 | void 61 | bdw_ll_config(plat_event_config_t *cfg) 62 | { 63 | memcpy(cfg, &s_bdw_ll, sizeof (plat_event_config_t)); 64 | } 65 | 66 | int 67 | bdw_offcore_num(void) 68 | { 69 | return (2); 70 | } 71 | -------------------------------------------------------------------------------- /x86/include/bdw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_INTEL_BDW_H 30 | #define _NUMATOP_INTEL_BDW_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include 37 | #include 38 | #include "../../common/include/types.h" 39 | 40 | struct _plat_event_config; 41 | 42 | extern void bdw_profiling_config(perf_count_id_t, struct _plat_event_config *); 43 | extern void bdw_ll_config(struct _plat_event_config *); 44 | extern int bdw_offcore_num(void); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* _NUMATOP_INTEL_BDW_H */ 51 | -------------------------------------------------------------------------------- /x86/include/nhm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_INTEL_NHM_H 30 | #define _NUMATOP_INTEL_NHM_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include 37 | #include 38 | #include "../../common/include/types.h" 39 | 40 | struct _plat_event_config; 41 | 42 | extern void nhmex_profiling_config(perf_count_id_t, struct _plat_event_config *); 43 | extern void nhmep_profiling_config(perf_count_id_t, struct _plat_event_config *); 44 | extern void nhmex_ll_config(struct _plat_event_config *); 45 | extern void nhmep_ll_config(struct _plat_event_config *); 46 | extern int nhm_offcore_num(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* _NUMATOP_INTEL_NHM_H */ 53 | -------------------------------------------------------------------------------- /x86/include/skl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_INTEL_SKL_H 30 | #define _NUMATOP_INTEL_SKL_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include 37 | #include 38 | #include "../../common/include/types.h" 39 | 40 | struct _plat_event_config; 41 | 42 | extern void skl_profiling_config(perf_count_id_t, struct _plat_event_config *); 43 | extern void skl_ll_config(struct _plat_event_config *); 44 | extern int skl_offcore_num(void); 45 | 46 | extern void icx_profiling_config(perf_count_id_t, struct _plat_event_config *); 47 | extern void icx_ll_config(struct _plat_event_config *); 48 | extern int icx_offcore_num(void); 49 | 50 | extern void spr_profiling_config(perf_count_id_t, struct _plat_event_config *); 51 | extern void spr_ll_config(struct _plat_event_config *); 52 | extern int spr_offcore_num(void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* _NUMATOP_INTEL_SKL_H */ 59 | -------------------------------------------------------------------------------- /x86/include/snb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_INTEL_SNB_H 30 | #define _NUMATOP_INTEL_SNB_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include 37 | #include 38 | #include "../../common/include/types.h" 39 | 40 | struct _plat_event_config; 41 | 42 | extern void snbep_profiling_config(perf_count_id_t, struct _plat_event_config *); 43 | extern void snbep_ll_config(struct _plat_event_config *); 44 | extern int snb_offcore_num(void); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* _NUMATOP_INTEL_SNB_H */ 51 | -------------------------------------------------------------------------------- /x86/include/srf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_INTEL_SRF_H 30 | #define _NUMATOP_INTEL_SRF_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include 37 | #include 38 | #include "../../common/include/types.h" 39 | 40 | struct _plat_event_config; 41 | 42 | extern void srf_profiling_config(perf_count_id_t, struct _plat_event_config *); 43 | extern void srf_ll_config(struct _plat_event_config *); 44 | extern int srf_offcore_num(void); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif 49 | 50 | #endif /* _NUMATOP_INTEL_SRF_H */ -------------------------------------------------------------------------------- /x86/include/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * Copyright (c) 2017, IBM Corporation 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Intel Corporation nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _NUMATOP_X86_TYPES_H 31 | #define _NUMATOP_X86_TYPES_H 32 | 33 | #include "../../common/include/types.h" 34 | 35 | #define CORP "Intel" 36 | 37 | typedef enum { 38 | CPU_UNSUP = 0, 39 | CPU_WSM_EX, 40 | CPU_SNB_EP, 41 | CPU_NHM_EX, 42 | CPU_NHM_EP, 43 | CPU_WSM_EP, 44 | CPU_IVB_EX, 45 | CPU_HSX, 46 | CPU_BDX, 47 | CPU_SKX, 48 | CPU_ICX, 49 | CPU_SPR, 50 | CPU_EMR, 51 | CPU_GNR, 52 | CPU_SRF, 53 | CPU_ZEN, 54 | CPU_ZEN3, 55 | CPU_ZEN4 56 | } cpu_type_t; 57 | 58 | #define CPU_TYPE_NUM 18 59 | 60 | typedef enum { 61 | PERF_COUNT_INVALID = -1, 62 | PERF_COUNT_CORE_CLK = 0, 63 | PERF_COUNT_RMA, 64 | PERF_COUNT_CLK, 65 | PERF_COUNT_IR, 66 | PERF_COUNT_LMA 67 | } perf_count_id_t; 68 | 69 | #define PERF_COUNT_NUM 5 70 | 71 | #endif /* _NUMATOP_X86_TYPES_H */ 72 | -------------------------------------------------------------------------------- /x86/include/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * Copyright (c) 2017, IBM Corporation 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Intel Corporation nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _NUMATOP_X86_UTIL_H 31 | #define _NUMATOP_X86_UTIL_H 32 | 33 | #define CPU_FAMILY(eax) \ 34 | (((eax) & 0x0F00) >> 8) 35 | 36 | #define CPU_MODEL(eax) \ 37 | (((eax) & 0x00F0) >> 4) 38 | 39 | #define CPU_EXT_FAMILY(eax) \ 40 | (((eax) & 0x0FF00000) >> 20) 41 | 42 | #define CPU_EXT_MODEL(eax) \ 43 | (((eax) & 0xF0000) >> 16) 44 | 45 | #endif /* _NUMATOP_X86_UTIL_H */ 46 | -------------------------------------------------------------------------------- /x86/include/wsm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_INTEL_WSM_H 30 | #define _NUMATOP_INTEL_WSM_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include 37 | #include 38 | #include "../../common/include/types.h" 39 | 40 | struct _plat_event_config; 41 | 42 | extern void wsmex_profiling_config(perf_count_id_t, struct _plat_event_config *); 43 | extern void wsmep_profiling_config(perf_count_id_t, struct _plat_event_config *); 44 | extern void wsmex_ll_config(struct _plat_event_config *); 45 | extern void wsmep_ll_config(struct _plat_event_config *); 46 | extern int wsm_offcore_num(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* _NUMATOP_INTEL_WSM_H */ 53 | -------------------------------------------------------------------------------- /x86/include/zen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, AMD Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _NUMATOP_AMD_ZEN_H 30 | #define _NUMATOP_AMD_ZEN_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #include 37 | #include 38 | #include "../../common/include/types.h" 39 | 40 | struct _plat_event_config; 41 | 42 | extern void zen_profiling_config(perf_count_id_t, struct _plat_event_config *); 43 | extern void zen3_profiling_config(perf_count_id_t, struct _plat_event_config *); 44 | extern void zen4_profiling_config(perf_count_id_t, struct _plat_event_config *); 45 | extern void zen_ll_config(struct _plat_event_config *); 46 | extern int zen_offcore_num(void); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* _NUMATOP_AMD_ZEN_H */ 53 | -------------------------------------------------------------------------------- /x86/nhm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* This file contains the Nehalem platform specific functions. */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "../common/include/os/linux/perf_event.h" 39 | #include "../common/include/os/plat.h" 40 | #include "../common/include/os/os_perf.h" 41 | #include "include/nhm.h" 42 | 43 | static plat_event_config_t s_nhm_profiling[PERF_COUNT_NUM] = { 44 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.core" }, 45 | { PERF_TYPE_RAW, 0x01B7, 0x53, 0x2011, 0, 0, "off_core_response_0" }, 46 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.ref" }, 47 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "instr_retired.any" }, 48 | { PERF_TYPE_RAW, INVALID_CODE_UMASK, 0, 0, 0, 0, "off_core_response_1" } 49 | }; 50 | 51 | static plat_event_config_t s_nhm_ll = { 52 | PERF_TYPE_RAW, 0x100B, 0x53, LL_THRESH, 0, 1, "mem_inst_retired.latency_above_threshold" 53 | }; 54 | 55 | static void 56 | config_get(perf_count_id_t perf_count_id, plat_event_config_t *cfg, plat_event_config_t *cfg_arr) 57 | { 58 | cfg->type = cfg_arr[perf_count_id].type; 59 | cfg->config = cfg_arr[perf_count_id].config; 60 | cfg->other_attr = cfg_arr[perf_count_id].other_attr; 61 | cfg->extra_value = cfg_arr[perf_count_id].extra_value; 62 | strncpy(cfg->desc, cfg_arr[perf_count_id].desc, PLAT_EVENT_DESC_SIZE); 63 | cfg->desc[PLAT_EVENT_DESC_SIZE - 1] = 0; 64 | } 65 | 66 | void 67 | nhmex_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 68 | { 69 | config_get(perf_count_id, cfg, s_nhm_profiling); 70 | } 71 | 72 | void 73 | nhmep_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 74 | { 75 | config_get(perf_count_id, cfg, s_nhm_profiling); 76 | } 77 | 78 | void 79 | nhmex_ll_config(plat_event_config_t *cfg) 80 | { 81 | memcpy(cfg, &s_nhm_ll, sizeof (plat_event_config_t)); 82 | } 83 | 84 | void 85 | nhmep_ll_config(plat_event_config_t *cfg) 86 | { 87 | memcpy(cfg, &s_nhm_ll, sizeof (plat_event_config_t)); 88 | } 89 | 90 | int 91 | nhm_offcore_num(void) 92 | { 93 | return (1); 94 | } 95 | -------------------------------------------------------------------------------- /x86/plat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * Copyright (c) 2017, IBM Corporation 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Intel Corporation nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include "../common/include/os/plat.h" 32 | #include "include/types.h" 33 | #include "include/util.h" 34 | #include "include/nhm.h" 35 | #include "include/wsm.h" 36 | #include "include/snb.h" 37 | #include "include/bdw.h" 38 | #include "include/skl.h" 39 | #include "include/srf.h" 40 | #include "include/zen.h" 41 | 42 | pfn_plat_profiling_config_t 43 | s_plat_profiling_config[CPU_TYPE_NUM] = { 44 | NULL, 45 | wsmex_profiling_config, 46 | snbep_profiling_config, 47 | nhmex_profiling_config, 48 | nhmep_profiling_config, 49 | wsmep_profiling_config, 50 | snbep_profiling_config, 51 | snbep_profiling_config, 52 | bdw_profiling_config, 53 | skl_profiling_config, 54 | icx_profiling_config, 55 | spr_profiling_config, 56 | spr_profiling_config, /* EMR */ 57 | spr_profiling_config, /* GNR */ 58 | srf_profiling_config, 59 | zen_profiling_config, 60 | zen3_profiling_config, 61 | zen4_profiling_config 62 | }; 63 | 64 | pfn_plat_ll_config_t 65 | s_plat_ll_config[CPU_TYPE_NUM] = { 66 | NULL, 67 | wsmex_ll_config, 68 | snbep_ll_config, 69 | nhmex_ll_config, 70 | nhmep_ll_config, 71 | wsmep_ll_config, 72 | snbep_ll_config, 73 | snbep_ll_config, 74 | bdw_ll_config, 75 | skl_ll_config, 76 | icx_ll_config, 77 | spr_ll_config, 78 | spr_ll_config, /* EMR */ 79 | spr_ll_config, /* GNR */ 80 | srf_ll_config, 81 | zen_ll_config, 82 | zen_ll_config, 83 | zen_ll_config 84 | }; 85 | 86 | pfn_plat_offcore_num_t 87 | s_plat_offcore_num[CPU_TYPE_NUM] = { 88 | NULL, 89 | wsm_offcore_num, 90 | snb_offcore_num, 91 | nhm_offcore_num, 92 | nhm_offcore_num, 93 | wsm_offcore_num, 94 | snb_offcore_num, 95 | snb_offcore_num, 96 | bdw_offcore_num, 97 | skl_offcore_num, 98 | icx_offcore_num, 99 | spr_offcore_num, 100 | spr_offcore_num, /* EMR */ 101 | spr_offcore_num, /* GNR */ 102 | srf_offcore_num, 103 | zen_offcore_num, 104 | zen_offcore_num, 105 | zen_offcore_num 106 | }; 107 | 108 | /* ARGSUSED */ 109 | static void 110 | cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx, 111 | unsigned int *edx) 112 | { 113 | #if __x86_64 114 | __asm volatile( 115 | "cpuid\n\t" 116 | :"=a" (*eax), 117 | "=b" (*ebx), 118 | "=c" (*ecx), 119 | "=d" (*edx) 120 | :"a" (*eax)); 121 | #else 122 | __asm volatile( 123 | "push %%ebx\n\t" 124 | "cpuid\n\t" 125 | "mov %%ebx, (%4)\n\t" 126 | "pop %%ebx" 127 | :"=a" (*eax), 128 | "=c" (*ecx), 129 | "=d" (*edx) 130 | :"0" (*eax), 131 | "S" (ebx) 132 | :"memory"); 133 | #endif 134 | } 135 | 136 | static cpu_type_t 137 | cpu_type_get(void) 138 | { 139 | unsigned int eax, ebx, ecx, edx; 140 | int family, model; 141 | cpu_type_t type = CPU_UNSUP; 142 | char vendor[16]; 143 | 144 | eax = 0; 145 | cpuid(&eax, &ebx, &ecx, &edx); 146 | 147 | (void) strncpy(&vendor[0], (char *)(&ebx), 4); 148 | (void) strncpy(&vendor[4], (char *)(&ecx), 4); 149 | (void) strncpy(&vendor[8], (char *)(&edx), 4); 150 | vendor[12] = 0; 151 | 152 | if (strncmp(vendor, "Genu" "ntel" "ineI", 12) != 0 && 153 | strncmp(vendor, "Auth" "cAMD" "enti", 12) != 0) { 154 | return (CPU_UNSUP); 155 | } 156 | 157 | eax = 1; 158 | cpuid(&eax, &ebx, &ecx, &edx); 159 | 160 | family = CPU_FAMILY(eax); 161 | model = CPU_MODEL(eax); 162 | 163 | /* Extended Model ID is considered only when Family ID is either 6 or 15 */ 164 | if (family == 6 || family == 15) 165 | model += CPU_EXT_MODEL(eax) << 4; 166 | 167 | /* Extended Family ID is considered only when Family ID is 15 */ 168 | if (family == 15) 169 | family += CPU_EXT_FAMILY(eax); 170 | 171 | if (family == 6) { 172 | switch (model) { 173 | case 26: 174 | type = CPU_NHM_EP; 175 | break; 176 | case 44: 177 | type = CPU_WSM_EP; 178 | break; 179 | case 45: 180 | type = CPU_SNB_EP; 181 | break; 182 | case 46: 183 | type = CPU_NHM_EX; 184 | break; 185 | case 47: 186 | type = CPU_WSM_EX; 187 | break; 188 | case 62: 189 | type = CPU_IVB_EX; 190 | break; 191 | case 63: 192 | type = CPU_HSX; 193 | break; 194 | case 79: 195 | type = CPU_BDX; 196 | break; 197 | case 85: 198 | type = CPU_SKX; 199 | break; 200 | case 106: 201 | type = CPU_ICX; 202 | break; 203 | case 143: 204 | type = CPU_SPR; 205 | break; 206 | case 207: 207 | type = CPU_EMR; 208 | break; 209 | case 173: 210 | type = CPU_GNR; 211 | break; 212 | case 175: 213 | type = CPU_SRF; 214 | break; 215 | } 216 | } else if (family == 23) { /* Family 17h */ 217 | type = CPU_ZEN; 218 | } else if (family == 25) { /* Family 19h */ 219 | if ((model >= 0x00 && model <= 0x0f) || 220 | (model >= 0x20 && model <= 0x2f) || 221 | (model >= 0x40 && model <= 0x5f)) { 222 | type = CPU_ZEN3; 223 | } else { 224 | type = CPU_ZEN4; 225 | } 226 | } else if (family >= 26) { /* Family 1Ah and later */ 227 | type = CPU_ZEN4; 228 | } 229 | 230 | return (type); 231 | } 232 | 233 | /* 234 | * NumaTOP needs some special performance counters, 235 | * It can only run on WSM-EX/SNB-EP platforms now. 236 | */ 237 | int 238 | plat_detect(void) 239 | { 240 | int ret = -1; 241 | cpu_type_t cpu_type; 242 | 243 | if ((cpu_type = cpu_type_get()) == CPU_UNSUP) { 244 | return (-1); 245 | } 246 | 247 | switch (cpu_type) { 248 | case CPU_WSM_EX: 249 | /* fall through */ 250 | case CPU_SNB_EP: 251 | /* fall through */ 252 | case CPU_NHM_EX: 253 | /* fall through */ 254 | case CPU_NHM_EP: 255 | /* fall through */ 256 | case CPU_WSM_EP: 257 | /* fall through */ 258 | case CPU_IVB_EX: 259 | /* fall through */ 260 | case CPU_HSX: 261 | /* fall through */ 262 | case CPU_BDX: 263 | /* fall through */ 264 | case CPU_SKX: 265 | case CPU_ICX: 266 | case CPU_SPR: 267 | case CPU_EMR: 268 | case CPU_GNR: 269 | case CPU_SRF: 270 | case CPU_ZEN: 271 | case CPU_ZEN3: 272 | case CPU_ZEN4: 273 | ret = 0; 274 | s_cpu_type = cpu_type; 275 | break; 276 | default: 277 | break; 278 | } 279 | 280 | return (ret); 281 | } 282 | -------------------------------------------------------------------------------- /x86/skl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* This file contains the bdw platform specific functions. */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "../common/include/os/linux/perf_event.h" 39 | #include "../common/include/os/plat.h" 40 | #include "include/skl.h" 41 | 42 | static plat_event_config_t s_skl_config[PERF_COUNT_NUM] = { 43 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.core" }, 44 | { PERF_TYPE_RAW, 0x01B7, 0x53, 0x638000001, 0, 0, "off_core_response_0" }, 45 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.ref" }, 46 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "instr_retired.any" }, 47 | { PERF_TYPE_RAW, 0x01BB, 0x53, 0x1f84000001, 0, 0, "off_core_response_1" } 48 | }; 49 | 50 | static plat_event_config_t s_icx_config[PERF_COUNT_NUM] = { 51 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.core" }, 52 | { PERF_TYPE_RAW, 0x01B7, 0x53, 0x730000001, 0, 0, "off_core_response_0" }, 53 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.ref" }, 54 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "instr_retired.any" }, 55 | { PERF_TYPE_RAW, 0x01BB, 0x53, 0x104000001, 0, 0, "off_core_response_1" } 56 | }; 57 | 58 | static plat_event_config_t s_spr_config[PERF_COUNT_NUM] = { 59 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.core" }, 60 | { PERF_TYPE_RAW, 0x012A, 0x53, 0x730000001, 0, 0, "off_core_response_0" }, 61 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.ref" }, 62 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "instr_retired.any" }, 63 | { PERF_TYPE_RAW, 0x012B, 0x53, 0x104000001, 0, 0, "off_core_response_1" } 64 | }; 65 | 66 | static plat_event_config_t s_skl_ll = { 67 | PERF_TYPE_RAW, 0x01CD, 0x53, LL_THRESH, 0, 1, "mem_trans_retired.latency_above_threshold" 68 | }; 69 | 70 | void 71 | skl_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 72 | { 73 | plat_config_get(perf_count_id, cfg, s_skl_config); 74 | } 75 | 76 | void 77 | icx_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 78 | { 79 | plat_config_get(perf_count_id, cfg, s_icx_config); 80 | } 81 | 82 | void 83 | spr_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 84 | { 85 | plat_config_get(perf_count_id, cfg, s_spr_config); 86 | } 87 | 88 | void 89 | skl_ll_config(plat_event_config_t *cfg) 90 | { 91 | memcpy(cfg, &s_skl_ll, sizeof (plat_event_config_t)); 92 | } 93 | 94 | void 95 | icx_ll_config(plat_event_config_t *cfg) 96 | { 97 | skl_ll_config(cfg); 98 | } 99 | 100 | void 101 | spr_ll_config(plat_event_config_t *cfg) 102 | { 103 | skl_ll_config(cfg); 104 | } 105 | 106 | int 107 | skl_offcore_num(void) 108 | { 109 | return (2); 110 | } 111 | 112 | int 113 | icx_offcore_num(void) 114 | { 115 | return skl_offcore_num(); 116 | } 117 | 118 | int 119 | spr_offcore_num(void) 120 | { 121 | return skl_offcore_num(); 122 | } -------------------------------------------------------------------------------- /x86/snb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* This file contains the Sandy-Bridge platform specific functions. */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "../common/include/os/linux/perf_event.h" 39 | #include "../common/include/os/plat.h" 40 | #include "include/snb.h" 41 | 42 | static plat_event_config_t s_snb_ep_config[PERF_COUNT_NUM] = { 43 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.core" }, 44 | { PERF_TYPE_RAW, 0x01B7, 0x53, 0x67f800001, 0, 0, "off_core_response_0" }, 45 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.ref" }, 46 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "instr_retired.any" }, 47 | { PERF_TYPE_RAW, 0x01BB, 0x53, 0x600400001, 0, 0, "off_core_response_1" } 48 | }; 49 | 50 | static plat_event_config_t s_snb_ll = { 51 | PERF_TYPE_RAW, 0x01CD, 0x53, LL_THRESH, 0, 1, "mem_trans_retired.latency_above_threshold" 52 | }; 53 | 54 | void 55 | snbep_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 56 | { 57 | plat_config_get(perf_count_id, cfg, s_snb_ep_config); 58 | } 59 | 60 | void 61 | snbep_ll_config(plat_event_config_t *cfg) 62 | { 63 | memcpy(cfg, &s_snb_ll, sizeof (plat_event_config_t)); 64 | } 65 | 66 | int 67 | snb_offcore_num(void) 68 | { 69 | return (2); 70 | } 71 | -------------------------------------------------------------------------------- /x86/srf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* This file contains the bdw platform specific functions. */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "../common/include/os/linux/perf_event.h" 39 | #include "../common/include/os/plat.h" 40 | #include "include/srf.h" 41 | 42 | static plat_event_config_t s_srf_config[PERF_COUNT_NUM] = { 43 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.core" }, 44 | { PERF_TYPE_RAW, 0x01B7, 0x53, 0x730000001, 0, 0, "off_core_response_0" }, 45 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.ref" }, 46 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "instr_retired.any" }, 47 | { PERF_TYPE_RAW, 0x02B7, 0x53, 0x184000001, 0, 0, "off_core_response_1" } 48 | }; 49 | 50 | static plat_event_config_t s_srf_ll = { 51 | PERF_TYPE_RAW, 0x05D0, 0x53, LL_THRESH, 0, 1, "mem_trans_retired.latency_above_threshold" 52 | }; 53 | 54 | void 55 | srf_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 56 | { 57 | plat_config_get(perf_count_id, cfg, s_srf_config); 58 | } 59 | 60 | void 61 | srf_ll_config(plat_event_config_t *cfg) 62 | { 63 | memcpy(cfg, &s_srf_ll, sizeof (plat_event_config_t)); 64 | } 65 | 66 | int 67 | srf_offcore_num(void) 68 | { 69 | return (2); 70 | } -------------------------------------------------------------------------------- /x86/ui_perf_map.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, IBM Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "../common/include/ui_perf_map.h" 30 | 31 | ui_perf_count_map_t ui_perf_count_map[UI_COUNT_NUM] = { 32 | { UI_COUNT_CORE_CLK, 0, { PERF_COUNT_INVALID, PERF_COUNT_INVALID } }, 33 | { UI_COUNT_RMA, 1, { PERF_COUNT_RMA, PERF_COUNT_INVALID } }, 34 | { UI_COUNT_CLK, 1, { PERF_COUNT_CLK, PERF_COUNT_INVALID } }, 35 | { UI_COUNT_IR, 1, { PERF_COUNT_IR, PERF_COUNT_INVALID } }, 36 | { UI_COUNT_LMA, 1, { PERF_COUNT_LMA, PERF_COUNT_INVALID } } 37 | }; 38 | -------------------------------------------------------------------------------- /x86/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * Copyright (c) 2017, IBM Corporation 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * * Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * * Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * * Neither the name of Intel Corporation nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | * POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include "../common/include/os/os_util.h" 35 | 36 | #define KERNEL_ADDR_START 0xffffffff80000000 37 | 38 | /* 39 | * Get the TSC cycles. 40 | */ 41 | #ifdef __x86_64__ 42 | uint64_t 43 | rdtsc(void) 44 | { 45 | uint64_t var; 46 | uint32_t hi, lo; 47 | 48 | __asm volatile 49 | ("rdtsc" : "=a" (lo), "=d" (hi)); 50 | 51 | /* LINTED E_VAR_USED_BEFORE_SET */ 52 | var = ((uint64_t)hi << 32) | lo; 53 | return (var); 54 | } 55 | #else 56 | uint64_t 57 | rdtsc(void) 58 | { 59 | uint64_t var; 60 | 61 | __asm volatile 62 | ("rdtsc" : "=A" (var)); 63 | 64 | return (var); 65 | } 66 | #endif 67 | 68 | /* 69 | * Check the cpu name in proc info. Intel CPUs always have @ x.y 70 | * GHz and that is the TSC frequency. AMD CPUs do not advertise 71 | * clock frequency as a part of the model name. 72 | */ 73 | int 74 | arch__cpuinfo_freq(double *freq, char *unit) 75 | { 76 | FILE *f; 77 | char *line = NULL; 78 | size_t idx, len = 0; 79 | int ret = -1; 80 | 81 | if ((f = fopen(CPUINFO_PATH, "r")) == NULL) { 82 | return (-1); 83 | } 84 | 85 | while ((len = getline(&line, &len, f)) > 0) { 86 | if (strncmp(line, "model name", sizeof ("model name") - 1) != 0) { 87 | continue; 88 | } 89 | 90 | idx = strcspn(line, "@") + 1; 91 | 92 | /* 93 | * The model name will not change for other processors. So 94 | * bail out if "@" is not found. 95 | */ 96 | if (idx >= len) 97 | break; 98 | 99 | if (sscanf(line + idx, "%lf%10s", freq, unit) == 2) { 100 | if (strcasecmp(unit, "GHz") == 0) { 101 | *freq *= GHZ; 102 | } else if (strcasecmp(unit, "Mhz") == 0) { 103 | *freq *= MHZ; 104 | } 105 | ret = 0; 106 | break; 107 | } 108 | } 109 | 110 | free(line); 111 | fclose(f); 112 | return ret; 113 | } 114 | 115 | int 116 | is_userspace(uint64_t ip) 117 | { 118 | return ip < KERNEL_ADDR_START; 119 | } 120 | -------------------------------------------------------------------------------- /x86/wsm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, Intel Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* This file contains the Westmere platform specific functions. */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include "../common/include/os/linux/perf_event.h" 39 | #include "../common/include/os/plat.h" 40 | #include "include/wsm.h" 41 | 42 | static plat_event_config_t s_wsmex_profiling[PERF_COUNT_NUM] = { 43 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.core" }, 44 | { PERF_TYPE_RAW, 0x01B7, 0x53, 0x2011, 0, 0, "off_core_response_0" }, 45 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.ref" }, 46 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "instr_retired.any" }, 47 | { PERF_TYPE_RAW, 0x01BB, 0x53, 0x5011, 0, 0, "off_core_response_1" } 48 | }; 49 | 50 | static plat_event_config_t s_wsmep_profiling[PERF_COUNT_NUM] = { 51 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.core" }, 52 | { PERF_TYPE_RAW, 0x01B7, 0x53, 0x2011, 0, 0, "off_core_response_0" }, 53 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_REF_CPU_CYCLES, 0x53, 0, 0, 0, "cpu_clk_unhalted.ref" }, 54 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "instr_retired.any" }, 55 | { PERF_TYPE_RAW, 0x01BB, 0x53, 0x5011, 0, 0, "off_core_response_1" } 56 | }; 57 | 58 | static plat_event_config_t s_wsm_ll = { 59 | PERF_TYPE_RAW, 0x100B, 0x53, LL_THRESH, 0, 1, "mem_inst_retired.latency_above_threshold" 60 | }; 61 | 62 | void 63 | wsmex_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 64 | { 65 | plat_config_get(perf_count_id, cfg, s_wsmex_profiling); 66 | } 67 | 68 | void 69 | wsmep_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 70 | { 71 | plat_config_get(perf_count_id, cfg, s_wsmep_profiling); 72 | } 73 | 74 | void 75 | wsmex_ll_config(plat_event_config_t *cfg) 76 | { 77 | memcpy(cfg, &s_wsm_ll, sizeof (plat_event_config_t)); 78 | } 79 | 80 | void 81 | wsmep_ll_config(plat_event_config_t *cfg) 82 | { 83 | memcpy(cfg, &s_wsm_ll, sizeof (plat_event_config_t)); 84 | } 85 | 86 | int 87 | wsm_offcore_num(void) 88 | { 89 | return (2); 90 | } 91 | -------------------------------------------------------------------------------- /x86/zen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023, AMD Corporation 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * * Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * * Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * * Neither the name of Intel Corporation nor the names of its contributors 13 | * may be used to endorse or promote products derived from this software 14 | * without specific prior written permission. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | /* This file contains the Zen platform specific functions. */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include "../common/include/os/linux/perf_event.h" 41 | #include "../common/include/os/plat.h" 42 | #include "include/zen.h" 43 | 44 | #define IBS_OP_PMU_TYPE_PATH \ 45 | "/sys/bus/event_source/devices/ibs_op/type" 46 | 47 | static plat_event_config_t s_zen_config[PERF_COUNT_NUM] = { 48 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0, 0, 0, 0, "LsNotHaltedCyc" }, 49 | { PERF_TYPE_RAW, 0x0000000000004043, 0, 0, 0, 0, "LsDmndFillsFromSys.DRAM_IO_Far" }, 50 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0, 0, 0, 0, "LsNotHaltedCyc" }, 51 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "ExRetOps" }, 52 | { PERF_TYPE_RAW, 0x0000000000000843, 0, 0, 0, 0, "LsDmndFillsFromSys.DRAM_IO_Near" }, 53 | }; 54 | 55 | static plat_event_config_t s_zen3_config[PERF_COUNT_NUM] = { 56 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0, 0, 0, 0, "LsNotHaltedCyc" }, 57 | { PERF_TYPE_RAW, 0x0000000000004044, 0, 0, 0, 0, "LsAnyFillsFromSys.MemIoRemote" }, 58 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0, 0, 0, 0, "LsNotHaltedCyc" }, 59 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "ExRetOps" }, 60 | { PERF_TYPE_RAW, 0x0000000000000844, 0, 0, 0, 0, "LsAnyFillsFromSys.MemIoLocal" }, 61 | }; 62 | 63 | static plat_event_config_t s_zen4_config[PERF_COUNT_NUM] = { 64 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_CPU_CYCLES, 0, 0, 0, 0, "LsNotHaltedCyc" }, 65 | { PERF_TYPE_RAW, 0x0000000000004044, 0, 0, 0, 0, "LsAnyFillsFromSys.MemIoRemote" }, 66 | { PERF_TYPE_RAW, 0x0000000100000120, 0, 0, 0, 0, "LsNotHaltedP0Cyc.P0FreqCyc" }, 67 | { PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS, 0x53, 0, 0, 0, "ExRetOps" }, 68 | { PERF_TYPE_RAW, 0x0000000000000844, 0, 0, 0, 0, "LsAnyFillsFromSys.MemIoLocal" }, 69 | }; 70 | 71 | /* 72 | * Owing to the nature of IBS uop tagging, a higher sampling period is 73 | * required to capture meaningful samples. All samples may not originate 74 | * from a memory access instruction and require additional filtering. 75 | */ 76 | static plat_event_config_t s_zen_ll = { 77 | 0, 0x0000000000000000, 0, 0, LL_THRESH * 10, 0, "IbsOpCntCycles" 78 | }; 79 | 80 | void 81 | zen_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 82 | { 83 | plat_config_get(perf_count_id, cfg, s_zen_config); 84 | } 85 | 86 | void 87 | zen3_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 88 | { 89 | plat_config_get(perf_count_id, cfg, s_zen3_config); 90 | } 91 | 92 | void 93 | zen4_profiling_config(perf_count_id_t perf_count_id, plat_event_config_t *cfg) 94 | { 95 | plat_config_get(perf_count_id, cfg, s_zen4_config); 96 | } 97 | 98 | static int 99 | zen_ibs_op_pmu_type(void) 100 | { 101 | int fd, type, i; 102 | char buf[32]; 103 | 104 | if ((fd = open(IBS_OP_PMU_TYPE_PATH, O_RDONLY)) < 0) 105 | return (-1); 106 | 107 | if ((i = read(fd, buf, sizeof (buf) - 1)) <= 0) { 108 | close(fd); 109 | return (-1); 110 | } 111 | 112 | close(fd); 113 | buf[i] = 0; 114 | if ((type = atoi(buf)) == 0) 115 | return (-1); 116 | 117 | return (type); 118 | } 119 | 120 | void 121 | zen_ll_config(plat_event_config_t *cfg) 122 | { 123 | memcpy(cfg, &s_zen_ll, sizeof (plat_event_config_t)); 124 | cfg->type = zen_ibs_op_pmu_type(); 125 | } 126 | 127 | int 128 | zen_offcore_num(void) 129 | { 130 | return (2); 131 | } 132 | --------------------------------------------------------------------------------