StateMachine.py revision 8232
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 36657Snate@binkert.org# All rights reserved. 46657Snate@binkert.org# 56657Snate@binkert.org# Redistribution and use in source and binary forms, with or without 66657Snate@binkert.org# modification, are permitted provided that the following conditions are 76657Snate@binkert.org# met: redistributions of source code must retain the above copyright 86657Snate@binkert.org# notice, this list of conditions and the following disclaimer; 96657Snate@binkert.org# redistributions in binary form must reproduce the above copyright 106657Snate@binkert.org# notice, this list of conditions and the following disclaimer in the 116657Snate@binkert.org# documentation and/or other materials provided with the distribution; 126657Snate@binkert.org# neither the name of the copyright holders nor the names of its 136657Snate@binkert.org# contributors may be used to endorse or promote products derived from 146657Snate@binkert.org# this software without specific prior written permission. 156657Snate@binkert.org# 166657Snate@binkert.org# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176657Snate@binkert.org# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186657Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196657Snate@binkert.org# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206657Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216657Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226657Snate@binkert.org# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236657Snate@binkert.org# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246657Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256657Snate@binkert.org# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266657Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276657Snate@binkert.org 286999Snate@binkert.orgfrom m5.util import orderdict 296657Snate@binkert.org 306657Snate@binkert.orgfrom slicc.symbols.Symbol import Symbol 316657Snate@binkert.orgfrom slicc.symbols.Var import Var 326657Snate@binkert.orgimport slicc.generate.html as html 338189SLisa.Hsu@amd.comimport re 346657Snate@binkert.org 356882SBrad.Beckmann@amd.compython_class_map = {"int": "Int", 367055Snate@binkert.org "std::string": "String", 376882SBrad.Beckmann@amd.com "bool": "Bool", 386882SBrad.Beckmann@amd.com "CacheMemory": "RubyCache", 398191SLisa.Hsu@amd.com "WireBuffer": "RubyWireBuffer", 406882SBrad.Beckmann@amd.com "Sequencer": "RubySequencer", 416882SBrad.Beckmann@amd.com "DirectoryMemory": "RubyDirectoryMemory", 426882SBrad.Beckmann@amd.com "MemoryControl": "RubyMemoryControl", 436888SBrad.Beckmann@amd.com "DMASequencer": "DMASequencer" 446882SBrad.Beckmann@amd.com } 456882SBrad.Beckmann@amd.com 466657Snate@binkert.orgclass StateMachine(Symbol): 476657Snate@binkert.org def __init__(self, symtab, ident, location, pairs, config_parameters): 486657Snate@binkert.org super(StateMachine, self).__init__(symtab, ident, location, pairs) 496657Snate@binkert.org self.table = None 506657Snate@binkert.org self.config_parameters = config_parameters 517839Snilay@cs.wisc.edu 526657Snate@binkert.org for param in config_parameters: 536882SBrad.Beckmann@amd.com if param.pointer: 546882SBrad.Beckmann@amd.com var = Var(symtab, param.name, location, param.type_ast.type, 556882SBrad.Beckmann@amd.com "(*m_%s_ptr)" % param.name, {}, self) 566882SBrad.Beckmann@amd.com else: 576882SBrad.Beckmann@amd.com var = Var(symtab, param.name, location, param.type_ast.type, 586882SBrad.Beckmann@amd.com "m_%s" % param.name, {}, self) 596657Snate@binkert.org self.symtab.registerSym(param.name, var) 606657Snate@binkert.org 616657Snate@binkert.org self.states = orderdict() 626657Snate@binkert.org self.events = orderdict() 636657Snate@binkert.org self.actions = orderdict() 646657Snate@binkert.org self.transitions = [] 656657Snate@binkert.org self.in_ports = [] 666657Snate@binkert.org self.functions = [] 676657Snate@binkert.org self.objects = [] 687839Snilay@cs.wisc.edu self.TBEType = None 697839Snilay@cs.wisc.edu self.EntryType = None 706657Snate@binkert.org 716657Snate@binkert.org self.message_buffer_names = [] 726657Snate@binkert.org 736657Snate@binkert.org def __repr__(self): 746657Snate@binkert.org return "[StateMachine: %s]" % self.ident 756657Snate@binkert.org 766657Snate@binkert.org def addState(self, state): 776657Snate@binkert.org assert self.table is None 786657Snate@binkert.org self.states[state.ident] = state 796657Snate@binkert.org 806657Snate@binkert.org def addEvent(self, event): 816657Snate@binkert.org assert self.table is None 826657Snate@binkert.org self.events[event.ident] = event 836657Snate@binkert.org 846657Snate@binkert.org def addAction(self, action): 856657Snate@binkert.org assert self.table is None 866657Snate@binkert.org 876657Snate@binkert.org # Check for duplicate action 886657Snate@binkert.org for other in self.actions.itervalues(): 896657Snate@binkert.org if action.ident == other.ident: 906779SBrad.Beckmann@amd.com action.warning("Duplicate action definition: %s" % action.ident) 916657Snate@binkert.org action.error("Duplicate action definition: %s" % action.ident) 926657Snate@binkert.org if action.short == other.short: 936657Snate@binkert.org other.warning("Duplicate action shorthand: %s" % other.ident) 946657Snate@binkert.org other.warning(" shorthand = %s" % other.short) 956657Snate@binkert.org action.warning("Duplicate action shorthand: %s" % action.ident) 966657Snate@binkert.org action.error(" shorthand = %s" % action.short) 976657Snate@binkert.org 986657Snate@binkert.org self.actions[action.ident] = action 996657Snate@binkert.org 1006657Snate@binkert.org def addTransition(self, trans): 1016657Snate@binkert.org assert self.table is None 1026657Snate@binkert.org self.transitions.append(trans) 1036657Snate@binkert.org 1046657Snate@binkert.org def addInPort(self, var): 1056657Snate@binkert.org self.in_ports.append(var) 1066657Snate@binkert.org 1076657Snate@binkert.org def addFunc(self, func): 1086657Snate@binkert.org # register func in the symbol table 1096657Snate@binkert.org self.symtab.registerSym(str(func), func) 1106657Snate@binkert.org self.functions.append(func) 1116657Snate@binkert.org 1126657Snate@binkert.org def addObject(self, obj): 1136657Snate@binkert.org self.objects.append(obj) 1146657Snate@binkert.org 1157839Snilay@cs.wisc.edu def addType(self, type): 1167839Snilay@cs.wisc.edu type_ident = '%s' % type.c_ident 1177839Snilay@cs.wisc.edu 1187839Snilay@cs.wisc.edu if type_ident == "%s_TBE" %self.ident: 1197839Snilay@cs.wisc.edu if self.TBEType != None: 1207839Snilay@cs.wisc.edu self.error("Multiple Transaction Buffer types in a " \ 1217839Snilay@cs.wisc.edu "single machine."); 1227839Snilay@cs.wisc.edu self.TBEType = type 1237839Snilay@cs.wisc.edu 1247839Snilay@cs.wisc.edu elif "interface" in type and "AbstractCacheEntry" == type["interface"]: 1257839Snilay@cs.wisc.edu if self.EntryType != None: 1267839Snilay@cs.wisc.edu self.error("Multiple AbstractCacheEntry types in a " \ 1277839Snilay@cs.wisc.edu "single machine."); 1287839Snilay@cs.wisc.edu self.EntryType = type 1297839Snilay@cs.wisc.edu 1306657Snate@binkert.org # Needs to be called before accessing the table 1316657Snate@binkert.org def buildTable(self): 1326657Snate@binkert.org assert self.table is None 1336657Snate@binkert.org 1346657Snate@binkert.org table = {} 1356657Snate@binkert.org 1366657Snate@binkert.org for trans in self.transitions: 1376657Snate@binkert.org # Track which actions we touch so we know if we use them 1386657Snate@binkert.org # all -- really this should be done for all symbols as 1396657Snate@binkert.org # part of the symbol table, then only trigger it for 1406657Snate@binkert.org # Actions, States, Events, etc. 1416657Snate@binkert.org 1426657Snate@binkert.org for action in trans.actions: 1436657Snate@binkert.org action.used = True 1446657Snate@binkert.org 1456657Snate@binkert.org index = (trans.state, trans.event) 1466657Snate@binkert.org if index in table: 1476657Snate@binkert.org table[index].warning("Duplicate transition: %s" % table[index]) 1486657Snate@binkert.org trans.error("Duplicate transition: %s" % trans) 1496657Snate@binkert.org table[index] = trans 1506657Snate@binkert.org 1516657Snate@binkert.org # Look at all actions to make sure we used them all 1526657Snate@binkert.org for action in self.actions.itervalues(): 1536657Snate@binkert.org if not action.used: 1546657Snate@binkert.org error_msg = "Unused action: %s" % action.ident 1556657Snate@binkert.org if "desc" in action: 1566657Snate@binkert.org error_msg += ", " + action.desc 1576657Snate@binkert.org action.warning(error_msg) 1586657Snate@binkert.org self.table = table 1596657Snate@binkert.org 1606657Snate@binkert.org def writeCodeFiles(self, path): 1616877Ssteve.reinhardt@amd.com self.printControllerPython(path) 1626657Snate@binkert.org self.printControllerHH(path) 1636657Snate@binkert.org self.printControllerCC(path) 1646657Snate@binkert.org self.printCSwitch(path) 1656657Snate@binkert.org self.printCWakeup(path) 1666657Snate@binkert.org self.printProfilerCC(path) 1676657Snate@binkert.org self.printProfilerHH(path) 1687542SBrad.Beckmann@amd.com self.printProfileDumperCC(path) 1697542SBrad.Beckmann@amd.com self.printProfileDumperHH(path) 1706657Snate@binkert.org 1716657Snate@binkert.org for func in self.functions: 1726657Snate@binkert.org func.writeCodeFiles(path) 1736657Snate@binkert.org 1746877Ssteve.reinhardt@amd.com def printControllerPython(self, path): 1756999Snate@binkert.org code = self.symtab.codeFormatter() 1766877Ssteve.reinhardt@amd.com ident = self.ident 1776877Ssteve.reinhardt@amd.com py_ident = "%s_Controller" % ident 1786877Ssteve.reinhardt@amd.com c_ident = "%s_Controller" % self.ident 1796877Ssteve.reinhardt@amd.com code(''' 1806877Ssteve.reinhardt@amd.comfrom m5.params import * 1816877Ssteve.reinhardt@amd.comfrom m5.SimObject import SimObject 1826877Ssteve.reinhardt@amd.comfrom Controller import RubyController 1836877Ssteve.reinhardt@amd.com 1846877Ssteve.reinhardt@amd.comclass $py_ident(RubyController): 1856877Ssteve.reinhardt@amd.com type = '$py_ident' 1866877Ssteve.reinhardt@amd.com''') 1876877Ssteve.reinhardt@amd.com code.indent() 1886877Ssteve.reinhardt@amd.com for param in self.config_parameters: 1896877Ssteve.reinhardt@amd.com dflt_str = '' 1906877Ssteve.reinhardt@amd.com if param.default is not None: 1916877Ssteve.reinhardt@amd.com dflt_str = str(param.default) + ', ' 1926882SBrad.Beckmann@amd.com if python_class_map.has_key(param.type_ast.type.c_ident): 1936882SBrad.Beckmann@amd.com python_type = python_class_map[param.type_ast.type.c_ident] 1946882SBrad.Beckmann@amd.com code('${{param.name}} = Param.${{python_type}}(${dflt_str}"")') 1956882SBrad.Beckmann@amd.com else: 1966882SBrad.Beckmann@amd.com self.error("Unknown c++ to python class conversion for c++ " \ 1976882SBrad.Beckmann@amd.com "type: '%s'. Please update the python_class_map " \ 1986882SBrad.Beckmann@amd.com "in StateMachine.py", param.type_ast.type.c_ident) 1996877Ssteve.reinhardt@amd.com code.dedent() 2006877Ssteve.reinhardt@amd.com code.write(path, '%s.py' % py_ident) 2016877Ssteve.reinhardt@amd.com 2026877Ssteve.reinhardt@amd.com 2036657Snate@binkert.org def printControllerHH(self, path): 2046657Snate@binkert.org '''Output the method declarations for the class declaration''' 2056999Snate@binkert.org code = self.symtab.codeFormatter() 2066657Snate@binkert.org ident = self.ident 2076657Snate@binkert.org c_ident = "%s_Controller" % self.ident 2086657Snate@binkert.org 2096657Snate@binkert.org self.message_buffer_names = [] 2106657Snate@binkert.org 2116657Snate@binkert.org code(''' 2127007Snate@binkert.org/** \\file $c_ident.hh 2136657Snate@binkert.org * 2146657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__ 2156657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}" 2166657Snate@binkert.org */ 2176657Snate@binkert.org 2187007Snate@binkert.org#ifndef __${ident}_CONTROLLER_HH__ 2197007Snate@binkert.org#define __${ident}_CONTROLLER_HH__ 2206657Snate@binkert.org 2217002Snate@binkert.org#include <iostream> 2227002Snate@binkert.org#include <sstream> 2237002Snate@binkert.org#include <string> 2247002Snate@binkert.org 2258229Snate@binkert.org#include "mem/protocol/${ident}_ProfileDumper.hh" 2268229Snate@binkert.org#include "mem/protocol/${ident}_Profiler.hh" 2276657Snate@binkert.org#include "mem/protocol/TransitionResult.hh" 2286657Snate@binkert.org#include "mem/protocol/Types.hh" 2298229Snate@binkert.org#include "mem/ruby/common/Consumer.hh" 2308229Snate@binkert.org#include "mem/ruby/common/Global.hh" 2318229Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh" 2328229Snate@binkert.org#include "params/$c_ident.hh" 2336657Snate@binkert.org''') 2346657Snate@binkert.org 2356657Snate@binkert.org seen_types = set() 2366657Snate@binkert.org for var in self.objects: 2376793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 2386657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 2396657Snate@binkert.org seen_types.add(var.type.ident) 2406657Snate@binkert.org 2416657Snate@binkert.org # for adding information to the protocol debug trace 2426657Snate@binkert.org code(''' 2437002Snate@binkert.orgextern std::stringstream ${ident}_transitionComment; 2446657Snate@binkert.org 2457007Snate@binkert.orgclass $c_ident : public AbstractController 2467007Snate@binkert.org{ 2477007Snate@binkert.org// the coherence checker needs to call isBlockExclusive() and isBlockShared() 2487007Snate@binkert.org// making the Chip a friend class is an easy way to do this for now 2497007Snate@binkert.org 2506657Snate@binkert.orgpublic: 2516877Ssteve.reinhardt@amd.com typedef ${c_ident}Params Params; 2526877Ssteve.reinhardt@amd.com $c_ident(const Params *p); 2536657Snate@binkert.org static int getNumControllers(); 2546877Ssteve.reinhardt@amd.com void init(); 2556657Snate@binkert.org MessageBuffer* getMandatoryQueue() const; 2566657Snate@binkert.org const int & getVersion() const; 2577002Snate@binkert.org const std::string toString() const; 2587002Snate@binkert.org const std::string getName() const; 2596657Snate@binkert.org const MachineType getMachineType() const; 2607567SBrad.Beckmann@amd.com void stallBuffer(MessageBuffer* buf, Address addr); 2617567SBrad.Beckmann@amd.com void wakeUpBuffers(Address addr); 2627922SBrad.Beckmann@amd.com void wakeUpAllBuffers(); 2636881SBrad.Beckmann@amd.com void initNetworkPtr(Network* net_ptr) { m_net_ptr = net_ptr; } 2647002Snate@binkert.org void print(std::ostream& out) const; 2657002Snate@binkert.org void printConfig(std::ostream& out) const; 2666657Snate@binkert.org void wakeup(); 2677002Snate@binkert.org void printStats(std::ostream& out) const; 2686902SBrad.Beckmann@amd.com void clearStats(); 2696863Sdrh5@cs.wisc.edu void blockOnQueue(Address addr, MessageBuffer* port); 2706863Sdrh5@cs.wisc.edu void unblock(Address addr); 2717007Snate@binkert.org 2726657Snate@binkert.orgprivate: 2736657Snate@binkert.org''') 2746657Snate@binkert.org 2756657Snate@binkert.org code.indent() 2766657Snate@binkert.org # added by SS 2776657Snate@binkert.org for param in self.config_parameters: 2786882SBrad.Beckmann@amd.com if param.pointer: 2796882SBrad.Beckmann@amd.com code('${{param.type_ast.type}}* m_${{param.ident}}_ptr;') 2806882SBrad.Beckmann@amd.com else: 2816882SBrad.Beckmann@amd.com code('${{param.type_ast.type}} m_${{param.ident}};') 2826657Snate@binkert.org 2836657Snate@binkert.org code(''' 2846657Snate@binkert.orgint m_number_of_TBEs; 2856657Snate@binkert.org 2867007Snate@binkert.orgTransitionResult doTransition(${ident}_Event event, 2877839Snilay@cs.wisc.edu''') 2887839Snilay@cs.wisc.edu 2897839Snilay@cs.wisc.edu if self.EntryType != None: 2907839Snilay@cs.wisc.edu code(''' 2917839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}* m_cache_entry_ptr, 2927839Snilay@cs.wisc.edu''') 2937839Snilay@cs.wisc.edu if self.TBEType != None: 2947839Snilay@cs.wisc.edu code(''' 2957839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}* m_tbe_ptr, 2967839Snilay@cs.wisc.edu''') 2977839Snilay@cs.wisc.edu 2987839Snilay@cs.wisc.edu code(''' 2997007Snate@binkert.org const Address& addr); 3007007Snate@binkert.org 3017007Snate@binkert.orgTransitionResult doTransitionWorker(${ident}_Event event, 3027007Snate@binkert.org ${ident}_State state, 3037007Snate@binkert.org ${ident}_State& next_state, 3047839Snilay@cs.wisc.edu''') 3057839Snilay@cs.wisc.edu 3067839Snilay@cs.wisc.edu if self.TBEType != None: 3077839Snilay@cs.wisc.edu code(''' 3087839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}*& m_tbe_ptr, 3097839Snilay@cs.wisc.edu''') 3107839Snilay@cs.wisc.edu if self.EntryType != None: 3117839Snilay@cs.wisc.edu code(''' 3127839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, 3137839Snilay@cs.wisc.edu''') 3147839Snilay@cs.wisc.edu 3157839Snilay@cs.wisc.edu code(''' 3167007Snate@binkert.org const Address& addr); 3177007Snate@binkert.org 3187002Snate@binkert.orgstd::string m_name; 3196657Snate@binkert.orgint m_transitions_per_cycle; 3206657Snate@binkert.orgint m_buffer_size; 3216657Snate@binkert.orgint m_recycle_latency; 3227055Snate@binkert.orgstd::map<std::string, std::string> m_cfg; 3236657Snate@binkert.orgNodeID m_version; 3246657Snate@binkert.orgNetwork* m_net_ptr; 3256657Snate@binkert.orgMachineID m_machineID; 3266863Sdrh5@cs.wisc.edubool m_is_blocking; 3277055Snate@binkert.orgstd::map<Address, MessageBuffer*> m_block_map; 3287567SBrad.Beckmann@amd.comtypedef std::vector<MessageBuffer*> MsgVecType; 3297567SBrad.Beckmann@amd.comtypedef m5::hash_map< Address, MsgVecType* > WaitingBufType; 3307567SBrad.Beckmann@amd.comWaitingBufType m_waiting_buffers; 3317567SBrad.Beckmann@amd.comint m_max_in_port_rank; 3327567SBrad.Beckmann@amd.comint m_cur_in_port_rank; 3337542SBrad.Beckmann@amd.comstatic ${ident}_ProfileDumper s_profileDumper; 3347542SBrad.Beckmann@amd.com${ident}_Profiler m_profiler; 3356657Snate@binkert.orgstatic int m_num_controllers; 3367007Snate@binkert.org 3376657Snate@binkert.org// Internal functions 3386657Snate@binkert.org''') 3396657Snate@binkert.org 3406657Snate@binkert.org for func in self.functions: 3416657Snate@binkert.org proto = func.prototype 3426657Snate@binkert.org if proto: 3436657Snate@binkert.org code('$proto') 3446657Snate@binkert.org 3457839Snilay@cs.wisc.edu if self.EntryType != None: 3467839Snilay@cs.wisc.edu code(''' 3477839Snilay@cs.wisc.edu 3487839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable 3497839Snilay@cs.wisc.eduvoid set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry); 3507839Snilay@cs.wisc.eduvoid unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr); 3518086SBrad.Beckmann@amd.com// Set permissions for the cache_entry 3528086SBrad.Beckmann@amd.comvoid set_permission(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AccessPermission perm); 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 3587839Snilay@cs.wisc.edu// Set and Reset for tbe variable 3597839Snilay@cs.wisc.eduvoid set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${ident}_TBE* m_new_tbe); 3607839Snilay@cs.wisc.eduvoid unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr); 3617839Snilay@cs.wisc.edu''') 3627839Snilay@cs.wisc.edu 3636657Snate@binkert.org code(''' 3646657Snate@binkert.org 3656657Snate@binkert.org// Actions 3666657Snate@binkert.org''') 3677839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 3687839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3697839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3707839Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr);') 3717839Snilay@cs.wisc.edu elif self.TBEType != None: 3727839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3737839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3747839Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, const Address& addr);') 3757839Snilay@cs.wisc.edu elif self.EntryType != None: 3767839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3777839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3787839Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr);') 3797839Snilay@cs.wisc.edu else: 3807839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3817839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3827839Snilay@cs.wisc.edu code('void ${{action.ident}}(const Address& addr);') 3836657Snate@binkert.org 3846657Snate@binkert.org # the controller internal variables 3856657Snate@binkert.org code(''' 3866657Snate@binkert.org 3877007Snate@binkert.org// Objects 3886657Snate@binkert.org''') 3896657Snate@binkert.org for var in self.objects: 3906657Snate@binkert.org th = var.get("template_hack", "") 3916657Snate@binkert.org code('${{var.type.c_ident}}$th* m_${{var.c_ident}}_ptr;') 3926657Snate@binkert.org 3936657Snate@binkert.org if var.type.ident == "MessageBuffer": 3946657Snate@binkert.org self.message_buffer_names.append("m_%s_ptr" % var.c_ident) 3956657Snate@binkert.org 3966657Snate@binkert.org code.dedent() 3976657Snate@binkert.org code('};') 3987007Snate@binkert.org code('#endif // __${ident}_CONTROLLER_H__') 3996657Snate@binkert.org code.write(path, '%s.hh' % c_ident) 4006657Snate@binkert.org 4016657Snate@binkert.org def printControllerCC(self, path): 4026657Snate@binkert.org '''Output the actions for performing the actions''' 4036657Snate@binkert.org 4046999Snate@binkert.org code = self.symtab.codeFormatter() 4056657Snate@binkert.org ident = self.ident 4066657Snate@binkert.org c_ident = "%s_Controller" % self.ident 4076657Snate@binkert.org 4086657Snate@binkert.org code(''' 4097007Snate@binkert.org/** \\file $c_ident.cc 4106657Snate@binkert.org * 4116657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__ 4126657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}" 4136657Snate@binkert.org */ 4146657Snate@binkert.org 4157832Snate@binkert.org#include <cassert> 4167002Snate@binkert.org#include <sstream> 4177002Snate@binkert.org#include <string> 4187002Snate@binkert.org 4197056Snate@binkert.org#include "base/cprintf.hh" 4208232Snate@binkert.org#include "debug/RubyGenerated.hh" 4218232Snate@binkert.org#include "debug/RubySlicc.hh" 4226657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 4238229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 4246657Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 4256657Snate@binkert.org#include "mem/protocol/Types.hh" 4267056Snate@binkert.org#include "mem/ruby/common/Global.hh" 4277056Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_includes.hh" 4286657Snate@binkert.org#include "mem/ruby/system/System.hh" 4297002Snate@binkert.org 4307002Snate@binkert.orgusing namespace std; 4316657Snate@binkert.org''') 4326657Snate@binkert.org 4336657Snate@binkert.org # include object classes 4346657Snate@binkert.org seen_types = set() 4356657Snate@binkert.org for var in self.objects: 4366793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 4376657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 4386657Snate@binkert.org seen_types.add(var.type.ident) 4396657Snate@binkert.org 4406657Snate@binkert.org code(''' 4416877Ssteve.reinhardt@amd.com$c_ident * 4426877Ssteve.reinhardt@amd.com${c_ident}Params::create() 4436877Ssteve.reinhardt@amd.com{ 4446877Ssteve.reinhardt@amd.com return new $c_ident(this); 4456877Ssteve.reinhardt@amd.com} 4466877Ssteve.reinhardt@amd.com 4476657Snate@binkert.orgint $c_ident::m_num_controllers = 0; 4487542SBrad.Beckmann@amd.com${ident}_ProfileDumper $c_ident::s_profileDumper; 4496657Snate@binkert.org 4507007Snate@binkert.org// for adding information to the protocol debug trace 4516657Snate@binkert.orgstringstream ${ident}_transitionComment; 4526657Snate@binkert.org#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str) 4537007Snate@binkert.org 4546657Snate@binkert.org/** \\brief constructor */ 4556877Ssteve.reinhardt@amd.com$c_ident::$c_ident(const Params *p) 4566877Ssteve.reinhardt@amd.com : AbstractController(p) 4576657Snate@binkert.org{ 4586877Ssteve.reinhardt@amd.com m_version = p->version; 4596877Ssteve.reinhardt@amd.com m_transitions_per_cycle = p->transitions_per_cycle; 4606877Ssteve.reinhardt@amd.com m_buffer_size = p->buffer_size; 4616877Ssteve.reinhardt@amd.com m_recycle_latency = p->recycle_latency; 4626877Ssteve.reinhardt@amd.com m_number_of_TBEs = p->number_of_TBEs; 4636969SBrad.Beckmann@amd.com m_is_blocking = false; 4646657Snate@binkert.org''') 4657567SBrad.Beckmann@amd.com # 4667567SBrad.Beckmann@amd.com # max_port_rank is used to size vectors and thus should be one plus the 4677567SBrad.Beckmann@amd.com # largest port rank 4687567SBrad.Beckmann@amd.com # 4697567SBrad.Beckmann@amd.com max_port_rank = self.in_ports[0].pairs["max_port_rank"] + 1 4707567SBrad.Beckmann@amd.com code(' m_max_in_port_rank = $max_port_rank;') 4716657Snate@binkert.org code.indent() 4726882SBrad.Beckmann@amd.com 4736882SBrad.Beckmann@amd.com # 4746882SBrad.Beckmann@amd.com # After initializing the universal machine parameters, initialize the 4756882SBrad.Beckmann@amd.com # this machines config parameters. Also detemine if these configuration 4766882SBrad.Beckmann@amd.com # params include a sequencer. This information will be used later for 4776882SBrad.Beckmann@amd.com # contecting the sequencer back to the L1 cache controller. 4786882SBrad.Beckmann@amd.com # 4798189SLisa.Hsu@amd.com contains_dma_sequencer = False 4808189SLisa.Hsu@amd.com sequencers = [] 4816877Ssteve.reinhardt@amd.com for param in self.config_parameters: 4828189SLisa.Hsu@amd.com if param.name == "dma_sequencer": 4838189SLisa.Hsu@amd.com contains_dma_sequencer = True 4848189SLisa.Hsu@amd.com elif re.compile("sequencer").search(param.name): 4858189SLisa.Hsu@amd.com sequencers.append(param.name) 4866882SBrad.Beckmann@amd.com if param.pointer: 4876882SBrad.Beckmann@amd.com code('m_${{param.name}}_ptr = p->${{param.name}};') 4886882SBrad.Beckmann@amd.com else: 4896882SBrad.Beckmann@amd.com code('m_${{param.name}} = p->${{param.name}};') 4906882SBrad.Beckmann@amd.com 4916882SBrad.Beckmann@amd.com # 4926882SBrad.Beckmann@amd.com # For the l1 cache controller, add the special atomic support which 4936882SBrad.Beckmann@amd.com # includes passing the sequencer a pointer to the controller. 4946882SBrad.Beckmann@amd.com # 4956882SBrad.Beckmann@amd.com if self.ident == "L1Cache": 4968189SLisa.Hsu@amd.com if not sequencers: 4976882SBrad.Beckmann@amd.com self.error("The L1Cache controller must include the sequencer " \ 4986882SBrad.Beckmann@amd.com "configuration parameter") 4996882SBrad.Beckmann@amd.com 5008189SLisa.Hsu@amd.com for seq in sequencers: 5018189SLisa.Hsu@amd.com code(''' 5028189SLisa.Hsu@amd.comm_${{seq}}_ptr->setController(this); 5038189SLisa.Hsu@amd.com ''') 5046888SBrad.Beckmann@amd.com # 5056888SBrad.Beckmann@amd.com # For the DMA controller, pass the sequencer a pointer to the 5066888SBrad.Beckmann@amd.com # controller. 5076888SBrad.Beckmann@amd.com # 5086888SBrad.Beckmann@amd.com if self.ident == "DMA": 5098189SLisa.Hsu@amd.com if not contains_dma_sequencer: 5106888SBrad.Beckmann@amd.com self.error("The DMA controller must include the sequencer " \ 5116888SBrad.Beckmann@amd.com "configuration parameter") 5126657Snate@binkert.org 5136888SBrad.Beckmann@amd.com code(''' 5146888SBrad.Beckmann@amd.comm_dma_sequencer_ptr->setController(this); 5156888SBrad.Beckmann@amd.com''') 5166888SBrad.Beckmann@amd.com 5176657Snate@binkert.org code('m_num_controllers++;') 5186657Snate@binkert.org for var in self.objects: 5196657Snate@binkert.org if var.ident.find("mandatoryQueue") >= 0: 5206657Snate@binkert.org code('m_${{var.c_ident}}_ptr = new ${{var.type.c_ident}}();') 5216657Snate@binkert.org 5226657Snate@binkert.org code.dedent() 5236657Snate@binkert.org code(''' 5246657Snate@binkert.org} 5256657Snate@binkert.org 5267007Snate@binkert.orgvoid 5277007Snate@binkert.org$c_ident::init() 5286657Snate@binkert.org{ 5297007Snate@binkert.org MachineType machine_type; 5307007Snate@binkert.org int base; 5317007Snate@binkert.org 5326657Snate@binkert.org m_machineID.type = MachineType_${ident}; 5336657Snate@binkert.org m_machineID.num = m_version; 5346657Snate@binkert.org 5357007Snate@binkert.org // initialize objects 5367542SBrad.Beckmann@amd.com m_profiler.setVersion(m_version); 5377542SBrad.Beckmann@amd.com s_profileDumper.registerProfiler(&m_profiler); 5387007Snate@binkert.org 5396657Snate@binkert.org''') 5406657Snate@binkert.org 5416657Snate@binkert.org code.indent() 5426657Snate@binkert.org for var in self.objects: 5436657Snate@binkert.org vtype = var.type 5446657Snate@binkert.org vid = "m_%s_ptr" % var.c_ident 5456657Snate@binkert.org if "network" not in var: 5466657Snate@binkert.org # Not a network port object 5476657Snate@binkert.org if "primitive" in vtype: 5486657Snate@binkert.org code('$vid = new ${{vtype.c_ident}};') 5496657Snate@binkert.org if "default" in var: 5506657Snate@binkert.org code('(*$vid) = ${{var["default"]}};') 5516657Snate@binkert.org else: 5526657Snate@binkert.org # Normal Object 5536657Snate@binkert.org # added by SS 5546657Snate@binkert.org if "factory" in var: 5556657Snate@binkert.org code('$vid = ${{var["factory"]}};') 5566657Snate@binkert.org elif var.ident.find("mandatoryQueue") < 0: 5576657Snate@binkert.org th = var.get("template_hack", "") 5586657Snate@binkert.org expr = "%s = new %s%s" % (vid, vtype.c_ident, th) 5596657Snate@binkert.org 5606657Snate@binkert.org args = "" 5616657Snate@binkert.org if "non_obj" not in vtype and not vtype.isEnumeration: 5626657Snate@binkert.org if expr.find("TBETable") >= 0: 5636657Snate@binkert.org args = "m_number_of_TBEs" 5646657Snate@binkert.org else: 5656657Snate@binkert.org args = var.get("constructor_hack", "") 5666657Snate@binkert.org 5677007Snate@binkert.org code('$expr($args);') 5686657Snate@binkert.org 5696657Snate@binkert.org code('assert($vid != NULL);') 5706657Snate@binkert.org 5716657Snate@binkert.org if "default" in var: 5727007Snate@binkert.org code('*$vid = ${{var["default"]}}; // Object default') 5736657Snate@binkert.org elif "default" in vtype: 5747007Snate@binkert.org comment = "Type %s default" % vtype.ident 5757007Snate@binkert.org code('*$vid = ${{vtype["default"]}}; // $comment') 5766657Snate@binkert.org 5776657Snate@binkert.org # Set ordering 5786657Snate@binkert.org if "ordered" in var and "trigger_queue" not in var: 5796657Snate@binkert.org # A buffer 5806657Snate@binkert.org code('$vid->setOrdering(${{var["ordered"]}});') 5816657Snate@binkert.org 5826657Snate@binkert.org # Set randomization 5836657Snate@binkert.org if "random" in var: 5846657Snate@binkert.org # A buffer 5856657Snate@binkert.org code('$vid->setRandomization(${{var["random"]}});') 5866657Snate@binkert.org 5876657Snate@binkert.org # Set Priority 5886657Snate@binkert.org if vtype.isBuffer and \ 5896657Snate@binkert.org "rank" in var and "trigger_queue" not in var: 5906657Snate@binkert.org code('$vid->setPriority(${{var["rank"]}});') 5917566SBrad.Beckmann@amd.com 5926657Snate@binkert.org else: 5936657Snate@binkert.org # Network port object 5946657Snate@binkert.org network = var["network"] 5956657Snate@binkert.org ordered = var["ordered"] 5966657Snate@binkert.org vnet = var["virtual_network"] 5976657Snate@binkert.org 5986657Snate@binkert.org assert var.machine is not None 5996657Snate@binkert.org code(''' 6007007Snate@binkert.orgmachine_type = string_to_MachineType("${{var.machine.ident}}"); 6017007Snate@binkert.orgbase = MachineType_base_number(machine_type); 6027007Snate@binkert.org$vid = m_net_ptr->get${network}NetQueue(m_version + base, $ordered, $vnet); 6036657Snate@binkert.org''') 6046657Snate@binkert.org 6056657Snate@binkert.org code('assert($vid != NULL);') 6066657Snate@binkert.org 6076657Snate@binkert.org # Set ordering 6086657Snate@binkert.org if "ordered" in var: 6096657Snate@binkert.org # A buffer 6106657Snate@binkert.org code('$vid->setOrdering(${{var["ordered"]}});') 6116657Snate@binkert.org 6126657Snate@binkert.org # Set randomization 6136657Snate@binkert.org if "random" in var: 6146657Snate@binkert.org # A buffer 6158187SLisa.Hsu@amd.com code('$vid->setRandomization(${{var["random"]}});') 6166657Snate@binkert.org 6176657Snate@binkert.org # Set Priority 6186657Snate@binkert.org if "rank" in var: 6196657Snate@binkert.org code('$vid->setPriority(${{var["rank"]}})') 6206657Snate@binkert.org 6216657Snate@binkert.org # Set buffer size 6226657Snate@binkert.org if vtype.isBuffer: 6236657Snate@binkert.org code(''' 6246657Snate@binkert.orgif (m_buffer_size > 0) { 6257454Snate@binkert.org $vid->resize(m_buffer_size); 6266657Snate@binkert.org} 6276657Snate@binkert.org''') 6286657Snate@binkert.org 6296657Snate@binkert.org # set description (may be overriden later by port def) 6307007Snate@binkert.org code(''' 6317056Snate@binkert.org$vid->setDescription("[Version " + to_string(m_version) + ", ${ident}, name=${{var.c_ident}}]"); 6327007Snate@binkert.org 6337007Snate@binkert.org''') 6346657Snate@binkert.org 6357566SBrad.Beckmann@amd.com if vtype.isBuffer: 6367566SBrad.Beckmann@amd.com if "recycle_latency" in var: 6377566SBrad.Beckmann@amd.com code('$vid->setRecycleLatency(${{var["recycle_latency"]}});') 6387566SBrad.Beckmann@amd.com else: 6397566SBrad.Beckmann@amd.com code('$vid->setRecycleLatency(m_recycle_latency);') 6407566SBrad.Beckmann@amd.com 6417566SBrad.Beckmann@amd.com 6426657Snate@binkert.org # Set the queue consumers 6437672Snate@binkert.org code() 6446657Snate@binkert.org for port in self.in_ports: 6456657Snate@binkert.org code('${{port.code}}.setConsumer(this);') 6466657Snate@binkert.org 6476657Snate@binkert.org # Set the queue descriptions 6487672Snate@binkert.org code() 6496657Snate@binkert.org for port in self.in_ports: 6507056Snate@binkert.org code('${{port.code}}.setDescription("[Version " + to_string(m_version) + ", $ident, $port]");') 6516657Snate@binkert.org 6526657Snate@binkert.org # Initialize the transition profiling 6537672Snate@binkert.org code() 6546657Snate@binkert.org for trans in self.transitions: 6556657Snate@binkert.org # Figure out if we stall 6566657Snate@binkert.org stall = False 6576657Snate@binkert.org for action in trans.actions: 6586657Snate@binkert.org if action.ident == "z_stall": 6596657Snate@binkert.org stall = True 6606657Snate@binkert.org 6616657Snate@binkert.org # Only possible if it is not a 'z' case 6626657Snate@binkert.org if not stall: 6636657Snate@binkert.org state = "%s_State_%s" % (self.ident, trans.state.ident) 6646657Snate@binkert.org event = "%s_Event_%s" % (self.ident, trans.event.ident) 6657542SBrad.Beckmann@amd.com code('m_profiler.possibleTransition($state, $event);') 6666657Snate@binkert.org 6676657Snate@binkert.org code.dedent() 6686657Snate@binkert.org code('}') 6696657Snate@binkert.org 6706657Snate@binkert.org has_mandatory_q = False 6716657Snate@binkert.org for port in self.in_ports: 6726657Snate@binkert.org if port.code.find("mandatoryQueue_ptr") >= 0: 6736657Snate@binkert.org has_mandatory_q = True 6746657Snate@binkert.org 6756657Snate@binkert.org if has_mandatory_q: 6766657Snate@binkert.org mq_ident = "m_%s_mandatoryQueue_ptr" % self.ident 6776657Snate@binkert.org else: 6786657Snate@binkert.org mq_ident = "NULL" 6796657Snate@binkert.org 6806657Snate@binkert.org code(''' 6817007Snate@binkert.orgint 6827007Snate@binkert.org$c_ident::getNumControllers() 6837007Snate@binkert.org{ 6846657Snate@binkert.org return m_num_controllers; 6856657Snate@binkert.org} 6866657Snate@binkert.org 6877007Snate@binkert.orgMessageBuffer* 6887007Snate@binkert.org$c_ident::getMandatoryQueue() const 6897007Snate@binkert.org{ 6906657Snate@binkert.org return $mq_ident; 6916657Snate@binkert.org} 6926657Snate@binkert.org 6937007Snate@binkert.orgconst int & 6947007Snate@binkert.org$c_ident::getVersion() const 6957007Snate@binkert.org{ 6966657Snate@binkert.org return m_version; 6976657Snate@binkert.org} 6986657Snate@binkert.org 6997007Snate@binkert.orgconst string 7007007Snate@binkert.org$c_ident::toString() const 7017007Snate@binkert.org{ 7026657Snate@binkert.org return "$c_ident"; 7036657Snate@binkert.org} 7046657Snate@binkert.org 7057007Snate@binkert.orgconst string 7067007Snate@binkert.org$c_ident::getName() const 7077007Snate@binkert.org{ 7086657Snate@binkert.org return m_name; 7096657Snate@binkert.org} 7107007Snate@binkert.org 7117007Snate@binkert.orgconst MachineType 7127007Snate@binkert.org$c_ident::getMachineType() const 7137007Snate@binkert.org{ 7146657Snate@binkert.org return MachineType_${ident}; 7156657Snate@binkert.org} 7166657Snate@binkert.org 7177007Snate@binkert.orgvoid 7187567SBrad.Beckmann@amd.com$c_ident::stallBuffer(MessageBuffer* buf, Address addr) 7197567SBrad.Beckmann@amd.com{ 7207567SBrad.Beckmann@amd.com if (m_waiting_buffers.count(addr) == 0) { 7217567SBrad.Beckmann@amd.com MsgVecType* msgVec = new MsgVecType; 7227567SBrad.Beckmann@amd.com msgVec->resize(m_max_in_port_rank, NULL); 7237567SBrad.Beckmann@amd.com m_waiting_buffers[addr] = msgVec; 7247567SBrad.Beckmann@amd.com } 7257567SBrad.Beckmann@amd.com (*(m_waiting_buffers[addr]))[m_cur_in_port_rank] = buf; 7267567SBrad.Beckmann@amd.com} 7277567SBrad.Beckmann@amd.com 7287567SBrad.Beckmann@amd.comvoid 7297567SBrad.Beckmann@amd.com$c_ident::wakeUpBuffers(Address addr) 7307567SBrad.Beckmann@amd.com{ 7318155Snilay@cs.wisc.edu if (m_waiting_buffers.count(addr) > 0) { 7328155Snilay@cs.wisc.edu // 7338155Snilay@cs.wisc.edu // Wake up all possible lower rank (i.e. lower priority) buffers that could 7348155Snilay@cs.wisc.edu // be waiting on this message. 7358155Snilay@cs.wisc.edu // 7368155Snilay@cs.wisc.edu for (int in_port_rank = m_cur_in_port_rank - 1; 7378155Snilay@cs.wisc.edu in_port_rank >= 0; 7388155Snilay@cs.wisc.edu in_port_rank--) { 7398155Snilay@cs.wisc.edu if ((*(m_waiting_buffers[addr]))[in_port_rank] != NULL) { 7408155Snilay@cs.wisc.edu (*(m_waiting_buffers[addr]))[in_port_rank]->reanalyzeMessages(addr); 7418155Snilay@cs.wisc.edu } 7427567SBrad.Beckmann@amd.com } 7438155Snilay@cs.wisc.edu delete m_waiting_buffers[addr]; 7448155Snilay@cs.wisc.edu m_waiting_buffers.erase(addr); 7457567SBrad.Beckmann@amd.com } 7467567SBrad.Beckmann@amd.com} 7477567SBrad.Beckmann@amd.com 7487567SBrad.Beckmann@amd.comvoid 7497922SBrad.Beckmann@amd.com$c_ident::wakeUpAllBuffers() 7507922SBrad.Beckmann@amd.com{ 7517922SBrad.Beckmann@amd.com // 7527922SBrad.Beckmann@amd.com // Wake up all possible buffers that could be waiting on any message. 7537922SBrad.Beckmann@amd.com // 7547922SBrad.Beckmann@amd.com 7557922SBrad.Beckmann@amd.com std::vector<MsgVecType*> wokeUpMsgVecs; 7567922SBrad.Beckmann@amd.com 7578154Snilay@cs.wisc.edu if(m_waiting_buffers.size() > 0) { 7588154Snilay@cs.wisc.edu for (WaitingBufType::iterator buf_iter = m_waiting_buffers.begin(); 7598154Snilay@cs.wisc.edu buf_iter != m_waiting_buffers.end(); 7608154Snilay@cs.wisc.edu ++buf_iter) { 7618154Snilay@cs.wisc.edu for (MsgVecType::iterator vec_iter = buf_iter->second->begin(); 7628154Snilay@cs.wisc.edu vec_iter != buf_iter->second->end(); 7638154Snilay@cs.wisc.edu ++vec_iter) { 7648154Snilay@cs.wisc.edu if (*vec_iter != NULL) { 7658154Snilay@cs.wisc.edu (*vec_iter)->reanalyzeAllMessages(); 7668154Snilay@cs.wisc.edu } 7678154Snilay@cs.wisc.edu } 7688154Snilay@cs.wisc.edu wokeUpMsgVecs.push_back(buf_iter->second); 7698154Snilay@cs.wisc.edu } 7708154Snilay@cs.wisc.edu 7718154Snilay@cs.wisc.edu for (std::vector<MsgVecType*>::iterator wb_iter = wokeUpMsgVecs.begin(); 7728154Snilay@cs.wisc.edu wb_iter != wokeUpMsgVecs.end(); 7738154Snilay@cs.wisc.edu ++wb_iter) { 7748154Snilay@cs.wisc.edu delete (*wb_iter); 7758154Snilay@cs.wisc.edu } 7768154Snilay@cs.wisc.edu 7778154Snilay@cs.wisc.edu m_waiting_buffers.clear(); 7787922SBrad.Beckmann@amd.com } 7797922SBrad.Beckmann@amd.com} 7807922SBrad.Beckmann@amd.com 7817922SBrad.Beckmann@amd.comvoid 7827007Snate@binkert.org$c_ident::blockOnQueue(Address addr, MessageBuffer* port) 7837007Snate@binkert.org{ 7846863Sdrh5@cs.wisc.edu m_is_blocking = true; 7856863Sdrh5@cs.wisc.edu m_block_map[addr] = port; 7866863Sdrh5@cs.wisc.edu} 7877007Snate@binkert.org 7887007Snate@binkert.orgvoid 7897007Snate@binkert.org$c_ident::unblock(Address addr) 7907007Snate@binkert.org{ 7916863Sdrh5@cs.wisc.edu m_block_map.erase(addr); 7926863Sdrh5@cs.wisc.edu if (m_block_map.size() == 0) { 7936863Sdrh5@cs.wisc.edu m_is_blocking = false; 7946863Sdrh5@cs.wisc.edu } 7956863Sdrh5@cs.wisc.edu} 7966863Sdrh5@cs.wisc.edu 7977007Snate@binkert.orgvoid 7987007Snate@binkert.org$c_ident::print(ostream& out) const 7997007Snate@binkert.org{ 8007007Snate@binkert.org out << "[$c_ident " << m_version << "]"; 8017007Snate@binkert.org} 8026657Snate@binkert.org 8037007Snate@binkert.orgvoid 8047007Snate@binkert.org$c_ident::printConfig(ostream& out) const 8057007Snate@binkert.org{ 8066657Snate@binkert.org out << "$c_ident config: " << m_name << endl; 8076657Snate@binkert.org out << " version: " << m_version << endl; 8087007Snate@binkert.org map<string, string>::const_iterator it; 8097007Snate@binkert.org for (it = m_cfg.begin(); it != m_cfg.end(); it++) 8107007Snate@binkert.org out << " " << it->first << ": " << it->second << endl; 8116657Snate@binkert.org} 8126657Snate@binkert.org 8137007Snate@binkert.orgvoid 8147007Snate@binkert.org$c_ident::printStats(ostream& out) const 8157007Snate@binkert.org{ 8166902SBrad.Beckmann@amd.com''') 8176902SBrad.Beckmann@amd.com # 8186902SBrad.Beckmann@amd.com # Cache and Memory Controllers have specific profilers associated with 8196902SBrad.Beckmann@amd.com # them. Print out these stats before dumping state transition stats. 8206902SBrad.Beckmann@amd.com # 8216902SBrad.Beckmann@amd.com for param in self.config_parameters: 8226902SBrad.Beckmann@amd.com if param.type_ast.type.ident == "CacheMemory" or \ 8237025SBrad.Beckmann@amd.com param.type_ast.type.ident == "DirectoryMemory" or \ 8246902SBrad.Beckmann@amd.com param.type_ast.type.ident == "MemoryControl": 8256902SBrad.Beckmann@amd.com assert(param.pointer) 8266902SBrad.Beckmann@amd.com code(' m_${{param.ident}}_ptr->printStats(out);') 8276902SBrad.Beckmann@amd.com 8286902SBrad.Beckmann@amd.com code(''' 8297542SBrad.Beckmann@amd.com if (m_version == 0) { 8307542SBrad.Beckmann@amd.com s_profileDumper.dumpStats(out); 8317542SBrad.Beckmann@amd.com } 8326902SBrad.Beckmann@amd.com} 8336902SBrad.Beckmann@amd.com 8346902SBrad.Beckmann@amd.comvoid $c_ident::clearStats() { 8356902SBrad.Beckmann@amd.com''') 8366902SBrad.Beckmann@amd.com # 8376902SBrad.Beckmann@amd.com # Cache and Memory Controllers have specific profilers associated with 8386902SBrad.Beckmann@amd.com # them. These stats must be cleared too. 8396902SBrad.Beckmann@amd.com # 8406902SBrad.Beckmann@amd.com for param in self.config_parameters: 8416902SBrad.Beckmann@amd.com if param.type_ast.type.ident == "CacheMemory" or \ 8426902SBrad.Beckmann@amd.com param.type_ast.type.ident == "MemoryControl": 8436902SBrad.Beckmann@amd.com assert(param.pointer) 8446902SBrad.Beckmann@amd.com code(' m_${{param.ident}}_ptr->clearStats();') 8456902SBrad.Beckmann@amd.com 8466902SBrad.Beckmann@amd.com code(''' 8477542SBrad.Beckmann@amd.com m_profiler.clearStats(); 8486902SBrad.Beckmann@amd.com} 8497839Snilay@cs.wisc.edu''') 8507839Snilay@cs.wisc.edu 8517839Snilay@cs.wisc.edu if self.EntryType != None: 8527839Snilay@cs.wisc.edu code(''' 8537839Snilay@cs.wisc.edu 8547839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable 8557839Snilay@cs.wisc.eduvoid 8567839Snilay@cs.wisc.edu$c_ident::set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry) 8577839Snilay@cs.wisc.edu{ 8587839Snilay@cs.wisc.edu m_cache_entry_ptr = (${{self.EntryType.c_ident}}*)m_new_cache_entry; 8597839Snilay@cs.wisc.edu} 8607839Snilay@cs.wisc.edu 8617839Snilay@cs.wisc.eduvoid 8627839Snilay@cs.wisc.edu$c_ident::unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr) 8637839Snilay@cs.wisc.edu{ 8647839Snilay@cs.wisc.edu m_cache_entry_ptr = 0; 8657839Snilay@cs.wisc.edu} 8668086SBrad.Beckmann@amd.com 8678086SBrad.Beckmann@amd.comvoid 8688086SBrad.Beckmann@amd.com$c_ident::set_permission(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, 8698086SBrad.Beckmann@amd.com AccessPermission perm) 8708086SBrad.Beckmann@amd.com{ 8718086SBrad.Beckmann@amd.com if (m_cache_entry_ptr != NULL) { 8728086SBrad.Beckmann@amd.com m_cache_entry_ptr->changePermission(perm); 8738086SBrad.Beckmann@amd.com } 8748086SBrad.Beckmann@amd.com} 8757839Snilay@cs.wisc.edu''') 8767839Snilay@cs.wisc.edu 8777839Snilay@cs.wisc.edu if self.TBEType != None: 8787839Snilay@cs.wisc.edu code(''' 8797839Snilay@cs.wisc.edu 8807839Snilay@cs.wisc.edu// Set and Reset for tbe variable 8817839Snilay@cs.wisc.eduvoid 8827839Snilay@cs.wisc.edu$c_ident::set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.TBEType.c_ident}}* m_new_tbe) 8837839Snilay@cs.wisc.edu{ 8847839Snilay@cs.wisc.edu m_tbe_ptr = m_new_tbe; 8857839Snilay@cs.wisc.edu} 8867839Snilay@cs.wisc.edu 8877839Snilay@cs.wisc.eduvoid 8887839Snilay@cs.wisc.edu$c_ident::unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr) 8897839Snilay@cs.wisc.edu{ 8907839Snilay@cs.wisc.edu m_tbe_ptr = NULL; 8917839Snilay@cs.wisc.edu} 8927839Snilay@cs.wisc.edu''') 8937839Snilay@cs.wisc.edu 8947839Snilay@cs.wisc.edu code(''' 8956902SBrad.Beckmann@amd.com 8966657Snate@binkert.org// Actions 8976657Snate@binkert.org''') 8987839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 8997839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9007839Snilay@cs.wisc.edu if "c_code" not in action: 9017839Snilay@cs.wisc.edu continue 9026657Snate@binkert.org 9037839Snilay@cs.wisc.edu code(''' 9047839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9057839Snilay@cs.wisc.eduvoid 9067839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr) 9077839Snilay@cs.wisc.edu{ 9088055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9097839Snilay@cs.wisc.edu ${{action["c_code"]}} 9107839Snilay@cs.wisc.edu} 9116657Snate@binkert.org 9127839Snilay@cs.wisc.edu''') 9137839Snilay@cs.wisc.edu elif self.TBEType != None: 9147839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9157839Snilay@cs.wisc.edu if "c_code" not in action: 9167839Snilay@cs.wisc.edu continue 9177839Snilay@cs.wisc.edu 9187839Snilay@cs.wisc.edu code(''' 9197839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9207839Snilay@cs.wisc.eduvoid 9217839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, const Address& addr) 9227839Snilay@cs.wisc.edu{ 9238055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9247839Snilay@cs.wisc.edu ${{action["c_code"]}} 9257839Snilay@cs.wisc.edu} 9267839Snilay@cs.wisc.edu 9277839Snilay@cs.wisc.edu''') 9287839Snilay@cs.wisc.edu elif self.EntryType != None: 9297839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9307839Snilay@cs.wisc.edu if "c_code" not in action: 9317839Snilay@cs.wisc.edu continue 9327839Snilay@cs.wisc.edu 9337839Snilay@cs.wisc.edu code(''' 9347839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9357839Snilay@cs.wisc.eduvoid 9367839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr) 9377839Snilay@cs.wisc.edu{ 9388055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9397839Snilay@cs.wisc.edu ${{action["c_code"]}} 9407839Snilay@cs.wisc.edu} 9417839Snilay@cs.wisc.edu 9427839Snilay@cs.wisc.edu''') 9437839Snilay@cs.wisc.edu else: 9447839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9457839Snilay@cs.wisc.edu if "c_code" not in action: 9467839Snilay@cs.wisc.edu continue 9477839Snilay@cs.wisc.edu 9487839Snilay@cs.wisc.edu code(''' 9496657Snate@binkert.org/** \\brief ${{action.desc}} */ 9507007Snate@binkert.orgvoid 9517007Snate@binkert.org$c_ident::${{action.ident}}(const Address& addr) 9526657Snate@binkert.org{ 9538055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9546657Snate@binkert.org ${{action["c_code"]}} 9556657Snate@binkert.org} 9566657Snate@binkert.org 9576657Snate@binkert.org''') 9586657Snate@binkert.org code.write(path, "%s.cc" % c_ident) 9596657Snate@binkert.org 9606657Snate@binkert.org def printCWakeup(self, path): 9616657Snate@binkert.org '''Output the wakeup loop for the events''' 9626657Snate@binkert.org 9636999Snate@binkert.org code = self.symtab.codeFormatter() 9646657Snate@binkert.org ident = self.ident 9656657Snate@binkert.org 9666657Snate@binkert.org code(''' 9676657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 9686657Snate@binkert.org// ${ident}: ${{self.short}} 9696657Snate@binkert.org 9707832Snate@binkert.org#include <cassert> 9717832Snate@binkert.org 9727007Snate@binkert.org#include "base/misc.hh" 9738232Snate@binkert.org#include "debug/RubySlicc.hh" 9748229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 9758229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 9768229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 9778229Snate@binkert.org#include "mem/protocol/Types.hh" 9786657Snate@binkert.org#include "mem/ruby/common/Global.hh" 9796657Snate@binkert.org#include "mem/ruby/slicc_interface/RubySlicc_includes.hh" 9806657Snate@binkert.org#include "mem/ruby/system/System.hh" 9816657Snate@binkert.org 9827055Snate@binkert.orgusing namespace std; 9837055Snate@binkert.org 9847007Snate@binkert.orgvoid 9857007Snate@binkert.org${ident}_Controller::wakeup() 9866657Snate@binkert.org{ 9876657Snate@binkert.org int counter = 0; 9886657Snate@binkert.org while (true) { 9896657Snate@binkert.org // Some cases will put us into an infinite loop without this limit 9906657Snate@binkert.org assert(counter <= m_transitions_per_cycle); 9916657Snate@binkert.org if (counter == m_transitions_per_cycle) { 9927007Snate@binkert.org // Count how often we are fully utilized 9937007Snate@binkert.org g_system_ptr->getProfiler()->controllerBusy(m_machineID); 9947007Snate@binkert.org 9957007Snate@binkert.org // Wakeup in another cycle and try again 9967007Snate@binkert.org g_eventQueue_ptr->scheduleEvent(this, 1); 9976657Snate@binkert.org break; 9986657Snate@binkert.org } 9996657Snate@binkert.org''') 10006657Snate@binkert.org 10016657Snate@binkert.org code.indent() 10026657Snate@binkert.org code.indent() 10036657Snate@binkert.org 10046657Snate@binkert.org # InPorts 10056657Snate@binkert.org # 10066657Snate@binkert.org for port in self.in_ports: 10076657Snate@binkert.org code.indent() 10086657Snate@binkert.org code('// ${ident}InPort $port') 10097567SBrad.Beckmann@amd.com if port.pairs.has_key("rank"): 10107567SBrad.Beckmann@amd.com code('m_cur_in_port_rank = ${{port.pairs["rank"]}};') 10117567SBrad.Beckmann@amd.com else: 10127567SBrad.Beckmann@amd.com code('m_cur_in_port_rank = 0;') 10136657Snate@binkert.org code('${{port["c_code_in_port"]}}') 10146657Snate@binkert.org code.dedent() 10156657Snate@binkert.org 10166657Snate@binkert.org code('') 10176657Snate@binkert.org 10186657Snate@binkert.org code.dedent() 10196657Snate@binkert.org code.dedent() 10206657Snate@binkert.org code(''' 10216657Snate@binkert.org break; // If we got this far, we have nothing left todo 10226657Snate@binkert.org } 10237007Snate@binkert.org // g_eventQueue_ptr->scheduleEvent(this, 1); 10246657Snate@binkert.org} 10256657Snate@binkert.org''') 10266657Snate@binkert.org 10276657Snate@binkert.org code.write(path, "%s_Wakeup.cc" % self.ident) 10286657Snate@binkert.org 10296657Snate@binkert.org def printCSwitch(self, path): 10306657Snate@binkert.org '''Output switch statement for transition table''' 10316657Snate@binkert.org 10326999Snate@binkert.org code = self.symtab.codeFormatter() 10336657Snate@binkert.org ident = self.ident 10346657Snate@binkert.org 10356657Snate@binkert.org code(''' 10366657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 10376657Snate@binkert.org// ${ident}: ${{self.short}} 10386657Snate@binkert.org 10397832Snate@binkert.org#include <cassert> 10407832Snate@binkert.org 10417805Snilay@cs.wisc.edu#include "base/misc.hh" 10427832Snate@binkert.org#include "base/trace.hh" 10438232Snate@binkert.org#include "debug/ProtocolTrace.hh" 10448232Snate@binkert.org#include "debug/RubyGenerated.hh" 10458229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 10468229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 10478229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 10488229Snate@binkert.org#include "mem/protocol/Types.hh" 10496657Snate@binkert.org#include "mem/ruby/common/Global.hh" 10506657Snate@binkert.org#include "mem/ruby/system/System.hh" 10516657Snate@binkert.org 10526657Snate@binkert.org#define HASH_FUN(state, event) ((int(state)*${ident}_Event_NUM)+int(event)) 10536657Snate@binkert.org 10546657Snate@binkert.org#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str()) 10556657Snate@binkert.org#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str("")) 10566657Snate@binkert.org 10577007Snate@binkert.orgTransitionResult 10587007Snate@binkert.org${ident}_Controller::doTransition(${ident}_Event event, 10597839Snilay@cs.wisc.edu''') 10607839Snilay@cs.wisc.edu if self.EntryType != None: 10617839Snilay@cs.wisc.edu code(''' 10627839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}* m_cache_entry_ptr, 10637839Snilay@cs.wisc.edu''') 10647839Snilay@cs.wisc.edu if self.TBEType != None: 10657839Snilay@cs.wisc.edu code(''' 10667839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}* m_tbe_ptr, 10677839Snilay@cs.wisc.edu''') 10687839Snilay@cs.wisc.edu code(''' 10697007Snate@binkert.org const Address &addr) 10706657Snate@binkert.org{ 10717839Snilay@cs.wisc.edu''') 10727839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 10737839Snilay@cs.wisc.edu code('${ident}_State state = ${ident}_getState(m_tbe_ptr, m_cache_entry_ptr, addr);') 10747839Snilay@cs.wisc.edu elif self.TBEType != None: 10757839Snilay@cs.wisc.edu code('${ident}_State state = ${ident}_getState(m_tbe_ptr, addr);') 10767839Snilay@cs.wisc.edu elif self.EntryType != None: 10777839Snilay@cs.wisc.edu code('${ident}_State state = ${ident}_getState(m_cache_entry_ptr, addr);') 10787839Snilay@cs.wisc.edu else: 10797839Snilay@cs.wisc.edu code('${ident}_State state = ${ident}_getState(addr);') 10807839Snilay@cs.wisc.edu 10817839Snilay@cs.wisc.edu code(''' 10826657Snate@binkert.org ${ident}_State next_state = state; 10836657Snate@binkert.org 10847780Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "%s, Time: %lld, state: %s, event: %s, addr: %s\\n", 10857780Snilay@cs.wisc.edu *this, 10867780Snilay@cs.wisc.edu g_eventQueue_ptr->getTime(), 10877780Snilay@cs.wisc.edu ${ident}_State_to_string(state), 10887780Snilay@cs.wisc.edu ${ident}_Event_to_string(event), 10897780Snilay@cs.wisc.edu addr); 10906657Snate@binkert.org 10917007Snate@binkert.org TransitionResult result = 10927839Snilay@cs.wisc.edu''') 10937839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 10947839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_tbe_ptr, m_cache_entry_ptr, addr);') 10957839Snilay@cs.wisc.edu elif self.TBEType != None: 10967839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_tbe_ptr, addr);') 10977839Snilay@cs.wisc.edu elif self.EntryType != None: 10987839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_cache_entry_ptr, addr);') 10997839Snilay@cs.wisc.edu else: 11007839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, addr);') 11016657Snate@binkert.org 11027839Snilay@cs.wisc.edu code(''' 11036657Snate@binkert.org if (result == TransitionResult_Valid) { 11047780Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "next_state: %s\\n", 11057780Snilay@cs.wisc.edu ${ident}_State_to_string(next_state)); 11067542SBrad.Beckmann@amd.com m_profiler.countTransition(state, event); 11077832Snate@binkert.org DPRINTFR(ProtocolTrace, "%7d %3s %10s%20s %6s>%-6s %s %s\\n", 11087832Snate@binkert.org g_eventQueue_ptr->getTime(), m_version, "${ident}", 11097832Snate@binkert.org ${ident}_Event_to_string(event), 11107832Snate@binkert.org ${ident}_State_to_string(state), 11117832Snate@binkert.org ${ident}_State_to_string(next_state), 11127832Snate@binkert.org addr, GET_TRANSITION_COMMENT()); 11136657Snate@binkert.org 11147832Snate@binkert.org CLEAR_TRANSITION_COMMENT(); 11157839Snilay@cs.wisc.edu''') 11167839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 11177839Snilay@cs.wisc.edu code('${ident}_setState(m_tbe_ptr, m_cache_entry_ptr, addr, next_state);') 11188086SBrad.Beckmann@amd.com code('set_permission(m_cache_entry_ptr, ${ident}_State_to_permission(next_state));') 11197839Snilay@cs.wisc.edu elif self.TBEType != None: 11207839Snilay@cs.wisc.edu code('${ident}_setState(m_tbe_ptr, addr, next_state);') 11217839Snilay@cs.wisc.edu elif self.EntryType != None: 11227839Snilay@cs.wisc.edu code('${ident}_setState(m_cache_entry_ptr, addr, next_state);') 11238086SBrad.Beckmann@amd.com code('set_permission(m_cache_entry_ptr, ${ident}_State_to_permission(next_state));') 11247839Snilay@cs.wisc.edu else: 11257839Snilay@cs.wisc.edu code('${ident}_setState(addr, next_state);') 11267839Snilay@cs.wisc.edu 11277839Snilay@cs.wisc.edu code(''' 11286657Snate@binkert.org } else if (result == TransitionResult_ResourceStall) { 11297832Snate@binkert.org DPRINTFR(ProtocolTrace, "%7s %3s %10s%20s %6s>%-6s %s %s\\n", 11307832Snate@binkert.org g_eventQueue_ptr->getTime(), m_version, "${ident}", 11317832Snate@binkert.org ${ident}_Event_to_string(event), 11327832Snate@binkert.org ${ident}_State_to_string(state), 11337832Snate@binkert.org ${ident}_State_to_string(next_state), 11347832Snate@binkert.org addr, "Resource Stall"); 11356657Snate@binkert.org } else if (result == TransitionResult_ProtocolStall) { 11367780Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "stalling\\n"); 11377832Snate@binkert.org DPRINTFR(ProtocolTrace, "%7s %3s %10s%20s %6s>%-6s %s %s\\n", 11387832Snate@binkert.org g_eventQueue_ptr->getTime(), m_version, "${ident}", 11397832Snate@binkert.org ${ident}_Event_to_string(event), 11407832Snate@binkert.org ${ident}_State_to_string(state), 11417832Snate@binkert.org ${ident}_State_to_string(next_state), 11427832Snate@binkert.org addr, "Protocol Stall"); 11436657Snate@binkert.org } 11446657Snate@binkert.org 11456657Snate@binkert.org return result; 11466657Snate@binkert.org} 11476657Snate@binkert.org 11487007Snate@binkert.orgTransitionResult 11497007Snate@binkert.org${ident}_Controller::doTransitionWorker(${ident}_Event event, 11507007Snate@binkert.org ${ident}_State state, 11517007Snate@binkert.org ${ident}_State& next_state, 11527839Snilay@cs.wisc.edu''') 11537839Snilay@cs.wisc.edu 11547839Snilay@cs.wisc.edu if self.TBEType != None: 11557839Snilay@cs.wisc.edu code(''' 11567839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}*& m_tbe_ptr, 11577839Snilay@cs.wisc.edu''') 11587839Snilay@cs.wisc.edu if self.EntryType != None: 11597839Snilay@cs.wisc.edu code(''' 11607839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, 11617839Snilay@cs.wisc.edu''') 11627839Snilay@cs.wisc.edu code(''' 11637007Snate@binkert.org const Address& addr) 11646657Snate@binkert.org{ 11656657Snate@binkert.org switch(HASH_FUN(state, event)) { 11666657Snate@binkert.org''') 11676657Snate@binkert.org 11686657Snate@binkert.org # This map will allow suppress generating duplicate code 11696657Snate@binkert.org cases = orderdict() 11706657Snate@binkert.org 11716657Snate@binkert.org for trans in self.transitions: 11726657Snate@binkert.org case_string = "%s_State_%s, %s_Event_%s" % \ 11736657Snate@binkert.org (self.ident, trans.state.ident, self.ident, trans.event.ident) 11746657Snate@binkert.org 11756999Snate@binkert.org case = self.symtab.codeFormatter() 11766657Snate@binkert.org # Only set next_state if it changes 11776657Snate@binkert.org if trans.state != trans.nextState: 11786657Snate@binkert.org ns_ident = trans.nextState.ident 11796657Snate@binkert.org case('next_state = ${ident}_State_${ns_ident};') 11806657Snate@binkert.org 11816657Snate@binkert.org actions = trans.actions 11826657Snate@binkert.org 11836657Snate@binkert.org # Check for resources 11846657Snate@binkert.org case_sorter = [] 11856657Snate@binkert.org res = trans.resources 11866657Snate@binkert.org for key,val in res.iteritems(): 11876657Snate@binkert.org if key.type.ident != "DNUCAStopTable": 11886657Snate@binkert.org val = ''' 11897007Snate@binkert.orgif (!%s.areNSlotsAvailable(%s)) 11906657Snate@binkert.org return TransitionResult_ResourceStall; 11916657Snate@binkert.org''' % (key.code, val) 11926657Snate@binkert.org case_sorter.append(val) 11936657Snate@binkert.org 11946657Snate@binkert.org 11956657Snate@binkert.org # Emit the code sequences in a sorted order. This makes the 11966657Snate@binkert.org # output deterministic (without this the output order can vary 11976657Snate@binkert.org # since Map's keys() on a vector of pointers is not deterministic 11986657Snate@binkert.org for c in sorted(case_sorter): 11996657Snate@binkert.org case("$c") 12006657Snate@binkert.org 12016657Snate@binkert.org # Figure out if we stall 12026657Snate@binkert.org stall = False 12036657Snate@binkert.org for action in actions: 12046657Snate@binkert.org if action.ident == "z_stall": 12056657Snate@binkert.org stall = True 12066657Snate@binkert.org break 12076657Snate@binkert.org 12086657Snate@binkert.org if stall: 12096657Snate@binkert.org case('return TransitionResult_ProtocolStall;') 12106657Snate@binkert.org else: 12117839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 12127839Snilay@cs.wisc.edu for action in actions: 12137839Snilay@cs.wisc.edu case('${{action.ident}}(m_tbe_ptr, m_cache_entry_ptr, addr);') 12147839Snilay@cs.wisc.edu elif self.TBEType != None: 12157839Snilay@cs.wisc.edu for action in actions: 12167839Snilay@cs.wisc.edu case('${{action.ident}}(m_tbe_ptr, addr);') 12177839Snilay@cs.wisc.edu elif self.EntryType != None: 12187839Snilay@cs.wisc.edu for action in actions: 12197839Snilay@cs.wisc.edu case('${{action.ident}}(m_cache_entry_ptr, addr);') 12207839Snilay@cs.wisc.edu else: 12217839Snilay@cs.wisc.edu for action in actions: 12227839Snilay@cs.wisc.edu case('${{action.ident}}(addr);') 12236657Snate@binkert.org case('return TransitionResult_Valid;') 12246657Snate@binkert.org 12256657Snate@binkert.org case = str(case) 12266657Snate@binkert.org 12276657Snate@binkert.org # Look to see if this transition code is unique. 12286657Snate@binkert.org if case not in cases: 12296657Snate@binkert.org cases[case] = [] 12306657Snate@binkert.org 12316657Snate@binkert.org cases[case].append(case_string) 12326657Snate@binkert.org 12336657Snate@binkert.org # Walk through all of the unique code blocks and spit out the 12346657Snate@binkert.org # corresponding case statement elements 12356657Snate@binkert.org for case,transitions in cases.iteritems(): 12366657Snate@binkert.org # Iterative over all the multiple transitions that share 12376657Snate@binkert.org # the same code 12386657Snate@binkert.org for trans in transitions: 12396657Snate@binkert.org code(' case HASH_FUN($trans):') 12406657Snate@binkert.org code(' $case') 12416657Snate@binkert.org 12426657Snate@binkert.org code(''' 12436657Snate@binkert.org default: 12447805Snilay@cs.wisc.edu fatal("Invalid transition\\n" 12458159SBrad.Beckmann@amd.com "%s time: %d addr: %s event: %s state: %s\\n", 12468159SBrad.Beckmann@amd.com name(), g_eventQueue_ptr->getTime(), addr, event, state); 12476657Snate@binkert.org } 12486657Snate@binkert.org return TransitionResult_Valid; 12496657Snate@binkert.org} 12506657Snate@binkert.org''') 12516657Snate@binkert.org code.write(path, "%s_Transitions.cc" % self.ident) 12526657Snate@binkert.org 12537542SBrad.Beckmann@amd.com def printProfileDumperHH(self, path): 12547542SBrad.Beckmann@amd.com code = self.symtab.codeFormatter() 12557542SBrad.Beckmann@amd.com ident = self.ident 12567542SBrad.Beckmann@amd.com 12577542SBrad.Beckmann@amd.com code(''' 12587542SBrad.Beckmann@amd.com// Auto generated C++ code started by $__file__:$__line__ 12597542SBrad.Beckmann@amd.com// ${ident}: ${{self.short}} 12607542SBrad.Beckmann@amd.com 12617542SBrad.Beckmann@amd.com#ifndef __${ident}_PROFILE_DUMPER_HH__ 12627542SBrad.Beckmann@amd.com#define __${ident}_PROFILE_DUMPER_HH__ 12637542SBrad.Beckmann@amd.com 12647832Snate@binkert.org#include <cassert> 12657542SBrad.Beckmann@amd.com#include <iostream> 12667542SBrad.Beckmann@amd.com#include <vector> 12677542SBrad.Beckmann@amd.com 12688229Snate@binkert.org#include "${ident}_Event.hh" 12697542SBrad.Beckmann@amd.com#include "${ident}_Profiler.hh" 12707542SBrad.Beckmann@amd.com 12717542SBrad.Beckmann@amd.comtypedef std::vector<${ident}_Profiler *> ${ident}_profilers; 12727542SBrad.Beckmann@amd.com 12737542SBrad.Beckmann@amd.comclass ${ident}_ProfileDumper 12747542SBrad.Beckmann@amd.com{ 12757542SBrad.Beckmann@amd.com public: 12767542SBrad.Beckmann@amd.com ${ident}_ProfileDumper(); 12777542SBrad.Beckmann@amd.com void registerProfiler(${ident}_Profiler* profiler); 12787542SBrad.Beckmann@amd.com void dumpStats(std::ostream& out) const; 12797542SBrad.Beckmann@amd.com 12807542SBrad.Beckmann@amd.com private: 12817542SBrad.Beckmann@amd.com ${ident}_profilers m_profilers; 12827542SBrad.Beckmann@amd.com}; 12837542SBrad.Beckmann@amd.com 12847542SBrad.Beckmann@amd.com#endif // __${ident}_PROFILE_DUMPER_HH__ 12857542SBrad.Beckmann@amd.com''') 12867542SBrad.Beckmann@amd.com code.write(path, "%s_ProfileDumper.hh" % self.ident) 12877542SBrad.Beckmann@amd.com 12887542SBrad.Beckmann@amd.com def printProfileDumperCC(self, path): 12897542SBrad.Beckmann@amd.com code = self.symtab.codeFormatter() 12907542SBrad.Beckmann@amd.com ident = self.ident 12917542SBrad.Beckmann@amd.com 12927542SBrad.Beckmann@amd.com code(''' 12937542SBrad.Beckmann@amd.com// Auto generated C++ code started by $__file__:$__line__ 12947542SBrad.Beckmann@amd.com// ${ident}: ${{self.short}} 12957542SBrad.Beckmann@amd.com 12967542SBrad.Beckmann@amd.com#include "mem/protocol/${ident}_ProfileDumper.hh" 12977542SBrad.Beckmann@amd.com 12987542SBrad.Beckmann@amd.com${ident}_ProfileDumper::${ident}_ProfileDumper() 12997542SBrad.Beckmann@amd.com{ 13007542SBrad.Beckmann@amd.com} 13017542SBrad.Beckmann@amd.com 13027542SBrad.Beckmann@amd.comvoid 13037542SBrad.Beckmann@amd.com${ident}_ProfileDumper::registerProfiler(${ident}_Profiler* profiler) 13047542SBrad.Beckmann@amd.com{ 13057542SBrad.Beckmann@amd.com m_profilers.push_back(profiler); 13067542SBrad.Beckmann@amd.com} 13077542SBrad.Beckmann@amd.com 13087542SBrad.Beckmann@amd.comvoid 13097542SBrad.Beckmann@amd.com${ident}_ProfileDumper::dumpStats(std::ostream& out) const 13107542SBrad.Beckmann@amd.com{ 13117542SBrad.Beckmann@amd.com out << " --- ${ident} ---\\n"; 13127542SBrad.Beckmann@amd.com out << " - Event Counts -\\n"; 13137542SBrad.Beckmann@amd.com for (${ident}_Event event = ${ident}_Event_FIRST; 13147542SBrad.Beckmann@amd.com event < ${ident}_Event_NUM; 13157542SBrad.Beckmann@amd.com ++event) { 13167542SBrad.Beckmann@amd.com out << (${ident}_Event) event << " ["; 13177542SBrad.Beckmann@amd.com uint64 total = 0; 13187542SBrad.Beckmann@amd.com for (int i = 0; i < m_profilers.size(); i++) { 13197542SBrad.Beckmann@amd.com out << m_profilers[i]->getEventCount(event) << " "; 13207542SBrad.Beckmann@amd.com total += m_profilers[i]->getEventCount(event); 13217542SBrad.Beckmann@amd.com } 13227542SBrad.Beckmann@amd.com out << "] " << total << "\\n"; 13237542SBrad.Beckmann@amd.com } 13247542SBrad.Beckmann@amd.com out << "\\n"; 13257542SBrad.Beckmann@amd.com out << " - Transitions -\\n"; 13267542SBrad.Beckmann@amd.com for (${ident}_State state = ${ident}_State_FIRST; 13277542SBrad.Beckmann@amd.com state < ${ident}_State_NUM; 13287542SBrad.Beckmann@amd.com ++state) { 13297542SBrad.Beckmann@amd.com for (${ident}_Event event = ${ident}_Event_FIRST; 13307542SBrad.Beckmann@amd.com event < ${ident}_Event_NUM; 13317542SBrad.Beckmann@amd.com ++event) { 13327542SBrad.Beckmann@amd.com if (m_profilers[0]->isPossible(state, event)) { 13337542SBrad.Beckmann@amd.com out << (${ident}_State) state << " " 13347542SBrad.Beckmann@amd.com << (${ident}_Event) event << " ["; 13357542SBrad.Beckmann@amd.com uint64 total = 0; 13367542SBrad.Beckmann@amd.com for (int i = 0; i < m_profilers.size(); i++) { 13377542SBrad.Beckmann@amd.com out << m_profilers[i]->getTransitionCount(state, event) << " "; 13387542SBrad.Beckmann@amd.com total += m_profilers[i]->getTransitionCount(state, event); 13397542SBrad.Beckmann@amd.com } 13407542SBrad.Beckmann@amd.com out << "] " << total << "\\n"; 13417542SBrad.Beckmann@amd.com } 13427542SBrad.Beckmann@amd.com } 13437542SBrad.Beckmann@amd.com out << "\\n"; 13447542SBrad.Beckmann@amd.com } 13457542SBrad.Beckmann@amd.com} 13467542SBrad.Beckmann@amd.com''') 13477542SBrad.Beckmann@amd.com code.write(path, "%s_ProfileDumper.cc" % self.ident) 13487542SBrad.Beckmann@amd.com 13496657Snate@binkert.org def printProfilerHH(self, path): 13506999Snate@binkert.org code = self.symtab.codeFormatter() 13516657Snate@binkert.org ident = self.ident 13526657Snate@binkert.org 13536657Snate@binkert.org code(''' 13546657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 13556657Snate@binkert.org// ${ident}: ${{self.short}} 13566657Snate@binkert.org 13577542SBrad.Beckmann@amd.com#ifndef __${ident}_PROFILER_HH__ 13587542SBrad.Beckmann@amd.com#define __${ident}_PROFILER_HH__ 13596657Snate@binkert.org 13607832Snate@binkert.org#include <cassert> 13617002Snate@binkert.org#include <iostream> 13627002Snate@binkert.org 13638229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 13648229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 13656657Snate@binkert.org#include "mem/ruby/common/Global.hh" 13666657Snate@binkert.org 13677007Snate@binkert.orgclass ${ident}_Profiler 13687007Snate@binkert.org{ 13696657Snate@binkert.org public: 13706657Snate@binkert.org ${ident}_Profiler(); 13716657Snate@binkert.org void setVersion(int version); 13726657Snate@binkert.org void countTransition(${ident}_State state, ${ident}_Event event); 13736657Snate@binkert.org void possibleTransition(${ident}_State state, ${ident}_Event event); 13747542SBrad.Beckmann@amd.com uint64 getEventCount(${ident}_Event event); 13757542SBrad.Beckmann@amd.com bool isPossible(${ident}_State state, ${ident}_Event event); 13767542SBrad.Beckmann@amd.com uint64 getTransitionCount(${ident}_State state, ${ident}_Event event); 13776657Snate@binkert.org void clearStats(); 13786657Snate@binkert.org 13796657Snate@binkert.org private: 13806657Snate@binkert.org int m_counters[${ident}_State_NUM][${ident}_Event_NUM]; 13816657Snate@binkert.org int m_event_counters[${ident}_Event_NUM]; 13826657Snate@binkert.org bool m_possible[${ident}_State_NUM][${ident}_Event_NUM]; 13836657Snate@binkert.org int m_version; 13846657Snate@binkert.org}; 13856657Snate@binkert.org 13867007Snate@binkert.org#endif // __${ident}_PROFILER_HH__ 13876657Snate@binkert.org''') 13886657Snate@binkert.org code.write(path, "%s_Profiler.hh" % self.ident) 13896657Snate@binkert.org 13906657Snate@binkert.org def printProfilerCC(self, path): 13916999Snate@binkert.org code = self.symtab.codeFormatter() 13926657Snate@binkert.org ident = self.ident 13936657Snate@binkert.org 13946657Snate@binkert.org code(''' 13956657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 13966657Snate@binkert.org// ${ident}: ${{self.short}} 13976657Snate@binkert.org 13987832Snate@binkert.org#include <cassert> 13997832Snate@binkert.org 14006657Snate@binkert.org#include "mem/protocol/${ident}_Profiler.hh" 14016657Snate@binkert.org 14026657Snate@binkert.org${ident}_Profiler::${ident}_Profiler() 14036657Snate@binkert.org{ 14046657Snate@binkert.org for (int state = 0; state < ${ident}_State_NUM; state++) { 14056657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 14066657Snate@binkert.org m_possible[state][event] = false; 14076657Snate@binkert.org m_counters[state][event] = 0; 14086657Snate@binkert.org } 14096657Snate@binkert.org } 14106657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 14116657Snate@binkert.org m_event_counters[event] = 0; 14126657Snate@binkert.org } 14136657Snate@binkert.org} 14147007Snate@binkert.org 14157007Snate@binkert.orgvoid 14167007Snate@binkert.org${ident}_Profiler::setVersion(int version) 14176657Snate@binkert.org{ 14186657Snate@binkert.org m_version = version; 14196657Snate@binkert.org} 14207007Snate@binkert.org 14217007Snate@binkert.orgvoid 14227007Snate@binkert.org${ident}_Profiler::clearStats() 14236657Snate@binkert.org{ 14246657Snate@binkert.org for (int state = 0; state < ${ident}_State_NUM; state++) { 14256657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 14266657Snate@binkert.org m_counters[state][event] = 0; 14276657Snate@binkert.org } 14286657Snate@binkert.org } 14296657Snate@binkert.org 14306657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 14316657Snate@binkert.org m_event_counters[event] = 0; 14326657Snate@binkert.org } 14336657Snate@binkert.org} 14347007Snate@binkert.orgvoid 14357007Snate@binkert.org${ident}_Profiler::countTransition(${ident}_State state, ${ident}_Event event) 14366657Snate@binkert.org{ 14376657Snate@binkert.org assert(m_possible[state][event]); 14386657Snate@binkert.org m_counters[state][event]++; 14396657Snate@binkert.org m_event_counters[event]++; 14406657Snate@binkert.org} 14417007Snate@binkert.orgvoid 14427007Snate@binkert.org${ident}_Profiler::possibleTransition(${ident}_State state, 14437007Snate@binkert.org ${ident}_Event event) 14446657Snate@binkert.org{ 14456657Snate@binkert.org m_possible[state][event] = true; 14466657Snate@binkert.org} 14477007Snate@binkert.org 14487542SBrad.Beckmann@amd.comuint64 14497542SBrad.Beckmann@amd.com${ident}_Profiler::getEventCount(${ident}_Event event) 14506657Snate@binkert.org{ 14517542SBrad.Beckmann@amd.com return m_event_counters[event]; 14527542SBrad.Beckmann@amd.com} 14537002Snate@binkert.org 14547542SBrad.Beckmann@amd.combool 14557542SBrad.Beckmann@amd.com${ident}_Profiler::isPossible(${ident}_State state, ${ident}_Event event) 14567542SBrad.Beckmann@amd.com{ 14577542SBrad.Beckmann@amd.com return m_possible[state][event]; 14586657Snate@binkert.org} 14597542SBrad.Beckmann@amd.com 14607542SBrad.Beckmann@amd.comuint64 14617542SBrad.Beckmann@amd.com${ident}_Profiler::getTransitionCount(${ident}_State state, 14627542SBrad.Beckmann@amd.com ${ident}_Event event) 14637542SBrad.Beckmann@amd.com{ 14647542SBrad.Beckmann@amd.com return m_counters[state][event]; 14657542SBrad.Beckmann@amd.com} 14667542SBrad.Beckmann@amd.com 14676657Snate@binkert.org''') 14686657Snate@binkert.org code.write(path, "%s_Profiler.cc" % self.ident) 14696657Snate@binkert.org 14706657Snate@binkert.org # ************************** 14716657Snate@binkert.org # ******* HTML Files ******* 14726657Snate@binkert.org # ************************** 14737007Snate@binkert.org def frameRef(self, click_href, click_target, over_href, over_num, text): 14746999Snate@binkert.org code = self.symtab.codeFormatter(fix_newlines=False) 14757007Snate@binkert.org code("""<A href=\"$click_href\" target=\"$click_target\" onmouseover=\" 14767007Snate@binkert.org if (parent.frames[$over_num].location != parent.location + '$over_href') { 14777007Snate@binkert.org parent.frames[$over_num].location='$over_href' 14787007Snate@binkert.org }\"> 14797007Snate@binkert.org ${{html.formatShorthand(text)}} 14807007Snate@binkert.org </A>""") 14816657Snate@binkert.org return str(code) 14826657Snate@binkert.org 14836657Snate@binkert.org def writeHTMLFiles(self, path): 14846657Snate@binkert.org # Create table with no row hilighted 14856657Snate@binkert.org self.printHTMLTransitions(path, None) 14866657Snate@binkert.org 14876657Snate@binkert.org # Generate transition tables 14886657Snate@binkert.org for state in self.states.itervalues(): 14896657Snate@binkert.org self.printHTMLTransitions(path, state) 14906657Snate@binkert.org 14916657Snate@binkert.org # Generate action descriptions 14926657Snate@binkert.org for action in self.actions.itervalues(): 14936657Snate@binkert.org name = "%s_action_%s.html" % (self.ident, action.ident) 14946657Snate@binkert.org code = html.createSymbol(action, "Action") 14956657Snate@binkert.org code.write(path, name) 14966657Snate@binkert.org 14976657Snate@binkert.org # Generate state descriptions 14986657Snate@binkert.org for state in self.states.itervalues(): 14996657Snate@binkert.org name = "%s_State_%s.html" % (self.ident, state.ident) 15006657Snate@binkert.org code = html.createSymbol(state, "State") 15016657Snate@binkert.org code.write(path, name) 15026657Snate@binkert.org 15036657Snate@binkert.org # Generate event descriptions 15046657Snate@binkert.org for event in self.events.itervalues(): 15056657Snate@binkert.org name = "%s_Event_%s.html" % (self.ident, event.ident) 15066657Snate@binkert.org code = html.createSymbol(event, "Event") 15076657Snate@binkert.org code.write(path, name) 15086657Snate@binkert.org 15096657Snate@binkert.org def printHTMLTransitions(self, path, active_state): 15106999Snate@binkert.org code = self.symtab.codeFormatter() 15116657Snate@binkert.org 15126657Snate@binkert.org code(''' 15137007Snate@binkert.org<HTML> 15147007Snate@binkert.org<BODY link="blue" vlink="blue"> 15156657Snate@binkert.org 15166657Snate@binkert.org<H1 align="center">${{html.formatShorthand(self.short)}}: 15176657Snate@binkert.org''') 15186657Snate@binkert.org code.indent() 15196657Snate@binkert.org for i,machine in enumerate(self.symtab.getAllType(StateMachine)): 15206657Snate@binkert.org mid = machine.ident 15216657Snate@binkert.org if i != 0: 15226657Snate@binkert.org extra = " - " 15236657Snate@binkert.org else: 15246657Snate@binkert.org extra = "" 15256657Snate@binkert.org if machine == self: 15266657Snate@binkert.org code('$extra$mid') 15276657Snate@binkert.org else: 15286657Snate@binkert.org code('$extra<A target="Table" href="${mid}_table.html">$mid</A>') 15296657Snate@binkert.org code.dedent() 15306657Snate@binkert.org 15316657Snate@binkert.org code(""" 15326657Snate@binkert.org</H1> 15336657Snate@binkert.org 15346657Snate@binkert.org<TABLE border=1> 15356657Snate@binkert.org<TR> 15366657Snate@binkert.org <TH> </TH> 15376657Snate@binkert.org""") 15386657Snate@binkert.org 15396657Snate@binkert.org for event in self.events.itervalues(): 15406657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 15416657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 15426657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 15436657Snate@binkert.org 15446657Snate@binkert.org code('</TR>') 15456657Snate@binkert.org # -- Body of table 15466657Snate@binkert.org for state in self.states.itervalues(): 15476657Snate@binkert.org # -- Each row 15486657Snate@binkert.org if state == active_state: 15496657Snate@binkert.org color = "yellow" 15506657Snate@binkert.org else: 15516657Snate@binkert.org color = "white" 15526657Snate@binkert.org 15536657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 15546657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 15556657Snate@binkert.org text = html.formatShorthand(state.short) 15566657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 15576657Snate@binkert.org code(''' 15586657Snate@binkert.org<TR> 15596657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 15606657Snate@binkert.org''') 15616657Snate@binkert.org 15626657Snate@binkert.org # -- One column for each event 15636657Snate@binkert.org for event in self.events.itervalues(): 15646657Snate@binkert.org trans = self.table.get((state,event), None) 15656657Snate@binkert.org if trans is None: 15666657Snate@binkert.org # This is the no transition case 15676657Snate@binkert.org if state == active_state: 15686657Snate@binkert.org color = "#C0C000" 15696657Snate@binkert.org else: 15706657Snate@binkert.org color = "lightgrey" 15716657Snate@binkert.org 15726657Snate@binkert.org code('<TD bgcolor=$color> </TD>') 15736657Snate@binkert.org continue 15746657Snate@binkert.org 15756657Snate@binkert.org next = trans.nextState 15766657Snate@binkert.org stall_action = False 15776657Snate@binkert.org 15786657Snate@binkert.org # -- Get the actions 15796657Snate@binkert.org for action in trans.actions: 15806657Snate@binkert.org if action.ident == "z_stall" or \ 15816657Snate@binkert.org action.ident == "zz_recycleMandatoryQueue": 15826657Snate@binkert.org stall_action = True 15836657Snate@binkert.org 15846657Snate@binkert.org # -- Print out "actions/next-state" 15856657Snate@binkert.org if stall_action: 15866657Snate@binkert.org if state == active_state: 15876657Snate@binkert.org color = "#C0C000" 15886657Snate@binkert.org else: 15896657Snate@binkert.org color = "lightgrey" 15906657Snate@binkert.org 15916657Snate@binkert.org elif active_state and next.ident == active_state.ident: 15926657Snate@binkert.org color = "aqua" 15936657Snate@binkert.org elif state == active_state: 15946657Snate@binkert.org color = "yellow" 15956657Snate@binkert.org else: 15966657Snate@binkert.org color = "white" 15976657Snate@binkert.org 15986657Snate@binkert.org code('<TD bgcolor=$color>') 15996657Snate@binkert.org for action in trans.actions: 16006657Snate@binkert.org href = "%s_action_%s.html" % (self.ident, action.ident) 16016657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", 16026657Snate@binkert.org action.short) 16037007Snate@binkert.org code(' $ref') 16046657Snate@binkert.org if next != state: 16056657Snate@binkert.org if trans.actions: 16066657Snate@binkert.org code('/') 16076657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, next.ident) 16086657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, next.ident) 16096657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", next.short) 16106657Snate@binkert.org code("$ref") 16117007Snate@binkert.org code("</TD>") 16126657Snate@binkert.org 16136657Snate@binkert.org # -- Each row 16146657Snate@binkert.org if state == active_state: 16156657Snate@binkert.org color = "yellow" 16166657Snate@binkert.org else: 16176657Snate@binkert.org color = "white" 16186657Snate@binkert.org 16196657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 16206657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 16216657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 16226657Snate@binkert.org code(''' 16236657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 16246657Snate@binkert.org</TR> 16256657Snate@binkert.org''') 16266657Snate@binkert.org code(''' 16277007Snate@binkert.org<!- Column footer-> 16286657Snate@binkert.org<TR> 16296657Snate@binkert.org <TH> </TH> 16306657Snate@binkert.org''') 16316657Snate@binkert.org 16326657Snate@binkert.org for event in self.events.itervalues(): 16336657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 16346657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 16356657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 16366657Snate@binkert.org code(''' 16376657Snate@binkert.org</TR> 16386657Snate@binkert.org</TABLE> 16396657Snate@binkert.org</BODY></HTML> 16406657Snate@binkert.org''') 16416657Snate@binkert.org 16426657Snate@binkert.org 16436657Snate@binkert.org if active_state: 16446657Snate@binkert.org name = "%s_table_%s.html" % (self.ident, active_state.ident) 16456657Snate@binkert.org else: 16466657Snate@binkert.org name = "%s_table.html" % self.ident 16476657Snate@binkert.org code.write(path, name) 16486657Snate@binkert.org 16496657Snate@binkert.org__all__ = [ "StateMachine" ] 1650