forked from andreas-abel/nanoBench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hitMiss.py
executable file
·55 lines (46 loc) · 2.45 KB
/
hitMiss.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
#!/usr/bin/env python3
import argparse
import sys
from cacheLib import *
import cacheSim
import logging
log = logging.getLogger(__name__)
def main():
parser = argparse.ArgumentParser(description='Outputs whether the last access of a sequence results in a hit or miss')
parser.add_argument("-seq", help="Access sequence", required=True)
parser.add_argument("-seq_init", help="Initialization sequence", default='')
parser.add_argument("-level", help="Cache level (Default: 1)", type=int, default=1)
parser.add_argument("-sets", help="Cache sets (if not specified, all cache sets are used)")
parser.add_argument("-cBox", help="cBox (default: 1)", type=int, default=1) # use 1 as default, as, e.g., on SNB, box 0 only has 15 ways instead of 16
parser.add_argument("-slice", help="Slice (within the cBox) (default: 0)", type=int, default=0)
parser.add_argument("-noClearHL", help="Do not clear higher levels", action='store_true')
parser.add_argument("-loop", help="Loop count (Default: 1)", type=int, default=1)
parser.add_argument("-noWbinvd", help="Do not call wbinvd before each run", action='store_true')
parser.add_argument("-logLevel", help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)", default='WARNING')
parser.add_argument("-sim", help="Simulate the given policy instead of running the experiment on the hardware")
parser.add_argument("-simAssoc", help="Associativity of the simulated cache (default: 8)", type=int, default=8)
args = parser.parse_args()
logging.basicConfig(stream=sys.stdout, format='%(message)s', level=logging.getLevelName(args.logLevel))
if args.sim:
policyClass = cacheSim.AllPolicies[args.sim]
seq = re.sub('[?!]', '', ' '.join([args.seq_init, args.seq])).strip() + '?'
hits = cacheSim.getHits(seq, policyClass, args.simAssoc, args.sets)
if hits > 0:
print('HIT')
exit(1)
else:
print('MISS')
exit(0)
else:
setCount = len(parseCacheSetsStr(args.level, True, args.sets))
seq = re.sub('[?!]', '', args.seq).strip() + '?'
nb = runCacheExperiment(args.level, seq, initSeq=args.seq_init, cacheSets=args.sets, cBox=args.cBox, cSlice=args.slice, clearHL=(not args.noClearHL),
loop=args.loop, wbinvd=(not args.noWbinvd))
if nb['L' + str(args.level) + '_HIT']/setCount > .5:
print('HIT')
exit(1)
else:
print('MISS')
exit(0)
if __name__ == "__main__":
main()