Esempio n. 1
0
    def _InheritAccessFromSet(self, statesets):
        states = extract_states_from_sets(statesets)
        states = list(states.values())
        stablestates = get_stable_states(statesets)

        for state in stablestates:
            states.remove(state)

        for state in states:
            startstablestates = state.getstartstatesets()
            endstablestates = state.getendstatesets()

            minaccessset = []
            for stateset in endstablestates:
                stablestate = stateset.getstablestate()
                access = stablestate.getaccesshit()

                if access:
                    if not minaccessset:
                        minaccessset = access

                    if len(access) < len(minaccessset):
                        minaccessset = access

            for stateset in startstablestates:
                stablestate = stateset.getstablestate()
                access = stablestate.getaccesshit()

                if len(access) < len(minaccessset):
                    minaccessset = access

            if minaccessset:
                for access in minaccessset:
                    state.addtransitions(
                        self._CopyModifyTransition(access, state, state))
Esempio n. 2
0
    def access_completion(self, dirstatesets, accessmap):
        dirstates = extract_states_from_sets(dirstatesets)
        # Only multiple messages related to same access must be considered
        for access in accessmap:
            if len(accessmap[access]) > 1:
                msgtypes = accessmap[access]

                for state in dirstates.values():
                    foundmap = {}
                    misskeys = []
                    for msgtype in msgtypes:
                        transition = state.getmulttransitionsbyguard(msgtype)
                        if transition:
                            foundmap.update({msgtype: transition})
                        else:
                            misskeys.append(msgtype)

                    if len(foundmap):
                        for misskey in misskeys:
                            transitions = foundmap[next(iter(foundmap))]

                            for transition in transitions:
                                newtrans = copy.copy(transition)
                                newtrans.rename_inmsg_operation(
                                    str(transition.getinmsg()), misskey)
                                state.addtransitions(newtrans)
Esempio n. 3
0
    def find_progress_messages(self, statesets):
        statedict = extract_states_from_sets(statesets)

        for state in statedict:
            if statedict[state].getstartstatesets():
                for transition in statedict[state].gettransitions():
                    if not transition.getfinalstate().getstartstatesets():
                        if not transition.getguard() in self.progressMessages:
                            self.progressMessages.append(transition.getguard())
Esempio n. 4
0
    def find_hidden_progess_messages(self, statesets):
        statedict = extract_states_from_sets(statesets)

        for state in statedict:
            for transition in statedict[state].gettransitions():
                outmsgtypes = transition.getoutmsgtypes()
                for outmsg in outmsgtypes:
                    if outmsg in self.progressMessages and len(
                            outmsgtypes) > 1:
                        for outmsgadd in outmsgtypes:
                            if outmsgadd not in self.progressMessages:
                                self.progressMessages.append(outmsgadd)
                    break
Esempio n. 5
0
    def evict_completion(self, dirstatesets, evictaccess, non_hidden_evict):
        dirstates = extract_states_from_sets(dirstatesets)
        # The possible evictions need to be present in every state due to race conditions
        evictmap = {}
        evictmsgstatemap = {}

        for evict in evictaccess:
            for state in dirstates.values():
                for evictmsg in evictaccess[evict]:
                    transitions = state.getmulttransitionsbyguard(evictmsg)
                    if transitions:
                        for transition in transitions:
                            transarray = evictmap.get(evictmsg, 0)
                            if transarray:
                                if transition not in transarray:
                                    transarray.append(transition)
                            else:
                                evictmap.update({evictmsg: [transition]})
                                evictmsgstatemap.update(
                                    {state.getstatename(): evictmsg})

        # Handle cache states that are indistinguishable by directory such as E and M
        stateevictmap = {}

        for stateset in dirstatesets:
            state = dirstatesets[stateset].getstablestate().getstatename()
            for pair in self.hiddenChangeStates:
                if state in pair:
                    for entry in pair:
                        if entry != state:
                            if entry in stateevictmap:
                                stateevictmap[entry].append(evictmap[state])
                            else:
                                if state in evictmsgstatemap:
                                    stateevictmap.update(
                                        {entry: [evictmsgstatemap[state]]})

        # Evictions only need to be possible in stable states
        # Transient states automatically inherit from stable states
        for stateset in dirstatesets:
            state = dirstatesets[stateset].getstablestate()
            for evictaccess in evictmap:

                existtrans = state.getmulttransitionsbyguard(evictaccess)
                if existtrans:
                    continue

                for newevicttrans in evictmap[evictaccess]:

                    evicttranskey = newevicttrans.getguard() + "".join(
                        newevicttrans.getcond())

                    found = 0

                    # UNREACHABLE
                    # TODO: OLD STUPID COPY OPERATIONS TO BE REMOVED
                    #if existtrans:
                    #    for transition in existtrans:
                    #        transkey = transition.getguard() + "".join(transition.getcond())

                    #        if transkey in evicttranskey or evicttranskey in transkey:
                    #            found = 1

                    if not found:
                        hiddenstatetrans = 0
                        if state.getstatename() in stateevictmap:
                            if evictaccess in stateevictmap[
                                    state.getstatename()]:
                                hiddenstatetrans = 1

                        if hiddenstatetrans:
                            if newevicttrans.getstartstate(
                            ) == newevicttrans.getfinalstate():
                                state.addtransitions(
                                    newevicttrans.copy_modify_trans(
                                        state, state))
                            else:
                                state.addtransitions(
                                    newevicttrans.copy_modify_trans(
                                        state, newevicttrans.getfinalstate()))
                        else:
                            if non_hidden_evict:
                                state.addtransitions(
                                    newevicttrans.copy_modify_trans(
                                        state, state))
Esempio n. 6
0
 def getDirStates(self):
     return {
         self.level_id + self.directory.arch_name:
         extract_states_from_sets(self.directory.state_sets)
     }
Esempio n. 7
0
 def getCacheStates(self):
     return {
         self.level_id + self.cache.arch_name:
         extract_states_from_sets(self.cache.state_sets)
     }
Esempio n. 8
0
    def _ProcessArch(self):

        self.pheader("Caches")
        self.pdebug(str(self.level.cache))

        self.pheader("Directories")
        self.pdebug(str(self.level.directory))

        # Cache
        arch_name = str(self.level.cache)

        talgo = time.time()
        self.pheader("\nArchitecture: " + arch_name)

        stablestates = [str(state) for state in self.level.cache.stable_states]
        state_sets = self.level.cache.state_sets

        self._ProtoGenV2(self.level.cache, state_sets, self.maxNestingDepthCC)

        self._AssignAccess(state_sets, stablestates)

        if self.enableStateMerging:
            print("State reduction function enabled")
            self.MergeStates.merge_states(state_sets)
        else:
            print("State reduction function disabled")

        self.pdebug("Runtime: " + arch_name + " = " + str(time.time() - talgo))

        self.level.cache.update_transitions()
        statedict = extract_states_from_sets(state_sets)

        self._pTransitions(arch_name, statedict)
        # Run ProtoGen
        if self.dbg_graph:
            self._dArch(arch_name, statedict)

        self.cacheStateSets += list(state_sets.values())

        self.archProtoGen.update({arch_name: statedict})

        self.level.cache.update_transitions()

        # Directory
        arch_name = str(self.level.directory)
        talgo = time.time()
        self.pheader("\nArchitecture: " + arch_name)

        # General directory pre processing
        stablestates = [
            str(state) for state in self.level.directory.stable_states
        ]
        state_sets = self.level.directory.state_sets

        # ProtoGen
        self._ProtoGenAlgorithm(self.level.directory, state_sets, stablestates,
                                self.maxNestingDepthDC, self._DirectoryDefer)

        #self.merge_states(state_sets)

        self.pdebug("Runtime: " + arch_name + " = " + str(time.time() - talgo))

        self.level.directory.update_transitions()
        statedict = extract_states_from_sets(state_sets)

        self._pTransitions(arch_name, statedict)
        if self.dbg_graph:
            self._dArch(arch_name, statedict)

        self.archProtoGen.update({arch_name: statedict})
        self.pdebug("")
Esempio n. 9
0
 def _update_transitions(self):
     for state in extract_states_from_sets(self.state_sets).values():
         for transition in state.gettransitions():
             if transition not in self.transitions:
                 self.transitions.append(transition)
Esempio n. 10
0
 def get_states(self) -> Dict[str, State]:
     return extract_states_from_sets(self.state_sets)