forked from andikleen/pmu-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jkt_server_ratios.py
1536 lines (1404 loc) · 51.8 KB
/
jkt_server_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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# auto generated TopDown/TMAM 3.1 description for Intel Xeon E5 (code named SandyBridge EP)
# Please see http://ark.intel.com for more details on these CPUs.
#
# References:
# http://halobates.de/blog/p/262
# https://sites.google.com/site/analysismethods/yasin-pubs
# https://download.01.org/perfmon/
#
# Helpers
print_error = lambda msg: False
smt_enabled = False
version = "3.1"
# Constants
Pipeline_Width = 4
Mem_L3_Weight = 7
Mem_STLB_Hit_Cost = 7
MS_Switches_Cost = 3
OneMillion = 1000000
OneBillion = 1000000000
# Aux. formulas
# Floating Point computational (arithmetic) Operations Count
def FLOP_Count(self, EV, level):
return (1 *(EV("FP_COMP_OPS_EXE.SSE_SCALAR_SINGLE", level) + EV("FP_COMP_OPS_EXE.SSE_SCALAR_DOUBLE", level)) + 2 * EV("FP_COMP_OPS_EXE.SSE_PACKED_DOUBLE", level) + 4 *(EV("FP_COMP_OPS_EXE.SSE_PACKED_SINGLE", level) + EV("SIMD_FP_256.PACKED_DOUBLE", level)) + 8 * EV("SIMD_FP_256.PACKED_SINGLE", level))
def Recovery_Cycles(self, EV, level):
return (EV("INT_MISC.RECOVERY_CYCLES_ANY", level) / 2) if smt_enabled else EV("INT_MISC.RECOVERY_CYCLES", level)
def Execute_Cycles(self, EV, level):
return (EV("UOPS_DISPATCHED.CORE:c1", level) / 2) if smt_enabled else EV("UOPS_DISPATCHED.CORE:c1", level)
def ITLB_Miss_Cycles(self, EV, level):
return (Mem_STLB_Hit_Cost * EV("ITLB_MISSES.STLB_HIT", level) + EV("ITLB_MISSES.WALK_DURATION", level))
def Frontend_RS_Empty_Cycles(self, EV, level):
EV("RS_EVENTS.EMPTY_CYCLES", level)
return EV("RS_EVENTS.EMPTY_CYCLES", level) if(self.Frontend_Latency.compute(EV)> 0.1)else 0
def Frontend_Latency_Cycles(self, EV, level):
return EV(lambda EV , level : min(EV("CPU_CLK_UNHALTED.THREAD", level) , EV("IDQ_UOPS_NOT_DELIVERED.CYCLES_0_UOPS_DELIV.CORE", level)) , level )
def STALLS_MEM_ANY(self, EV, level):
return EV(lambda EV , level : min(EV("CPU_CLK_UNHALTED.THREAD", level) , EV("CYCLE_ACTIVITY.STALLS_L1D_PENDING", level)) , level )
def STALLS_TOTAL(self, EV, level):
return EV(lambda EV , level : min(EV("CPU_CLK_UNHALTED.THREAD", level) , EV("CYCLE_ACTIVITY.CYCLES_NO_DISPATCH", level)) , level )
def ORO_DRD_Any_Cycles(self, EV, level):
return EV(lambda EV , level : min(EV("CPU_CLK_UNHALTED.THREAD", level) , EV("OFFCORE_REQUESTS_OUTSTANDING.CYCLES_WITH_DATA_RD", level)) , level )
def ORO_DRD_BW_Cycles(self, EV, level):
return EV(lambda EV , level : min(EV("CPU_CLK_UNHALTED.THREAD", level) , EV("OFFCORE_REQUESTS_OUTSTANDING.ALL_DATA_RD:c6", level)) , level )
def Few_Uops_Executed_Threshold(self, EV, level):
EV("UOPS_DISPATCHED.THREAD:c3", level)
EV("UOPS_DISPATCHED.THREAD:c2", level)
return EV("UOPS_DISPATCHED.THREAD:c3", level) if(IPC(self, EV, level)> 1.8)else EV("UOPS_DISPATCHED.THREAD:c2", level)
def Backend_Bound_Cycles(self, EV, level):
return (STALLS_TOTAL(self, EV, level) + EV("UOPS_DISPATCHED.THREAD:c1", level) - Few_Uops_Executed_Threshold(self, EV, level) - Frontend_RS_Empty_Cycles(self, EV, level) + EV("RESOURCE_STALLS.SB", level))
def Memory_Bound_Fraction(self, EV, level):
return (STALLS_MEM_ANY(self, EV, level) + EV("RESOURCE_STALLS.SB", level)) / Backend_Bound_Cycles(self, EV, level)
def Mem_L3_Hit_Fraction(self, EV, level):
return EV("MEM_LOAD_UOPS_RETIRED.LLC_HIT", level) /(EV("MEM_LOAD_UOPS_RETIRED.LLC_HIT", level) + Mem_L3_Weight * EV("MEM_LOAD_UOPS_RETIRED.LLC_MISS", level))
def Mispred_Clears_Fraction(self, EV, level):
return EV("BR_MISP_RETIRED.ALL_BRANCHES", level) /(EV("BR_MISP_RETIRED.ALL_BRANCHES", level) + EV("MACHINE_CLEARS.COUNT", level))
def Avg_RS_Empty_Period_Clears(self, EV, level):
return (EV("RS_EVENTS.EMPTY_CYCLES", level) - ITLB_Miss_Cycles(self, EV, level)) / EV("RS_EVENTS.EMPTY_END", level)
def Retire_Uop_Fraction(self, EV, level):
return EV("UOPS_RETIRED.RETIRE_SLOTS", level) / EV("UOPS_ISSUED.ANY", level)
def DurationTimeInSeconds(self, EV, level):
return 0 if 0 > 0 else(EV("interval-ns", 0) / 1e+06 / 1000 )
def r2r_delta(self, EV, level):
return max_delta_clk
# Instructions Per Cycle (per logical thread)
def IPC(self, EV, level):
return EV("INST_RETIRED.ANY", level) / CLKS(self, EV, level)
# Uops Per Instruction
def UPI(self, EV, level):
return EV("UOPS_RETIRED.RETIRE_SLOTS", level) / EV("INST_RETIRED.ANY", level)
# Rough Estimation of fraction of fetched lines bytes that were likely consumed by program instructions
def IFetch_Line_Utilization(self, EV, level):
return min(1 , EV("UOPS_ISSUED.ANY", level) /(UPI(self, EV, level)* 32 *(EV("ICACHE.HIT", level) + EV("ICACHE.MISSES", level)) / 4))
# Fraction of Uops delivered by the DSB (decoded instructions cache)
def DSB_Coverage(self, EV, level):
return (EV("IDQ.DSB_UOPS", level) + EV("LSD.UOPS", level)) /(EV("IDQ.DSB_UOPS", level) + EV("LSD.UOPS", level) + EV("IDQ.MITE_UOPS", level) + EV("IDQ.MS_UOPS", level))
# Cycles Per Instruction (threaded)
def CPI(self, EV, level):
return 1 / IPC(self, EV, level)
# Per-thread actual clocks when the thread is active
def CLKS(self, EV, level):
return EV("CPU_CLK_UNHALTED.THREAD", level)
# Total issue-pipeline slots
def SLOTS(self, EV, level):
return Pipeline_Width * CORE_CLKS(self, EV, level)
# Instructions Per Cycle (per physical core)
def CoreIPC(self, EV, level):
return EV("INST_RETIRED.ANY", level) / CORE_CLKS(self, EV, level)
# Floating Point Operations Per Cycle
def FLOPc(self, EV, level):
return FLOP_Count(self, EV, level) / CORE_CLKS(self, EV, level)
# Instruction-Level-Parallelism (average number of uops executed when there is at least 1 uop executed)
def ILP(self, EV, level):
return EV("UOPS_DISPATCHED.THREAD", level) / Execute_Cycles(self, EV, level)
# Core actual clocks when any thread is active on the physical core
def CORE_CLKS(self, EV, level):
return (EV("CPU_CLK_UNHALTED.THREAD_ANY", level) / 2) if smt_enabled else CLKS(self, EV, level)
# Average CPU Utilization
def CPU_Utilization(self, EV, level):
return EV("CPU_CLK_UNHALTED.REF_TSC", level) / EV("msr/tsc/", 0)
# Giga Floating Point Operations Per Second
def GFLOPs(self, EV, level):
return FLOP_Count(self, EV, level) / OneBillion / DurationTimeInSeconds(self, EV, level)
# Average Frequency Utilization relative nominal frequency
def Turbo_Utilization(self, EV, level):
return CLKS(self, EV, level) / EV("CPU_CLK_UNHALTED.REF_TSC", level)
# Fraction of cycles where both hardware threads were active
def SMT_2T_Utilization(self, EV, level):
return 1 - EV("CPU_CLK_THREAD_UNHALTED.ONE_THREAD_ACTIVE", level) /(EV("CPU_CLK_THREAD_UNHALTED.REF_XCLK_ANY", level) / 2) if smt_enabled else 0
# Fraction of cycles spent in Kernel mode
def Kernel_Utilization(self, EV, level):
return EV("CPU_CLK_UNHALTED.REF_TSC:sup", level) / EV("CPU_CLK_UNHALTED.REF_TSC", level)
# Average external Memory Bandwidth Use for reads and writes [GB / sec]
def MEM_BW_GBs(self, EV, level):
return 64 *(EV("UNC_M_CAS_COUNT.RD", level) + EV("UNC_M_CAS_COUNT.WR", level)) / OneMillion / DurationTimeInSeconds(self, EV, level) / 1000
# Average latency of data read request to external memory (in Uncore cycles). Accounts for demand loads and L1/L2 prefetches
def MEM_Read_Latency(self, EV, level):
return EV("UNC_C_TOR_OCCUPANCY.MISS_OPCODE:Match=0x182", level) / EV("UNC_C_TOR_INSERTS.MISS_OPCODE:Match=0x182", level)
# Average number of parallel data read requests to external memory (in Uncore cycles). Accounts for demand loads and L1/L2 prefetches
def MEM_Parallel_Reads(self, EV, level):
return EV("UNC_C_TOR_OCCUPANCY.MISS_OPCODE:Match=0x182", level) / EV("UNC_C_TOR_OCCUPANCY.MISS_OPCODE:Match=0x182:c1", level)
# Run duration time in seconds
def Time(self, EV, level):
return DurationTimeInSeconds(self, EV, level)
# Event groups
class Frontend_Bound:
name = "Frontend_Bound"
domain = "Slots"
area = "FE"
desc = """
This category represents slots fraction where the
processor's Frontend undersupplies its Backend. Frontend
denotes the first part of the processor core responsible to
fetch operations that are executed later on by the Backend
part. Within the Frontend, a branch predictor predicts the
next address to fetch, cache-lines are fetched from the
memory subsystem, parsed into instructions, and lastly
decoded into micro-ops (uops). Ideally the Frontend can
issue 4 uops every cycle to the Backend. Frontend Bound
denotes unutilized issue-slots when there is no Backend
stall; i.e. bubbles where Frontend delivered no uops while
Backend could have accepted them. For example, stalls due to
instruction-cache misses would be categorized under Frontend
Bound."""
level = 1
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = EV("IDQ_UOPS_NOT_DELIVERED.CORE", 1) / SLOTS(self, EV, 1 )
self.thresh = (self.val > 0.2)
except ZeroDivisionError:
print_error("Frontend_Bound zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Frontend_Latency:
name = "Frontend_Latency"
domain = "Slots"
area = "FE"
desc = """
This metric represents slots fraction the CPU was stalled
due to Frontend latency issues. For example, instruction-
cache misses, iTLB misses or fetch stalls after a branch
misprediction are categorized under Frontend Latency. In
such cases, the Frontend eventually delivers no uops for
some period."""
level = 2
htoff = False
sample = ['RS_EVENTS.EMPTY_END']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = Pipeline_Width * Frontend_Latency_Cycles(self, EV, 2) / SLOTS(self, EV, 2 )
self.thresh = (self.val > 0.15) and self.parent.thresh
except ZeroDivisionError:
print_error("Frontend_Latency zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class ITLB_Misses:
name = "ITLB_Misses"
domain = "Clocks"
area = "FE"
desc = """
This metric represents cycles fraction the CPU was stalled
due to instruction TLB misses.. Using large code pages may
be considered here."""
level = 3
htoff = False
sample = ['ITLB_MISSES.WALK_COMPLETED']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = ITLB_Miss_Cycles(self, EV, 3) / CLKS(self, EV, 3 )
self.thresh = (self.val > 0.05) and self.parent.thresh
except ZeroDivisionError:
print_error("ITLB_Misses zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Branch_Resteers:
name = "Branch_Resteers"
domain = "Clocks"
area = "FE"
desc = """
This metric represents cycles fraction the CPU was stalled
due to Branch Resteers. Branch Resteers estimates the
Frontend delay in fetching operations from corrected path,
following all sorts of miss-predicted branches. For example,
branchy code with lots of miss-predictions might get
categorized under Branch Resteers. Note the value of this
node may overlap with its siblings."""
level = 3
htoff = False
sample = ['BR_MISP_RETIRED.ALL_BRANCHES:pp']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = Avg_RS_Empty_Period_Clears(self, EV, 3)*(EV("BR_MISP_RETIRED.ALL_BRANCHES", 3) + EV("MACHINE_CLEARS.COUNT", 3) + EV("BACLEARS.ANY", 3)) / CLKS(self, EV, 3 )
self.thresh = (self.val > 0.05) and self.parent.thresh
except ZeroDivisionError:
print_error("Branch_Resteers zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class DSB_Switches:
name = "DSB_Switches"
domain = "Clocks"
area = "FE"
desc = """
This metric represents cycles fraction the CPU was stalled
due to switches from DSB to MITE pipelines. The DSB (decoded
i-cache, introduced with the Sandy Bridge microarchitecture)
pipeline has shorter latency and delivered higher bandwidth
than the MITE (legacy instruction decode pipeline).
Switching between the two pipelines can cause penalties.
This metric estimates when such penalty can be exposed.
Optimizing for better DSB hit rate may be considered.. See
section \"Optimization for Decoded ICache\" in Optimization
Guide:. http://www.intel.com/content/www/us/en/architecture-
and-technology/64-ia-32-architectures-optimization-
manual.html"""
level = 3
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = EV("DSB2MITE_SWITCHES.PENALTY_CYCLES", 3) / CLKS(self, EV, 3 )
self.thresh = (self.val > 0.05) and self.parent.thresh
except ZeroDivisionError:
print_error("DSB_Switches zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class LCP:
name = "LCP"
domain = "Clocks"
area = "FE"
desc = """
This metric represents cycles fraction CPU was stalled due
to Length Changing Prefixes (LCPs). Using proper compiler
flags or Intel Compiler by default will certainly avoid
this."""
level = 3
htoff = False
sample = []
errcount = 0
sibling = None
server = False
def compute(self, EV):
try:
self.val = EV("ILD_STALL.LCP", 3) / CLKS(self, EV, 3 )
self.thresh = (self.val > 0.05) and self.parent.thresh
except ZeroDivisionError:
print_error("LCP zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class MS_Switches:
name = "MS_Switches"
domain = "Clocks"
area = "FE"
desc = """
This metric estimates the fraction of cycles when the CPU
was stalled due to switches of uop delivery to the Microcode
Sequencer (MS). Commonly used instructions are optimized for
delivery by the DSB or MITE pipelines. Certain operations
cannot be handled natively by the execution pipeline, and
must be performed by microcode (small programs injected into
the execution stream). Switching to the MS too often can
negatively impact performance. The MS is designated to
deliver long uop flows required by CISC instructions like
CPUID, or uncommon conditions like Floating Point Assists
when dealing with Denormals."""
level = 3
htoff = False
sample = ['IDQ.MS_SWITCHES']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = MS_Switches_Cost * EV("IDQ.MS_SWITCHES", 3) / CLKS(self, EV, 3 )
self.thresh = (self.val > 0.05) and self.parent.thresh
except ZeroDivisionError:
print_error("MS_Switches zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Frontend_Bandwidth:
name = "Frontend_Bandwidth"
domain = "Slots"
area = "BAD"
desc = """
This metric represents slots fraction the CPU was stalled
due to Frontend bandwidth issues. For example,
inefficiencies at the instruction decoders, or code
restrictions for caching in the DSB (decoded uops cache) are
categorized under Frontend Bandwidth. In such cases, the
Frontend typically delivers non-optimal amount of uops to
the Backend (less than four)."""
level = 2
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = self.Frontend_Bound.compute(EV) - self.Frontend_Latency.compute(EV )
self.thresh = (self.val > 0.1) & (IPC(self, EV, 2) > 2.0) and self.parent.thresh
except ZeroDivisionError:
print_error("Frontend_Bandwidth zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Bad_Speculation:
name = "Bad_Speculation"
domain = "Slots"
area = "BAD"
desc = """
This category represents slots fraction wasted due to
incorrect speculations. This include slots used to issue
uops that do not eventually get retired and slots for which
the issue-pipeline was blocked due to recovery from earlier
incorrect speculation. For example, wasted work due to miss-
predicted branches are categorized under Bad Speculation
category. Incorrect data speculation followed by Memory
Ordering Nukes is another example."""
level = 1
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = (EV("UOPS_ISSUED.ANY", 1) - EV("UOPS_RETIRED.RETIRE_SLOTS", 1) + Pipeline_Width * Recovery_Cycles(self, EV, 1)) / SLOTS(self, EV, 1 )
self.thresh = (self.val > 0.1)
except ZeroDivisionError:
print_error("Bad_Speculation zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Branch_Mispredicts:
name = "Branch_Mispredicts"
domain = "Slots"
area = "BAD"
desc = """
This metric represents slots fraction the CPU has wasted due
to Branch Misprediction. These slots are either wasted by
uops fetched from an incorrectly speculated program path, or
stalls when the out-of-order part of the machine needs to
recover its state from a speculative path.. Using profile
feedback in the compiler may help. Please see the
optimization manual for general strategies for addressing
branch misprediction issues..
http://www.intel.com/content/www/us/en/architecture-and-
technology/64-ia-32-architectures-optimization-manual.html"""
level = 2
htoff = False
sample = ['BR_MISP_RETIRED.ALL_BRANCHES:pp']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = Mispred_Clears_Fraction(self, EV, 2)* self.Bad_Speculation.compute(EV )
self.thresh = (self.val > 0.05) and self.parent.thresh
except ZeroDivisionError:
print_error("Branch_Mispredicts zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Machine_Clears:
name = "Machine_Clears"
domain = "Slots"
area = "BAD"
desc = """
This metric represents slots fraction the CPU has wasted due
to Machine Clears. These slots are either wasted by uops
fetched prior to the clear, or stalls the out-of-order
portion of the machine needs to recover its state after the
clear. For example, this can happen due to memory ordering
Nukes (e.g. Memory Disambiguation) or Self-Modifying-Code
(SMC) nukes.. See \"Memory Disambiguation\" in Optimization
Guide and:. https://software.intel.com/sites/default/files/m
/d/4/1/d/8/sma.pdf"""
level = 2
htoff = False
sample = ['MACHINE_CLEARS.COUNT']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = self.Bad_Speculation.compute(EV) - self.Branch_Mispredicts.compute(EV )
self.thresh = (self.val > 0.05) and self.parent.thresh
except ZeroDivisionError:
print_error("Machine_Clears zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Backend_Bound:
name = "Backend_Bound"
domain = "Slots"
area = "BE"
desc = """
This category represents slots fraction where no uops are
being delivered due to a lack of required resources for
accepting new uops in the Backend. Backend is the portion of
the processor core where the out-of-order scheduler
dispatches ready uops into their respective execution units,
and once completed these uops get retired according to
program order. For example, stalls due to data-cache misses
or stalls due to the divider unit being overloaded are both
categorized under Backend Bound. Backend Bound is further
divided into two main categories: Memory Bound and Core
Bound."""
level = 1
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = 1 -(self.Frontend_Bound.compute(EV) + self.Bad_Speculation.compute(EV) + self.Retiring.compute(EV))
self.thresh = (self.val > 0.2)
except ZeroDivisionError:
print_error("Backend_Bound zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Memory_Bound:
name = "Memory_Bound"
domain = "Slots"
area = "BE/Mem"
desc = """
This metric represents slots fraction the Memory subsystem
within the Backend was a bottleneck. Memory Bound estimates
slots fraction where pipeline is likely stalled due to
demand load or store instructions. This accounts mainly for
(1) non-completed in-flight memory demand loads which
coincides with execution units starvation, in addition to
(2) cases where stores could impose backpressure on the
pipeline when many of them get buffered at the same time
(less common out of the two)."""
level = 2
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = Memory_Bound_Fraction(self, EV, 2)* self.Backend_Bound.compute(EV )
self.thresh = (self.val > 0.2) and self.parent.thresh
except ZeroDivisionError:
print_error("Memory_Bound zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class DTLB_Load:
name = "DTLB_Load"
domain = "Clocks"
area = "BE/Mem"
desc = """
This metric represents cycles fraction where the TLB was
missed by load instructions. TLBs (Translation Look-aside
Buffers) are processor caches for recently used entries out
of the Page Tables that are used to map virtual- to
physical-addresses by the operating system. This metric
estimates the performance penalty paid by demand loads when
missing the first-level data TLB (DTLB). This includes
hitting in the second-level TLB (STLB) as well as performing
a hardware page walk on an STLB miss.."""
level = 4
htoff = False
sample = ['MEM_UOPS_RETIRED.STLB_MISS_LOADS:pp']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = (Mem_STLB_Hit_Cost * EV("DTLB_LOAD_MISSES.STLB_HIT", 4) + EV("DTLB_LOAD_MISSES.WALK_DURATION", 4)) / CLKS(self, EV, 4 )
self.thresh = (self.val > 0.1)
except ZeroDivisionError:
print_error("DTLB_Load zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class L3_Bound:
name = "L3_Bound"
domain = "Clocks"
area = "BE/Mem"
desc = """
This metric estimates how often the CPU was stalled due to
loads accesses to L3 cache or contended with a sibling Core.
Avoiding cache misses (i.e. L2 misses/L3 hits) can improve
the latency and increase performance."""
level = 3
htoff = False
sample = ['MEM_LOAD_UOPS_RETIRED.LLC_HIT:pp']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = Mem_L3_Hit_Fraction(self, EV, 3)* EV("CYCLE_ACTIVITY.STALLS_L2_PENDING", 3) / CLKS(self, EV, 3 )
self.thresh = (self.val > 0.1) and self.parent.thresh
except ZeroDivisionError:
print_error("L3_Bound zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class MEM_Bound:
name = "MEM_Bound"
domain = "Clocks"
area = "BE/Mem"
desc = """
This metric estimates how often the CPU was stalled on
accesses to external memory (DRAM) by loads. Better caching
can improve the latency and increase performance."""
level = 3
htoff = False
sample = ['MEM_LOAD_UOPS_RETIRED.LLC_MISS:pp']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = (1 - Mem_L3_Hit_Fraction(self, EV, 3))* EV("CYCLE_ACTIVITY.STALLS_L2_PENDING", 3) / CLKS(self, EV, 3 )
self.thresh = (self.val > 0.1) and self.parent.thresh
except ZeroDivisionError:
print_error("MEM_Bound zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class MEM_Bandwidth:
name = "MEM_Bandwidth"
domain = "Clocks"
area = "BE/Mem"
desc = """
This metric estimates cycles fraction where the core's
performance was likely hurt due to approaching bandwidth
limits of external memory (DRAM). The underlying heuristic
assumes that a similar off-core traffic is generated by all
IA cores. This metric does not aggregate non-data-read
requests by this thread, requests from other IA
threads/cores/sockets, or other non-IA devices like GPU;
hence the maximum external memory bandwidth limits may or
may not be approached when this metric is flagged (see
Uncore counters for that).. Improve data accesses to reduce
cacheline transfers from/to memory. Examples: 1) Consume all
bytes of a each cacheline before it is evicted (e.g. reorder
structure elements and split non-hot ones), 2) merge
computed-limited with BW-limited loops, 3) NUMA
optimizations in multi-socket system. Note: software
prefetches will not help BW-limited application.."""
level = 4
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = ORO_DRD_BW_Cycles(self, EV, 4) / CLKS(self, EV, 4 )
self.thresh = (self.val > 0.1) and self.parent.thresh
except ZeroDivisionError:
print_error("MEM_Bandwidth zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class MEM_Latency:
name = "MEM_Latency"
domain = "Clocks"
area = "BE/Mem"
desc = """
This metric estimates cycles fraction where the performance
was likely hurt due to latency from external memory (DRAM).
This metric does not aggregate requests from other
threads/cores/sockets (see Uncore counters for that)..
Improve data accesses or interleave them with compute.
Examples: 1) Data layout re-structuring, 2) Software
Prefetches (also through the compiler).."""
level = 4
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = ORO_DRD_Any_Cycles(self, EV, 4) / CLKS(self, EV, 4) - self.MEM_Bandwidth.compute(EV )
self.thresh = (self.val > 0.1) and self.parent.thresh
except ZeroDivisionError:
print_error("MEM_Latency zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Store_Bound:
name = "Store_Bound"
domain = "Clocks"
area = "BE/Mem"
desc = """
This metric estimates how often CPU was stalled due to
store memory accesses. Even though store accesses do not
typically stall out-of-order CPUs; there are few cases where
stores can lead to actual stalls. This metric will be
flagged should any of these cases be a bottleneck."""
level = 3
htoff = False
sample = ['MEM_UOPS_RETIRED.ALL_STORES:pp']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = EV("RESOURCE_STALLS.SB", 3) / CLKS(self, EV, 3 )
self.thresh = (self.val > 0.2) and self.parent.thresh
except ZeroDivisionError:
print_error("Store_Bound zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Core_Bound:
name = "Core_Bound"
domain = "Slots"
area = "BE/Core"
desc = """
This metric represents slots fraction where Core non-memory
issues were of a bottleneck. Shortage in hardware compute
resources, or dependencies in software's instructions are
both categorized under Core Bound. Hence it may indicate the
machine ran out of an out-of-order resource, certain
execution units are overloaded or dependencies in program's
data- or instruction-flow are limiting the performance (e.g.
FP-chained long-latency arithmetic operations).. Tip:
consider Port Saturation analysis as next step."""
level = 2
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = self.Backend_Bound.compute(EV) - self.Memory_Bound.compute(EV )
self.thresh = (self.val > 0.2) and self.parent.thresh
except ZeroDivisionError:
print_error("Core_Bound zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Divider:
name = "Divider"
domain = "Clocks"
area = "BE/Core"
desc = """
This metric represents cycles fraction where the Divider
unit was active. Divide and square root instructions are
performed by the Divider unit and can take considerably
longer latency than integer or Floating Point addition,
subtraction, or multiplication."""
level = 3
htoff = False
sample = ['ARITH.FPU_DIV_ACTIVE']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = EV("ARITH.FPU_DIV_ACTIVE", 3) / CORE_CLKS(self, EV, 3 )
self.thresh = (self.val > 0.2) and self.parent.thresh
except ZeroDivisionError:
print_error("Divider zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Ports_Utilization:
name = "Ports_Utilization"
domain = "Clocks"
area = "BE/Core"
desc = """
This metric estimates cycles fraction the CPU performance
was potentially limited due to Core computation issues (non
divider-related). Two distinct categories can be attributed
into this metric: (1) heavy data-dependency among contiguous
instructions would manifest in this metric - such cases are
often referred to as low Instruction Level Parallelism
(ILP). (2) Contention on some hardware execution unit other
than Divider. For example, when there are too many multiply
operations.. Loop Vectorization -most compilers feature
auto-Vectorization options today- reduces pressure on the
execution ports as multiple elements are calculated with
same uop."""
level = 3
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = (Backend_Bound_Cycles(self, EV, 3) - EV("RESOURCE_STALLS.SB", 3) - STALLS_MEM_ANY(self, EV, 3)) / CLKS(self, EV, 3 )
self.thresh = (self.val > 0.2) and self.parent.thresh
except ZeroDivisionError:
print_error("Ports_Utilization zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Retiring:
name = "Retiring"
domain = "Slots"
area = "RET"
desc = """
This category represents slots fraction utilized by useful
work i.e. issued uops that eventually get retired. Ideally,
all pipeline slots would be attributed to the Retiring
category. Retiring of 100% would indicate the maximum 4
uops retired per cycle has been achieved. Maximizing
Retiring typically increases the Instruction-Per-Cycle
metric. Note that a high Retiring value does not necessary
mean there is no room for more performance. For example,
Microcode assists are categorized under Retiring. They hurt
performance and can often be avoided. . A high Retiring
value for non-vectorized code may be a good hint for
programmer to consider vectorizing his code. Doing so
essentially lets more computations be done without
significantly increasing number of instructions thus
improving the performance."""
level = 1
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = EV("UOPS_RETIRED.RETIRE_SLOTS", 1) / SLOTS(self, EV, 1 )
self.thresh = (self.val > 0.7) | self.Microcode_Sequencer.thresh
except ZeroDivisionError:
print_error("Retiring zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class Base:
name = "Base"
domain = "Slots"
area = "RET"
desc = """
This metric represents slots fraction where the CPU was
retiring regular uops (ones not originated from the
microcode-sequencer). This correlates with total number of
instructions used by the program. A uops-per-instruction
ratio of 1 should be expected. While this is the most
desirable of the top 4 categories, high values does not
necessarily mean there no room for performance
optimizations.. Focus on techniques that reduce instruction
count or result in more efficient instructions generation
such as vectorization."""
level = 2
htoff = False
sample = ['INST_RETIRED.PREC_DIST']
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = self.Retiring.compute(EV) - self.Microcode_Sequencer.compute(EV )
self.thresh = (self.val > 0.6) and self.parent.thresh
except ZeroDivisionError:
print_error("Base zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class FP_Arith:
name = "FP_Arith"
domain = "Uops"
area = "RET"
desc = """
This metric represents overall arithmetic floating-point
(FP) uops fraction the CPU has executed (retired)"""
level = 3
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = self.X87_Use.compute(EV) + self.FP_Scalar.compute(EV) + self.FP_Vector.compute(EV )
self.thresh = (self.val > 0.2) and self.parent.thresh
except ZeroDivisionError:
print_error("FP_Arith zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class X87_Use:
name = "X87_Use"
domain = "Uops"
area = "RET"
desc = """
This metric serves as an approximation of legacy x87 usage.
It accounts for instructions beyond X87 FP arithmetic
operations; hence may be used as a thermometer to avoid X87
high usage and preferably upgrade to modern ISA. Tip:
consider compiler flags to generate newer AVX (or SSE)
instruction sets, which typically perform better and feature
vectors."""
level = 4
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = EV("FP_COMP_OPS_EXE.X87", 4) / EV("UOPS_DISPATCHED.THREAD", 4 )
self.thresh = (self.val > 0.1) and self.parent.thresh
except ZeroDivisionError:
print_error("X87_Use zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class FP_Scalar:
name = "FP_Scalar"
domain = "Uops"
area = "RET"
desc = """
This metric represents arithmetic floating-point (FP) scalar
uops fraction the CPU has executed (retired).. Investigate
what limits (compiler) generation of vector code."""
level = 4
htoff = False
sample = []
errcount = 0
sibling = None
server = True
def compute(self, EV):
try:
self.val = (EV("FP_COMP_OPS_EXE.SSE_SCALAR_SINGLE", 4) + EV("FP_COMP_OPS_EXE.SSE_SCALAR_DOUBLE", 4)) / EV("UOPS_DISPATCHED.THREAD", 4 )
self.thresh = (self.val > 0.1) and self.parent.thresh
except ZeroDivisionError:
print_error("FP_Scalar zero division")
self.errcount += 1
self.val = 0
self.thresh = False
return self.val
class FP_Vector:
name = "FP_Vector"
domain = "Uops"
area = "RET"
desc = """
This metric represents arithmetic floating-point (FP) vector
uops fraction the CPU has executed (retired) aggregated
across all vector widths.. Check if vector width is expected"""
level = 4
htoff = False
sample = []
errcount = 0
sibling = None