From 0d73b74b24d07bee374f4c5d4e0e08d03161d32b Mon Sep 17 00:00:00 2001 From: Daniel Hill Date: Thu, 31 Aug 2023 15:36:21 -0700 Subject: [PATCH] instruction mix utility and cleanup (#56) * remove tsc rounding for more accuracy * instruction mixes * revert version * check for perf --- events/clx_skx.txt | 2 - events/icx.txt | 2 - events/metric_icx.json | 5 -- events/metric_skx_clx.json | 5 -- instruction-mix.py | 99 ++++++++++++++++++++++++++++++++++++++ perf-collect.py | 5 +- requirements.txt | 1 + 7 files changed, 103 insertions(+), 16 deletions(-) create mode 100644 instruction-mix.py diff --git a/events/clx_skx.txt b/events/clx_skx.txt index 9c2abbb..aa716f9 100644 --- a/events/clx_skx.txt +++ b/events/clx_skx.txt @@ -125,7 +125,6 @@ cpu-cycles, ref-cycles, instructions; -cpu/event=0xb0,umask=0x10,period=100003,name='OFFCORE_REQUESTS.L3_MISS_DEMAND_DATA_RD'/, cpu/event=0xd1,umask=0x40,period=100007,name='MEM_LOAD_RETIRED.FB_HIT'/, cpu/event=0xa3,umask=0x10,cmask=0x16,period=2000003,name='CYCLE_ACTIVITY.CYCLES_MEM_ANY'/, cpu/event=0xa3,umask=0x08,cmask=0x08,period=2000003,name='CYCLE_ACTIVITY.CYCLES_L1D_MISS'/, @@ -134,7 +133,6 @@ ref-cycles, instructions; cpu/event=0x79,umask=0x30,period=2000003,name='IDQ.MS_UOPS'/, -cpu/event=0x60,umask=0x10,period=2000003,name='OFFCORE_REQUESTS_OUTSTANDING.L3_MISS_DEMAND_DATA_RD'/, cpu/event=0x83,umask=0x04,period=200003,name='ICACHE_64B.IFTAG_STALL'/, cpu/event=0x08,umask=0x20,cmask=0x01,period=2000003,name='DTLB_LOAD_MISSES.STLB_HIT:c1'/, cpu-cycles, diff --git a/events/icx.txt b/events/icx.txt index 590e01b..f7bfa8a 100644 --- a/events/icx.txt +++ b/events/icx.txt @@ -18,8 +18,6 @@ instructions; cpu/event=0xf1,umask=0x1f,period=100003,name='L2_LINES_IN.ALL'/, cpu/event=0xd1,umask=0x10,period=100021,name='MEM_LOAD_RETIRED.L2_MISS'/, -cpu/event=0x60,umask=0x10,period=2000003,name='OFFCORE_REQUESTS_OUTSTANDING.L3_MISS_DEMAND_DATA_RD'/, -cpu/event=0xb0,umask=0x10,period=100003,name='OFFCORE_REQUESTS.L3_MISS_DEMAND_DATA_RD'/, cpu-cycles, ref-cycles, instructions; diff --git a/events/metric_icx.json b/events/metric_icx.json index 9448c37..13ac99c 100644 --- a/events/metric_icx.json +++ b/events/metric_icx.json @@ -86,11 +86,6 @@ "expression": "[L2_RQSTS.CODE_RD_MISS] / [instructions]", "expression-txn": "[L2_RQSTS.CODE_RD_MISS] / [TXN]" }, - { - "name": "metric_Average LLC data read miss latency (in clks)", - "expression": "[OFFCORE_REQUESTS_OUTSTANDING.L3_MISS_DEMAND_DATA_RD] / [OFFCORE_REQUESTS.L3_MISS_DEMAND_DATA_RD]", - "origin": "perfspect" - }, { "name": "metric_UPI Data transmit BW (MB/sec) (only data)", "expression": "([UNC_UPI_TxL_FLITS.ALL_DATA] * (64 / 9.0) / 1000000) / 1" diff --git a/events/metric_skx_clx.json b/events/metric_skx_clx.json index 4caf3fa..0b4b49d 100644 --- a/events/metric_skx_clx.json +++ b/events/metric_skx_clx.json @@ -107,11 +107,6 @@ "expression-txn": "[OCR.ALL_READS.L3_MISS.REMOTE_HIT_FORWARD] / [TXN]", "origin": "perfspect" }, - { - "name": "metric_Average LLC data read miss latency (in clks)", - "expression": "[OFFCORE_REQUESTS_OUTSTANDING.L3_MISS_DEMAND_DATA_RD] / [OFFCORE_REQUESTS.L3_MISS_DEMAND_DATA_RD]", - "origin": "perfspect" - }, { "name": "metric_Average LLC data read miss latency (in ns)", "expression": "(1000000000 * [UNC_CHA_TOR_OCCUPANCY.IA_MISS.0x40433] / [UNC_CHA_TOR_INSERTS.IA_MISS.0x40433]) / ( [UNC_CHA_CLOCKTICKS] / ([CHAS_PER_SOCKET] * [SOCKET_COUNT]) )", diff --git a/instruction-mix.py b/instruction-mix.py new file mode 100644 index 0000000..1e4371c --- /dev/null +++ b/instruction-mix.py @@ -0,0 +1,99 @@ +#!/usr/bin/env python3 + +########################################################################################################### +# Copyright (C) 2021-2023 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause +########################################################################################################### + +import logging +import os +import platform +import shlex +import subprocess +import sys + +from iced_x86 import Decoder, Formatter, FormatterSyntax # type: ignore +from src.common import configure_logging, crash +from src.perf_helpers import get_perf_list + +formatter = Formatter(FormatterSyntax.NASM) + + +def get_insn(insn): + global formatter + insn = bytes.fromhex(insn.replace(" ", "")) + insnraw = formatter.format(Decoder(64, insn).decode()).split(" ", 1) + insn = insnraw[0] + reg = [] + if len(insnraw) > 1: + if "xmm" in insnraw[1]: + reg.append("AVX128") + if "ymm" in insnraw[1]: + reg.append("AVX256") + if "zmm" in insnraw[1]: + reg.append("AVX512") + if len(reg) > 0: + insn += ";" + ",".join(reg) + return insn + + +if __name__ == "__main__": + configure_logging(".") + + if len(sys.argv) != 2 or not sys.argv[1].isdigit(): + print('usage: "sudo ./instruction-mix 3 # run for 3 seconds"') + sys.exit() + if os.geteuid() != 0: + crash("Must run as root, please re-run") + if platform.system() != "Linux": + crash("PerfSpect currently supports Linux only") + get_perf_list() + + logging.info("collecting...") + + subprocess.run(shlex.split("perf record -a -F 99 sleep " + sys.argv[1])) + rawdata = ( + subprocess.Popen( + shlex.split("perf script -F comm,pid,insn"), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + .communicate()[0] + .decode() + .split("\n")[:-1] + ) + + logging.info("postprocessing...") + + processmap = {} + + for row in rawdata: + sides = row.split("insn:") + if len(sides) > 1: + insn = get_insn(sides[1]) + id = sides[0].split()[0] + ";" + insn + if id not in processmap: + processmap[id] = 0 + processmap[id] += 1 + + # generate freqs + col = "" + for p in processmap: + col += p + " " + str(processmap[p]) + "\n" + + with open("instruction-mix.svg", "w") as f: + subprocess.run( + shlex.split( + os.path.join( + getattr( + sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__)) + ), + "flamegraph.pl", + ) + ), + input=col.encode(), + stdout=f, + ) + + os.chmod("instruction-mix.svg", 0o666) + logging.info("generated instruction-mix.svg") diff --git a/perf-collect.py b/perf-collect.py index 98faeaa..26d34de 100644 --- a/perf-collect.py +++ b/perf-collect.py @@ -432,10 +432,11 @@ def validate_file(fname): elif args.app: cmd += f" {args.app}" - perfargs = shlex.split(cmd) - validate_perfargs(perfargs) if args.verbose: logging.info(cmd) + perfargs = shlex.split(cmd) + validate_perfargs(perfargs) + psi = [] logging.info("Collection started!") start = time.time() diff --git a/requirements.txt b/requirements.txt index 9afde2e..73d9483 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ black flake8 +iced-x86 pytype simpleeval pandas