Question: I am simulating mesi protocol this is my log file, lecturer said there is small bug, can you spot any bug here, if yes what
I am simulating mesi protocol this is my log file, lecturer said "there is small bug", can you spot any bug here, if yes what might be the problem
and following is the mesi protocol code
class MESIProtocol:
def initself cores:
self.cores cores
def readself core, address:
sharingcores c for c in self.cores if c core and self.findlineincacheccache, address
line self.findlineincachecorecache, address
if not line:
line self.loadlinefrommemorycore address, sharingcores
if line.state I:
if anyccache.findlineincacheaddressstate M for c in sharingcores:
modifiedcore nextc for c in sharingcores if ccache.findlineincacheaddressstate M
self.flushifmodifiedmodifiedcore.cache.findlineincacheaddress
modifiedcore.cache.findlineincacheaddressstate S
line.state S if sharingcores else E
return line.value
def writeself core, address, value:
self.invalidateotherscore address
line self.findlineincachecorecache, address
if not line:
line self.loadlinefrommemorycore address
if line.state E or line.state S:
self.flushifmodifiedline
line.value value
line.state M
def invalidateothersself core, address:
for othercore in self.cores:
if othercore core:
line self.findlineincacheothercore.cache, address
if line and line.state I:
self.flushifmodifiedline
line.state I
def loadlinefrommemoryself core, address, sharingcores:
isshared anyselffindlineincacheccache, address for c in sharingcores if c core
line core.cache.replacelinecorecache.findlineaddress address, core.memory.storageaddress False
line.state S if isshared else E
return line
def findlineincacheself cache, address:
setindex cache.findlineaddress
set cache.setssetindex
for line in set:
if line.address address and line.valid:
return line
return None
def flushifmodifiedself line:
if line.state M:
line.memory.storagelineaddress line.value # Flush to memory
line.dirty False
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
