-
Notifications
You must be signed in to change notification settings - Fork 332
/
slm_ratios.py
231 lines (188 loc) · 6.61 KB
/
slm_ratios.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#
# Silvermont top level model
# Can be collected without multiplexing
# Please see http://ark.intel.com for more details on these CPUs.
#
from __future__ import print_function
import metrics
import node
print_error = lambda msg: False
version = "1.0"
# Override using set_clks_event_name()
CLKS_EVENT_NAME = "CPU_CLK_UNHALTED.CORE"
# Module-level function used to work around event name differences,
# e.g. Knights Landing
def set_clks_event_name(ev_name):
global CLKS_EVENT_NAME
CLKS_EVENT_NAME = ev_name
# Instructions Per Cycle
def IPC(EV, level):
return EV("INST_RETIRED.ANY", level) / EV("cycles", 1)
# Average Frequency Utilization relative nominal frequency
def TurboUtilization(EV, level):
return EV("cycles", level) / EV("CPU_CLK_UNHALTED.REF_TSC", level)
def DurationTimeInSeconds(EV, level):
return EV("interval-ns", 0) / 1e+06 / 1000
# Run duration time in seconds
def Time(EV, level):
return DurationTimeInSeconds(EV, level)
# Per-thread actual clocks
def CLKS(EV, level):
return EV(CLKS_EVENT_NAME, level)
# Cycles Per Instruction (threaded)
def CPI(EV, level):
return 1 / IPC(EV, level)
def icache_line_fetch_cost(ev, level):
return ev("FETCH_STALL.ICACHE_FILL_PENDING_CYCLES", level) / \
CLKS(ev, level)
def predecode_wrong_cost(ev, level):
return (ev("DECODE_RESTRICTION.PREDECODE_WRONG", level) * 3 /
CLKS(ev, level))
def ba_clears_cost(ev, level):
return ev("BACLEARS.ALL", level) * 5 / CLKS(ev, level)
def ms_entry_cost(ev, level):
return ev("MS_DECODED.MS_ENTRY", level) * 5 / CLKS(ev, level)
def itlb_misses_cost(ev, level):
return ev("PAGE_WALKS.I_SIDE_CYCLES", level) / CLKS(ev, level)
# LEVEL 0, user-visible metrics"
class CyclesPerUop(metrics.MetricBase):
name = "CyclesPerUop"
domain = "Metric"
desc = "\nCycles per uop."
def _compute(self, ev):
return ev(CLKS_EVENT_NAME, self.level) / \
ev("UOPS_RETIRED.ALL", self.level)
# LEVEL 1
class FrontendBound(metrics.FrontendBound):
def _compute(self, ev):
return ev("NO_ALLOC_CYCLES.NOT_DELIVERED", 1) / CLKS(ev, self.level)
@node.requires("retiring", "bad_speculation", "frontend")
class BackendBound(metrics.BackendBound):
@node.check_refs
def _compute(self, ev):
return 1 - (self.retiring.compute(ev) +
self.bad_speculation.compute(ev) +
self.frontend.compute(ev))
class BadSpeculation(metrics.BadSpeculation):
def _compute(self, ev):
return ev("NO_ALLOC_CYCLES.MISPREDICTS", 1) / CLKS(ev, self.level)
class Retiring(metrics.Retiring):
def _compute(self, ev):
return ev("UOPS_RETIRED.ALL", 1) / (2 * CLKS(ev, self.level))
# LEVEL 2
@node.requires("icache_misses", "itlb", "ms_cost", "frontend")
class FrontendLatency(metrics.FrontendLatency):
@node.check_refs
def _compute(self, ev):
return (self.icache_misses.compute(ev) + self.itlb.compute(ev) +
self.ms_cost.compute(ev) + ba_clears_cost(ev, self.level)
) / CLKS(ev, self.level)
# LEVEL 3
class ICacheMisses(metrics.ICacheMisses):
def _compute(self, ev):
return (icache_line_fetch_cost(ev, self.level) +
predecode_wrong_cost(ev, self.level))
class ITLBMisses(metrics.ITLBMisses):
def _compute(self, ev):
return itlb_misses_cost(ev, self.level)
class MSSwitches(metrics.MSSwitches):
def _compute(self, ev):
return ms_entry_cost(ev, self.level)
class Metric_IPC:
name = "IPC"
desc = """
Instructions Per Cycle"""
def compute(self, EV):
try:
self.val = IPC(EV, 0)
except ZeroDivisionError:
print("IPC zero division")
self.val = 0
class Metric_TurboUtilization:
name = "TurboUtilization"
desc = """
Average Frequency Utilization relative nominal frequency"""
def compute(self, EV):
try:
self.val = TurboUtilization(EV, 0)
except ZeroDivisionError:
print("TurboUtilization zero division")
self.val = 0
class Metric_CLKS:
name = "CLKS"
desc = """
Per-thread actual clocks"""
domain = "Count"
maxval = 0
errcount = 0
def compute(self, EV):
try:
self.val = CLKS(EV, 0)
except ZeroDivisionError:
print_error("CLKS zero division")
self.errcount += 1
self.val = 0
class Metric_Time:
name = "Time"
desc = """
Run duration time in seconds"""
domain = "Count"
maxval = 0
errcount = 0
def compute(self, EV):
try:
self.val = Time(EV, 0)
except ZeroDivisionError:
print_error("Time zero division")
self.errcount += 1
self.val = 0
class Metric_CPI:
name = "CPI"
desc = """
Cycles Per Instruction (threaded)"""
domain = "Metric"
maxval = 0
errcount = 0
def compute(self, EV):
try:
self.val = CPI(EV, 0)
except ZeroDivisionError:
print_error("CPI zero division")
self.errcount += 1
self.val = 0
class Setup:
def __init__(self, runner):
# Instantiate nodes as required to be able to specify their
# references
# L3 objects
icache_misses = ICacheMisses()
itlb_misses = ITLBMisses()
ms_cost = MSSwitches()
#L1 objects
frontend = FrontendBound()
bad_speculation = BadSpeculation()
retiring = Retiring()
backend = BackendBound(retiring=retiring,
bad_speculation=bad_speculation,
frontend=frontend)
# L2 objects
frontend_latency = FrontendLatency(icache_misses=icache_misses,
itlb=itlb_misses,
ms_cost=ms_cost,
frontend=frontend
)
# Set parents
node.set_parent(None, [frontend, bad_speculation, retiring, backend])
node.set_parent(frontend, [frontend_latency])
node.set_parent(frontend_latency,
[icache_misses, itlb_misses, ms_cost])
# User visible metrics
user_metrics = [Metric_IPC(), Metric_CPI(), Metric_TurboUtilization(),
Metric_CLKS(), Metric_Time(), CyclesPerUop()]
nodes = [obj for obj in locals().values()
if issubclass(obj.__class__, metrics.MetricBase) and
obj.level > 0]
nodes = sorted(nodes, key=lambda n: n.level)
# Pass to runner
list(map(runner.run, nodes))
list(map(runner.metric, user_metrics))