Skip to content

Commit

Permalink
instruction mix utility and cleanup (#56)
Browse files Browse the repository at this point in the history
* remove tsc rounding for more accuracy

* instruction mixes

* revert version

* check for perf
  • Loading branch information
hilldani authored Aug 31, 2023
1 parent 7c2e32e commit 0d73b74
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 16 deletions.
2 changes: 0 additions & 2 deletions events/clx_skx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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'/,
Expand All @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions events/icx.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions events/metric_icx.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 0 additions & 5 deletions events/metric_skx_clx.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]) )",
Expand Down
99 changes: 99 additions & 0 deletions instruction-mix.py
Original file line number Diff line number Diff line change
@@ -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")
5 changes: 3 additions & 2 deletions perf-collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
black
flake8
iced-x86
pytype
simpleeval
pandas
Expand Down

0 comments on commit 0d73b74

Please sign in to comment.