Esempio n. 1
0
def main():
    processors = 4
    shared_bus = bus()
    caches = []
    #for cache_id in range(processors):
    #   cache = nway_cache(cache_id)
    #   caches.append(cache)
    c = direct_cache(0)
    b = direct_cache(1)
    caches.append(c)
    caches.append(b)
    #print(c.operation("st", 66, 45))
    print(c.write(66, 45))
    #print(c.write(194, 75))
    print(b.read(66))
    #print(c.operation("st", 332, 40))
    #print(c.operation("st", 167, 57))
    print(c.write(66, 67))
    print(c.write(194, 50))
    c.print_cache()
    b.print_cache()
    #print()

    dump_dict = {}
    #for i in cache_list:
    dump_dict.update(c.return_cache_dict())
    json_dump("cache.json", dump_dict)
Esempio n. 2
0
 def __init__(self,
              ID,
              size=128,
              line_size=8,
              mem_size=512,
              bus=bus(),
              file=None,
              LSR=[],
              PC=0):
     super().__init__(ID, size, line_size, mem_size, bus, file, LSR, PC)
Esempio n. 3
0
 def __init__(self,
              ID,
              size=128,
              line_size=8,
              mem_size=512,
              way=2,
              bus=bus(),
              file=None,
              LSR=[],
              PC=0):
     super().__init__(ID, size, line_size, mem_size, bus, file, LSR, PC)
     self.way = way
     # For LSR
     #self.line_queue = []
     if len(LSR) == 0:
         for i in range(int(self.cache_num_line / self.way)):
             list_temp = []
             self.line_queue.append(list_temp)
def main():
    shared_bus = bus()
    #inst_file   = open(sys.argv[1], 'r')
    #inst_dict   = json.load(inst_file)
    inst_dict = json.loads(sys.argv[1])
    reset = inst_dict["reset"]
    num_cache = inst_dict["num_cache"]
    cache_type = inst_dict["cache_type"]
    cache_size = inst_dict["cache_size"]
    line_size = inst_dict["line_size"]
    mem_size = inst_dict["mem_size"]
    cache_way = inst_dict["cache_way"]
    run_node = inst_dict["run_node"]
    node_inst = {}
    for i in range(num_cache):
        node_inst[i] = inst_dict[f"node_{i}"]

    if len(sys.argv) == 3:
        #cache_file = open(sys.argv[2], 'r')
        #cache_dict = json.load(cache_file)
        cache_dict = json.loads(sys.argv[2])
    else:
        cache_dict = None

    cache_list = []
    if cache_type == "d":
        for i in range(num_cache):
            if cache_dict != None:
                cache_list.append(
                    direct_cache(i, cache_size, line_size, mem_size,
                                 shared_bus, cache_dict[str(i)]["cache"],
                                 cache_dict[str(i)]["LSR"],
                                 cache_dict[str(i)]["PC"]))
            else:
                cache_list.append(
                    direct_cache(i, cache_size, line_size, mem_size,
                                 shared_bus, None, [], 0))
    elif cache_type == "f":
        for i in range(num_cache):
            if cache_dict != None:
                cache_list.append(
                    fully_cache(i, cache_size, line_size, mem_size, shared_bus,
                                cache_dict[str(i)]["cache"],
                                cache_dict[str(i)]["LSR"],
                                cache_dict[str(i)]["PC"]))
            else:
                cache_list.append(
                    fully_cache(i, cache_size, line_size, mem_size, shared_bus,
                                None, [], 0))
    else:
        for i in range(num_cache):
            if cache_dict != None:
                cache_list.append(
                    nway_cache(i, cache_size, line_size, mem_size, cache_way,
                               shared_bus, cache_dict[str(i)]["cache"],
                               cache_dict[str(i)]["LSR"],
                               cache_dict[str(i)]["PC"]))
            else:
                cache_list.append(
                    nway_cache(i, cache_size, line_size, mem_size, cache_way,
                               shared_bus, None, [], 0))

    k = node_inst[run_node][cache_list[run_node].PC]
    # Bus operation
    bus_reply = []
    if k[0] == "st":
        cache_list[run_node].write(k[1])
    else:
        cache_list[run_node].read(k[1])

    #cache_list[0].write(66, 67)
    #cache_list[0].read(66)
    #cache_list[1].read(66)

    cache_list[run_node].PC = cache_list[run_node].PC + 1

    dump_dict = {}
    for i in cache_list:
        dump_dict.update(i.return_cache_dict())
    json_dump("cache.json", dump_dict)

    total_dict = {"inst": inst_dict, "cache": dump_dict}
    print(json.dumps(total_dict, indent=2))