Пример #1
0
 def __init__(self, hddname, sizekBs, sched, rambus):
     Process.__init__(self, "Cache of %s"%(hddname))
     self.sched = sched
     self.rambus = rambus
     self.openReqs = []
     self.closedReqs = []
     self.buffer = Buffer(self.name, sizekBs, 0)
     self.size = sizekBs
     self.flushNow = SimEvent(name="Flush Now")
     self.flush = Flush(self)
Пример #2
0
class Cache(Process):
    def __init__(self, hddname, sizekBs, sched, rambus):
        Process.__init__(self, "Cache of %s"%(hddname))
        self.sched = sched
        self.rambus = rambus
        self.openReqs = []
        self.closedReqs = []
        self.buffer = Buffer(self.name, sizekBs, 0)
        self.size = sizekBs
        self.flushNow = SimEvent(name="Flush Now")
        self.flush = Flush(self)

    def fillCache(self, waitInterval):
        activate(self.flush, self.flush.flushCache())
        while True:
            # Attempts to get a new request from the scheduler's sorted list
            # if it fails, the cache will wait waitInterval ms and try again.
            try:
                nextIO = self.sched.nextRequest()
            except IndexError:
                yield hold, self, waitInterval
                continue

            # Once the cache has found a request to be processed by the HDD,
            # it waits for the cache to have enough space for the data.
            print "IO being added to HDD Cache", nextIO
            while nextIO.size > self.buffer.freeSpace():
                print "not enough rooom for nextIO, %i items to flush"%len(self.closedReqs)
                if len(self.closedReqs) > 2:
                    self.flushNow.signal()
                    yield waitevent, self, self.flush.flushComplete
                else:
                    yield hold, self, waitInterval

            # Once enough bytes free up, the cache marks that the new request's
            # data size is being used in the cache and adds the request to
            # the cache's FIFO list of pending requests.  If the request is a
            # write request, it is marked as complete.
            yield put, self, self.buffer, nextIO.size
            self.openReqs.append(nextIO)
            if nextIO.write:
                self.closedReqs.append(nextIO)