StateMachine.py revision 13665
16657Snate@binkert.org# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 26657Snate@binkert.org# Copyright (c) 2009 The Hewlett-Packard Development Company 310972Sdavid.hashe@amd.com# Copyright (c) 2013 Advanced Micro Devices, Inc. 46657Snate@binkert.org# All rights reserved. 56657Snate@binkert.org# 66657Snate@binkert.org# Redistribution and use in source and binary forms, with or without 76657Snate@binkert.org# modification, are permitted provided that the following conditions are 86657Snate@binkert.org# met: redistributions of source code must retain the above copyright 96657Snate@binkert.org# notice, this list of conditions and the following disclaimer; 106657Snate@binkert.org# redistributions in binary form must reproduce the above copyright 116657Snate@binkert.org# notice, this list of conditions and the following disclaimer in the 126657Snate@binkert.org# documentation and/or other materials provided with the distribution; 136657Snate@binkert.org# neither the name of the copyright holders nor the names of its 146657Snate@binkert.org# contributors may be used to endorse or promote products derived from 156657Snate@binkert.org# this software without specific prior written permission. 166657Snate@binkert.org# 176657Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 186657Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 196657Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 206657Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 216657Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 226657Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 236657Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 246657Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 256657Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 266657Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 276657Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 286657Snate@binkert.org 296999Snate@binkert.orgfrom m5.util import orderdict 306657Snate@binkert.org 316657Snate@binkert.orgfrom slicc.symbols.Symbol import Symbol 326657Snate@binkert.orgfrom slicc.symbols.Var import Var 336657Snate@binkert.orgimport slicc.generate.html as html 348189SLisa.Hsu@amd.comimport re 356657Snate@binkert.org 369499Snilay@cs.wisc.edupython_class_map = { 379499Snilay@cs.wisc.edu "int": "Int", 3811308Santhony.gutierrez@amd.com "NodeID": "Int", 399364Snilay@cs.wisc.edu "uint32_t" : "UInt32", 407055Snate@binkert.org "std::string": "String", 416882SBrad.Beckmann@amd.com "bool": "Bool", 426882SBrad.Beckmann@amd.com "CacheMemory": "RubyCache", 438191SLisa.Hsu@amd.com "WireBuffer": "RubyWireBuffer", 446882SBrad.Beckmann@amd.com "Sequencer": "RubySequencer", 4511308Santhony.gutierrez@amd.com "GPUCoalescer" : "RubyGPUCoalescer", 4611308Santhony.gutierrez@amd.com "VIPERCoalescer" : "VIPERCoalescer", 476882SBrad.Beckmann@amd.com "DirectoryMemory": "RubyDirectoryMemory", 4811308Santhony.gutierrez@amd.com "PerfectCacheMemory": "RubyPerfectCacheMemory", 499102SNuwan.Jayasena@amd.com "MemoryControl": "MemoryControl", 5011084Snilay@cs.wisc.edu "MessageBuffer": "MessageBuffer", 519366Snilay@cs.wisc.edu "DMASequencer": "DMASequencer", 529499Snilay@cs.wisc.edu "Prefetcher":"Prefetcher", 539499Snilay@cs.wisc.edu "Cycles":"Cycles", 549499Snilay@cs.wisc.edu } 556882SBrad.Beckmann@amd.com 566657Snate@binkert.orgclass StateMachine(Symbol): 576657Snate@binkert.org def __init__(self, symtab, ident, location, pairs, config_parameters): 586657Snate@binkert.org super(StateMachine, self).__init__(symtab, ident, location, pairs) 596657Snate@binkert.org self.table = None 6010311Snilay@cs.wisc.edu 6110311Snilay@cs.wisc.edu # Data members in the State Machine that have been declared before 6210311Snilay@cs.wisc.edu # the opening brace '{' of the machine. Note that these along with 6310311Snilay@cs.wisc.edu # the members in self.objects form the entire set of data members. 646657Snate@binkert.org self.config_parameters = config_parameters 6510311Snilay@cs.wisc.edu 669366Snilay@cs.wisc.edu self.prefetchers = [] 677839Snilay@cs.wisc.edu 686657Snate@binkert.org for param in config_parameters: 696882SBrad.Beckmann@amd.com if param.pointer: 7010308Snilay@cs.wisc.edu var = Var(symtab, param.ident, location, param.type_ast.type, 7110308Snilay@cs.wisc.edu "(*m_%s_ptr)" % param.ident, {}, self) 726882SBrad.Beckmann@amd.com else: 7310308Snilay@cs.wisc.edu var = Var(symtab, param.ident, location, param.type_ast.type, 7410308Snilay@cs.wisc.edu "m_%s" % param.ident, {}, self) 7510308Snilay@cs.wisc.edu 7610308Snilay@cs.wisc.edu self.symtab.registerSym(param.ident, var) 7710308Snilay@cs.wisc.edu 789366Snilay@cs.wisc.edu if str(param.type_ast.type) == "Prefetcher": 799366Snilay@cs.wisc.edu self.prefetchers.append(var) 806657Snate@binkert.org 816657Snate@binkert.org self.states = orderdict() 826657Snate@binkert.org self.events = orderdict() 836657Snate@binkert.org self.actions = orderdict() 849104Shestness@cs.utexas.edu self.request_types = orderdict() 856657Snate@binkert.org self.transitions = [] 866657Snate@binkert.org self.in_ports = [] 876657Snate@binkert.org self.functions = [] 8810311Snilay@cs.wisc.edu 8910311Snilay@cs.wisc.edu # Data members in the State Machine that have been declared inside 9010311Snilay@cs.wisc.edu # the {} machine. Note that these along with the config params 9110311Snilay@cs.wisc.edu # form the entire set of data members of the machine. 926657Snate@binkert.org self.objects = [] 937839Snilay@cs.wisc.edu self.TBEType = None 947839Snilay@cs.wisc.edu self.EntryType = None 9510972Sdavid.hashe@amd.com self.debug_flags = set() 9610972Sdavid.hashe@amd.com self.debug_flags.add('RubyGenerated') 9710972Sdavid.hashe@amd.com self.debug_flags.add('RubySlicc') 986657Snate@binkert.org 996657Snate@binkert.org def __repr__(self): 1006657Snate@binkert.org return "[StateMachine: %s]" % self.ident 1016657Snate@binkert.org 1026657Snate@binkert.org def addState(self, state): 1036657Snate@binkert.org assert self.table is None 1046657Snate@binkert.org self.states[state.ident] = state 1056657Snate@binkert.org 1066657Snate@binkert.org def addEvent(self, event): 1076657Snate@binkert.org assert self.table is None 1086657Snate@binkert.org self.events[event.ident] = event 1096657Snate@binkert.org 1106657Snate@binkert.org def addAction(self, action): 1116657Snate@binkert.org assert self.table is None 1126657Snate@binkert.org 1136657Snate@binkert.org # Check for duplicate action 1146657Snate@binkert.org for other in self.actions.itervalues(): 1156657Snate@binkert.org if action.ident == other.ident: 1166779SBrad.Beckmann@amd.com action.warning("Duplicate action definition: %s" % action.ident) 1176657Snate@binkert.org action.error("Duplicate action definition: %s" % action.ident) 1186657Snate@binkert.org if action.short == other.short: 1196657Snate@binkert.org other.warning("Duplicate action shorthand: %s" % other.ident) 1206657Snate@binkert.org other.warning(" shorthand = %s" % other.short) 1216657Snate@binkert.org action.warning("Duplicate action shorthand: %s" % action.ident) 1226657Snate@binkert.org action.error(" shorthand = %s" % action.short) 1236657Snate@binkert.org 1246657Snate@binkert.org self.actions[action.ident] = action 1256657Snate@binkert.org 12610972Sdavid.hashe@amd.com def addDebugFlag(self, flag): 12710972Sdavid.hashe@amd.com self.debug_flags.add(flag) 12810972Sdavid.hashe@amd.com 1299104Shestness@cs.utexas.edu def addRequestType(self, request_type): 1309104Shestness@cs.utexas.edu assert self.table is None 1319104Shestness@cs.utexas.edu self.request_types[request_type.ident] = request_type 1329104Shestness@cs.utexas.edu 1336657Snate@binkert.org def addTransition(self, trans): 1346657Snate@binkert.org assert self.table is None 1356657Snate@binkert.org self.transitions.append(trans) 1366657Snate@binkert.org 1376657Snate@binkert.org def addInPort(self, var): 1386657Snate@binkert.org self.in_ports.append(var) 1396657Snate@binkert.org 1406657Snate@binkert.org def addFunc(self, func): 1416657Snate@binkert.org # register func in the symbol table 1426657Snate@binkert.org self.symtab.registerSym(str(func), func) 1436657Snate@binkert.org self.functions.append(func) 1446657Snate@binkert.org 1456657Snate@binkert.org def addObject(self, obj): 14610307Snilay@cs.wisc.edu self.symtab.registerSym(str(obj), obj) 1476657Snate@binkert.org self.objects.append(obj) 1486657Snate@binkert.org 1497839Snilay@cs.wisc.edu def addType(self, type): 1507839Snilay@cs.wisc.edu type_ident = '%s' % type.c_ident 1517839Snilay@cs.wisc.edu 1527839Snilay@cs.wisc.edu if type_ident == "%s_TBE" %self.ident: 1537839Snilay@cs.wisc.edu if self.TBEType != None: 1547839Snilay@cs.wisc.edu self.error("Multiple Transaction Buffer types in a " \ 1557839Snilay@cs.wisc.edu "single machine."); 1567839Snilay@cs.wisc.edu self.TBEType = type 1577839Snilay@cs.wisc.edu 1587839Snilay@cs.wisc.edu elif "interface" in type and "AbstractCacheEntry" == type["interface"]: 15910968Sdavid.hashe@amd.com if "main" in type and "false" == type["main"].lower(): 16010968Sdavid.hashe@amd.com pass # this isn't the EntryType 16110968Sdavid.hashe@amd.com else: 16210968Sdavid.hashe@amd.com if self.EntryType != None: 16310968Sdavid.hashe@amd.com self.error("Multiple AbstractCacheEntry types in a " \ 16410968Sdavid.hashe@amd.com "single machine."); 16510968Sdavid.hashe@amd.com self.EntryType = type 1667839Snilay@cs.wisc.edu 1676657Snate@binkert.org # Needs to be called before accessing the table 1686657Snate@binkert.org def buildTable(self): 1696657Snate@binkert.org assert self.table is None 1706657Snate@binkert.org 1716657Snate@binkert.org table = {} 1726657Snate@binkert.org 1736657Snate@binkert.org for trans in self.transitions: 1746657Snate@binkert.org # Track which actions we touch so we know if we use them 1756657Snate@binkert.org # all -- really this should be done for all symbols as 1766657Snate@binkert.org # part of the symbol table, then only trigger it for 1776657Snate@binkert.org # Actions, States, Events, etc. 1786657Snate@binkert.org 1796657Snate@binkert.org for action in trans.actions: 1806657Snate@binkert.org action.used = True 1816657Snate@binkert.org 1826657Snate@binkert.org index = (trans.state, trans.event) 1836657Snate@binkert.org if index in table: 1846657Snate@binkert.org table[index].warning("Duplicate transition: %s" % table[index]) 1856657Snate@binkert.org trans.error("Duplicate transition: %s" % trans) 1866657Snate@binkert.org table[index] = trans 1876657Snate@binkert.org 1886657Snate@binkert.org # Look at all actions to make sure we used them all 1896657Snate@binkert.org for action in self.actions.itervalues(): 1906657Snate@binkert.org if not action.used: 1916657Snate@binkert.org error_msg = "Unused action: %s" % action.ident 1926657Snate@binkert.org if "desc" in action: 1936657Snate@binkert.org error_msg += ", " + action.desc 1946657Snate@binkert.org action.warning(error_msg) 1956657Snate@binkert.org self.table = table 1966657Snate@binkert.org 19710963Sdavid.hashe@amd.com # determine the port->msg buffer mappings 19810963Sdavid.hashe@amd.com def getBufferMaps(self, ident): 19910963Sdavid.hashe@amd.com msg_bufs = [] 20010963Sdavid.hashe@amd.com port_to_buf_map = {} 20110963Sdavid.hashe@amd.com in_msg_bufs = {} 20210963Sdavid.hashe@amd.com for port in self.in_ports: 20311095Snilay@cs.wisc.edu buf_name = "m_%s_ptr" % port.pairs["buffer_expr"].name 20410963Sdavid.hashe@amd.com msg_bufs.append(buf_name) 20510963Sdavid.hashe@amd.com port_to_buf_map[port] = msg_bufs.index(buf_name) 20610963Sdavid.hashe@amd.com if buf_name not in in_msg_bufs: 20710963Sdavid.hashe@amd.com in_msg_bufs[buf_name] = [port] 20810963Sdavid.hashe@amd.com else: 20910963Sdavid.hashe@amd.com in_msg_bufs[buf_name].append(port) 21010963Sdavid.hashe@amd.com return port_to_buf_map, in_msg_bufs, msg_bufs 21110963Sdavid.hashe@amd.com 2129219Spower.jg@gmail.com def writeCodeFiles(self, path, includes): 2136877Ssteve.reinhardt@amd.com self.printControllerPython(path) 2146657Snate@binkert.org self.printControllerHH(path) 2159219Spower.jg@gmail.com self.printControllerCC(path, includes) 2166657Snate@binkert.org self.printCSwitch(path) 2179219Spower.jg@gmail.com self.printCWakeup(path, includes) 2186657Snate@binkert.org 2196877Ssteve.reinhardt@amd.com def printControllerPython(self, path): 2206999Snate@binkert.org code = self.symtab.codeFormatter() 2216877Ssteve.reinhardt@amd.com ident = self.ident 22210308Snilay@cs.wisc.edu 2236877Ssteve.reinhardt@amd.com py_ident = "%s_Controller" % ident 2246877Ssteve.reinhardt@amd.com c_ident = "%s_Controller" % self.ident 22510308Snilay@cs.wisc.edu 2266877Ssteve.reinhardt@amd.com code(''' 2276877Ssteve.reinhardt@amd.comfrom m5.params import * 2286877Ssteve.reinhardt@amd.comfrom m5.SimObject import SimObject 22913665Sandreas.sandberg@arm.comfrom m5.objects.Controller import RubyController 2306877Ssteve.reinhardt@amd.com 2316877Ssteve.reinhardt@amd.comclass $py_ident(RubyController): 2326877Ssteve.reinhardt@amd.com type = '$py_ident' 2339338SAndreas.Sandberg@arm.com cxx_header = 'mem/protocol/${c_ident}.hh' 2346877Ssteve.reinhardt@amd.com''') 2356877Ssteve.reinhardt@amd.com code.indent() 2366877Ssteve.reinhardt@amd.com for param in self.config_parameters: 2376877Ssteve.reinhardt@amd.com dflt_str = '' 23810308Snilay@cs.wisc.edu 23910308Snilay@cs.wisc.edu if param.rvalue is not None: 24010308Snilay@cs.wisc.edu dflt_str = str(param.rvalue.inline()) + ', ' 24110308Snilay@cs.wisc.edu 24211084Snilay@cs.wisc.edu if python_class_map.has_key(param.type_ast.type.c_ident): 2436882SBrad.Beckmann@amd.com python_type = python_class_map[param.type_ast.type.c_ident] 24410308Snilay@cs.wisc.edu code('${{param.ident}} = Param.${{python_type}}(${dflt_str}"")') 24510308Snilay@cs.wisc.edu 2466882SBrad.Beckmann@amd.com else: 2476882SBrad.Beckmann@amd.com self.error("Unknown c++ to python class conversion for c++ " \ 2486882SBrad.Beckmann@amd.com "type: '%s'. Please update the python_class_map " \ 2496882SBrad.Beckmann@amd.com "in StateMachine.py", param.type_ast.type.c_ident) 25011021Sjthestness@gmail.com 2516877Ssteve.reinhardt@amd.com code.dedent() 2526877Ssteve.reinhardt@amd.com code.write(path, '%s.py' % py_ident) 25310917Sbrandon.potter@amd.com 2546877Ssteve.reinhardt@amd.com 2556657Snate@binkert.org def printControllerHH(self, path): 2566657Snate@binkert.org '''Output the method declarations for the class declaration''' 2576999Snate@binkert.org code = self.symtab.codeFormatter() 2586657Snate@binkert.org ident = self.ident 2596657Snate@binkert.org c_ident = "%s_Controller" % self.ident 2606657Snate@binkert.org 2616657Snate@binkert.org code(''' 2627007Snate@binkert.org/** \\file $c_ident.hh 2636657Snate@binkert.org * 2646657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__ 2656657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}" 2666657Snate@binkert.org */ 2676657Snate@binkert.org 2687007Snate@binkert.org#ifndef __${ident}_CONTROLLER_HH__ 2697007Snate@binkert.org#define __${ident}_CONTROLLER_HH__ 2706657Snate@binkert.org 2717002Snate@binkert.org#include <iostream> 2727002Snate@binkert.org#include <sstream> 2737002Snate@binkert.org#include <string> 2747002Snate@binkert.org 2756657Snate@binkert.org#include "mem/protocol/TransitionResult.hh" 2766657Snate@binkert.org#include "mem/protocol/Types.hh" 2778229Snate@binkert.org#include "mem/ruby/common/Consumer.hh" 2788229Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh" 2798229Snate@binkert.org#include "params/$c_ident.hh" 28010972Sdavid.hashe@amd.com 2816657Snate@binkert.org''') 2826657Snate@binkert.org 2836657Snate@binkert.org seen_types = set() 2846657Snate@binkert.org for var in self.objects: 2856793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 2866657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 28710311Snilay@cs.wisc.edu seen_types.add(var.type.ident) 2886657Snate@binkert.org 2896657Snate@binkert.org # for adding information to the protocol debug trace 2906657Snate@binkert.org code(''' 2917002Snate@binkert.orgextern std::stringstream ${ident}_transitionComment; 2926657Snate@binkert.org 2937007Snate@binkert.orgclass $c_ident : public AbstractController 2947007Snate@binkert.org{ 2959271Snilay@cs.wisc.edu public: 2966877Ssteve.reinhardt@amd.com typedef ${c_ident}Params Params; 2976877Ssteve.reinhardt@amd.com $c_ident(const Params *p); 2986657Snate@binkert.org static int getNumControllers(); 2996877Ssteve.reinhardt@amd.com void init(); 30010311Snilay@cs.wisc.edu 30111084Snilay@cs.wisc.edu MessageBuffer *getMandatoryQueue() const; 30211084Snilay@cs.wisc.edu MessageBuffer *getMemoryQueue() const; 30311021Sjthestness@gmail.com void initNetQueues(); 3049745Snilay@cs.wisc.edu 3057002Snate@binkert.org void print(std::ostream& out) const; 3066657Snate@binkert.org void wakeup(); 30710012Snilay@cs.wisc.edu void resetStats(); 3089745Snilay@cs.wisc.edu void regStats(); 3099745Snilay@cs.wisc.edu void collateStats(); 3109745Snilay@cs.wisc.edu 3118683Snilay@cs.wisc.edu void recordCacheTrace(int cntrl, CacheRecorder* tr); 31211308Santhony.gutierrez@amd.com Sequencer* getCPUSequencer() const; 31311309Sdavid.hashe@amd.com GPUCoalescer* getGPUCoalescer() const; 3147007Snate@binkert.org 31510524Snilay@cs.wisc.edu int functionalWriteBuffers(PacketPtr&); 3169302Snilay@cs.wisc.edu 3179745Snilay@cs.wisc.edu void countTransition(${ident}_State state, ${ident}_Event event); 3189745Snilay@cs.wisc.edu void possibleTransition(${ident}_State state, ${ident}_Event event); 31911061Snilay@cs.wisc.edu uint64_t getEventCount(${ident}_Event event); 3209745Snilay@cs.wisc.edu bool isPossible(${ident}_State state, ${ident}_Event event); 32111061Snilay@cs.wisc.edu uint64_t getTransitionCount(${ident}_State state, ${ident}_Event event); 3229745Snilay@cs.wisc.edu 3236657Snate@binkert.orgprivate: 3246657Snate@binkert.org''') 3256657Snate@binkert.org 3266657Snate@binkert.org code.indent() 3276657Snate@binkert.org # added by SS 3286657Snate@binkert.org for param in self.config_parameters: 3296882SBrad.Beckmann@amd.com if param.pointer: 3306882SBrad.Beckmann@amd.com code('${{param.type_ast.type}}* m_${{param.ident}}_ptr;') 3316882SBrad.Beckmann@amd.com else: 3326882SBrad.Beckmann@amd.com code('${{param.type_ast.type}} m_${{param.ident}};') 3336657Snate@binkert.org 3346657Snate@binkert.org code(''' 3357007Snate@binkert.orgTransitionResult doTransition(${ident}_Event event, 3367839Snilay@cs.wisc.edu''') 3377839Snilay@cs.wisc.edu 3387839Snilay@cs.wisc.edu if self.EntryType != None: 3397839Snilay@cs.wisc.edu code(''' 3407839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}* m_cache_entry_ptr, 3417839Snilay@cs.wisc.edu''') 3427839Snilay@cs.wisc.edu if self.TBEType != None: 3437839Snilay@cs.wisc.edu code(''' 3447839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}* m_tbe_ptr, 3457839Snilay@cs.wisc.edu''') 3467839Snilay@cs.wisc.edu 3477839Snilay@cs.wisc.edu code(''' 34811025Snilay@cs.wisc.edu Addr addr); 3497007Snate@binkert.org 3507007Snate@binkert.orgTransitionResult doTransitionWorker(${ident}_Event event, 3517007Snate@binkert.org ${ident}_State state, 3527007Snate@binkert.org ${ident}_State& next_state, 3537839Snilay@cs.wisc.edu''') 3547839Snilay@cs.wisc.edu 3557839Snilay@cs.wisc.edu if self.TBEType != None: 3567839Snilay@cs.wisc.edu code(''' 3577839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}*& m_tbe_ptr, 3587839Snilay@cs.wisc.edu''') 3597839Snilay@cs.wisc.edu if self.EntryType != None: 3607839Snilay@cs.wisc.edu code(''' 3617839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, 3627839Snilay@cs.wisc.edu''') 3637839Snilay@cs.wisc.edu 3647839Snilay@cs.wisc.edu code(''' 36511025Snilay@cs.wisc.edu Addr addr); 3667007Snate@binkert.org 3679745Snilay@cs.wisc.eduint m_counters[${ident}_State_NUM][${ident}_Event_NUM]; 3689745Snilay@cs.wisc.eduint m_event_counters[${ident}_Event_NUM]; 3699745Snilay@cs.wisc.edubool m_possible[${ident}_State_NUM][${ident}_Event_NUM]; 3709745Snilay@cs.wisc.edu 3719745Snilay@cs.wisc.edustatic std::vector<Stats::Vector *> eventVec; 3729745Snilay@cs.wisc.edustatic std::vector<std::vector<Stats::Vector *> > transVec; 3736657Snate@binkert.orgstatic int m_num_controllers; 3747007Snate@binkert.org 3756657Snate@binkert.org// Internal functions 3766657Snate@binkert.org''') 3776657Snate@binkert.org 3786657Snate@binkert.org for func in self.functions: 3796657Snate@binkert.org proto = func.prototype 3806657Snate@binkert.org if proto: 3816657Snate@binkert.org code('$proto') 3826657Snate@binkert.org 3837839Snilay@cs.wisc.edu if self.EntryType != None: 3847839Snilay@cs.wisc.edu code(''' 3857839Snilay@cs.wisc.edu 3867839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable 3877839Snilay@cs.wisc.eduvoid set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry); 3887839Snilay@cs.wisc.eduvoid unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr); 3897839Snilay@cs.wisc.edu''') 3907839Snilay@cs.wisc.edu 3917839Snilay@cs.wisc.edu if self.TBEType != None: 3927839Snilay@cs.wisc.edu code(''' 3937839Snilay@cs.wisc.edu 3947839Snilay@cs.wisc.edu// Set and Reset for tbe variable 3957839Snilay@cs.wisc.eduvoid set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${ident}_TBE* m_new_tbe); 3967839Snilay@cs.wisc.eduvoid unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr); 3977839Snilay@cs.wisc.edu''') 3987839Snilay@cs.wisc.edu 39910121Snilay@cs.wisc.edu # Prototype the actions that the controller can take 4006657Snate@binkert.org code(''' 4016657Snate@binkert.org 4026657Snate@binkert.org// Actions 4036657Snate@binkert.org''') 4047839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 4057839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 4067839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 40710121Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& ' 40810121Snilay@cs.wisc.edu 'm_tbe_ptr, ${{self.EntryType.c_ident}}*& ' 40911025Snilay@cs.wisc.edu 'm_cache_entry_ptr, Addr addr);') 4107839Snilay@cs.wisc.edu elif self.TBEType != None: 4117839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 4127839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 41310121Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& ' 41411025Snilay@cs.wisc.edu 'm_tbe_ptr, Addr addr);') 4157839Snilay@cs.wisc.edu elif self.EntryType != None: 4167839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 4177839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 41810121Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.EntryType.c_ident}}*& ' 41911025Snilay@cs.wisc.edu 'm_cache_entry_ptr, Addr addr);') 4207839Snilay@cs.wisc.edu else: 4217839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 4227839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 42311025Snilay@cs.wisc.edu code('void ${{action.ident}}(Addr addr);') 4246657Snate@binkert.org 4256657Snate@binkert.org # the controller internal variables 4266657Snate@binkert.org code(''' 4276657Snate@binkert.org 4287007Snate@binkert.org// Objects 4296657Snate@binkert.org''') 4306657Snate@binkert.org for var in self.objects: 4319273Snilay@cs.wisc.edu th = var.get("template", "") 43210305Snilay@cs.wisc.edu code('${{var.type.c_ident}}$th* m_${{var.ident}}_ptr;') 4336657Snate@binkert.org 4346657Snate@binkert.org code.dedent() 4356657Snate@binkert.org code('};') 4367007Snate@binkert.org code('#endif // __${ident}_CONTROLLER_H__') 4376657Snate@binkert.org code.write(path, '%s.hh' % c_ident) 4386657Snate@binkert.org 4399219Spower.jg@gmail.com def printControllerCC(self, path, includes): 4406657Snate@binkert.org '''Output the actions for performing the actions''' 4416657Snate@binkert.org 4426999Snate@binkert.org code = self.symtab.codeFormatter() 4436657Snate@binkert.org ident = self.ident 4446657Snate@binkert.org c_ident = "%s_Controller" % self.ident 4456657Snate@binkert.org 4466657Snate@binkert.org code(''' 4477007Snate@binkert.org/** \\file $c_ident.cc 4486657Snate@binkert.org * 4496657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__ 4506657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}" 4516657Snate@binkert.org */ 4526657Snate@binkert.org 4538946Sandreas.hansson@arm.com#include <sys/types.h> 4548946Sandreas.hansson@arm.com#include <unistd.h> 4558946Sandreas.hansson@arm.com 4567832Snate@binkert.org#include <cassert> 4577002Snate@binkert.org#include <sstream> 4587002Snate@binkert.org#include <string> 45910972Sdavid.hashe@amd.com#include <typeinfo> 4607002Snate@binkert.org 4618641Snate@binkert.org#include "base/compiler.hh" 46211704Santhony.gutierrez@amd.com#include "mem/ruby/common/BoolVec.hh" 4637056Snate@binkert.org#include "base/cprintf.hh" 46410972Sdavid.hashe@amd.com 46510972Sdavid.hashe@amd.com''') 46610972Sdavid.hashe@amd.com for f in self.debug_flags: 46710972Sdavid.hashe@amd.com code('#include "debug/${{f}}.hh"') 46810972Sdavid.hashe@amd.com code(''' 4696657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 4708229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 4716657Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 4726657Snate@binkert.org#include "mem/protocol/Types.hh" 47311793Sbrandon.potter@amd.com#include "mem/ruby/network/Network.hh" 47411108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh" 47510972Sdavid.hashe@amd.com 4769219Spower.jg@gmail.com''') 4779219Spower.jg@gmail.com for include_path in includes: 4789219Spower.jg@gmail.com code('#include "${{include_path}}"') 4799219Spower.jg@gmail.com 4809219Spower.jg@gmail.com code(''' 4817002Snate@binkert.org 4827002Snate@binkert.orgusing namespace std; 4836657Snate@binkert.org''') 4846657Snate@binkert.org 4856657Snate@binkert.org # include object classes 4866657Snate@binkert.org seen_types = set() 4876657Snate@binkert.org for var in self.objects: 4886793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 4896657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 4906657Snate@binkert.org seen_types.add(var.type.ident) 4916657Snate@binkert.org 49210121Snilay@cs.wisc.edu num_in_ports = len(self.in_ports) 49310121Snilay@cs.wisc.edu 4946657Snate@binkert.org code(''' 4956877Ssteve.reinhardt@amd.com$c_ident * 4966877Ssteve.reinhardt@amd.com${c_ident}Params::create() 4976877Ssteve.reinhardt@amd.com{ 4986877Ssteve.reinhardt@amd.com return new $c_ident(this); 4996877Ssteve.reinhardt@amd.com} 5006877Ssteve.reinhardt@amd.com 5016657Snate@binkert.orgint $c_ident::m_num_controllers = 0; 5029745Snilay@cs.wisc.edustd::vector<Stats::Vector *> $c_ident::eventVec; 5039745Snilay@cs.wisc.edustd::vector<std::vector<Stats::Vector *> > $c_ident::transVec; 5046657Snate@binkert.org 5057007Snate@binkert.org// for adding information to the protocol debug trace 5066657Snate@binkert.orgstringstream ${ident}_transitionComment; 5079801Snilay@cs.wisc.edu 5089801Snilay@cs.wisc.edu#ifndef NDEBUG 5096657Snate@binkert.org#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str) 5109801Snilay@cs.wisc.edu#else 5119801Snilay@cs.wisc.edu#define APPEND_TRANSITION_COMMENT(str) do {} while (0) 5129801Snilay@cs.wisc.edu#endif 5137007Snate@binkert.org 5146657Snate@binkert.org/** \\brief constructor */ 5156877Ssteve.reinhardt@amd.com$c_ident::$c_ident(const Params *p) 5166877Ssteve.reinhardt@amd.com : AbstractController(p) 5176657Snate@binkert.org{ 51810078Snilay@cs.wisc.edu m_machineID.type = MachineType_${ident}; 51910078Snilay@cs.wisc.edu m_machineID.num = m_version; 52010121Snilay@cs.wisc.edu m_num_controllers++; 52110121Snilay@cs.wisc.edu 52210121Snilay@cs.wisc.edu m_in_ports = $num_in_ports; 5236657Snate@binkert.org''') 5246657Snate@binkert.org code.indent() 5256882SBrad.Beckmann@amd.com 5266882SBrad.Beckmann@amd.com # 5276882SBrad.Beckmann@amd.com # After initializing the universal machine parameters, initialize the 52810121Snilay@cs.wisc.edu # this machines config parameters. Also if these configuration params 52910121Snilay@cs.wisc.edu # include a sequencer, connect the it to the controller. 5306882SBrad.Beckmann@amd.com # 5316877Ssteve.reinhardt@amd.com for param in self.config_parameters: 5326882SBrad.Beckmann@amd.com if param.pointer: 53310308Snilay@cs.wisc.edu code('m_${{param.ident}}_ptr = p->${{param.ident}};') 5346882SBrad.Beckmann@amd.com else: 53510308Snilay@cs.wisc.edu code('m_${{param.ident}} = p->${{param.ident}};') 53610311Snilay@cs.wisc.edu 53711308Santhony.gutierrez@amd.com if re.compile("sequencer").search(param.ident) or \ 53811308Santhony.gutierrez@amd.com param.type_ast.type.c_ident == "GPUCoalescer" or \ 53911308Santhony.gutierrez@amd.com param.type_ast.type.c_ident == "VIPERCoalescer": 54011308Santhony.gutierrez@amd.com code(''' 54111308Santhony.gutierrez@amd.comif (m_${{param.ident}}_ptr != NULL) { 54211308Santhony.gutierrez@amd.com m_${{param.ident}}_ptr->setController(this); 54311308Santhony.gutierrez@amd.com} 54411308Santhony.gutierrez@amd.com''') 54510917Sbrandon.potter@amd.com 5469595Snilay@cs.wisc.edu code(''' 5479745Snilay@cs.wisc.edu 5489745Snilay@cs.wisc.edufor (int state = 0; state < ${ident}_State_NUM; state++) { 5499745Snilay@cs.wisc.edu for (int event = 0; event < ${ident}_Event_NUM; event++) { 5509745Snilay@cs.wisc.edu m_possible[state][event] = false; 5519745Snilay@cs.wisc.edu m_counters[state][event] = 0; 5529745Snilay@cs.wisc.edu } 5539745Snilay@cs.wisc.edu} 5549745Snilay@cs.wisc.edufor (int event = 0; event < ${ident}_Event_NUM; event++) { 5559745Snilay@cs.wisc.edu m_event_counters[event] = 0; 5569745Snilay@cs.wisc.edu} 5579595Snilay@cs.wisc.edu''') 5586657Snate@binkert.org code.dedent() 5596657Snate@binkert.org code(''' 5606657Snate@binkert.org} 5616657Snate@binkert.org 5627007Snate@binkert.orgvoid 56311021Sjthestness@gmail.com$c_ident::initNetQueues() 56410311Snilay@cs.wisc.edu{ 56510311Snilay@cs.wisc.edu MachineType machine_type = string_to_MachineType("${{self.ident}}"); 56610311Snilay@cs.wisc.edu int base M5_VAR_USED = MachineType_base_number(machine_type); 56710311Snilay@cs.wisc.edu 56810311Snilay@cs.wisc.edu''') 56910311Snilay@cs.wisc.edu code.indent() 57010311Snilay@cs.wisc.edu 57110311Snilay@cs.wisc.edu # set for maintaining the vnet, direction pairs already seen for this 57210311Snilay@cs.wisc.edu # machine. This map helps in implementing the check for avoiding 57310311Snilay@cs.wisc.edu # multiple message buffers being mapped to the same vnet. 57410311Snilay@cs.wisc.edu vnet_dir_set = set() 57510311Snilay@cs.wisc.edu 57610311Snilay@cs.wisc.edu for var in self.config_parameters: 57711084Snilay@cs.wisc.edu vid = "m_%s_ptr" % var.ident 57810311Snilay@cs.wisc.edu if "network" in var: 57910311Snilay@cs.wisc.edu vtype = var.type_ast.type 58011021Sjthestness@gmail.com code('assert($vid != NULL);') 58111021Sjthestness@gmail.com 58210311Snilay@cs.wisc.edu # Network port object 58310311Snilay@cs.wisc.edu network = var["network"] 58410311Snilay@cs.wisc.edu 58510311Snilay@cs.wisc.edu if "virtual_network" in var: 58610311Snilay@cs.wisc.edu vnet = var["virtual_network"] 58710311Snilay@cs.wisc.edu vnet_type = var["vnet_type"] 58810311Snilay@cs.wisc.edu 58910311Snilay@cs.wisc.edu assert (vnet, network) not in vnet_dir_set 59010311Snilay@cs.wisc.edu vnet_dir_set.add((vnet,network)) 59110311Snilay@cs.wisc.edu 59210311Snilay@cs.wisc.edu code(''' 59311021Sjthestness@gmail.comm_net_ptr->set${network}NetQueue(m_version + base, $vid->getOrdered(), $vnet, 59411021Sjthestness@gmail.com "$vnet_type", $vid); 59510311Snilay@cs.wisc.edu''') 59610311Snilay@cs.wisc.edu # Set Priority 59710311Snilay@cs.wisc.edu if "rank" in var: 59810311Snilay@cs.wisc.edu code('$vid->setPriority(${{var["rank"]}})') 59910311Snilay@cs.wisc.edu 60010311Snilay@cs.wisc.edu code.dedent() 60110311Snilay@cs.wisc.edu code(''' 60210311Snilay@cs.wisc.edu} 60310311Snilay@cs.wisc.edu 60410311Snilay@cs.wisc.eduvoid 6057007Snate@binkert.org$c_ident::init() 6066657Snate@binkert.org{ 6077007Snate@binkert.org // initialize objects 6086657Snate@binkert.org''') 6096657Snate@binkert.org 6106657Snate@binkert.org code.indent() 61110311Snilay@cs.wisc.edu 6126657Snate@binkert.org for var in self.objects: 6136657Snate@binkert.org vtype = var.type 61410305Snilay@cs.wisc.edu vid = "m_%s_ptr" % var.ident 6156657Snate@binkert.org if "network" not in var: 6166657Snate@binkert.org # Not a network port object 6176657Snate@binkert.org if "primitive" in vtype: 6186657Snate@binkert.org code('$vid = new ${{vtype.c_ident}};') 6196657Snate@binkert.org if "default" in var: 6206657Snate@binkert.org code('(*$vid) = ${{var["default"]}};') 6216657Snate@binkert.org else: 6226657Snate@binkert.org # Normal Object 62311084Snilay@cs.wisc.edu th = var.get("template", "") 62411084Snilay@cs.wisc.edu expr = "%s = new %s%s" % (vid, vtype.c_ident, th) 62511084Snilay@cs.wisc.edu args = "" 62611084Snilay@cs.wisc.edu if "non_obj" not in vtype and not vtype.isEnumeration: 62711084Snilay@cs.wisc.edu args = var.get("constructor", "") 6286657Snate@binkert.org 62911084Snilay@cs.wisc.edu code('$expr($args);') 6306657Snate@binkert.org code('assert($vid != NULL);') 6316657Snate@binkert.org 6326657Snate@binkert.org if "default" in var: 6337007Snate@binkert.org code('*$vid = ${{var["default"]}}; // Object default') 6346657Snate@binkert.org elif "default" in vtype: 6357007Snate@binkert.org comment = "Type %s default" % vtype.ident 6367007Snate@binkert.org code('*$vid = ${{vtype["default"]}}; // $comment') 6376657Snate@binkert.org 6389366Snilay@cs.wisc.edu # Set the prefetchers 6399366Snilay@cs.wisc.edu code() 6409366Snilay@cs.wisc.edu for prefetcher in self.prefetchers: 6419366Snilay@cs.wisc.edu code('${{prefetcher.code}}.setController(this);') 6427566SBrad.Beckmann@amd.com 6437672Snate@binkert.org code() 6446657Snate@binkert.org for port in self.in_ports: 6459465Snilay@cs.wisc.edu # Set the queue consumers 6466657Snate@binkert.org code('${{port.code}}.setConsumer(this);') 6476657Snate@binkert.org 6486657Snate@binkert.org # Initialize the transition profiling 6497672Snate@binkert.org code() 6506657Snate@binkert.org for trans in self.transitions: 6516657Snate@binkert.org # Figure out if we stall 6526657Snate@binkert.org stall = False 6536657Snate@binkert.org for action in trans.actions: 6546657Snate@binkert.org if action.ident == "z_stall": 6556657Snate@binkert.org stall = True 6566657Snate@binkert.org 6576657Snate@binkert.org # Only possible if it is not a 'z' case 6586657Snate@binkert.org if not stall: 6596657Snate@binkert.org state = "%s_State_%s" % (self.ident, trans.state.ident) 6606657Snate@binkert.org event = "%s_Event_%s" % (self.ident, trans.event.ident) 6619745Snilay@cs.wisc.edu code('possibleTransition($state, $event);') 6626657Snate@binkert.org 6636657Snate@binkert.org code.dedent() 6649496Snilay@cs.wisc.edu code(''' 6659496Snilay@cs.wisc.edu AbstractController::init(); 66610012Snilay@cs.wisc.edu resetStats(); 6679496Snilay@cs.wisc.edu} 6689496Snilay@cs.wisc.edu''') 6696657Snate@binkert.org 67010121Snilay@cs.wisc.edu mq_ident = "NULL" 6716657Snate@binkert.org for port in self.in_ports: 6726657Snate@binkert.org if port.code.find("mandatoryQueue_ptr") >= 0: 67310305Snilay@cs.wisc.edu mq_ident = "m_mandatoryQueue_ptr" 6746657Snate@binkert.org 67511021Sjthestness@gmail.com memq_ident = "NULL" 67611021Sjthestness@gmail.com for port in self.in_ports: 67711021Sjthestness@gmail.com if port.code.find("responseFromMemory_ptr") >= 0: 67811021Sjthestness@gmail.com memq_ident = "m_responseFromMemory_ptr" 67911021Sjthestness@gmail.com 6808683Snilay@cs.wisc.edu seq_ident = "NULL" 6818683Snilay@cs.wisc.edu for param in self.config_parameters: 68210308Snilay@cs.wisc.edu if param.ident == "sequencer": 6838683Snilay@cs.wisc.edu assert(param.pointer) 68410308Snilay@cs.wisc.edu seq_ident = "m_%s_ptr" % param.ident 6858683Snilay@cs.wisc.edu 68611309Sdavid.hashe@amd.com coal_ident = "NULL" 68711309Sdavid.hashe@amd.com for param in self.config_parameters: 68811309Sdavid.hashe@amd.com if param.ident == "coalescer": 68911309Sdavid.hashe@amd.com assert(param.pointer) 69011309Sdavid.hashe@amd.com coal_ident = "m_%s_ptr" % param.ident 69111309Sdavid.hashe@amd.com 69211308Santhony.gutierrez@amd.com if seq_ident != "NULL": 69311308Santhony.gutierrez@amd.com code(''' 69411308Santhony.gutierrez@amd.comSequencer* 69511308Santhony.gutierrez@amd.com$c_ident::getCPUSequencer() const 69611308Santhony.gutierrez@amd.com{ 69711308Santhony.gutierrez@amd.com if (NULL != $seq_ident && $seq_ident->isCPUSequencer()) { 69811308Santhony.gutierrez@amd.com return $seq_ident; 69911308Santhony.gutierrez@amd.com } else { 70011308Santhony.gutierrez@amd.com return NULL; 70111308Santhony.gutierrez@amd.com } 70211308Santhony.gutierrez@amd.com} 70311308Santhony.gutierrez@amd.com''') 70411308Santhony.gutierrez@amd.com else: 70511308Santhony.gutierrez@amd.com code(''' 70611308Santhony.gutierrez@amd.com 70711308Santhony.gutierrez@amd.comSequencer* 70811308Santhony.gutierrez@amd.com$c_ident::getCPUSequencer() const 70911308Santhony.gutierrez@amd.com{ 71011308Santhony.gutierrez@amd.com return NULL; 71111308Santhony.gutierrez@amd.com} 71211308Santhony.gutierrez@amd.com''') 71311308Santhony.gutierrez@amd.com 71411309Sdavid.hashe@amd.com if coal_ident != "NULL": 71511309Sdavid.hashe@amd.com code(''' 71611309Sdavid.hashe@amd.comGPUCoalescer* 71711309Sdavid.hashe@amd.com$c_ident::getGPUCoalescer() const 71811309Sdavid.hashe@amd.com{ 71911309Sdavid.hashe@amd.com if (NULL != $coal_ident && !$coal_ident->isCPUSequencer()) { 72011309Sdavid.hashe@amd.com return $coal_ident; 72111309Sdavid.hashe@amd.com } else { 72211309Sdavid.hashe@amd.com return NULL; 72311309Sdavid.hashe@amd.com } 72411309Sdavid.hashe@amd.com} 72511309Sdavid.hashe@amd.com''') 72611309Sdavid.hashe@amd.com else: 72711309Sdavid.hashe@amd.com code(''' 72811309Sdavid.hashe@amd.com 72911309Sdavid.hashe@amd.comGPUCoalescer* 73011309Sdavid.hashe@amd.com$c_ident::getGPUCoalescer() const 73111309Sdavid.hashe@amd.com{ 73211309Sdavid.hashe@amd.com return NULL; 73311309Sdavid.hashe@amd.com} 73411309Sdavid.hashe@amd.com''') 73511309Sdavid.hashe@amd.com 7366657Snate@binkert.org code(''' 7379745Snilay@cs.wisc.edu 7389745Snilay@cs.wisc.eduvoid 7399745Snilay@cs.wisc.edu$c_ident::regStats() 7409745Snilay@cs.wisc.edu{ 74110012Snilay@cs.wisc.edu AbstractController::regStats(); 74210012Snilay@cs.wisc.edu 7439745Snilay@cs.wisc.edu if (m_version == 0) { 7449745Snilay@cs.wisc.edu for (${ident}_Event event = ${ident}_Event_FIRST; 7459745Snilay@cs.wisc.edu event < ${ident}_Event_NUM; ++event) { 7469745Snilay@cs.wisc.edu Stats::Vector *t = new Stats::Vector(); 7479745Snilay@cs.wisc.edu t->init(m_num_controllers); 74810919Sbrandon.potter@amd.com t->name(params()->ruby_system->name() + ".${c_ident}." + 74910012Snilay@cs.wisc.edu ${ident}_Event_to_string(event)); 7509745Snilay@cs.wisc.edu t->flags(Stats::pdf | Stats::total | Stats::oneline | 7519745Snilay@cs.wisc.edu Stats::nozero); 7529745Snilay@cs.wisc.edu 7539745Snilay@cs.wisc.edu eventVec.push_back(t); 7549745Snilay@cs.wisc.edu } 7559745Snilay@cs.wisc.edu 7569745Snilay@cs.wisc.edu for (${ident}_State state = ${ident}_State_FIRST; 7579745Snilay@cs.wisc.edu state < ${ident}_State_NUM; ++state) { 7589745Snilay@cs.wisc.edu 7599745Snilay@cs.wisc.edu transVec.push_back(std::vector<Stats::Vector *>()); 7609745Snilay@cs.wisc.edu 7619745Snilay@cs.wisc.edu for (${ident}_Event event = ${ident}_Event_FIRST; 7629745Snilay@cs.wisc.edu event < ${ident}_Event_NUM; ++event) { 7639745Snilay@cs.wisc.edu 7649745Snilay@cs.wisc.edu Stats::Vector *t = new Stats::Vector(); 7659745Snilay@cs.wisc.edu t->init(m_num_controllers); 76610919Sbrandon.potter@amd.com t->name(params()->ruby_system->name() + ".${c_ident}." + 76710012Snilay@cs.wisc.edu ${ident}_State_to_string(state) + 7689745Snilay@cs.wisc.edu "." + ${ident}_Event_to_string(event)); 7699745Snilay@cs.wisc.edu 7709745Snilay@cs.wisc.edu t->flags(Stats::pdf | Stats::total | Stats::oneline | 7719745Snilay@cs.wisc.edu Stats::nozero); 7729745Snilay@cs.wisc.edu transVec[state].push_back(t); 7739745Snilay@cs.wisc.edu } 7749745Snilay@cs.wisc.edu } 7759745Snilay@cs.wisc.edu } 7769745Snilay@cs.wisc.edu} 7779745Snilay@cs.wisc.edu 7789745Snilay@cs.wisc.eduvoid 7799745Snilay@cs.wisc.edu$c_ident::collateStats() 7809745Snilay@cs.wisc.edu{ 7819745Snilay@cs.wisc.edu for (${ident}_Event event = ${ident}_Event_FIRST; 7829745Snilay@cs.wisc.edu event < ${ident}_Event_NUM; ++event) { 7839745Snilay@cs.wisc.edu for (unsigned int i = 0; i < m_num_controllers; ++i) { 78410920Sbrandon.potter@amd.com RubySystem *rs = params()->ruby_system; 7859745Snilay@cs.wisc.edu std::map<uint32_t, AbstractController *>::iterator it = 78610920Sbrandon.potter@amd.com rs->m_abstract_controls[MachineType_${ident}].find(i); 78710920Sbrandon.potter@amd.com assert(it != rs->m_abstract_controls[MachineType_${ident}].end()); 7889745Snilay@cs.wisc.edu (*eventVec[event])[i] = 7899745Snilay@cs.wisc.edu (($c_ident *)(*it).second)->getEventCount(event); 7909745Snilay@cs.wisc.edu } 7919745Snilay@cs.wisc.edu } 7929745Snilay@cs.wisc.edu 7939745Snilay@cs.wisc.edu for (${ident}_State state = ${ident}_State_FIRST; 7949745Snilay@cs.wisc.edu state < ${ident}_State_NUM; ++state) { 7959745Snilay@cs.wisc.edu 7969745Snilay@cs.wisc.edu for (${ident}_Event event = ${ident}_Event_FIRST; 7979745Snilay@cs.wisc.edu event < ${ident}_Event_NUM; ++event) { 7989745Snilay@cs.wisc.edu 7999745Snilay@cs.wisc.edu for (unsigned int i = 0; i < m_num_controllers; ++i) { 80010920Sbrandon.potter@amd.com RubySystem *rs = params()->ruby_system; 8019745Snilay@cs.wisc.edu std::map<uint32_t, AbstractController *>::iterator it = 80210920Sbrandon.potter@amd.com rs->m_abstract_controls[MachineType_${ident}].find(i); 80310920Sbrandon.potter@amd.com assert(it != rs->m_abstract_controls[MachineType_${ident}].end()); 8049745Snilay@cs.wisc.edu (*transVec[state][event])[i] = 8059745Snilay@cs.wisc.edu (($c_ident *)(*it).second)->getTransitionCount(state, event); 8069745Snilay@cs.wisc.edu } 8079745Snilay@cs.wisc.edu } 8089745Snilay@cs.wisc.edu } 8099745Snilay@cs.wisc.edu} 8109745Snilay@cs.wisc.edu 8119745Snilay@cs.wisc.eduvoid 8129745Snilay@cs.wisc.edu$c_ident::countTransition(${ident}_State state, ${ident}_Event event) 8139745Snilay@cs.wisc.edu{ 8149745Snilay@cs.wisc.edu assert(m_possible[state][event]); 8159745Snilay@cs.wisc.edu m_counters[state][event]++; 8169745Snilay@cs.wisc.edu m_event_counters[event]++; 8179745Snilay@cs.wisc.edu} 8189745Snilay@cs.wisc.eduvoid 8199745Snilay@cs.wisc.edu$c_ident::possibleTransition(${ident}_State state, 8209745Snilay@cs.wisc.edu ${ident}_Event event) 8219745Snilay@cs.wisc.edu{ 8229745Snilay@cs.wisc.edu m_possible[state][event] = true; 8239745Snilay@cs.wisc.edu} 8249745Snilay@cs.wisc.edu 82511061Snilay@cs.wisc.eduuint64_t 8269745Snilay@cs.wisc.edu$c_ident::getEventCount(${ident}_Event event) 8279745Snilay@cs.wisc.edu{ 8289745Snilay@cs.wisc.edu return m_event_counters[event]; 8299745Snilay@cs.wisc.edu} 8309745Snilay@cs.wisc.edu 8319745Snilay@cs.wisc.edubool 8329745Snilay@cs.wisc.edu$c_ident::isPossible(${ident}_State state, ${ident}_Event event) 8339745Snilay@cs.wisc.edu{ 8349745Snilay@cs.wisc.edu return m_possible[state][event]; 8359745Snilay@cs.wisc.edu} 8369745Snilay@cs.wisc.edu 83711061Snilay@cs.wisc.eduuint64_t 8389745Snilay@cs.wisc.edu$c_ident::getTransitionCount(${ident}_State state, 8399745Snilay@cs.wisc.edu ${ident}_Event event) 8409745Snilay@cs.wisc.edu{ 8419745Snilay@cs.wisc.edu return m_counters[state][event]; 8429745Snilay@cs.wisc.edu} 8439745Snilay@cs.wisc.edu 8447007Snate@binkert.orgint 8457007Snate@binkert.org$c_ident::getNumControllers() 8467007Snate@binkert.org{ 8476657Snate@binkert.org return m_num_controllers; 8486657Snate@binkert.org} 8496657Snate@binkert.org 8507007Snate@binkert.orgMessageBuffer* 8517007Snate@binkert.org$c_ident::getMandatoryQueue() const 8527007Snate@binkert.org{ 8536657Snate@binkert.org return $mq_ident; 8546657Snate@binkert.org} 8556657Snate@binkert.org 85611021Sjthestness@gmail.comMessageBuffer* 85711021Sjthestness@gmail.com$c_ident::getMemoryQueue() const 85811021Sjthestness@gmail.com{ 85911021Sjthestness@gmail.com return $memq_ident; 86011021Sjthestness@gmail.com} 86111021Sjthestness@gmail.com 8627007Snate@binkert.orgvoid 8637007Snate@binkert.org$c_ident::print(ostream& out) const 8647007Snate@binkert.org{ 8657007Snate@binkert.org out << "[$c_ident " << m_version << "]"; 8667007Snate@binkert.org} 8676657Snate@binkert.org 86810012Snilay@cs.wisc.eduvoid $c_ident::resetStats() 8699745Snilay@cs.wisc.edu{ 8709745Snilay@cs.wisc.edu for (int state = 0; state < ${ident}_State_NUM; state++) { 8719745Snilay@cs.wisc.edu for (int event = 0; event < ${ident}_Event_NUM; event++) { 8729745Snilay@cs.wisc.edu m_counters[state][event] = 0; 8739745Snilay@cs.wisc.edu } 8749745Snilay@cs.wisc.edu } 8756902SBrad.Beckmann@amd.com 8769745Snilay@cs.wisc.edu for (int event = 0; event < ${ident}_Event_NUM; event++) { 8779745Snilay@cs.wisc.edu m_event_counters[event] = 0; 8789745Snilay@cs.wisc.edu } 8799745Snilay@cs.wisc.edu 88010012Snilay@cs.wisc.edu AbstractController::resetStats(); 8816902SBrad.Beckmann@amd.com} 8827839Snilay@cs.wisc.edu''') 8837839Snilay@cs.wisc.edu 8847839Snilay@cs.wisc.edu if self.EntryType != None: 8857839Snilay@cs.wisc.edu code(''' 8867839Snilay@cs.wisc.edu 8877839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable 8887839Snilay@cs.wisc.eduvoid 8897839Snilay@cs.wisc.edu$c_ident::set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry) 8907839Snilay@cs.wisc.edu{ 8917839Snilay@cs.wisc.edu m_cache_entry_ptr = (${{self.EntryType.c_ident}}*)m_new_cache_entry; 8927839Snilay@cs.wisc.edu} 8937839Snilay@cs.wisc.edu 8947839Snilay@cs.wisc.eduvoid 8957839Snilay@cs.wisc.edu$c_ident::unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr) 8967839Snilay@cs.wisc.edu{ 8977839Snilay@cs.wisc.edu m_cache_entry_ptr = 0; 8987839Snilay@cs.wisc.edu} 8997839Snilay@cs.wisc.edu''') 9007839Snilay@cs.wisc.edu 9017839Snilay@cs.wisc.edu if self.TBEType != None: 9027839Snilay@cs.wisc.edu code(''' 9037839Snilay@cs.wisc.edu 9047839Snilay@cs.wisc.edu// Set and Reset for tbe variable 9057839Snilay@cs.wisc.eduvoid 9067839Snilay@cs.wisc.edu$c_ident::set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.TBEType.c_ident}}* m_new_tbe) 9077839Snilay@cs.wisc.edu{ 9087839Snilay@cs.wisc.edu m_tbe_ptr = m_new_tbe; 9097839Snilay@cs.wisc.edu} 9107839Snilay@cs.wisc.edu 9117839Snilay@cs.wisc.eduvoid 9127839Snilay@cs.wisc.edu$c_ident::unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr) 9137839Snilay@cs.wisc.edu{ 9147839Snilay@cs.wisc.edu m_tbe_ptr = NULL; 9157839Snilay@cs.wisc.edu} 9167839Snilay@cs.wisc.edu''') 9177839Snilay@cs.wisc.edu 9187839Snilay@cs.wisc.edu code(''' 9196902SBrad.Beckmann@amd.com 9208683Snilay@cs.wisc.eduvoid 9218683Snilay@cs.wisc.edu$c_ident::recordCacheTrace(int cntrl, CacheRecorder* tr) 9228683Snilay@cs.wisc.edu{ 9238683Snilay@cs.wisc.edu''') 9248683Snilay@cs.wisc.edu # 9258683Snilay@cs.wisc.edu # Record cache contents for all associated caches. 9268683Snilay@cs.wisc.edu # 9278683Snilay@cs.wisc.edu code.indent() 9288683Snilay@cs.wisc.edu for param in self.config_parameters: 9298683Snilay@cs.wisc.edu if param.type_ast.type.ident == "CacheMemory": 9308683Snilay@cs.wisc.edu assert(param.pointer) 9318683Snilay@cs.wisc.edu code('m_${{param.ident}}_ptr->recordCacheContents(cntrl, tr);') 9328683Snilay@cs.wisc.edu 9338683Snilay@cs.wisc.edu code.dedent() 9348683Snilay@cs.wisc.edu code(''' 9358683Snilay@cs.wisc.edu} 9368683Snilay@cs.wisc.edu 9376657Snate@binkert.org// Actions 9386657Snate@binkert.org''') 9397839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 9407839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9417839Snilay@cs.wisc.edu if "c_code" not in action: 9427839Snilay@cs.wisc.edu continue 9436657Snate@binkert.org 9447839Snilay@cs.wisc.edu code(''' 9457839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9467839Snilay@cs.wisc.eduvoid 94711025Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, Addr addr) 9487839Snilay@cs.wisc.edu{ 9498055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 95010963Sdavid.hashe@amd.com try { 95110963Sdavid.hashe@amd.com ${{action["c_code"]}} 95210963Sdavid.hashe@amd.com } catch (const RejectException & e) { 95310963Sdavid.hashe@amd.com fatal("Error in action ${{ident}}:${{action.ident}}: " 95410963Sdavid.hashe@amd.com "executed a peek statement with the wrong message " 95510963Sdavid.hashe@amd.com "type specified. "); 95610963Sdavid.hashe@amd.com } 9577839Snilay@cs.wisc.edu} 9586657Snate@binkert.org 9597839Snilay@cs.wisc.edu''') 9607839Snilay@cs.wisc.edu elif self.TBEType != None: 9617839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9627839Snilay@cs.wisc.edu if "c_code" not in action: 9637839Snilay@cs.wisc.edu continue 9647839Snilay@cs.wisc.edu 9657839Snilay@cs.wisc.edu code(''' 9667839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9677839Snilay@cs.wisc.eduvoid 96811025Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, Addr addr) 9697839Snilay@cs.wisc.edu{ 9708055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9717839Snilay@cs.wisc.edu ${{action["c_code"]}} 9727839Snilay@cs.wisc.edu} 9737839Snilay@cs.wisc.edu 9747839Snilay@cs.wisc.edu''') 9757839Snilay@cs.wisc.edu elif self.EntryType != None: 9767839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9777839Snilay@cs.wisc.edu if "c_code" not in action: 9787839Snilay@cs.wisc.edu continue 9797839Snilay@cs.wisc.edu 9807839Snilay@cs.wisc.edu code(''' 9817839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9827839Snilay@cs.wisc.eduvoid 98311025Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, Addr addr) 9847839Snilay@cs.wisc.edu{ 9858055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9867839Snilay@cs.wisc.edu ${{action["c_code"]}} 9877839Snilay@cs.wisc.edu} 9887839Snilay@cs.wisc.edu 9897839Snilay@cs.wisc.edu''') 9907839Snilay@cs.wisc.edu else: 9917839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9927839Snilay@cs.wisc.edu if "c_code" not in action: 9937839Snilay@cs.wisc.edu continue 9947839Snilay@cs.wisc.edu 9957839Snilay@cs.wisc.edu code(''' 9966657Snate@binkert.org/** \\brief ${{action.desc}} */ 9977007Snate@binkert.orgvoid 99811025Snilay@cs.wisc.edu$c_ident::${{action.ident}}(Addr addr) 9996657Snate@binkert.org{ 10008055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 10016657Snate@binkert.org ${{action["c_code"]}} 10026657Snate@binkert.org} 10036657Snate@binkert.org 10046657Snate@binkert.org''') 10058478Snilay@cs.wisc.edu for func in self.functions: 10068478Snilay@cs.wisc.edu code(func.generateCode()) 10078478Snilay@cs.wisc.edu 10089302Snilay@cs.wisc.edu # Function for functional writes to messages buffered in the controller 10099302Snilay@cs.wisc.edu code(''' 101010524Snilay@cs.wisc.eduint 10119302Snilay@cs.wisc.edu$c_ident::functionalWriteBuffers(PacketPtr& pkt) 10129302Snilay@cs.wisc.edu{ 101310524Snilay@cs.wisc.edu int num_functional_writes = 0; 10149302Snilay@cs.wisc.edu''') 10159302Snilay@cs.wisc.edu for var in self.objects: 10169302Snilay@cs.wisc.edu vtype = var.type 10179302Snilay@cs.wisc.edu if vtype.isBuffer: 101810305Snilay@cs.wisc.edu vid = "m_%s_ptr" % var.ident 10199302Snilay@cs.wisc.edu code('num_functional_writes += $vid->functionalWrite(pkt);') 102010311Snilay@cs.wisc.edu 102110311Snilay@cs.wisc.edu for var in self.config_parameters: 102210311Snilay@cs.wisc.edu vtype = var.type_ast.type 102310311Snilay@cs.wisc.edu if vtype.isBuffer: 102410311Snilay@cs.wisc.edu vid = "m_%s_ptr" % var.ident 102510311Snilay@cs.wisc.edu code('num_functional_writes += $vid->functionalWrite(pkt);') 102610311Snilay@cs.wisc.edu 10279302Snilay@cs.wisc.edu code(''' 10289302Snilay@cs.wisc.edu return num_functional_writes; 10299302Snilay@cs.wisc.edu} 10309302Snilay@cs.wisc.edu''') 10319302Snilay@cs.wisc.edu 10326657Snate@binkert.org code.write(path, "%s.cc" % c_ident) 10336657Snate@binkert.org 10349219Spower.jg@gmail.com def printCWakeup(self, path, includes): 10356657Snate@binkert.org '''Output the wakeup loop for the events''' 10366657Snate@binkert.org 10376999Snate@binkert.org code = self.symtab.codeFormatter() 10386657Snate@binkert.org ident = self.ident 10396657Snate@binkert.org 10409104Shestness@cs.utexas.edu outputRequest_types = True 10419104Shestness@cs.utexas.edu if len(self.request_types) == 0: 10429104Shestness@cs.utexas.edu outputRequest_types = False 10439104Shestness@cs.utexas.edu 10446657Snate@binkert.org code(''' 10456657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 10466657Snate@binkert.org// ${ident}: ${{self.short}} 10476657Snate@binkert.org 10488946Sandreas.hansson@arm.com#include <sys/types.h> 10498946Sandreas.hansson@arm.com#include <unistd.h> 10508946Sandreas.hansson@arm.com 10517832Snate@binkert.org#include <cassert> 105210972Sdavid.hashe@amd.com#include <typeinfo> 10537832Snate@binkert.org 105412334Sgabeblack@google.com#include "base/logging.hh" 105510972Sdavid.hashe@amd.com 105610972Sdavid.hashe@amd.com''') 105710972Sdavid.hashe@amd.com for f in self.debug_flags: 105810972Sdavid.hashe@amd.com code('#include "debug/${{f}}.hh"') 105910972Sdavid.hashe@amd.com code(''' 10608229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 10618229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 10628229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 106310972Sdavid.hashe@amd.com 10649104Shestness@cs.utexas.edu''') 10659104Shestness@cs.utexas.edu 10669104Shestness@cs.utexas.edu if outputRequest_types: 10679104Shestness@cs.utexas.edu code('''#include "mem/protocol/${ident}_RequestType.hh"''') 10689104Shestness@cs.utexas.edu 10699104Shestness@cs.utexas.edu code(''' 10708229Snate@binkert.org#include "mem/protocol/Types.hh" 107111108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh" 107210972Sdavid.hashe@amd.com 10739219Spower.jg@gmail.com''') 10749219Spower.jg@gmail.com 10759219Spower.jg@gmail.com 10769219Spower.jg@gmail.com for include_path in includes: 10779219Spower.jg@gmail.com code('#include "${{include_path}}"') 10789219Spower.jg@gmail.com 107910963Sdavid.hashe@amd.com port_to_buf_map, in_msg_bufs, msg_bufs = self.getBufferMaps(ident) 108010963Sdavid.hashe@amd.com 10819219Spower.jg@gmail.com code(''' 10826657Snate@binkert.org 10837055Snate@binkert.orgusing namespace std; 10847055Snate@binkert.org 10857007Snate@binkert.orgvoid 10867007Snate@binkert.org${ident}_Controller::wakeup() 10876657Snate@binkert.org{ 10886657Snate@binkert.org int counter = 0; 10896657Snate@binkert.org while (true) { 109010963Sdavid.hashe@amd.com unsigned char rejected[${{len(msg_bufs)}}]; 109110963Sdavid.hashe@amd.com memset(rejected, 0, sizeof(unsigned char)*${{len(msg_bufs)}}); 10926657Snate@binkert.org // Some cases will put us into an infinite loop without this limit 10936657Snate@binkert.org assert(counter <= m_transitions_per_cycle); 10946657Snate@binkert.org if (counter == m_transitions_per_cycle) { 10957007Snate@binkert.org // Count how often we are fully utilized 10969496Snilay@cs.wisc.edu m_fully_busy_cycles++; 10977007Snate@binkert.org 10987007Snate@binkert.org // Wakeup in another cycle and try again 10999499Snilay@cs.wisc.edu scheduleEvent(Cycles(1)); 11006657Snate@binkert.org break; 11016657Snate@binkert.org } 11026657Snate@binkert.org''') 11036657Snate@binkert.org 11046657Snate@binkert.org code.indent() 11056657Snate@binkert.org code.indent() 11066657Snate@binkert.org 11076657Snate@binkert.org # InPorts 11086657Snate@binkert.org # 11096657Snate@binkert.org for port in self.in_ports: 11106657Snate@binkert.org code.indent() 11116657Snate@binkert.org code('// ${ident}InPort $port') 11127567SBrad.Beckmann@amd.com if port.pairs.has_key("rank"): 11139996Snilay@cs.wisc.edu code('m_cur_in_port = ${{port.pairs["rank"]}};') 11147567SBrad.Beckmann@amd.com else: 11159996Snilay@cs.wisc.edu code('m_cur_in_port = 0;') 111610963Sdavid.hashe@amd.com if port in port_to_buf_map: 111710963Sdavid.hashe@amd.com code('try {') 111810963Sdavid.hashe@amd.com code.indent() 11196657Snate@binkert.org code('${{port["c_code_in_port"]}}') 112010963Sdavid.hashe@amd.com 112110963Sdavid.hashe@amd.com if port in port_to_buf_map: 112210963Sdavid.hashe@amd.com code.dedent() 112310963Sdavid.hashe@amd.com code(''' 112410963Sdavid.hashe@amd.com } catch (const RejectException & e) { 112510963Sdavid.hashe@amd.com rejected[${{port_to_buf_map[port]}}]++; 112610963Sdavid.hashe@amd.com } 112710963Sdavid.hashe@amd.com''') 11286657Snate@binkert.org code.dedent() 11296657Snate@binkert.org code('') 11306657Snate@binkert.org 11316657Snate@binkert.org code.dedent() 11326657Snate@binkert.org code.dedent() 11336657Snate@binkert.org code(''' 113410963Sdavid.hashe@amd.com // If we got this far, we have nothing left todo or something went 113510963Sdavid.hashe@amd.com // wrong''') 113610963Sdavid.hashe@amd.com for buf_name, ports in in_msg_bufs.items(): 113710963Sdavid.hashe@amd.com if len(ports) > 1: 113810963Sdavid.hashe@amd.com # only produce checks when a buffer is shared by multiple ports 113910963Sdavid.hashe@amd.com code(''' 114011116Santhony.gutierrez@amd.com if (${{buf_name}}->isReady(clockEdge()) && rejected[${{port_to_buf_map[ports[0]]}}] == ${{len(ports)}}) 114110963Sdavid.hashe@amd.com { 114210963Sdavid.hashe@amd.com // no port claimed the message on the top of this buffer 114310963Sdavid.hashe@amd.com panic("Runtime Error at Ruby Time: %d. " 114410963Sdavid.hashe@amd.com "All ports rejected a message. " 114510963Sdavid.hashe@amd.com "You are probably sending a message type to this controller " 114610963Sdavid.hashe@amd.com "over a virtual network that do not define an in_port for " 114710963Sdavid.hashe@amd.com "the incoming message type.\\n", 114810963Sdavid.hashe@amd.com Cycles(1)); 114910963Sdavid.hashe@amd.com } 115010963Sdavid.hashe@amd.com''') 115110963Sdavid.hashe@amd.com code(''' 115210963Sdavid.hashe@amd.com break; 11536657Snate@binkert.org } 11546657Snate@binkert.org} 11556657Snate@binkert.org''') 11566657Snate@binkert.org 11576657Snate@binkert.org code.write(path, "%s_Wakeup.cc" % self.ident) 11586657Snate@binkert.org 11596657Snate@binkert.org def printCSwitch(self, path): 11606657Snate@binkert.org '''Output switch statement for transition table''' 11616657Snate@binkert.org 11626999Snate@binkert.org code = self.symtab.codeFormatter() 11636657Snate@binkert.org ident = self.ident 11646657Snate@binkert.org 11656657Snate@binkert.org code(''' 11666657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 11676657Snate@binkert.org// ${ident}: ${{self.short}} 11686657Snate@binkert.org 11697832Snate@binkert.org#include <cassert> 11707832Snate@binkert.org 117112334Sgabeblack@google.com#include "base/logging.hh" 11727832Snate@binkert.org#include "base/trace.hh" 11738232Snate@binkert.org#include "debug/ProtocolTrace.hh" 11748232Snate@binkert.org#include "debug/RubyGenerated.hh" 11758229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 11768229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 11778229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 11788229Snate@binkert.org#include "mem/protocol/Types.hh" 117911108Sdavid.hashe@amd.com#include "mem/ruby/system/RubySystem.hh" 11806657Snate@binkert.org 11816657Snate@binkert.org#define HASH_FUN(state, event) ((int(state)*${ident}_Event_NUM)+int(event)) 11826657Snate@binkert.org 11836657Snate@binkert.org#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str()) 11846657Snate@binkert.org#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str("")) 11856657Snate@binkert.org 11867007Snate@binkert.orgTransitionResult 11877007Snate@binkert.org${ident}_Controller::doTransition(${ident}_Event event, 11887839Snilay@cs.wisc.edu''') 11897839Snilay@cs.wisc.edu if self.EntryType != None: 11907839Snilay@cs.wisc.edu code(''' 11917839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}* m_cache_entry_ptr, 11927839Snilay@cs.wisc.edu''') 11937839Snilay@cs.wisc.edu if self.TBEType != None: 11947839Snilay@cs.wisc.edu code(''' 11957839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}* m_tbe_ptr, 11967839Snilay@cs.wisc.edu''') 11977839Snilay@cs.wisc.edu code(''' 119811025Snilay@cs.wisc.edu Addr addr) 11996657Snate@binkert.org{ 12007839Snilay@cs.wisc.edu''') 120110305Snilay@cs.wisc.edu code.indent() 120210305Snilay@cs.wisc.edu 12037839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 12048337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_tbe_ptr, m_cache_entry_ptr, addr);') 12057839Snilay@cs.wisc.edu elif self.TBEType != None: 12068337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_tbe_ptr, addr);') 12077839Snilay@cs.wisc.edu elif self.EntryType != None: 12088337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_cache_entry_ptr, addr);') 12097839Snilay@cs.wisc.edu else: 12108337Snilay@cs.wisc.edu code('${ident}_State state = getState(addr);') 12117839Snilay@cs.wisc.edu 12127839Snilay@cs.wisc.edu code(''' 121310305Snilay@cs.wisc.edu${ident}_State next_state = state; 12146657Snate@binkert.org 121511118Snilay@cs.wisc.eduDPRINTF(RubyGenerated, "%s, Time: %lld, state: %s, event: %s, addr: %#x\\n", 121610305Snilay@cs.wisc.edu *this, curCycle(), ${ident}_State_to_string(state), 121710305Snilay@cs.wisc.edu ${ident}_Event_to_string(event), addr); 12186657Snate@binkert.org 121910305Snilay@cs.wisc.eduTransitionResult result = 12207839Snilay@cs.wisc.edu''') 12217839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 12227839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_tbe_ptr, m_cache_entry_ptr, addr);') 12237839Snilay@cs.wisc.edu elif self.TBEType != None: 12247839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_tbe_ptr, addr);') 12257839Snilay@cs.wisc.edu elif self.EntryType != None: 12267839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_cache_entry_ptr, addr);') 12277839Snilay@cs.wisc.edu else: 12287839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, addr);') 12296657Snate@binkert.org 123011049Snilay@cs.wisc.edu port_to_buf_map, in_msg_bufs, msg_bufs = self.getBufferMaps(ident) 123111049Snilay@cs.wisc.edu 12327839Snilay@cs.wisc.edu code(''' 12336657Snate@binkert.org 123410305Snilay@cs.wisc.eduif (result == TransitionResult_Valid) { 123510305Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "next_state: %s\\n", 123610305Snilay@cs.wisc.edu ${ident}_State_to_string(next_state)); 123710305Snilay@cs.wisc.edu countTransition(state, event); 123810305Snilay@cs.wisc.edu 123911025Snilay@cs.wisc.edu DPRINTFR(ProtocolTrace, "%15d %3s %10s%20s %6s>%-6s %#x %s\\n", 124010305Snilay@cs.wisc.edu curTick(), m_version, "${ident}", 124110305Snilay@cs.wisc.edu ${ident}_Event_to_string(event), 124210305Snilay@cs.wisc.edu ${ident}_State_to_string(state), 124310305Snilay@cs.wisc.edu ${ident}_State_to_string(next_state), 124411118Snilay@cs.wisc.edu printAddress(addr), GET_TRANSITION_COMMENT()); 124510305Snilay@cs.wisc.edu 124610305Snilay@cs.wisc.edu CLEAR_TRANSITION_COMMENT(); 12477839Snilay@cs.wisc.edu''') 12487839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 12498337Snilay@cs.wisc.edu code('setState(m_tbe_ptr, m_cache_entry_ptr, addr, next_state);') 12508341Snilay@cs.wisc.edu code('setAccessPermission(m_cache_entry_ptr, addr, next_state);') 12517839Snilay@cs.wisc.edu elif self.TBEType != None: 12528337Snilay@cs.wisc.edu code('setState(m_tbe_ptr, addr, next_state);') 12538341Snilay@cs.wisc.edu code('setAccessPermission(addr, next_state);') 12547839Snilay@cs.wisc.edu elif self.EntryType != None: 12558337Snilay@cs.wisc.edu code('setState(m_cache_entry_ptr, addr, next_state);') 12568341Snilay@cs.wisc.edu code('setAccessPermission(m_cache_entry_ptr, addr, next_state);') 12577839Snilay@cs.wisc.edu else: 12588337Snilay@cs.wisc.edu code('setState(addr, next_state);') 12598341Snilay@cs.wisc.edu code('setAccessPermission(addr, next_state);') 12607839Snilay@cs.wisc.edu 12617839Snilay@cs.wisc.edu code(''' 126210305Snilay@cs.wisc.edu} else if (result == TransitionResult_ResourceStall) { 126311025Snilay@cs.wisc.edu DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %#x %s\\n", 126410305Snilay@cs.wisc.edu curTick(), m_version, "${ident}", 126510305Snilay@cs.wisc.edu ${ident}_Event_to_string(event), 126610305Snilay@cs.wisc.edu ${ident}_State_to_string(state), 126710305Snilay@cs.wisc.edu ${ident}_State_to_string(next_state), 126811118Snilay@cs.wisc.edu printAddress(addr), "Resource Stall"); 126910305Snilay@cs.wisc.edu} else if (result == TransitionResult_ProtocolStall) { 127010305Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "stalling\\n"); 127111025Snilay@cs.wisc.edu DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %#x %s\\n", 127210305Snilay@cs.wisc.edu curTick(), m_version, "${ident}", 127310305Snilay@cs.wisc.edu ${ident}_Event_to_string(event), 127410305Snilay@cs.wisc.edu ${ident}_State_to_string(state), 127510305Snilay@cs.wisc.edu ${ident}_State_to_string(next_state), 127611118Snilay@cs.wisc.edu printAddress(addr), "Protocol Stall"); 127710305Snilay@cs.wisc.edu} 12786657Snate@binkert.org 127910305Snilay@cs.wisc.edureturn result; 128010305Snilay@cs.wisc.edu''') 128110305Snilay@cs.wisc.edu code.dedent() 128210305Snilay@cs.wisc.edu code(''' 12836657Snate@binkert.org} 12846657Snate@binkert.org 12857007Snate@binkert.orgTransitionResult 12867007Snate@binkert.org${ident}_Controller::doTransitionWorker(${ident}_Event event, 12877007Snate@binkert.org ${ident}_State state, 12887007Snate@binkert.org ${ident}_State& next_state, 12897839Snilay@cs.wisc.edu''') 12907839Snilay@cs.wisc.edu 12917839Snilay@cs.wisc.edu if self.TBEType != None: 12927839Snilay@cs.wisc.edu code(''' 12937839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}*& m_tbe_ptr, 12947839Snilay@cs.wisc.edu''') 12957839Snilay@cs.wisc.edu if self.EntryType != None: 12967839Snilay@cs.wisc.edu code(''' 12977839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, 12987839Snilay@cs.wisc.edu''') 12997839Snilay@cs.wisc.edu code(''' 130011025Snilay@cs.wisc.edu Addr addr) 13016657Snate@binkert.org{ 13026657Snate@binkert.org switch(HASH_FUN(state, event)) { 13036657Snate@binkert.org''') 13046657Snate@binkert.org 13056657Snate@binkert.org # This map will allow suppress generating duplicate code 13066657Snate@binkert.org cases = orderdict() 13076657Snate@binkert.org 13086657Snate@binkert.org for trans in self.transitions: 13096657Snate@binkert.org case_string = "%s_State_%s, %s_Event_%s" % \ 13106657Snate@binkert.org (self.ident, trans.state.ident, self.ident, trans.event.ident) 13116657Snate@binkert.org 13126999Snate@binkert.org case = self.symtab.codeFormatter() 13136657Snate@binkert.org # Only set next_state if it changes 13146657Snate@binkert.org if trans.state != trans.nextState: 131510964Sdavid.hashe@amd.com if trans.nextState.isWildcard(): 131610964Sdavid.hashe@amd.com # When * is encountered as an end state of a transition, 131710964Sdavid.hashe@amd.com # the next state is determined by calling the 131810964Sdavid.hashe@amd.com # machine-specific getNextState function. The next state 131910964Sdavid.hashe@amd.com # is determined before any actions of the transition 132010964Sdavid.hashe@amd.com # execute, and therefore the next state calculation cannot 132110964Sdavid.hashe@amd.com # depend on any of the transitionactions. 132210964Sdavid.hashe@amd.com case('next_state = getNextState(addr);') 132310964Sdavid.hashe@amd.com else: 132410964Sdavid.hashe@amd.com ns_ident = trans.nextState.ident 132510964Sdavid.hashe@amd.com case('next_state = ${ident}_State_${ns_ident};') 13266657Snate@binkert.org 13276657Snate@binkert.org actions = trans.actions 13289104Shestness@cs.utexas.edu request_types = trans.request_types 13296657Snate@binkert.org 13306657Snate@binkert.org # Check for resources 13316657Snate@binkert.org case_sorter = [] 13326657Snate@binkert.org res = trans.resources 13336657Snate@binkert.org for key,val in res.iteritems(): 133410228Snilay@cs.wisc.edu val = ''' 133511111Snilay@cs.wisc.eduif (!%s.areNSlotsAvailable(%s, clockEdge())) 13366657Snate@binkert.org return TransitionResult_ResourceStall; 13376657Snate@binkert.org''' % (key.code, val) 13386657Snate@binkert.org case_sorter.append(val) 13396657Snate@binkert.org 13409105SBrad.Beckmann@amd.com # Check all of the request_types for resource constraints 13419105SBrad.Beckmann@amd.com for request_type in request_types: 13429105SBrad.Beckmann@amd.com val = ''' 13439105SBrad.Beckmann@amd.comif (!checkResourceAvailable(%s_RequestType_%s, addr)) { 13449105SBrad.Beckmann@amd.com return TransitionResult_ResourceStall; 13459105SBrad.Beckmann@amd.com} 13469105SBrad.Beckmann@amd.com''' % (self.ident, request_type.ident) 13479105SBrad.Beckmann@amd.com case_sorter.append(val) 13486657Snate@binkert.org 13496657Snate@binkert.org # Emit the code sequences in a sorted order. This makes the 13506657Snate@binkert.org # output deterministic (without this the output order can vary 13516657Snate@binkert.org # since Map's keys() on a vector of pointers is not deterministic 13526657Snate@binkert.org for c in sorted(case_sorter): 13536657Snate@binkert.org case("$c") 13546657Snate@binkert.org 13559104Shestness@cs.utexas.edu # Record access types for this transition 13569104Shestness@cs.utexas.edu for request_type in request_types: 13579104Shestness@cs.utexas.edu case('recordRequestType(${ident}_RequestType_${{request_type.ident}}, addr);') 13589104Shestness@cs.utexas.edu 13596657Snate@binkert.org # Figure out if we stall 13606657Snate@binkert.org stall = False 13616657Snate@binkert.org for action in actions: 13626657Snate@binkert.org if action.ident == "z_stall": 13636657Snate@binkert.org stall = True 13646657Snate@binkert.org break 13656657Snate@binkert.org 13666657Snate@binkert.org if stall: 13676657Snate@binkert.org case('return TransitionResult_ProtocolStall;') 13686657Snate@binkert.org else: 13697839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 13707839Snilay@cs.wisc.edu for action in actions: 13717839Snilay@cs.wisc.edu case('${{action.ident}}(m_tbe_ptr, m_cache_entry_ptr, addr);') 13727839Snilay@cs.wisc.edu elif self.TBEType != None: 13737839Snilay@cs.wisc.edu for action in actions: 13747839Snilay@cs.wisc.edu case('${{action.ident}}(m_tbe_ptr, addr);') 13757839Snilay@cs.wisc.edu elif self.EntryType != None: 13767839Snilay@cs.wisc.edu for action in actions: 13777839Snilay@cs.wisc.edu case('${{action.ident}}(m_cache_entry_ptr, addr);') 13787839Snilay@cs.wisc.edu else: 13797839Snilay@cs.wisc.edu for action in actions: 13807839Snilay@cs.wisc.edu case('${{action.ident}}(addr);') 13816657Snate@binkert.org case('return TransitionResult_Valid;') 13826657Snate@binkert.org 13836657Snate@binkert.org case = str(case) 13846657Snate@binkert.org 13856657Snate@binkert.org # Look to see if this transition code is unique. 13866657Snate@binkert.org if case not in cases: 13876657Snate@binkert.org cases[case] = [] 13886657Snate@binkert.org 13896657Snate@binkert.org cases[case].append(case_string) 13906657Snate@binkert.org 13916657Snate@binkert.org # Walk through all of the unique code blocks and spit out the 13926657Snate@binkert.org # corresponding case statement elements 13936657Snate@binkert.org for case,transitions in cases.iteritems(): 13946657Snate@binkert.org # Iterative over all the multiple transitions that share 13956657Snate@binkert.org # the same code 13966657Snate@binkert.org for trans in transitions: 13976657Snate@binkert.org code(' case HASH_FUN($trans):') 139810305Snilay@cs.wisc.edu code(' $case\n') 13996657Snate@binkert.org 14006657Snate@binkert.org code(''' 14016657Snate@binkert.org default: 140210962SBrad.Beckmann@amd.com panic("Invalid transition\\n" 140312612Sjason@lowepower.com "%s time: %d addr: %#x event: %s state: %s\\n", 14049465Snilay@cs.wisc.edu name(), curCycle(), addr, event, state); 14056657Snate@binkert.org } 140610305Snilay@cs.wisc.edu 14076657Snate@binkert.org return TransitionResult_Valid; 14086657Snate@binkert.org} 14096657Snate@binkert.org''') 14106657Snate@binkert.org code.write(path, "%s_Transitions.cc" % self.ident) 14116657Snate@binkert.org 14126657Snate@binkert.org 14136657Snate@binkert.org # ************************** 14146657Snate@binkert.org # ******* HTML Files ******* 14156657Snate@binkert.org # ************************** 14167007Snate@binkert.org def frameRef(self, click_href, click_target, over_href, over_num, text): 14176999Snate@binkert.org code = self.symtab.codeFormatter(fix_newlines=False) 14187007Snate@binkert.org code("""<A href=\"$click_href\" target=\"$click_target\" onmouseover=\" 14197007Snate@binkert.org if (parent.frames[$over_num].location != parent.location + '$over_href') { 14207007Snate@binkert.org parent.frames[$over_num].location='$over_href' 14217007Snate@binkert.org }\"> 14227007Snate@binkert.org ${{html.formatShorthand(text)}} 14237007Snate@binkert.org </A>""") 14246657Snate@binkert.org return str(code) 14256657Snate@binkert.org 14266657Snate@binkert.org def writeHTMLFiles(self, path): 14276657Snate@binkert.org # Create table with no row hilighted 14286657Snate@binkert.org self.printHTMLTransitions(path, None) 14296657Snate@binkert.org 14306657Snate@binkert.org # Generate transition tables 14316657Snate@binkert.org for state in self.states.itervalues(): 14326657Snate@binkert.org self.printHTMLTransitions(path, state) 14336657Snate@binkert.org 14346657Snate@binkert.org # Generate action descriptions 14356657Snate@binkert.org for action in self.actions.itervalues(): 14366657Snate@binkert.org name = "%s_action_%s.html" % (self.ident, action.ident) 14376657Snate@binkert.org code = html.createSymbol(action, "Action") 14386657Snate@binkert.org code.write(path, name) 14396657Snate@binkert.org 14406657Snate@binkert.org # Generate state descriptions 14416657Snate@binkert.org for state in self.states.itervalues(): 14426657Snate@binkert.org name = "%s_State_%s.html" % (self.ident, state.ident) 14436657Snate@binkert.org code = html.createSymbol(state, "State") 14446657Snate@binkert.org code.write(path, name) 14456657Snate@binkert.org 14466657Snate@binkert.org # Generate event descriptions 14476657Snate@binkert.org for event in self.events.itervalues(): 14486657Snate@binkert.org name = "%s_Event_%s.html" % (self.ident, event.ident) 14496657Snate@binkert.org code = html.createSymbol(event, "Event") 14506657Snate@binkert.org code.write(path, name) 14516657Snate@binkert.org 14526657Snate@binkert.org def printHTMLTransitions(self, path, active_state): 14536999Snate@binkert.org code = self.symtab.codeFormatter() 14546657Snate@binkert.org 14556657Snate@binkert.org code(''' 14567007Snate@binkert.org<HTML> 14577007Snate@binkert.org<BODY link="blue" vlink="blue"> 14586657Snate@binkert.org 14596657Snate@binkert.org<H1 align="center">${{html.formatShorthand(self.short)}}: 14606657Snate@binkert.org''') 14616657Snate@binkert.org code.indent() 14626657Snate@binkert.org for i,machine in enumerate(self.symtab.getAllType(StateMachine)): 14636657Snate@binkert.org mid = machine.ident 14646657Snate@binkert.org if i != 0: 14656657Snate@binkert.org extra = " - " 14666657Snate@binkert.org else: 14676657Snate@binkert.org extra = "" 14686657Snate@binkert.org if machine == self: 14696657Snate@binkert.org code('$extra$mid') 14706657Snate@binkert.org else: 14716657Snate@binkert.org code('$extra<A target="Table" href="${mid}_table.html">$mid</A>') 14726657Snate@binkert.org code.dedent() 14736657Snate@binkert.org 14746657Snate@binkert.org code(""" 14756657Snate@binkert.org</H1> 14766657Snate@binkert.org 14776657Snate@binkert.org<TABLE border=1> 14786657Snate@binkert.org<TR> 14796657Snate@binkert.org <TH> </TH> 14806657Snate@binkert.org""") 14816657Snate@binkert.org 14826657Snate@binkert.org for event in self.events.itervalues(): 14836657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 14846657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 14856657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 14866657Snate@binkert.org 14876657Snate@binkert.org code('</TR>') 14886657Snate@binkert.org # -- Body of table 14896657Snate@binkert.org for state in self.states.itervalues(): 14906657Snate@binkert.org # -- Each row 14916657Snate@binkert.org if state == active_state: 14926657Snate@binkert.org color = "yellow" 14936657Snate@binkert.org else: 14946657Snate@binkert.org color = "white" 14956657Snate@binkert.org 14966657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 14976657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 14986657Snate@binkert.org text = html.formatShorthand(state.short) 14996657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 15006657Snate@binkert.org code(''' 15016657Snate@binkert.org<TR> 15026657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 15036657Snate@binkert.org''') 15046657Snate@binkert.org 15056657Snate@binkert.org # -- One column for each event 15066657Snate@binkert.org for event in self.events.itervalues(): 15076657Snate@binkert.org trans = self.table.get((state,event), None) 15086657Snate@binkert.org if trans is None: 15096657Snate@binkert.org # This is the no transition case 15106657Snate@binkert.org if state == active_state: 15116657Snate@binkert.org color = "#C0C000" 15126657Snate@binkert.org else: 15136657Snate@binkert.org color = "lightgrey" 15146657Snate@binkert.org 15156657Snate@binkert.org code('<TD bgcolor=$color> </TD>') 15166657Snate@binkert.org continue 15176657Snate@binkert.org 15186657Snate@binkert.org next = trans.nextState 15196657Snate@binkert.org stall_action = False 15206657Snate@binkert.org 15216657Snate@binkert.org # -- Get the actions 15226657Snate@binkert.org for action in trans.actions: 15236657Snate@binkert.org if action.ident == "z_stall" or \ 15246657Snate@binkert.org action.ident == "zz_recycleMandatoryQueue": 15256657Snate@binkert.org stall_action = True 15266657Snate@binkert.org 15276657Snate@binkert.org # -- Print out "actions/next-state" 15286657Snate@binkert.org if stall_action: 15296657Snate@binkert.org if state == active_state: 15306657Snate@binkert.org color = "#C0C000" 15316657Snate@binkert.org else: 15326657Snate@binkert.org color = "lightgrey" 15336657Snate@binkert.org 15346657Snate@binkert.org elif active_state and next.ident == active_state.ident: 15356657Snate@binkert.org color = "aqua" 15366657Snate@binkert.org elif state == active_state: 15376657Snate@binkert.org color = "yellow" 15386657Snate@binkert.org else: 15396657Snate@binkert.org color = "white" 15406657Snate@binkert.org 15416657Snate@binkert.org code('<TD bgcolor=$color>') 15426657Snate@binkert.org for action in trans.actions: 15436657Snate@binkert.org href = "%s_action_%s.html" % (self.ident, action.ident) 15446657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", 15456657Snate@binkert.org action.short) 15467007Snate@binkert.org code(' $ref') 15476657Snate@binkert.org if next != state: 15486657Snate@binkert.org if trans.actions: 15496657Snate@binkert.org code('/') 15506657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, next.ident) 15516657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, next.ident) 15526657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", next.short) 15536657Snate@binkert.org code("$ref") 15547007Snate@binkert.org code("</TD>") 15556657Snate@binkert.org 15566657Snate@binkert.org # -- Each row 15576657Snate@binkert.org if state == active_state: 15586657Snate@binkert.org color = "yellow" 15596657Snate@binkert.org else: 15606657Snate@binkert.org color = "white" 15616657Snate@binkert.org 15626657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 15636657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 15646657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 15656657Snate@binkert.org code(''' 15666657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 15676657Snate@binkert.org</TR> 15686657Snate@binkert.org''') 15696657Snate@binkert.org code(''' 157010917Sbrandon.potter@amd.com<!- Column footer-> 15716657Snate@binkert.org<TR> 15726657Snate@binkert.org <TH> </TH> 15736657Snate@binkert.org''') 15746657Snate@binkert.org 15756657Snate@binkert.org for event in self.events.itervalues(): 15766657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 15776657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 15786657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 15796657Snate@binkert.org code(''' 15806657Snate@binkert.org</TR> 15816657Snate@binkert.org</TABLE> 15826657Snate@binkert.org</BODY></HTML> 15836657Snate@binkert.org''') 15846657Snate@binkert.org 15856657Snate@binkert.org 15866657Snate@binkert.org if active_state: 15876657Snate@binkert.org name = "%s_table_%s.html" % (self.ident, active_state.ident) 15886657Snate@binkert.org else: 15896657Snate@binkert.org name = "%s_table.html" % self.ident 15906657Snate@binkert.org code.write(path, name) 15916657Snate@binkert.org 15926657Snate@binkert.org__all__ = [ "StateMachine" ] 1593