-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththresh_cmp.py
58 lines (43 loc) · 1.7 KB
/
thresh_cmp.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
#Script to create event code with thresh_cmp value
#!/usr/bin/python
#
#Max latency for thresholding
MAX_LATENCY = 130048
#Number of bits for thresh cmp exponent and mantissa
THRESH_CMP_EXP = 3
THRESH_CMP_MANTISSA = 7
def get_threshold(latency, event_code):
exp = 0
mant = 0
mask = 0x1FF80
check_mask = 0x60
thresh_cmp = latency
while(thresh_cmp & mask):
thresh_cmp = thresh_cmp >> 2
exp += 1
mant = thresh_cmp
if ((exp != 0) and not(mant & check_mask)):
print("Unexpected error: Upper two bits of mant is 0\n");
exit()
print("Thresh_cmp value = " + str(latency) + " : Mantissa = " +
str(hex(mant)) + " and Exponent = " + str(hex(exp)) + "\n")
thresh_cmp = (exp << THRESH_CMP_MANTISSA) | mant;
event_code_thresh_mask = thresh_cmp << (63 - 23)
#resultant event code
event_code |= event_code_thresh_mask
print(" Resultant event code = " + str(hex(event_code)))
#perf script command
print("\n*********************************************************************************\n")
print(" Use command: 'perf record --weight -e cpu/event=" + str(hex(event_code)) + "/ <workload>'")
print("\n*********************************************************************************\n")
print("\n")
eventcode = input("Input event code in hex: ")
thresh_cmp = input("Input threshold latency in decimal: ")
print("\n")
eventcode = int(eventcode, 16) # parse string into an hex
thresh_cmp = int(thresh_cmp) # parse string into an integer
if thresh_cmp > MAX_LATENCY:
print("Error: Max latency supported by hardware is : " + str(MAX_LATENCY))
print("Try with smaller value\n")
exit()
get_threshold(thresh_cmp, eventcode);