mirror of
https://github.com/andreas-abel/nanoBench.git
synced 2026-01-06 04:10:56 +01:00
option for not using other slices for clearing HL caches
This commit is contained in:
@@ -13,7 +13,6 @@ log = logging.getLogger(__name__)
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='Tests if the L3 cache uses set dueling')
|
||||
parser.add_argument("-level", help="Cache level (Default: 3)", type=int, default=3)
|
||||
parser.add_argument("-nRuns", help="Maximum number of runs", type=int, default=25)
|
||||
parser.add_argument("-loop", help="Loop count", type=int, default=25)
|
||||
parser.add_argument("-length", help="Length of the acc. seq. (Default: associativity*4/3)", type=int)
|
||||
@@ -25,8 +24,9 @@ def main():
|
||||
|
||||
logging.basicConfig(stream=sys.stdout, format='%(message)s', level=logging.getLevelName(args.logLevel))
|
||||
|
||||
assoc = getCacheInfo(args.level).assoc
|
||||
nSets = getCacheInfo(args.level).nSets
|
||||
assoc = getCacheInfo(3).assoc
|
||||
nL3Sets = getCacheInfo(3).nSets
|
||||
nL2Sets = getCacheInfo(2).nSets
|
||||
lineSize = getCacheInfo(1).lineSize
|
||||
nCBoxes = max(1, getNCBoxUnits())
|
||||
nSlicesPerCBox = 1
|
||||
@@ -38,53 +38,61 @@ def main():
|
||||
hitSeq = ' '.join('B' + str(i) + '?' for i in range(0, assoc))
|
||||
missSeq = ' '.join('B' + str(i) + '?' for i in range(0, 3*assoc))
|
||||
|
||||
title = cpuid.cpu_name(cpuid.CPUID()) + ', L' + str(args.level) + ' Hits'
|
||||
title = cpuid.cpu_name(cpuid.CPUID()) + ', L3 Hits'
|
||||
html = ['<html>', '<head>', '<title>' + title + '</title>', '<script src="https://cdn.plot.ly/plotly-latest.min.js">', '</script>', '</head>', '<body>']
|
||||
html += ['<h3>' + title + '</h3>']
|
||||
|
||||
setsForSlice = {cBox: {cSlice: range(0,nSets) for cSlice in range(0, nSlicesPerCBox)} for cBox in range(0, nCBoxes)}
|
||||
yValuesForSlice = {cBox: {cSlice: [[] for s in range(0, nSets)] for cSlice in range(0, nSlicesPerCBox)} for cBox in range(0, nCBoxes)}
|
||||
setsForSlice = {cBox: {cSlice: range(0,nL3Sets) for cSlice in range(0, nSlicesPerCBox)} for cBox in range(0, nCBoxes)}
|
||||
L3HitsDict = {cBox: {cSlice: [[] for s in range(0, nL3Sets)] for cSlice in range(0, nSlicesPerCBox)} for cBox in range(0, nCBoxes)}
|
||||
|
||||
prevOti = ''
|
||||
i = -1
|
||||
notChanged = -1
|
||||
while notChanged < 10:
|
||||
for useHitSeq in [False, True]:
|
||||
i += 1
|
||||
notChanged += 1
|
||||
for cBox in range(0, nCBoxes):
|
||||
for cSlice in range(0, nSlicesPerCBox):
|
||||
yValuesList = yValuesForSlice[cBox][cSlice]
|
||||
for doNotUseOtherCBoxes in ([False, True] if (not args.noClearHL and nL2Sets < nL3Sets) else [False]):
|
||||
for useHitSeq in [False, True]:
|
||||
i += 1
|
||||
notChanged += 1
|
||||
for cBox in range(0, nCBoxes):
|
||||
for cSlice in range(0, nSlicesPerCBox):
|
||||
curSets = setsForSlice[cBox][cSlice]
|
||||
random.shuffle(curSets)
|
||||
prevSets = curSets[:]
|
||||
|
||||
curSets = setsForSlice[cBox][cSlice]
|
||||
random.shuffle(curSets)
|
||||
prevSets = curSets[:]
|
||||
for si, s in enumerate(prevSets):
|
||||
codeSet = (s + random.randint(1, nL3Sets - 100)) % nL3Sets
|
||||
codeOffset = lineSize * codeSet
|
||||
L3Hits = L3HitsDict[cBox][cSlice][s]
|
||||
|
||||
for si, s in enumerate(prevSets):
|
||||
codeSet = (s + random.randint(1, nSets - 100)) % nSets
|
||||
codeOffset = lineSize * codeSet
|
||||
yv = yValuesList[s]
|
||||
ec = getCodeForCacheExperiment(3, seq, '', [s], cBox, cSlice, (not args.noClearHL), doNotUseOtherCBoxes, True)
|
||||
nb = runCacheExperimentCode(ec.code, ec.init, prevOti + ec.oneTimeInit, loop=args.loop, warmUpCount=0, codeOffset=codeOffset,
|
||||
nMeasurements=args.nMeasurements, agg='med')
|
||||
|
||||
ec = getCodeForCacheExperiment(args.level, seq, '', [s], cBox, cSlice, (not args.noClearHL), True)
|
||||
nb = runCacheExperimentCode(ec.code, ec.init, prevOti + ec.oneTimeInit, loop=args.loop, warmUpCount=0, codeOffset=codeOffset,
|
||||
nMeasurements=args.nMeasurements, agg='med')
|
||||
yv.append(nb['L' + str(args.level) + '_HIT'])
|
||||
yv.sort()
|
||||
if nb['L1_MISS'] < seqLength - .2:
|
||||
print 'Hit in L1'
|
||||
continue
|
||||
|
||||
yvStr = str(yv) if len(yv) <= 5 else '[%s, %s, ..., %s, %s]' % (yv[0], yv[1], yv[-2], yv[-1])
|
||||
log.info('CBox ' + str(cBox) + ', slice: ' + str(cSlice) + ', run ' + str(i) + ', set: ' + str(si+1) + '/' + str(len(prevSets)) +
|
||||
' (' + str(s) + '), ' + yvStr)
|
||||
if nb['L2_MISS'] < seqLength - .2:
|
||||
print 'Hit in L2'
|
||||
continue
|
||||
|
||||
if len(yv) > 1:
|
||||
if yv[-1]-yv[0] > 1:
|
||||
curSets.remove(s)
|
||||
notChanged = 0
|
||||
else:
|
||||
if useHitSeq:
|
||||
ec = getCodeForCacheExperiment(args.level, hitSeq, '', [s], cBox, cSlice, (not args.noClearHL), True)
|
||||
L3Hits.append(nb['L3_HIT'])
|
||||
L3Hits.sort()
|
||||
|
||||
L3HitsStr = str(L3Hits) if len(L3Hits) <= 5 else '[%s, %s, ..., %s, %s]' % (L3Hits[0], L3Hits[1], L3Hits[-2], L3Hits[-1])
|
||||
log.info('CBox ' + str(cBox) + ', slice: ' + str(cSlice) + ', run ' + str(i) + ', set: ' + str(si+1) + '/' + str(len(prevSets)) +
|
||||
' (' + str(s) + '), ' + L3HitsStr)
|
||||
|
||||
if len(L3Hits) > 1:
|
||||
if L3Hits[-1]-L3Hits[0] > 1:
|
||||
curSets.remove(s)
|
||||
notChanged = 0
|
||||
else:
|
||||
ec = getCodeForCacheExperiment(args.level, missSeq, '', [s], cBox, cSlice, (not args.noClearHL), True)
|
||||
prevOti = ec.oneTimeInit + 'mov R15, 100; pLoop:' + ec.code + '; dec R15; jnz pLoop; '
|
||||
if useHitSeq:
|
||||
ec = getCodeForCacheExperiment(3, hitSeq, '', [s], cBox, cSlice, (not args.noClearHL), doNotUseOtherCBoxes, True)
|
||||
else:
|
||||
ec = getCodeForCacheExperiment(3, missSeq, '', [s], cBox, cSlice, (not args.noClearHL), doNotUseOtherCBoxes, True)
|
||||
prevOti = ec.oneTimeInit + 'mov R15, 100; pLoop:' + ec.code + '; dec R15; jnz pLoop; '
|
||||
|
||||
for cBox in range(0, nCBoxes):
|
||||
for cSlice in range(0, nSlicesPerCBox):
|
||||
@@ -98,13 +106,13 @@ def main():
|
||||
fig.update_layout(showlegend=True)
|
||||
fig.update_xaxes(title_text='Set')
|
||||
|
||||
yValuesMinMax = [min(x) + (max(x)-min(x))/2 for x in yValuesForSlice[cBox][cSlice] if x]
|
||||
yValuesMinMax = [min(s) + (max(s)-min(s))/2 for s in L3HitsDict[cBox][cSlice] if s]
|
||||
fig.add_trace(go.Scatter(y=yValuesMinMax, mode='lines+markers', name='Min+(Max-Min)/2'))
|
||||
|
||||
yValuesMin = [min(x) for x in yValuesForSlice[cBox][cSlice] if x]
|
||||
yValuesMin = [min(s) for s in L3HitsDict[cBox][cSlice] if s]
|
||||
fig.add_trace(go.Scatter(y=yValuesMin, mode='lines+markers', visible = 'legendonly', name='Min'))
|
||||
|
||||
yValuesMax = [max(x) for x in yValuesForSlice[cBox][cSlice] if x]
|
||||
yValuesMax = [max(s) for s in L3HitsDict[cBox][cSlice] if s]
|
||||
fig.add_trace(go.Scatter(y=yValuesMax, mode='lines+markers', visible = 'legendonly', name='Max'))
|
||||
|
||||
html.append(plot(fig, include_plotlyjs=False, output_type='div'))
|
||||
|
||||
Reference in New Issue
Block a user