-
Notifications
You must be signed in to change notification settings - Fork 332
/
simple_ratios.py
180 lines (154 loc) · 5.11 KB
/
simple_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
#
# Simple 5 event top level model
#
print_error = lambda msg: False
version = "1.0"
check_event = lambda ev: False
# Constants
PipelineWidth = 4
uops_retired_slots = "UOPS_RETIRED.RETIRE_SLOTS"
def CLKS(EV):
return EV("CPU_CLK_UNHALTED.THREAD", 1)
def SLOTS(EV):
return PipelineWidth * CLKS(EV)
# Instructions Per Cycle
def IPC(EV, level):
return EV("INST_RETIRED.ANY", level) / CLKS(EV)
# Uops Per Instruction
def UPI(EV, level):
return EV(uops_retired_slots, level) / EV("INST_RETIRED.ANY", level)
# Average Frequency Utilization relative nominal frequency
def TurboUtilization(EV, level):
return CLKS(EV) / EV("CPU_CLK_UNHALTED.REF_TSC", level)
class FrontendBound:
name = "Frontend Bound"
domain = "Slots"
desc = """
This category reflects slots where the Frontend of the processor undersupplies
its Backend."""
level = 1
def compute(self, EV):
try:
self.val = EV("IDQ_UOPS_NOT_DELIVERED.CORE", 1) / SLOTS(EV)
self.thresh = self.val > 0.2
except ZeroDivisionError:
self.val = 0
self.thresh = False
return self.val
class BadSpeculation:
name = "Bad Speculation"
domain = "Slots"
desc = """
This category reflects slots wasted due to incorrect speculations, which
include slots used to allocate uops that do not eventually get retired and
slots for which allocation was blocked due to recovery from earlier incorrect
speculation. For example, wasted work due to miss-predicted branches is
categorized under the Bad Speculation category"""
level = 1
def compute(self, EV):
try:
self.val = ( EV("UOPS_ISSUED.ANY", 1) - EV(uops_retired_slots, 1) + PipelineWidth * EV("INT_MISC.RECOVERY_CYCLES", 1) ) / SLOTS(EV)
self.thresh = self.val > 0.1
except ZeroDivisionError:
self.val = 0
self.thresh = False
return self.val
class BackendBound:
name = "Backend Bound"
domain = "Slots"
desc = """
This category reflects slots where no uops are being delivered due to a lack
of required resources for accepting more uops in the Backend of the pipeline."""
level = 1
def compute(self, EV):
try:
self.val = 1 - ( self.FrontendBound.compute(EV) + self.BadSpeculation.compute(EV) + self.Retiring.compute(EV) )
self.thresh = self.val > 0.2
except ZeroDivisionError:
self.val = 0
self.thresh = False
return self.val
class Retiring:
name = "Retiring"
domain = "Slots"
desc = """
This category reflects slots utilized by good uops i.e. allocated uops that
eventually get retired."""
level = 1
def compute(self, EV):
try:
self.val = EV(uops_retired_slots, 1) / SLOTS(EV)
self.thresh = self.val > 0.7
except ZeroDivisionError:
self.val = 0
self.thresh = False
return self.val
class Metric_IPC:
name = "IPC"
desc = """
Instructions Per Cycle"""
errcount = 0
def compute(self, EV):
try:
self.val = IPC(EV, 0)
except ZeroDivisionError:
print_error("IPC zero division")
self.errcount += 1
self.val = 0
class Metric_UPI:
name = "UPI"
desc = """
Uops Per Instruction"""
errcount = 0
def compute(self, EV):
try:
self.val = UPI(EV, 0)
except ZeroDivisionError:
print_error("UPI zero division")
self.errcount += 1
self.val = 0
class Metric_TurboUtilization:
name = "TurboUtilization"
desc = """
Average Frequency Utilization relative nominal frequency"""
errcount = 0
def compute(self, EV):
try:
self.val = TurboUtilization(EV, 0)
except ZeroDivisionError:
print_error("TurboUtilization zero division")
self.errcount += 1
self.val = 0
class Setup:
def __init__(self, r):
if check_event("UOPS_RETIRED.SLOTS"):
global uops_retired_slots
uops_retired_slots = "UOPS_RETIRED.SLOTS"
o = dict()
n = FrontendBound() ; r.run(n)
o["FrontendBound"] = n
n = BadSpeculation() ; r.run(n)
o["BadSpeculation"] = n
n = BackendBound() ; r.run(n)
o["BackendBound"] = n
n = Retiring() ; r.run(n)
o["Retiring"] = n
o["FrontendBound"].parent = None
o["BadSpeculation"].parent = None
o["BackendBound"].parent = None
o["Retiring"].parent = None
o["BackendBound"].FrontendBound = o["FrontendBound"]
o["BackendBound"].BadSpeculation = o["BadSpeculation"]
o["BackendBound"].Retiring = o["Retiring"]
o["FrontendBound"].sibling = None
o["BadSpeculation"].sibling = None
o["BackendBound"].sibling = None
o["Retiring"].sibling = None
o["FrontendBound"].sample = []
o["BadSpeculation"].sample = []
o["BackendBound"].sample = []
o["Retiring"].sample = []
# user visible metrics
n = Metric_IPC() ; r.metric(n)
n = Metric_UPI() ; r.metric(n)
n = Metric_TurboUtilization() ; r.metric(n)