Skip to content

Commit

Permalink
添加cache大小的循环以及相应数据处理
Browse files Browse the repository at this point in the history
  • Loading branch information
FindHao committed Jul 25, 2016
1 parent 6234211 commit 58e6450
Show file tree
Hide file tree
Showing 3 changed files with 177 additions and 35 deletions.
4 changes: 2 additions & 2 deletions devlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ graphy.py文件实现根据输入展示不同的图标

## July 23, 2016 3:37 PM
LRU,FIFO时间戳的说明单独说明


## July 24, 2016 8:27 AM
实验数据统计



Expand Down
181 changes: 159 additions & 22 deletions graphy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
import re
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
import numpy as np
mapping_ways = [1, 2, 4, 8, 12, 16]
line_size = [32, 64, 128]
swap_style = [0, 1, 2]
class rate:
def __init__(self, size, way, swap):
def __init__(self, cache_size, line_size, way, swap):
self.way = int(way)
self.size = int(size)
self.line_size = int(line_size)
self.size = int(cache_size)
self.swap = int(swap)
self.miss_rate = 0
self.read = 0
self.write = 0
def __str__(self):
return "%s %s" %(self.way,self.size)
return "%s %s" %(self.way,self.line_size)

rates = []
def work():
Expand All @@ -24,10 +26,10 @@ def work():
line = f.readline()
while line:
if line.find('line_size') >=0:
reg = re.compile("line_size: (\d+).+mapping ways (\d+).+swap_style (\d+)")
reg = re.compile("cache_size: (\d+) Bytes.+line_size: (\d+).+mapping ways (\d+).+swap_style (\d+)")
ans = reg.findall(line)
ans = ans[0]
arate = rate(ans[0], ans[1],ans[2])
arate = rate(ans[0], ans[1],ans[2],ans[3])
f.readline()
f.readline()
line = f.readline()
Expand Down Expand Up @@ -58,28 +60,158 @@ def draw_way():
color_map = 'rgbyck'
plts = []
my_patches = []
for line in swap:
x = []
y = []
for node in rates:
# print(type(node.swap), type(node.size))
if (node.size == 32) and (node.swap == line) and (node.way != 1):
y.append(node.miss_rate)
x.append(node.way)
# plt.subplot(221+ swap.index(line))
plt.plot(x, y, color_map[line], )
# 添加图例
my_patches.append(mpatches.Patch(color=color_map[line],label=swap_description[line]))
# for line in swap:
line = 1
x = []
y = []
y1 = []
y2 = []
for node in rates:
# print(type(node.swap), type(node.line_size))
if (node.line_size == 32) and (node.swap == line) :
# y.append(node.miss_rate)
y1.append(node.read)
y2.append(node.write)
x.append(node.way)
# plt.subplot(221+ swap.index(line))
plt.plot(x, y1, color_map[line], )
# plt.plot(x, y2,color_map[line+1])
print(x,y1,y2)
# 添加图例
my_patches.append(mpatches.Patch(color=color_map[line],label=swap_description[line]))
line += 1
my_patches.append(mpatches.Patch(color=color_map[line],label=swap_description[line]))

plt.legend(handles=my_patches)

def draw_cache_line_size():
"""
不同cache line 大小时的影响
固定替换策略LRU 1
固定way8
"""
line_size = [32,64,128]
swap = [0,1,2]
swap_description = ["FIFO",'LRU','RAND']
color_map = 'rgbyck'
plts = []
my_patches = []
# for line in swap:
line = 1
x = []
y = []
y1 = []
y2 = []
for node in rates:
# print(type(node.swap), type(node.line_size))
if (node.way ==8) and (node.swap == line) :
# y.append(node.miss_rate)
x.append(node.line_size)
y1.append(node.read)
y2.append(node.write)
# plt.subplot(221+ swap.index(line))
# plt.plot(x, y, color_map[line])
plt.plot(x, y1, color_map[line])
plt.plot(x, y2,color_map[line+1])
# 添加图例
# my_patches.append(mpatches.Patch(color=color_map[line],label=swap_description[line]))
# line += 1
# my_patches.append(mpatches.Patch(color=color_map[line],label=swap_description[line]))
my_patches.append(mpatches.Patch(color=color_map[line],label="Read"))
line += 1
my_patches.append(mpatches.Patch(color=color_map[line],label="Write"))
plt.legend(handles=my_patches)

def draw_swap():
"""
不同替换策略的影响
固定cache line size 32bytes
固定way8
"""
line_size = [32,64,128]
swap = [0,1,2]
swap_description = ["FIFO",'LRU','RAND']
color_map = 'rgbyck'
plts = []
my_patches = []
index = np.arange(3)

# for line in swap:
line = 0
x = [[],[],[]]
y = [[],[],[]]
y1 = []
y2 = []
for node in rates:
temp_x = []
temp_y = []
# print(type(node.swap), type(node.line_size))
if (node.line_size == 32) and (node.way==8) :
# y.append(node.miss_rate)
x[node.swap].append(node.size)
y[node.swap].append(node.miss_rate)
# y1.append(node.read)
# y2.append(node.write)
# plt.subplot(221+ swap.index(line))
bar_width = 0.4
plt.plot(x[line],y[line],color_map[line])
my_patches.append(mpatches.Patch(color=color_map[line],label="FIFO"))
line+=1
plt.plot(x[line],y[line],color_map[line])
my_patches.append(mpatches.Patch(color=color_map[line],label="LRU"))
line+=1
plt.plot(x[line],y[line],color_map[line])
my_patches.append(mpatches.Patch(color=color_map[line],label="RAND"))
line += 1
for i in range(len(y[0])):
print("|%d|%f|%f|%f|" %(x[0][i]>>10,y[0][i],y[1][i],y[2][i]))
plt.legend(handles=my_patches)

def draw_cache_size():
"""
仅有总大小变化。line 32, swap LRU way 8
"""
line_size = [32,64,128]
size = [8, 16, 32, 64, 128,256,512]
swap = [0,1,2]
swap_description = ["FIFO",'LRU','RAND']
color_map = 'rgbyck'
plts = []
my_patches = []
# for line in swap:
line = 1
x = []
y = []
y1 = []
y2 = []
for node in rates:
# print(type(node.swap), type(node.line_size))
if (node.way ==8) and (node.swap == 1) and node.line_size == 32 :
# y.append(node.miss_rate)
x.append(node.size)
y1.append(node.read)
y2.append(node.write)
# plt.subplot(221+ swap.index(line))
# print(x,y)
# plt.plot(x, y, color_map[line])
plt.plot(x, y1, color_map[line])
plt.plot(x, y2,color_map[line+1])
# 添加图例
# my_patches.append(mpatches.Patch(color=color_map[line],label=swap_description[line]))
# line += 1
# my_patches.append(mpatches.Patch(color=color_map[line],label=swap_description[line]))
my_patches.append(mpatches.Patch(color=color_map[line],label="Read"))
line += 1
my_patches.append(mpatches.Patch(color=color_map[line],label="Write"))
plt.legend(handles=my_patches)
def draw():
global rates
# 不同way的miss rate 相同替换策略 0 ,相同cache line size 32byte
y = []
x = []
for node in rates:
# print(type(node.swap), type(node.size))
if (node.size == 32) and (node.swap == 0):
# print(type(node.swap), type(node.line_size))
if (node.line_size == 64) and (node.swap == 0):
y.append(node.miss_rate)
x.append(node.way)
print(x)
Expand All @@ -94,7 +226,7 @@ def draw():
# y1 = []
# y2 = []
# for node in rates:
# if node.size == 32 and node.way == 8:
# if node.line_size == 32 and node.way == 8:
# x1.append(node.swap)
# # y1.append(node.miss_rate)
# y1.append(node.read)
Expand All @@ -110,7 +242,7 @@ def draw():
# y3 = []
# for node in rates:
# if node.way == 8 and node.swap == 1:
# x3.append(node.size)
# x3.append(node.line_size)
# y3.append(node.miss_rate)
# print(x3,y3)
# plt.subplot(222)
Expand All @@ -119,5 +251,10 @@ def draw():
# plt.show()

work()
draw_way()
# draw_way()
# draw_cache_line_size()
draw_swap()
# draw_cache_size()


plt.show()
27 changes: 16 additions & 11 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ using namespace std;
int main() {
char test_case [100]= "/home/find/ddown/traces/gcc.trace";

int line_size[] = {32, 64, 128};
int ways[] = {1, 2, 4, 8, 12, 16};
int i,j;
// int line_size[] = {8, 16, 32, 64, 128};
int line_size[] = {32};
int ways[] = {1, 2, 4, 8, 12, 16, 32};
// int ways[] = {8};
int cache_size[] = {0x800,0x1000,0x2000,0x4000,0x8000,0x10000,0x20000,0x40000,0x80000};
int i,j,m;
CacheSim *cache;
for (i=0; i<sizeof(line_size)/sizeof(int); i++){
for (j=0; j<sizeof(ways)/sizeof(int); j++){
for (int k = CACHE_SWAP_FIFO; k < CACHE_SWAP_MAX; ++k) {
printf("\nline_size: %d\t mapping ways %d \t swap_style %d \n", line_size[i], ways[j], k);
cache = new CacheSim(0x8000, line_size[i], ways[j]);
cache->set_swap_style(k);
cache->load_trace(test_case);
delete cache;
for (m = 0;m<6;m ++){
for (i=0; i<sizeof(line_size)/sizeof(int); i++){
for (j=0; j<sizeof(ways)/sizeof(int); j++){
for (int k = CACHE_SWAP_FIFO; k < CACHE_SWAP_MAX; ++k) {
printf("\ncache_size: %d Bytes\tline_size: %d\t mapping ways %d \t swap_style %d \n", cache_size[m],line_size[i], ways[j], k);
cache = new CacheSim(cache_size[m], line_size[i], ways[j]);
cache->set_swap_style(k);
cache->load_trace(test_case);
delete cache;
}
}
}
}
Expand Down

0 comments on commit 58e6450

Please sign in to comment.