StateMachine.py revision 9219
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", 429102SNuwan.Jayasena@amd.com "MemoryControl": "MemoryControl", 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() 649104Shestness@cs.utexas.edu self.request_types = orderdict() 656657Snate@binkert.org self.transitions = [] 666657Snate@binkert.org self.in_ports = [] 676657Snate@binkert.org self.functions = [] 686657Snate@binkert.org self.objects = [] 697839Snilay@cs.wisc.edu self.TBEType = None 707839Snilay@cs.wisc.edu self.EntryType = None 716657Snate@binkert.org 726657Snate@binkert.org self.message_buffer_names = [] 736657Snate@binkert.org 746657Snate@binkert.org def __repr__(self): 756657Snate@binkert.org return "[StateMachine: %s]" % self.ident 766657Snate@binkert.org 776657Snate@binkert.org def addState(self, state): 786657Snate@binkert.org assert self.table is None 796657Snate@binkert.org self.states[state.ident] = state 806657Snate@binkert.org 816657Snate@binkert.org def addEvent(self, event): 826657Snate@binkert.org assert self.table is None 836657Snate@binkert.org self.events[event.ident] = event 846657Snate@binkert.org 856657Snate@binkert.org def addAction(self, action): 866657Snate@binkert.org assert self.table is None 876657Snate@binkert.org 886657Snate@binkert.org # Check for duplicate action 896657Snate@binkert.org for other in self.actions.itervalues(): 906657Snate@binkert.org if action.ident == other.ident: 916779SBrad.Beckmann@amd.com action.warning("Duplicate action definition: %s" % action.ident) 926657Snate@binkert.org action.error("Duplicate action definition: %s" % action.ident) 936657Snate@binkert.org if action.short == other.short: 946657Snate@binkert.org other.warning("Duplicate action shorthand: %s" % other.ident) 956657Snate@binkert.org other.warning(" shorthand = %s" % other.short) 966657Snate@binkert.org action.warning("Duplicate action shorthand: %s" % action.ident) 976657Snate@binkert.org action.error(" shorthand = %s" % action.short) 986657Snate@binkert.org 996657Snate@binkert.org self.actions[action.ident] = action 1006657Snate@binkert.org 1019104Shestness@cs.utexas.edu def addRequestType(self, request_type): 1029104Shestness@cs.utexas.edu assert self.table is None 1039104Shestness@cs.utexas.edu self.request_types[request_type.ident] = request_type 1049104Shestness@cs.utexas.edu 1056657Snate@binkert.org def addTransition(self, trans): 1066657Snate@binkert.org assert self.table is None 1076657Snate@binkert.org self.transitions.append(trans) 1086657Snate@binkert.org 1096657Snate@binkert.org def addInPort(self, var): 1106657Snate@binkert.org self.in_ports.append(var) 1116657Snate@binkert.org 1126657Snate@binkert.org def addFunc(self, func): 1136657Snate@binkert.org # register func in the symbol table 1146657Snate@binkert.org self.symtab.registerSym(str(func), func) 1156657Snate@binkert.org self.functions.append(func) 1166657Snate@binkert.org 1176657Snate@binkert.org def addObject(self, obj): 1186657Snate@binkert.org self.objects.append(obj) 1196657Snate@binkert.org 1207839Snilay@cs.wisc.edu def addType(self, type): 1217839Snilay@cs.wisc.edu type_ident = '%s' % type.c_ident 1227839Snilay@cs.wisc.edu 1237839Snilay@cs.wisc.edu if type_ident == "%s_TBE" %self.ident: 1247839Snilay@cs.wisc.edu if self.TBEType != None: 1257839Snilay@cs.wisc.edu self.error("Multiple Transaction Buffer types in a " \ 1267839Snilay@cs.wisc.edu "single machine."); 1277839Snilay@cs.wisc.edu self.TBEType = type 1287839Snilay@cs.wisc.edu 1297839Snilay@cs.wisc.edu elif "interface" in type and "AbstractCacheEntry" == type["interface"]: 1307839Snilay@cs.wisc.edu if self.EntryType != None: 1317839Snilay@cs.wisc.edu self.error("Multiple AbstractCacheEntry types in a " \ 1327839Snilay@cs.wisc.edu "single machine."); 1337839Snilay@cs.wisc.edu self.EntryType = type 1347839Snilay@cs.wisc.edu 1356657Snate@binkert.org # Needs to be called before accessing the table 1366657Snate@binkert.org def buildTable(self): 1376657Snate@binkert.org assert self.table is None 1386657Snate@binkert.org 1396657Snate@binkert.org table = {} 1406657Snate@binkert.org 1416657Snate@binkert.org for trans in self.transitions: 1426657Snate@binkert.org # Track which actions we touch so we know if we use them 1436657Snate@binkert.org # all -- really this should be done for all symbols as 1446657Snate@binkert.org # part of the symbol table, then only trigger it for 1456657Snate@binkert.org # Actions, States, Events, etc. 1466657Snate@binkert.org 1476657Snate@binkert.org for action in trans.actions: 1486657Snate@binkert.org action.used = True 1496657Snate@binkert.org 1506657Snate@binkert.org index = (trans.state, trans.event) 1516657Snate@binkert.org if index in table: 1526657Snate@binkert.org table[index].warning("Duplicate transition: %s" % table[index]) 1536657Snate@binkert.org trans.error("Duplicate transition: %s" % trans) 1546657Snate@binkert.org table[index] = trans 1556657Snate@binkert.org 1566657Snate@binkert.org # Look at all actions to make sure we used them all 1576657Snate@binkert.org for action in self.actions.itervalues(): 1586657Snate@binkert.org if not action.used: 1596657Snate@binkert.org error_msg = "Unused action: %s" % action.ident 1606657Snate@binkert.org if "desc" in action: 1616657Snate@binkert.org error_msg += ", " + action.desc 1626657Snate@binkert.org action.warning(error_msg) 1636657Snate@binkert.org self.table = table 1646657Snate@binkert.org 1659219Spower.jg@gmail.com def writeCodeFiles(self, path, includes): 1666877Ssteve.reinhardt@amd.com self.printControllerPython(path) 1676657Snate@binkert.org self.printControllerHH(path) 1689219Spower.jg@gmail.com self.printControllerCC(path, includes) 1696657Snate@binkert.org self.printCSwitch(path) 1709219Spower.jg@gmail.com self.printCWakeup(path, includes) 1716657Snate@binkert.org self.printProfilerCC(path) 1726657Snate@binkert.org self.printProfilerHH(path) 1737542SBrad.Beckmann@amd.com self.printProfileDumperCC(path) 1747542SBrad.Beckmann@amd.com self.printProfileDumperHH(path) 1756657Snate@binkert.org 1766877Ssteve.reinhardt@amd.com def printControllerPython(self, path): 1776999Snate@binkert.org code = self.symtab.codeFormatter() 1786877Ssteve.reinhardt@amd.com ident = self.ident 1796877Ssteve.reinhardt@amd.com py_ident = "%s_Controller" % ident 1806877Ssteve.reinhardt@amd.com c_ident = "%s_Controller" % self.ident 1816877Ssteve.reinhardt@amd.com code(''' 1826877Ssteve.reinhardt@amd.comfrom m5.params import * 1836877Ssteve.reinhardt@amd.comfrom m5.SimObject import SimObject 1846877Ssteve.reinhardt@amd.comfrom Controller import RubyController 1856877Ssteve.reinhardt@amd.com 1866877Ssteve.reinhardt@amd.comclass $py_ident(RubyController): 1876877Ssteve.reinhardt@amd.com type = '$py_ident' 1886877Ssteve.reinhardt@amd.com''') 1896877Ssteve.reinhardt@amd.com code.indent() 1906877Ssteve.reinhardt@amd.com for param in self.config_parameters: 1916877Ssteve.reinhardt@amd.com dflt_str = '' 1926877Ssteve.reinhardt@amd.com if param.default is not None: 1936877Ssteve.reinhardt@amd.com dflt_str = str(param.default) + ', ' 1946882SBrad.Beckmann@amd.com if python_class_map.has_key(param.type_ast.type.c_ident): 1956882SBrad.Beckmann@amd.com python_type = python_class_map[param.type_ast.type.c_ident] 1966882SBrad.Beckmann@amd.com code('${{param.name}} = Param.${{python_type}}(${dflt_str}"")') 1976882SBrad.Beckmann@amd.com else: 1986882SBrad.Beckmann@amd.com self.error("Unknown c++ to python class conversion for c++ " \ 1996882SBrad.Beckmann@amd.com "type: '%s'. Please update the python_class_map " \ 2006882SBrad.Beckmann@amd.com "in StateMachine.py", param.type_ast.type.c_ident) 2016877Ssteve.reinhardt@amd.com code.dedent() 2026877Ssteve.reinhardt@amd.com code.write(path, '%s.py' % py_ident) 2036877Ssteve.reinhardt@amd.com 2046877Ssteve.reinhardt@amd.com 2056657Snate@binkert.org def printControllerHH(self, path): 2066657Snate@binkert.org '''Output the method declarations for the class declaration''' 2076999Snate@binkert.org code = self.symtab.codeFormatter() 2086657Snate@binkert.org ident = self.ident 2096657Snate@binkert.org c_ident = "%s_Controller" % self.ident 2106657Snate@binkert.org 2116657Snate@binkert.org self.message_buffer_names = [] 2126657Snate@binkert.org 2136657Snate@binkert.org code(''' 2147007Snate@binkert.org/** \\file $c_ident.hh 2156657Snate@binkert.org * 2166657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__ 2176657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}" 2186657Snate@binkert.org */ 2196657Snate@binkert.org 2207007Snate@binkert.org#ifndef __${ident}_CONTROLLER_HH__ 2217007Snate@binkert.org#define __${ident}_CONTROLLER_HH__ 2226657Snate@binkert.org 2237002Snate@binkert.org#include <iostream> 2247002Snate@binkert.org#include <sstream> 2257002Snate@binkert.org#include <string> 2267002Snate@binkert.org 2278229Snate@binkert.org#include "mem/protocol/${ident}_ProfileDumper.hh" 2288229Snate@binkert.org#include "mem/protocol/${ident}_Profiler.hh" 2296657Snate@binkert.org#include "mem/protocol/TransitionResult.hh" 2306657Snate@binkert.org#include "mem/protocol/Types.hh" 2318229Snate@binkert.org#include "mem/ruby/common/Consumer.hh" 2328229Snate@binkert.org#include "mem/ruby/common/Global.hh" 2338229Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh" 2348229Snate@binkert.org#include "params/$c_ident.hh" 2356657Snate@binkert.org''') 2366657Snate@binkert.org 2376657Snate@binkert.org seen_types = set() 2386657Snate@binkert.org for var in self.objects: 2396793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 2406657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 2416657Snate@binkert.org seen_types.add(var.type.ident) 2426657Snate@binkert.org 2436657Snate@binkert.org # for adding information to the protocol debug trace 2446657Snate@binkert.org code(''' 2457002Snate@binkert.orgextern std::stringstream ${ident}_transitionComment; 2466657Snate@binkert.org 2477007Snate@binkert.orgclass $c_ident : public AbstractController 2487007Snate@binkert.org{ 2497007Snate@binkert.org// the coherence checker needs to call isBlockExclusive() and isBlockShared() 2507007Snate@binkert.org// making the Chip a friend class is an easy way to do this for now 2517007Snate@binkert.org 2526657Snate@binkert.orgpublic: 2536877Ssteve.reinhardt@amd.com typedef ${c_ident}Params Params; 2546877Ssteve.reinhardt@amd.com $c_ident(const Params *p); 2556657Snate@binkert.org static int getNumControllers(); 2566877Ssteve.reinhardt@amd.com void init(); 2576657Snate@binkert.org MessageBuffer* getMandatoryQueue() const; 2586657Snate@binkert.org const int & getVersion() const; 2597002Snate@binkert.org const std::string toString() const; 2607002Snate@binkert.org const std::string getName() const; 2617567SBrad.Beckmann@amd.com void stallBuffer(MessageBuffer* buf, Address addr); 2627567SBrad.Beckmann@amd.com void wakeUpBuffers(Address addr); 2637922SBrad.Beckmann@amd.com void wakeUpAllBuffers(); 2646881SBrad.Beckmann@amd.com void initNetworkPtr(Network* net_ptr) { m_net_ptr = net_ptr; } 2657002Snate@binkert.org void print(std::ostream& out) const; 2667002Snate@binkert.org void printConfig(std::ostream& out) const; 2676657Snate@binkert.org void wakeup(); 2687002Snate@binkert.org void printStats(std::ostream& out) const; 2696902SBrad.Beckmann@amd.com void clearStats(); 2706863Sdrh5@cs.wisc.edu void blockOnQueue(Address addr, MessageBuffer* port); 2716863Sdrh5@cs.wisc.edu void unblock(Address addr); 2728683Snilay@cs.wisc.edu void recordCacheTrace(int cntrl, CacheRecorder* tr); 2738683Snilay@cs.wisc.edu Sequencer* getSequencer() const; 2747007Snate@binkert.org 2756657Snate@binkert.orgprivate: 2766657Snate@binkert.org''') 2776657Snate@binkert.org 2786657Snate@binkert.org code.indent() 2796657Snate@binkert.org # added by SS 2806657Snate@binkert.org for param in self.config_parameters: 2816882SBrad.Beckmann@amd.com if param.pointer: 2826882SBrad.Beckmann@amd.com code('${{param.type_ast.type}}* m_${{param.ident}}_ptr;') 2836882SBrad.Beckmann@amd.com else: 2846882SBrad.Beckmann@amd.com code('${{param.type_ast.type}} m_${{param.ident}};') 2856657Snate@binkert.org 2866657Snate@binkert.org code(''' 2876657Snate@binkert.orgint m_number_of_TBEs; 2886657Snate@binkert.org 2897007Snate@binkert.orgTransitionResult doTransition(${ident}_Event event, 2907839Snilay@cs.wisc.edu''') 2917839Snilay@cs.wisc.edu 2927839Snilay@cs.wisc.edu if self.EntryType != None: 2937839Snilay@cs.wisc.edu code(''' 2947839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}* m_cache_entry_ptr, 2957839Snilay@cs.wisc.edu''') 2967839Snilay@cs.wisc.edu if self.TBEType != None: 2977839Snilay@cs.wisc.edu code(''' 2987839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}* m_tbe_ptr, 2997839Snilay@cs.wisc.edu''') 3007839Snilay@cs.wisc.edu 3017839Snilay@cs.wisc.edu code(''' 3027007Snate@binkert.org const Address& addr); 3037007Snate@binkert.org 3047007Snate@binkert.orgTransitionResult doTransitionWorker(${ident}_Event event, 3057007Snate@binkert.org ${ident}_State state, 3067007Snate@binkert.org ${ident}_State& next_state, 3077839Snilay@cs.wisc.edu''') 3087839Snilay@cs.wisc.edu 3097839Snilay@cs.wisc.edu if self.TBEType != None: 3107839Snilay@cs.wisc.edu code(''' 3117839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}*& m_tbe_ptr, 3127839Snilay@cs.wisc.edu''') 3137839Snilay@cs.wisc.edu if self.EntryType != None: 3147839Snilay@cs.wisc.edu code(''' 3157839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, 3167839Snilay@cs.wisc.edu''') 3177839Snilay@cs.wisc.edu 3187839Snilay@cs.wisc.edu code(''' 3197007Snate@binkert.org const Address& addr); 3207007Snate@binkert.org 3217002Snate@binkert.orgstd::string m_name; 3226657Snate@binkert.orgint m_transitions_per_cycle; 3236657Snate@binkert.orgint m_buffer_size; 3246657Snate@binkert.orgint m_recycle_latency; 3257055Snate@binkert.orgstd::map<std::string, std::string> m_cfg; 3266657Snate@binkert.orgNodeID m_version; 3276657Snate@binkert.orgNetwork* m_net_ptr; 3286657Snate@binkert.orgMachineID m_machineID; 3296863Sdrh5@cs.wisc.edubool m_is_blocking; 3307055Snate@binkert.orgstd::map<Address, MessageBuffer*> m_block_map; 3317567SBrad.Beckmann@amd.comtypedef std::vector<MessageBuffer*> MsgVecType; 3328943Sandreas.hansson@arm.comtypedef std::map< Address, MsgVecType* > WaitingBufType; 3337567SBrad.Beckmann@amd.comWaitingBufType m_waiting_buffers; 3347567SBrad.Beckmann@amd.comint m_max_in_port_rank; 3357567SBrad.Beckmann@amd.comint m_cur_in_port_rank; 3367542SBrad.Beckmann@amd.comstatic ${ident}_ProfileDumper s_profileDumper; 3377542SBrad.Beckmann@amd.com${ident}_Profiler m_profiler; 3386657Snate@binkert.orgstatic int m_num_controllers; 3397007Snate@binkert.org 3406657Snate@binkert.org// Internal functions 3416657Snate@binkert.org''') 3426657Snate@binkert.org 3436657Snate@binkert.org for func in self.functions: 3446657Snate@binkert.org proto = func.prototype 3456657Snate@binkert.org if proto: 3466657Snate@binkert.org code('$proto') 3476657Snate@binkert.org 3487839Snilay@cs.wisc.edu if self.EntryType != None: 3497839Snilay@cs.wisc.edu code(''' 3507839Snilay@cs.wisc.edu 3517839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable 3527839Snilay@cs.wisc.eduvoid set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry); 3537839Snilay@cs.wisc.eduvoid unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr); 3547839Snilay@cs.wisc.edu''') 3557839Snilay@cs.wisc.edu 3567839Snilay@cs.wisc.edu if self.TBEType != None: 3577839Snilay@cs.wisc.edu code(''' 3587839Snilay@cs.wisc.edu 3597839Snilay@cs.wisc.edu// Set and Reset for tbe variable 3607839Snilay@cs.wisc.eduvoid set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${ident}_TBE* m_new_tbe); 3617839Snilay@cs.wisc.eduvoid unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr); 3627839Snilay@cs.wisc.edu''') 3637839Snilay@cs.wisc.edu 3646657Snate@binkert.org code(''' 3656657Snate@binkert.org 3666657Snate@binkert.org// Actions 3676657Snate@binkert.org''') 3687839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 3697839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3707839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3717839Snilay@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);') 3727839Snilay@cs.wisc.edu elif self.TBEType != None: 3737839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3747839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3757839Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, const Address& addr);') 3767839Snilay@cs.wisc.edu elif self.EntryType != None: 3777839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3787839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3797839Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr);') 3807839Snilay@cs.wisc.edu else: 3817839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3827839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3837839Snilay@cs.wisc.edu code('void ${{action.ident}}(const Address& addr);') 3846657Snate@binkert.org 3856657Snate@binkert.org # the controller internal variables 3866657Snate@binkert.org code(''' 3876657Snate@binkert.org 3887007Snate@binkert.org// Objects 3896657Snate@binkert.org''') 3906657Snate@binkert.org for var in self.objects: 3916657Snate@binkert.org th = var.get("template_hack", "") 3926657Snate@binkert.org code('${{var.type.c_ident}}$th* m_${{var.c_ident}}_ptr;') 3936657Snate@binkert.org 3946657Snate@binkert.org if var.type.ident == "MessageBuffer": 3956657Snate@binkert.org self.message_buffer_names.append("m_%s_ptr" % var.c_ident) 3966657Snate@binkert.org 3976657Snate@binkert.org code.dedent() 3986657Snate@binkert.org code('};') 3997007Snate@binkert.org code('#endif // __${ident}_CONTROLLER_H__') 4006657Snate@binkert.org code.write(path, '%s.hh' % c_ident) 4016657Snate@binkert.org 4029219Spower.jg@gmail.com def printControllerCC(self, path, includes): 4036657Snate@binkert.org '''Output the actions for performing the actions''' 4046657Snate@binkert.org 4056999Snate@binkert.org code = self.symtab.codeFormatter() 4066657Snate@binkert.org ident = self.ident 4076657Snate@binkert.org c_ident = "%s_Controller" % self.ident 4086657Snate@binkert.org 4096657Snate@binkert.org code(''' 4107007Snate@binkert.org/** \\file $c_ident.cc 4116657Snate@binkert.org * 4126657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__ 4136657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}" 4146657Snate@binkert.org */ 4156657Snate@binkert.org 4168946Sandreas.hansson@arm.com#include <sys/types.h> 4178946Sandreas.hansson@arm.com#include <unistd.h> 4188946Sandreas.hansson@arm.com 4197832Snate@binkert.org#include <cassert> 4207002Snate@binkert.org#include <sstream> 4217002Snate@binkert.org#include <string> 4227002Snate@binkert.org 4238641Snate@binkert.org#include "base/compiler.hh" 4247056Snate@binkert.org#include "base/cprintf.hh" 4258232Snate@binkert.org#include "debug/RubyGenerated.hh" 4268232Snate@binkert.org#include "debug/RubySlicc.hh" 4276657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 4288229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 4296657Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 4306657Snate@binkert.org#include "mem/protocol/Types.hh" 4317056Snate@binkert.org#include "mem/ruby/common/Global.hh" 4326657Snate@binkert.org#include "mem/ruby/system/System.hh" 4339219Spower.jg@gmail.com''') 4349219Spower.jg@gmail.com for include_path in includes: 4359219Spower.jg@gmail.com code('#include "${{include_path}}"') 4369219Spower.jg@gmail.com 4379219Spower.jg@gmail.com code(''' 4387002Snate@binkert.org 4397002Snate@binkert.orgusing namespace std; 4406657Snate@binkert.org''') 4416657Snate@binkert.org 4426657Snate@binkert.org # include object classes 4436657Snate@binkert.org seen_types = set() 4446657Snate@binkert.org for var in self.objects: 4456793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 4466657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 4476657Snate@binkert.org seen_types.add(var.type.ident) 4486657Snate@binkert.org 4496657Snate@binkert.org code(''' 4506877Ssteve.reinhardt@amd.com$c_ident * 4516877Ssteve.reinhardt@amd.com${c_ident}Params::create() 4526877Ssteve.reinhardt@amd.com{ 4536877Ssteve.reinhardt@amd.com return new $c_ident(this); 4546877Ssteve.reinhardt@amd.com} 4556877Ssteve.reinhardt@amd.com 4566657Snate@binkert.orgint $c_ident::m_num_controllers = 0; 4577542SBrad.Beckmann@amd.com${ident}_ProfileDumper $c_ident::s_profileDumper; 4586657Snate@binkert.org 4597007Snate@binkert.org// for adding information to the protocol debug trace 4606657Snate@binkert.orgstringstream ${ident}_transitionComment; 4616657Snate@binkert.org#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str) 4627007Snate@binkert.org 4636657Snate@binkert.org/** \\brief constructor */ 4646877Ssteve.reinhardt@amd.com$c_ident::$c_ident(const Params *p) 4656877Ssteve.reinhardt@amd.com : AbstractController(p) 4666657Snate@binkert.org{ 4676877Ssteve.reinhardt@amd.com m_version = p->version; 4686877Ssteve.reinhardt@amd.com m_transitions_per_cycle = p->transitions_per_cycle; 4696877Ssteve.reinhardt@amd.com m_buffer_size = p->buffer_size; 4706877Ssteve.reinhardt@amd.com m_recycle_latency = p->recycle_latency; 4716877Ssteve.reinhardt@amd.com m_number_of_TBEs = p->number_of_TBEs; 4726969SBrad.Beckmann@amd.com m_is_blocking = false; 4738532SLisa.Hsu@amd.com m_name = "${ident}"; 4746657Snate@binkert.org''') 4757567SBrad.Beckmann@amd.com # 4767567SBrad.Beckmann@amd.com # max_port_rank is used to size vectors and thus should be one plus the 4777567SBrad.Beckmann@amd.com # largest port rank 4787567SBrad.Beckmann@amd.com # 4797567SBrad.Beckmann@amd.com max_port_rank = self.in_ports[0].pairs["max_port_rank"] + 1 4807567SBrad.Beckmann@amd.com code(' m_max_in_port_rank = $max_port_rank;') 4816657Snate@binkert.org code.indent() 4826882SBrad.Beckmann@amd.com 4836882SBrad.Beckmann@amd.com # 4846882SBrad.Beckmann@amd.com # After initializing the universal machine parameters, initialize the 4856882SBrad.Beckmann@amd.com # this machines config parameters. Also detemine if these configuration 4866882SBrad.Beckmann@amd.com # params include a sequencer. This information will be used later for 4876882SBrad.Beckmann@amd.com # contecting the sequencer back to the L1 cache controller. 4886882SBrad.Beckmann@amd.com # 4898189SLisa.Hsu@amd.com contains_dma_sequencer = False 4908189SLisa.Hsu@amd.com sequencers = [] 4916877Ssteve.reinhardt@amd.com for param in self.config_parameters: 4928189SLisa.Hsu@amd.com if param.name == "dma_sequencer": 4938189SLisa.Hsu@amd.com contains_dma_sequencer = True 4948189SLisa.Hsu@amd.com elif re.compile("sequencer").search(param.name): 4958189SLisa.Hsu@amd.com sequencers.append(param.name) 4966882SBrad.Beckmann@amd.com if param.pointer: 4976882SBrad.Beckmann@amd.com code('m_${{param.name}}_ptr = p->${{param.name}};') 4986882SBrad.Beckmann@amd.com else: 4996882SBrad.Beckmann@amd.com code('m_${{param.name}} = p->${{param.name}};') 5006882SBrad.Beckmann@amd.com 5016882SBrad.Beckmann@amd.com # 5026882SBrad.Beckmann@amd.com # For the l1 cache controller, add the special atomic support which 5036882SBrad.Beckmann@amd.com # includes passing the sequencer a pointer to the controller. 5046882SBrad.Beckmann@amd.com # 5056882SBrad.Beckmann@amd.com if self.ident == "L1Cache": 5068189SLisa.Hsu@amd.com if not sequencers: 5076882SBrad.Beckmann@amd.com self.error("The L1Cache controller must include the sequencer " \ 5086882SBrad.Beckmann@amd.com "configuration parameter") 5096882SBrad.Beckmann@amd.com 5108189SLisa.Hsu@amd.com for seq in sequencers: 5118189SLisa.Hsu@amd.com code(''' 5128189SLisa.Hsu@amd.comm_${{seq}}_ptr->setController(this); 5138189SLisa.Hsu@amd.com ''') 5148938SLisa.Hsu@amd.com 5158938SLisa.Hsu@amd.com else: 5168938SLisa.Hsu@amd.com for seq in sequencers: 5178938SLisa.Hsu@amd.com code(''' 5188938SLisa.Hsu@amd.comm_${{seq}}_ptr->setController(this); 5198938SLisa.Hsu@amd.com ''') 5208938SLisa.Hsu@amd.com 5216888SBrad.Beckmann@amd.com # 5226888SBrad.Beckmann@amd.com # For the DMA controller, pass the sequencer a pointer to the 5236888SBrad.Beckmann@amd.com # controller. 5246888SBrad.Beckmann@amd.com # 5256888SBrad.Beckmann@amd.com if self.ident == "DMA": 5268189SLisa.Hsu@amd.com if not contains_dma_sequencer: 5276888SBrad.Beckmann@amd.com self.error("The DMA controller must include the sequencer " \ 5286888SBrad.Beckmann@amd.com "configuration parameter") 5296657Snate@binkert.org 5306888SBrad.Beckmann@amd.com code(''' 5316888SBrad.Beckmann@amd.comm_dma_sequencer_ptr->setController(this); 5326888SBrad.Beckmann@amd.com''') 5336888SBrad.Beckmann@amd.com 5346657Snate@binkert.org code('m_num_controllers++;') 5356657Snate@binkert.org for var in self.objects: 5366657Snate@binkert.org if var.ident.find("mandatoryQueue") >= 0: 5376657Snate@binkert.org code('m_${{var.c_ident}}_ptr = new ${{var.type.c_ident}}();') 5386657Snate@binkert.org 5396657Snate@binkert.org code.dedent() 5406657Snate@binkert.org code(''' 5416657Snate@binkert.org} 5426657Snate@binkert.org 5437007Snate@binkert.orgvoid 5447007Snate@binkert.org$c_ident::init() 5456657Snate@binkert.org{ 5467007Snate@binkert.org MachineType machine_type; 5477007Snate@binkert.org int base; 5487007Snate@binkert.org 5496657Snate@binkert.org m_machineID.type = MachineType_${ident}; 5506657Snate@binkert.org m_machineID.num = m_version; 5516657Snate@binkert.org 5527007Snate@binkert.org // initialize objects 5537542SBrad.Beckmann@amd.com m_profiler.setVersion(m_version); 5547542SBrad.Beckmann@amd.com s_profileDumper.registerProfiler(&m_profiler); 5557007Snate@binkert.org 5566657Snate@binkert.org''') 5576657Snate@binkert.org 5586657Snate@binkert.org code.indent() 5596657Snate@binkert.org for var in self.objects: 5606657Snate@binkert.org vtype = var.type 5616657Snate@binkert.org vid = "m_%s_ptr" % var.c_ident 5626657Snate@binkert.org if "network" not in var: 5636657Snate@binkert.org # Not a network port object 5646657Snate@binkert.org if "primitive" in vtype: 5656657Snate@binkert.org code('$vid = new ${{vtype.c_ident}};') 5666657Snate@binkert.org if "default" in var: 5676657Snate@binkert.org code('(*$vid) = ${{var["default"]}};') 5686657Snate@binkert.org else: 5696657Snate@binkert.org # Normal Object 5706657Snate@binkert.org # added by SS 5716657Snate@binkert.org if "factory" in var: 5726657Snate@binkert.org code('$vid = ${{var["factory"]}};') 5736657Snate@binkert.org elif var.ident.find("mandatoryQueue") < 0: 5746657Snate@binkert.org th = var.get("template_hack", "") 5756657Snate@binkert.org expr = "%s = new %s%s" % (vid, vtype.c_ident, th) 5766657Snate@binkert.org 5776657Snate@binkert.org args = "" 5786657Snate@binkert.org if "non_obj" not in vtype and not vtype.isEnumeration: 5796657Snate@binkert.org if expr.find("TBETable") >= 0: 5806657Snate@binkert.org args = "m_number_of_TBEs" 5816657Snate@binkert.org else: 5826657Snate@binkert.org args = var.get("constructor_hack", "") 5836657Snate@binkert.org 5847007Snate@binkert.org code('$expr($args);') 5856657Snate@binkert.org 5866657Snate@binkert.org code('assert($vid != NULL);') 5876657Snate@binkert.org 5886657Snate@binkert.org if "default" in var: 5897007Snate@binkert.org code('*$vid = ${{var["default"]}}; // Object default') 5906657Snate@binkert.org elif "default" in vtype: 5917007Snate@binkert.org comment = "Type %s default" % vtype.ident 5927007Snate@binkert.org code('*$vid = ${{vtype["default"]}}; // $comment') 5936657Snate@binkert.org 5946657Snate@binkert.org # Set ordering 5956657Snate@binkert.org if "ordered" in var and "trigger_queue" not in var: 5966657Snate@binkert.org # A buffer 5976657Snate@binkert.org code('$vid->setOrdering(${{var["ordered"]}});') 5986657Snate@binkert.org 5996657Snate@binkert.org # Set randomization 6006657Snate@binkert.org if "random" in var: 6016657Snate@binkert.org # A buffer 6026657Snate@binkert.org code('$vid->setRandomization(${{var["random"]}});') 6036657Snate@binkert.org 6046657Snate@binkert.org # Set Priority 6056657Snate@binkert.org if vtype.isBuffer and \ 6066657Snate@binkert.org "rank" in var and "trigger_queue" not in var: 6076657Snate@binkert.org code('$vid->setPriority(${{var["rank"]}});') 6087566SBrad.Beckmann@amd.com 6096657Snate@binkert.org else: 6106657Snate@binkert.org # Network port object 6116657Snate@binkert.org network = var["network"] 6126657Snate@binkert.org ordered = var["ordered"] 6136657Snate@binkert.org vnet = var["virtual_network"] 6148308Stushar@csail.mit.edu vnet_type = var["vnet_type"] 6156657Snate@binkert.org 6166657Snate@binkert.org assert var.machine is not None 6176657Snate@binkert.org code(''' 6187007Snate@binkert.orgmachine_type = string_to_MachineType("${{var.machine.ident}}"); 6197007Snate@binkert.orgbase = MachineType_base_number(machine_type); 6208308Stushar@csail.mit.edu$vid = m_net_ptr->get${network}NetQueue(m_version + base, $ordered, $vnet, "$vnet_type"); 6216657Snate@binkert.org''') 6226657Snate@binkert.org 6236657Snate@binkert.org code('assert($vid != NULL);') 6246657Snate@binkert.org 6256657Snate@binkert.org # Set ordering 6266657Snate@binkert.org if "ordered" in var: 6276657Snate@binkert.org # A buffer 6286657Snate@binkert.org code('$vid->setOrdering(${{var["ordered"]}});') 6296657Snate@binkert.org 6306657Snate@binkert.org # Set randomization 6316657Snate@binkert.org if "random" in var: 6326657Snate@binkert.org # A buffer 6338187SLisa.Hsu@amd.com code('$vid->setRandomization(${{var["random"]}});') 6346657Snate@binkert.org 6356657Snate@binkert.org # Set Priority 6366657Snate@binkert.org if "rank" in var: 6376657Snate@binkert.org code('$vid->setPriority(${{var["rank"]}})') 6386657Snate@binkert.org 6396657Snate@binkert.org # Set buffer size 6406657Snate@binkert.org if vtype.isBuffer: 6416657Snate@binkert.org code(''' 6426657Snate@binkert.orgif (m_buffer_size > 0) { 6437454Snate@binkert.org $vid->resize(m_buffer_size); 6446657Snate@binkert.org} 6456657Snate@binkert.org''') 6466657Snate@binkert.org 6476657Snate@binkert.org # set description (may be overriden later by port def) 6487007Snate@binkert.org code(''' 6497056Snate@binkert.org$vid->setDescription("[Version " + to_string(m_version) + ", ${ident}, name=${{var.c_ident}}]"); 6507007Snate@binkert.org 6517007Snate@binkert.org''') 6526657Snate@binkert.org 6537566SBrad.Beckmann@amd.com if vtype.isBuffer: 6547566SBrad.Beckmann@amd.com if "recycle_latency" in var: 6557566SBrad.Beckmann@amd.com code('$vid->setRecycleLatency(${{var["recycle_latency"]}});') 6567566SBrad.Beckmann@amd.com else: 6577566SBrad.Beckmann@amd.com code('$vid->setRecycleLatency(m_recycle_latency);') 6587566SBrad.Beckmann@amd.com 6597566SBrad.Beckmann@amd.com 6606657Snate@binkert.org # Set the queue consumers 6617672Snate@binkert.org code() 6626657Snate@binkert.org for port in self.in_ports: 6636657Snate@binkert.org code('${{port.code}}.setConsumer(this);') 6646657Snate@binkert.org 6656657Snate@binkert.org # Set the queue descriptions 6667672Snate@binkert.org code() 6676657Snate@binkert.org for port in self.in_ports: 6687056Snate@binkert.org code('${{port.code}}.setDescription("[Version " + to_string(m_version) + ", $ident, $port]");') 6696657Snate@binkert.org 6706657Snate@binkert.org # Initialize the transition profiling 6717672Snate@binkert.org code() 6726657Snate@binkert.org for trans in self.transitions: 6736657Snate@binkert.org # Figure out if we stall 6746657Snate@binkert.org stall = False 6756657Snate@binkert.org for action in trans.actions: 6766657Snate@binkert.org if action.ident == "z_stall": 6776657Snate@binkert.org stall = True 6786657Snate@binkert.org 6796657Snate@binkert.org # Only possible if it is not a 'z' case 6806657Snate@binkert.org if not stall: 6816657Snate@binkert.org state = "%s_State_%s" % (self.ident, trans.state.ident) 6826657Snate@binkert.org event = "%s_Event_%s" % (self.ident, trans.event.ident) 6837542SBrad.Beckmann@amd.com code('m_profiler.possibleTransition($state, $event);') 6846657Snate@binkert.org 6856657Snate@binkert.org code.dedent() 6866657Snate@binkert.org code('}') 6876657Snate@binkert.org 6886657Snate@binkert.org has_mandatory_q = False 6896657Snate@binkert.org for port in self.in_ports: 6906657Snate@binkert.org if port.code.find("mandatoryQueue_ptr") >= 0: 6916657Snate@binkert.org has_mandatory_q = True 6926657Snate@binkert.org 6936657Snate@binkert.org if has_mandatory_q: 6946657Snate@binkert.org mq_ident = "m_%s_mandatoryQueue_ptr" % self.ident 6956657Snate@binkert.org else: 6966657Snate@binkert.org mq_ident = "NULL" 6976657Snate@binkert.org 6988683Snilay@cs.wisc.edu seq_ident = "NULL" 6998683Snilay@cs.wisc.edu for param in self.config_parameters: 7008683Snilay@cs.wisc.edu if param.name == "sequencer": 7018683Snilay@cs.wisc.edu assert(param.pointer) 7028683Snilay@cs.wisc.edu seq_ident = "m_%s_ptr" % param.name 7038683Snilay@cs.wisc.edu 7046657Snate@binkert.org code(''' 7057007Snate@binkert.orgint 7067007Snate@binkert.org$c_ident::getNumControllers() 7077007Snate@binkert.org{ 7086657Snate@binkert.org return m_num_controllers; 7096657Snate@binkert.org} 7106657Snate@binkert.org 7117007Snate@binkert.orgMessageBuffer* 7127007Snate@binkert.org$c_ident::getMandatoryQueue() const 7137007Snate@binkert.org{ 7146657Snate@binkert.org return $mq_ident; 7156657Snate@binkert.org} 7166657Snate@binkert.org 7178683Snilay@cs.wisc.eduSequencer* 7188683Snilay@cs.wisc.edu$c_ident::getSequencer() const 7198683Snilay@cs.wisc.edu{ 7208683Snilay@cs.wisc.edu return $seq_ident; 7218683Snilay@cs.wisc.edu} 7228683Snilay@cs.wisc.edu 7237007Snate@binkert.orgconst int & 7247007Snate@binkert.org$c_ident::getVersion() const 7257007Snate@binkert.org{ 7266657Snate@binkert.org return m_version; 7276657Snate@binkert.org} 7286657Snate@binkert.org 7297007Snate@binkert.orgconst string 7307007Snate@binkert.org$c_ident::toString() const 7317007Snate@binkert.org{ 7326657Snate@binkert.org return "$c_ident"; 7336657Snate@binkert.org} 7346657Snate@binkert.org 7357007Snate@binkert.orgconst string 7367007Snate@binkert.org$c_ident::getName() const 7377007Snate@binkert.org{ 7386657Snate@binkert.org return m_name; 7396657Snate@binkert.org} 7407007Snate@binkert.org 7417007Snate@binkert.orgvoid 7427567SBrad.Beckmann@amd.com$c_ident::stallBuffer(MessageBuffer* buf, Address addr) 7437567SBrad.Beckmann@amd.com{ 7447567SBrad.Beckmann@amd.com if (m_waiting_buffers.count(addr) == 0) { 7457567SBrad.Beckmann@amd.com MsgVecType* msgVec = new MsgVecType; 7467567SBrad.Beckmann@amd.com msgVec->resize(m_max_in_port_rank, NULL); 7477567SBrad.Beckmann@amd.com m_waiting_buffers[addr] = msgVec; 7487567SBrad.Beckmann@amd.com } 7497567SBrad.Beckmann@amd.com (*(m_waiting_buffers[addr]))[m_cur_in_port_rank] = buf; 7507567SBrad.Beckmann@amd.com} 7517567SBrad.Beckmann@amd.com 7527567SBrad.Beckmann@amd.comvoid 7537567SBrad.Beckmann@amd.com$c_ident::wakeUpBuffers(Address addr) 7547567SBrad.Beckmann@amd.com{ 7558155Snilay@cs.wisc.edu if (m_waiting_buffers.count(addr) > 0) { 7568155Snilay@cs.wisc.edu // 7578155Snilay@cs.wisc.edu // Wake up all possible lower rank (i.e. lower priority) buffers that could 7588155Snilay@cs.wisc.edu // be waiting on this message. 7598155Snilay@cs.wisc.edu // 7608155Snilay@cs.wisc.edu for (int in_port_rank = m_cur_in_port_rank - 1; 7618155Snilay@cs.wisc.edu in_port_rank >= 0; 7628155Snilay@cs.wisc.edu in_port_rank--) { 7638155Snilay@cs.wisc.edu if ((*(m_waiting_buffers[addr]))[in_port_rank] != NULL) { 7648155Snilay@cs.wisc.edu (*(m_waiting_buffers[addr]))[in_port_rank]->reanalyzeMessages(addr); 7658155Snilay@cs.wisc.edu } 7667567SBrad.Beckmann@amd.com } 7678155Snilay@cs.wisc.edu delete m_waiting_buffers[addr]; 7688155Snilay@cs.wisc.edu m_waiting_buffers.erase(addr); 7697567SBrad.Beckmann@amd.com } 7707567SBrad.Beckmann@amd.com} 7717567SBrad.Beckmann@amd.com 7727567SBrad.Beckmann@amd.comvoid 7737922SBrad.Beckmann@amd.com$c_ident::wakeUpAllBuffers() 7747922SBrad.Beckmann@amd.com{ 7757922SBrad.Beckmann@amd.com // 7767922SBrad.Beckmann@amd.com // Wake up all possible buffers that could be waiting on any message. 7777922SBrad.Beckmann@amd.com // 7787922SBrad.Beckmann@amd.com 7797922SBrad.Beckmann@amd.com std::vector<MsgVecType*> wokeUpMsgVecs; 7807922SBrad.Beckmann@amd.com 7818154Snilay@cs.wisc.edu if(m_waiting_buffers.size() > 0) { 7828154Snilay@cs.wisc.edu for (WaitingBufType::iterator buf_iter = m_waiting_buffers.begin(); 7838154Snilay@cs.wisc.edu buf_iter != m_waiting_buffers.end(); 7848154Snilay@cs.wisc.edu ++buf_iter) { 7858154Snilay@cs.wisc.edu for (MsgVecType::iterator vec_iter = buf_iter->second->begin(); 7868154Snilay@cs.wisc.edu vec_iter != buf_iter->second->end(); 7878154Snilay@cs.wisc.edu ++vec_iter) { 7888154Snilay@cs.wisc.edu if (*vec_iter != NULL) { 7898154Snilay@cs.wisc.edu (*vec_iter)->reanalyzeAllMessages(); 7908154Snilay@cs.wisc.edu } 7918154Snilay@cs.wisc.edu } 7928154Snilay@cs.wisc.edu wokeUpMsgVecs.push_back(buf_iter->second); 7938154Snilay@cs.wisc.edu } 7948154Snilay@cs.wisc.edu 7958154Snilay@cs.wisc.edu for (std::vector<MsgVecType*>::iterator wb_iter = wokeUpMsgVecs.begin(); 7968154Snilay@cs.wisc.edu wb_iter != wokeUpMsgVecs.end(); 7978154Snilay@cs.wisc.edu ++wb_iter) { 7988154Snilay@cs.wisc.edu delete (*wb_iter); 7998154Snilay@cs.wisc.edu } 8008154Snilay@cs.wisc.edu 8018154Snilay@cs.wisc.edu m_waiting_buffers.clear(); 8027922SBrad.Beckmann@amd.com } 8037922SBrad.Beckmann@amd.com} 8047922SBrad.Beckmann@amd.com 8057922SBrad.Beckmann@amd.comvoid 8067007Snate@binkert.org$c_ident::blockOnQueue(Address addr, MessageBuffer* port) 8077007Snate@binkert.org{ 8086863Sdrh5@cs.wisc.edu m_is_blocking = true; 8096863Sdrh5@cs.wisc.edu m_block_map[addr] = port; 8106863Sdrh5@cs.wisc.edu} 8117007Snate@binkert.org 8127007Snate@binkert.orgvoid 8137007Snate@binkert.org$c_ident::unblock(Address addr) 8147007Snate@binkert.org{ 8156863Sdrh5@cs.wisc.edu m_block_map.erase(addr); 8166863Sdrh5@cs.wisc.edu if (m_block_map.size() == 0) { 8176863Sdrh5@cs.wisc.edu m_is_blocking = false; 8186863Sdrh5@cs.wisc.edu } 8196863Sdrh5@cs.wisc.edu} 8206863Sdrh5@cs.wisc.edu 8217007Snate@binkert.orgvoid 8227007Snate@binkert.org$c_ident::print(ostream& out) const 8237007Snate@binkert.org{ 8247007Snate@binkert.org out << "[$c_ident " << m_version << "]"; 8257007Snate@binkert.org} 8266657Snate@binkert.org 8277007Snate@binkert.orgvoid 8287007Snate@binkert.org$c_ident::printConfig(ostream& out) const 8297007Snate@binkert.org{ 8306657Snate@binkert.org out << "$c_ident config: " << m_name << endl; 8316657Snate@binkert.org out << " version: " << m_version << endl; 8327007Snate@binkert.org map<string, string>::const_iterator it; 8337007Snate@binkert.org for (it = m_cfg.begin(); it != m_cfg.end(); it++) 8347007Snate@binkert.org out << " " << it->first << ": " << it->second << endl; 8356657Snate@binkert.org} 8366657Snate@binkert.org 8377007Snate@binkert.orgvoid 8387007Snate@binkert.org$c_ident::printStats(ostream& out) const 8397007Snate@binkert.org{ 8406902SBrad.Beckmann@amd.com''') 8416902SBrad.Beckmann@amd.com # 8426902SBrad.Beckmann@amd.com # Cache and Memory Controllers have specific profilers associated with 8436902SBrad.Beckmann@amd.com # them. Print out these stats before dumping state transition stats. 8446902SBrad.Beckmann@amd.com # 8456902SBrad.Beckmann@amd.com for param in self.config_parameters: 8466902SBrad.Beckmann@amd.com if param.type_ast.type.ident == "CacheMemory" or \ 8477025SBrad.Beckmann@amd.com param.type_ast.type.ident == "DirectoryMemory" or \ 8486902SBrad.Beckmann@amd.com param.type_ast.type.ident == "MemoryControl": 8496902SBrad.Beckmann@amd.com assert(param.pointer) 8506902SBrad.Beckmann@amd.com code(' m_${{param.ident}}_ptr->printStats(out);') 8516902SBrad.Beckmann@amd.com 8526902SBrad.Beckmann@amd.com code(''' 8537542SBrad.Beckmann@amd.com if (m_version == 0) { 8547542SBrad.Beckmann@amd.com s_profileDumper.dumpStats(out); 8557542SBrad.Beckmann@amd.com } 8566902SBrad.Beckmann@amd.com} 8576902SBrad.Beckmann@amd.com 8586902SBrad.Beckmann@amd.comvoid $c_ident::clearStats() { 8596902SBrad.Beckmann@amd.com''') 8606902SBrad.Beckmann@amd.com # 8616902SBrad.Beckmann@amd.com # Cache and Memory Controllers have specific profilers associated with 8626902SBrad.Beckmann@amd.com # them. These stats must be cleared too. 8636902SBrad.Beckmann@amd.com # 8646902SBrad.Beckmann@amd.com for param in self.config_parameters: 8656902SBrad.Beckmann@amd.com if param.type_ast.type.ident == "CacheMemory" or \ 8666902SBrad.Beckmann@amd.com param.type_ast.type.ident == "MemoryControl": 8676902SBrad.Beckmann@amd.com assert(param.pointer) 8686902SBrad.Beckmann@amd.com code(' m_${{param.ident}}_ptr->clearStats();') 8696902SBrad.Beckmann@amd.com 8706902SBrad.Beckmann@amd.com code(''' 8717542SBrad.Beckmann@amd.com m_profiler.clearStats(); 8726902SBrad.Beckmann@amd.com} 8737839Snilay@cs.wisc.edu''') 8747839Snilay@cs.wisc.edu 8757839Snilay@cs.wisc.edu if self.EntryType != None: 8767839Snilay@cs.wisc.edu code(''' 8777839Snilay@cs.wisc.edu 8787839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable 8797839Snilay@cs.wisc.eduvoid 8807839Snilay@cs.wisc.edu$c_ident::set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry) 8817839Snilay@cs.wisc.edu{ 8827839Snilay@cs.wisc.edu m_cache_entry_ptr = (${{self.EntryType.c_ident}}*)m_new_cache_entry; 8837839Snilay@cs.wisc.edu} 8847839Snilay@cs.wisc.edu 8857839Snilay@cs.wisc.eduvoid 8867839Snilay@cs.wisc.edu$c_ident::unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr) 8877839Snilay@cs.wisc.edu{ 8887839Snilay@cs.wisc.edu m_cache_entry_ptr = 0; 8897839Snilay@cs.wisc.edu} 8907839Snilay@cs.wisc.edu''') 8917839Snilay@cs.wisc.edu 8927839Snilay@cs.wisc.edu if self.TBEType != None: 8937839Snilay@cs.wisc.edu code(''' 8947839Snilay@cs.wisc.edu 8957839Snilay@cs.wisc.edu// Set and Reset for tbe variable 8967839Snilay@cs.wisc.eduvoid 8977839Snilay@cs.wisc.edu$c_ident::set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.TBEType.c_ident}}* m_new_tbe) 8987839Snilay@cs.wisc.edu{ 8997839Snilay@cs.wisc.edu m_tbe_ptr = m_new_tbe; 9007839Snilay@cs.wisc.edu} 9017839Snilay@cs.wisc.edu 9027839Snilay@cs.wisc.eduvoid 9037839Snilay@cs.wisc.edu$c_ident::unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr) 9047839Snilay@cs.wisc.edu{ 9057839Snilay@cs.wisc.edu m_tbe_ptr = NULL; 9067839Snilay@cs.wisc.edu} 9077839Snilay@cs.wisc.edu''') 9087839Snilay@cs.wisc.edu 9097839Snilay@cs.wisc.edu code(''' 9106902SBrad.Beckmann@amd.com 9118683Snilay@cs.wisc.eduvoid 9128683Snilay@cs.wisc.edu$c_ident::recordCacheTrace(int cntrl, CacheRecorder* tr) 9138683Snilay@cs.wisc.edu{ 9148683Snilay@cs.wisc.edu''') 9158683Snilay@cs.wisc.edu # 9168683Snilay@cs.wisc.edu # Record cache contents for all associated caches. 9178683Snilay@cs.wisc.edu # 9188683Snilay@cs.wisc.edu code.indent() 9198683Snilay@cs.wisc.edu for param in self.config_parameters: 9208683Snilay@cs.wisc.edu if param.type_ast.type.ident == "CacheMemory": 9218683Snilay@cs.wisc.edu assert(param.pointer) 9228683Snilay@cs.wisc.edu code('m_${{param.ident}}_ptr->recordCacheContents(cntrl, tr);') 9238683Snilay@cs.wisc.edu 9248683Snilay@cs.wisc.edu code.dedent() 9258683Snilay@cs.wisc.edu code(''' 9268683Snilay@cs.wisc.edu} 9278683Snilay@cs.wisc.edu 9286657Snate@binkert.org// Actions 9296657Snate@binkert.org''') 9307839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 9317839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9327839Snilay@cs.wisc.edu if "c_code" not in action: 9337839Snilay@cs.wisc.edu continue 9346657Snate@binkert.org 9357839Snilay@cs.wisc.edu code(''' 9367839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9377839Snilay@cs.wisc.eduvoid 9387839Snilay@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) 9397839Snilay@cs.wisc.edu{ 9408055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9417839Snilay@cs.wisc.edu ${{action["c_code"]}} 9427839Snilay@cs.wisc.edu} 9436657Snate@binkert.org 9447839Snilay@cs.wisc.edu''') 9457839Snilay@cs.wisc.edu elif self.TBEType != None: 9467839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9477839Snilay@cs.wisc.edu if "c_code" not in action: 9487839Snilay@cs.wisc.edu continue 9497839Snilay@cs.wisc.edu 9507839Snilay@cs.wisc.edu code(''' 9517839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9527839Snilay@cs.wisc.eduvoid 9537839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, const Address& addr) 9547839Snilay@cs.wisc.edu{ 9558055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9567839Snilay@cs.wisc.edu ${{action["c_code"]}} 9577839Snilay@cs.wisc.edu} 9587839Snilay@cs.wisc.edu 9597839Snilay@cs.wisc.edu''') 9607839Snilay@cs.wisc.edu elif self.EntryType != 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 9687839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& 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 else: 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(''' 9816657Snate@binkert.org/** \\brief ${{action.desc}} */ 9827007Snate@binkert.orgvoid 9837007Snate@binkert.org$c_ident::${{action.ident}}(const Address& addr) 9846657Snate@binkert.org{ 9858055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9866657Snate@binkert.org ${{action["c_code"]}} 9876657Snate@binkert.org} 9886657Snate@binkert.org 9896657Snate@binkert.org''') 9908478Snilay@cs.wisc.edu for func in self.functions: 9918478Snilay@cs.wisc.edu code(func.generateCode()) 9928478Snilay@cs.wisc.edu 9936657Snate@binkert.org code.write(path, "%s.cc" % c_ident) 9946657Snate@binkert.org 9959219Spower.jg@gmail.com def printCWakeup(self, path, includes): 9966657Snate@binkert.org '''Output the wakeup loop for the events''' 9976657Snate@binkert.org 9986999Snate@binkert.org code = self.symtab.codeFormatter() 9996657Snate@binkert.org ident = self.ident 10006657Snate@binkert.org 10019104Shestness@cs.utexas.edu outputRequest_types = True 10029104Shestness@cs.utexas.edu if len(self.request_types) == 0: 10039104Shestness@cs.utexas.edu outputRequest_types = False 10049104Shestness@cs.utexas.edu 10056657Snate@binkert.org code(''' 10066657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 10076657Snate@binkert.org// ${ident}: ${{self.short}} 10086657Snate@binkert.org 10098946Sandreas.hansson@arm.com#include <sys/types.h> 10108946Sandreas.hansson@arm.com#include <unistd.h> 10118946Sandreas.hansson@arm.com 10127832Snate@binkert.org#include <cassert> 10137832Snate@binkert.org 10147007Snate@binkert.org#include "base/misc.hh" 10158232Snate@binkert.org#include "debug/RubySlicc.hh" 10168229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 10178229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 10188229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 10199104Shestness@cs.utexas.edu''') 10209104Shestness@cs.utexas.edu 10219104Shestness@cs.utexas.edu if outputRequest_types: 10229104Shestness@cs.utexas.edu code('''#include "mem/protocol/${ident}_RequestType.hh"''') 10239104Shestness@cs.utexas.edu 10249104Shestness@cs.utexas.edu code(''' 10258229Snate@binkert.org#include "mem/protocol/Types.hh" 10266657Snate@binkert.org#include "mem/ruby/common/Global.hh" 10276657Snate@binkert.org#include "mem/ruby/system/System.hh" 10289219Spower.jg@gmail.com''') 10299219Spower.jg@gmail.com 10309219Spower.jg@gmail.com 10319219Spower.jg@gmail.com for include_path in includes: 10329219Spower.jg@gmail.com code('#include "${{include_path}}"') 10339219Spower.jg@gmail.com 10349219Spower.jg@gmail.com code(''' 10356657Snate@binkert.org 10367055Snate@binkert.orgusing namespace std; 10377055Snate@binkert.org 10387007Snate@binkert.orgvoid 10397007Snate@binkert.org${ident}_Controller::wakeup() 10406657Snate@binkert.org{ 10416657Snate@binkert.org int counter = 0; 10426657Snate@binkert.org while (true) { 10436657Snate@binkert.org // Some cases will put us into an infinite loop without this limit 10446657Snate@binkert.org assert(counter <= m_transitions_per_cycle); 10456657Snate@binkert.org if (counter == m_transitions_per_cycle) { 10467007Snate@binkert.org // Count how often we are fully utilized 10477007Snate@binkert.org g_system_ptr->getProfiler()->controllerBusy(m_machineID); 10487007Snate@binkert.org 10497007Snate@binkert.org // Wakeup in another cycle and try again 10509171Snilay@cs.wisc.edu scheduleEvent(this, 1); 10516657Snate@binkert.org break; 10526657Snate@binkert.org } 10536657Snate@binkert.org''') 10546657Snate@binkert.org 10556657Snate@binkert.org code.indent() 10566657Snate@binkert.org code.indent() 10576657Snate@binkert.org 10586657Snate@binkert.org # InPorts 10596657Snate@binkert.org # 10606657Snate@binkert.org for port in self.in_ports: 10616657Snate@binkert.org code.indent() 10626657Snate@binkert.org code('// ${ident}InPort $port') 10637567SBrad.Beckmann@amd.com if port.pairs.has_key("rank"): 10647567SBrad.Beckmann@amd.com code('m_cur_in_port_rank = ${{port.pairs["rank"]}};') 10657567SBrad.Beckmann@amd.com else: 10667567SBrad.Beckmann@amd.com code('m_cur_in_port_rank = 0;') 10676657Snate@binkert.org code('${{port["c_code_in_port"]}}') 10686657Snate@binkert.org code.dedent() 10696657Snate@binkert.org 10706657Snate@binkert.org code('') 10716657Snate@binkert.org 10726657Snate@binkert.org code.dedent() 10736657Snate@binkert.org code.dedent() 10746657Snate@binkert.org code(''' 10756657Snate@binkert.org break; // If we got this far, we have nothing left todo 10766657Snate@binkert.org } 10776657Snate@binkert.org} 10786657Snate@binkert.org''') 10796657Snate@binkert.org 10806657Snate@binkert.org code.write(path, "%s_Wakeup.cc" % self.ident) 10816657Snate@binkert.org 10826657Snate@binkert.org def printCSwitch(self, path): 10836657Snate@binkert.org '''Output switch statement for transition table''' 10846657Snate@binkert.org 10856999Snate@binkert.org code = self.symtab.codeFormatter() 10866657Snate@binkert.org ident = self.ident 10876657Snate@binkert.org 10886657Snate@binkert.org code(''' 10896657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 10906657Snate@binkert.org// ${ident}: ${{self.short}} 10916657Snate@binkert.org 10927832Snate@binkert.org#include <cassert> 10937832Snate@binkert.org 10947805Snilay@cs.wisc.edu#include "base/misc.hh" 10957832Snate@binkert.org#include "base/trace.hh" 10968232Snate@binkert.org#include "debug/ProtocolTrace.hh" 10978232Snate@binkert.org#include "debug/RubyGenerated.hh" 10988229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 10998229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 11008229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 11018229Snate@binkert.org#include "mem/protocol/Types.hh" 11026657Snate@binkert.org#include "mem/ruby/common/Global.hh" 11036657Snate@binkert.org#include "mem/ruby/system/System.hh" 11046657Snate@binkert.org 11056657Snate@binkert.org#define HASH_FUN(state, event) ((int(state)*${ident}_Event_NUM)+int(event)) 11066657Snate@binkert.org 11076657Snate@binkert.org#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str()) 11086657Snate@binkert.org#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str("")) 11096657Snate@binkert.org 11107007Snate@binkert.orgTransitionResult 11117007Snate@binkert.org${ident}_Controller::doTransition(${ident}_Event event, 11127839Snilay@cs.wisc.edu''') 11137839Snilay@cs.wisc.edu if self.EntryType != None: 11147839Snilay@cs.wisc.edu code(''' 11157839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}* m_cache_entry_ptr, 11167839Snilay@cs.wisc.edu''') 11177839Snilay@cs.wisc.edu if self.TBEType != None: 11187839Snilay@cs.wisc.edu code(''' 11197839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}* m_tbe_ptr, 11207839Snilay@cs.wisc.edu''') 11217839Snilay@cs.wisc.edu code(''' 11227007Snate@binkert.org const Address &addr) 11236657Snate@binkert.org{ 11247839Snilay@cs.wisc.edu''') 11257839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 11268337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_tbe_ptr, m_cache_entry_ptr, addr);') 11277839Snilay@cs.wisc.edu elif self.TBEType != None: 11288337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_tbe_ptr, addr);') 11297839Snilay@cs.wisc.edu elif self.EntryType != None: 11308337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_cache_entry_ptr, addr);') 11317839Snilay@cs.wisc.edu else: 11328337Snilay@cs.wisc.edu code('${ident}_State state = getState(addr);') 11337839Snilay@cs.wisc.edu 11347839Snilay@cs.wisc.edu code(''' 11356657Snate@binkert.org ${ident}_State next_state = state; 11366657Snate@binkert.org 11377780Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "%s, Time: %lld, state: %s, event: %s, addr: %s\\n", 11389171Snilay@cs.wisc.edu *this, g_system_ptr->getTime(), ${ident}_State_to_string(state), 11399171Snilay@cs.wisc.edu ${ident}_Event_to_string(event), addr); 11406657Snate@binkert.org 11417007Snate@binkert.org TransitionResult result = 11427839Snilay@cs.wisc.edu''') 11437839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 11447839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_tbe_ptr, m_cache_entry_ptr, addr);') 11457839Snilay@cs.wisc.edu elif self.TBEType != None: 11467839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_tbe_ptr, addr);') 11477839Snilay@cs.wisc.edu elif self.EntryType != None: 11487839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_cache_entry_ptr, addr);') 11497839Snilay@cs.wisc.edu else: 11507839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, addr);') 11516657Snate@binkert.org 11527839Snilay@cs.wisc.edu code(''' 11536657Snate@binkert.org if (result == TransitionResult_Valid) { 11547780Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "next_state: %s\\n", 11557780Snilay@cs.wisc.edu ${ident}_State_to_string(next_state)); 11567542SBrad.Beckmann@amd.com m_profiler.countTransition(state, event); 11578266Sksewell@umich.edu DPRINTFR(ProtocolTrace, "%15d %3s %10s%20s %6s>%-6s %s %s\\n", 11588266Sksewell@umich.edu curTick(), m_version, "${ident}", 11598266Sksewell@umich.edu ${ident}_Event_to_string(event), 11608266Sksewell@umich.edu ${ident}_State_to_string(state), 11618266Sksewell@umich.edu ${ident}_State_to_string(next_state), 11628266Sksewell@umich.edu addr, GET_TRANSITION_COMMENT()); 11636657Snate@binkert.org 11647832Snate@binkert.org CLEAR_TRANSITION_COMMENT(); 11657839Snilay@cs.wisc.edu''') 11667839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 11678337Snilay@cs.wisc.edu code('setState(m_tbe_ptr, m_cache_entry_ptr, addr, next_state);') 11688341Snilay@cs.wisc.edu code('setAccessPermission(m_cache_entry_ptr, addr, next_state);') 11697839Snilay@cs.wisc.edu elif self.TBEType != None: 11708337Snilay@cs.wisc.edu code('setState(m_tbe_ptr, addr, next_state);') 11718341Snilay@cs.wisc.edu code('setAccessPermission(addr, next_state);') 11727839Snilay@cs.wisc.edu elif self.EntryType != None: 11738337Snilay@cs.wisc.edu code('setState(m_cache_entry_ptr, addr, next_state);') 11748341Snilay@cs.wisc.edu code('setAccessPermission(m_cache_entry_ptr, addr, next_state);') 11757839Snilay@cs.wisc.edu else: 11768337Snilay@cs.wisc.edu code('setState(addr, next_state);') 11778341Snilay@cs.wisc.edu code('setAccessPermission(addr, next_state);') 11787839Snilay@cs.wisc.edu 11797839Snilay@cs.wisc.edu code(''' 11806657Snate@binkert.org } else if (result == TransitionResult_ResourceStall) { 11818266Sksewell@umich.edu DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\\n", 11828266Sksewell@umich.edu curTick(), m_version, "${ident}", 11838266Sksewell@umich.edu ${ident}_Event_to_string(event), 11848266Sksewell@umich.edu ${ident}_State_to_string(state), 11858266Sksewell@umich.edu ${ident}_State_to_string(next_state), 11868266Sksewell@umich.edu addr, "Resource Stall"); 11876657Snate@binkert.org } else if (result == TransitionResult_ProtocolStall) { 11887780Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "stalling\\n"); 11898266Sksewell@umich.edu DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\\n", 11908266Sksewell@umich.edu curTick(), m_version, "${ident}", 11918266Sksewell@umich.edu ${ident}_Event_to_string(event), 11928266Sksewell@umich.edu ${ident}_State_to_string(state), 11938266Sksewell@umich.edu ${ident}_State_to_string(next_state), 11948266Sksewell@umich.edu addr, "Protocol Stall"); 11956657Snate@binkert.org } 11966657Snate@binkert.org 11976657Snate@binkert.org return result; 11986657Snate@binkert.org} 11996657Snate@binkert.org 12007007Snate@binkert.orgTransitionResult 12017007Snate@binkert.org${ident}_Controller::doTransitionWorker(${ident}_Event event, 12027007Snate@binkert.org ${ident}_State state, 12037007Snate@binkert.org ${ident}_State& next_state, 12047839Snilay@cs.wisc.edu''') 12057839Snilay@cs.wisc.edu 12067839Snilay@cs.wisc.edu if self.TBEType != None: 12077839Snilay@cs.wisc.edu code(''' 12087839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}*& m_tbe_ptr, 12097839Snilay@cs.wisc.edu''') 12107839Snilay@cs.wisc.edu if self.EntryType != None: 12117839Snilay@cs.wisc.edu code(''' 12127839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, 12137839Snilay@cs.wisc.edu''') 12147839Snilay@cs.wisc.edu code(''' 12157007Snate@binkert.org const Address& addr) 12166657Snate@binkert.org{ 12176657Snate@binkert.org switch(HASH_FUN(state, event)) { 12186657Snate@binkert.org''') 12196657Snate@binkert.org 12206657Snate@binkert.org # This map will allow suppress generating duplicate code 12216657Snate@binkert.org cases = orderdict() 12226657Snate@binkert.org 12236657Snate@binkert.org for trans in self.transitions: 12246657Snate@binkert.org case_string = "%s_State_%s, %s_Event_%s" % \ 12256657Snate@binkert.org (self.ident, trans.state.ident, self.ident, trans.event.ident) 12266657Snate@binkert.org 12276999Snate@binkert.org case = self.symtab.codeFormatter() 12286657Snate@binkert.org # Only set next_state if it changes 12296657Snate@binkert.org if trans.state != trans.nextState: 12306657Snate@binkert.org ns_ident = trans.nextState.ident 12316657Snate@binkert.org case('next_state = ${ident}_State_${ns_ident};') 12326657Snate@binkert.org 12336657Snate@binkert.org actions = trans.actions 12349104Shestness@cs.utexas.edu request_types = trans.request_types 12356657Snate@binkert.org 12366657Snate@binkert.org # Check for resources 12376657Snate@binkert.org case_sorter = [] 12386657Snate@binkert.org res = trans.resources 12396657Snate@binkert.org for key,val in res.iteritems(): 12406657Snate@binkert.org if key.type.ident != "DNUCAStopTable": 12416657Snate@binkert.org val = ''' 12427007Snate@binkert.orgif (!%s.areNSlotsAvailable(%s)) 12436657Snate@binkert.org return TransitionResult_ResourceStall; 12446657Snate@binkert.org''' % (key.code, val) 12456657Snate@binkert.org case_sorter.append(val) 12466657Snate@binkert.org 12479105SBrad.Beckmann@amd.com # Check all of the request_types for resource constraints 12489105SBrad.Beckmann@amd.com for request_type in request_types: 12499105SBrad.Beckmann@amd.com val = ''' 12509105SBrad.Beckmann@amd.comif (!checkResourceAvailable(%s_RequestType_%s, addr)) { 12519105SBrad.Beckmann@amd.com return TransitionResult_ResourceStall; 12529105SBrad.Beckmann@amd.com} 12539105SBrad.Beckmann@amd.com''' % (self.ident, request_type.ident) 12549105SBrad.Beckmann@amd.com case_sorter.append(val) 12556657Snate@binkert.org 12566657Snate@binkert.org # Emit the code sequences in a sorted order. This makes the 12576657Snate@binkert.org # output deterministic (without this the output order can vary 12586657Snate@binkert.org # since Map's keys() on a vector of pointers is not deterministic 12596657Snate@binkert.org for c in sorted(case_sorter): 12606657Snate@binkert.org case("$c") 12616657Snate@binkert.org 12629104Shestness@cs.utexas.edu # Record access types for this transition 12639104Shestness@cs.utexas.edu for request_type in request_types: 12649104Shestness@cs.utexas.edu case('recordRequestType(${ident}_RequestType_${{request_type.ident}}, addr);') 12659104Shestness@cs.utexas.edu 12666657Snate@binkert.org # Figure out if we stall 12676657Snate@binkert.org stall = False 12686657Snate@binkert.org for action in actions: 12696657Snate@binkert.org if action.ident == "z_stall": 12706657Snate@binkert.org stall = True 12716657Snate@binkert.org break 12726657Snate@binkert.org 12736657Snate@binkert.org if stall: 12746657Snate@binkert.org case('return TransitionResult_ProtocolStall;') 12756657Snate@binkert.org else: 12767839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 12777839Snilay@cs.wisc.edu for action in actions: 12787839Snilay@cs.wisc.edu case('${{action.ident}}(m_tbe_ptr, m_cache_entry_ptr, addr);') 12797839Snilay@cs.wisc.edu elif self.TBEType != None: 12807839Snilay@cs.wisc.edu for action in actions: 12817839Snilay@cs.wisc.edu case('${{action.ident}}(m_tbe_ptr, addr);') 12827839Snilay@cs.wisc.edu elif self.EntryType != None: 12837839Snilay@cs.wisc.edu for action in actions: 12847839Snilay@cs.wisc.edu case('${{action.ident}}(m_cache_entry_ptr, addr);') 12857839Snilay@cs.wisc.edu else: 12867839Snilay@cs.wisc.edu for action in actions: 12877839Snilay@cs.wisc.edu case('${{action.ident}}(addr);') 12886657Snate@binkert.org case('return TransitionResult_Valid;') 12896657Snate@binkert.org 12906657Snate@binkert.org case = str(case) 12916657Snate@binkert.org 12926657Snate@binkert.org # Look to see if this transition code is unique. 12936657Snate@binkert.org if case not in cases: 12946657Snate@binkert.org cases[case] = [] 12956657Snate@binkert.org 12966657Snate@binkert.org cases[case].append(case_string) 12976657Snate@binkert.org 12986657Snate@binkert.org # Walk through all of the unique code blocks and spit out the 12996657Snate@binkert.org # corresponding case statement elements 13006657Snate@binkert.org for case,transitions in cases.iteritems(): 13016657Snate@binkert.org # Iterative over all the multiple transitions that share 13026657Snate@binkert.org # the same code 13036657Snate@binkert.org for trans in transitions: 13046657Snate@binkert.org code(' case HASH_FUN($trans):') 13056657Snate@binkert.org code(' $case') 13066657Snate@binkert.org 13076657Snate@binkert.org code(''' 13086657Snate@binkert.org default: 13097805Snilay@cs.wisc.edu fatal("Invalid transition\\n" 13108159SBrad.Beckmann@amd.com "%s time: %d addr: %s event: %s state: %s\\n", 13119171Snilay@cs.wisc.edu name(), g_system_ptr->getTime(), addr, event, state); 13126657Snate@binkert.org } 13136657Snate@binkert.org return TransitionResult_Valid; 13146657Snate@binkert.org} 13156657Snate@binkert.org''') 13166657Snate@binkert.org code.write(path, "%s_Transitions.cc" % self.ident) 13176657Snate@binkert.org 13187542SBrad.Beckmann@amd.com def printProfileDumperHH(self, path): 13197542SBrad.Beckmann@amd.com code = self.symtab.codeFormatter() 13207542SBrad.Beckmann@amd.com ident = self.ident 13217542SBrad.Beckmann@amd.com 13227542SBrad.Beckmann@amd.com code(''' 13237542SBrad.Beckmann@amd.com// Auto generated C++ code started by $__file__:$__line__ 13247542SBrad.Beckmann@amd.com// ${ident}: ${{self.short}} 13257542SBrad.Beckmann@amd.com 13267542SBrad.Beckmann@amd.com#ifndef __${ident}_PROFILE_DUMPER_HH__ 13277542SBrad.Beckmann@amd.com#define __${ident}_PROFILE_DUMPER_HH__ 13287542SBrad.Beckmann@amd.com 13297832Snate@binkert.org#include <cassert> 13307542SBrad.Beckmann@amd.com#include <iostream> 13317542SBrad.Beckmann@amd.com#include <vector> 13327542SBrad.Beckmann@amd.com 13338229Snate@binkert.org#include "${ident}_Event.hh" 13347542SBrad.Beckmann@amd.com#include "${ident}_Profiler.hh" 13357542SBrad.Beckmann@amd.com 13367542SBrad.Beckmann@amd.comtypedef std::vector<${ident}_Profiler *> ${ident}_profilers; 13377542SBrad.Beckmann@amd.com 13387542SBrad.Beckmann@amd.comclass ${ident}_ProfileDumper 13397542SBrad.Beckmann@amd.com{ 13407542SBrad.Beckmann@amd.com public: 13417542SBrad.Beckmann@amd.com ${ident}_ProfileDumper(); 13427542SBrad.Beckmann@amd.com void registerProfiler(${ident}_Profiler* profiler); 13437542SBrad.Beckmann@amd.com void dumpStats(std::ostream& out) const; 13447542SBrad.Beckmann@amd.com 13457542SBrad.Beckmann@amd.com private: 13467542SBrad.Beckmann@amd.com ${ident}_profilers m_profilers; 13477542SBrad.Beckmann@amd.com}; 13487542SBrad.Beckmann@amd.com 13497542SBrad.Beckmann@amd.com#endif // __${ident}_PROFILE_DUMPER_HH__ 13507542SBrad.Beckmann@amd.com''') 13517542SBrad.Beckmann@amd.com code.write(path, "%s_ProfileDumper.hh" % self.ident) 13527542SBrad.Beckmann@amd.com 13537542SBrad.Beckmann@amd.com def printProfileDumperCC(self, path): 13547542SBrad.Beckmann@amd.com code = self.symtab.codeFormatter() 13557542SBrad.Beckmann@amd.com ident = self.ident 13567542SBrad.Beckmann@amd.com 13577542SBrad.Beckmann@amd.com code(''' 13587542SBrad.Beckmann@amd.com// Auto generated C++ code started by $__file__:$__line__ 13597542SBrad.Beckmann@amd.com// ${ident}: ${{self.short}} 13607542SBrad.Beckmann@amd.com 13617542SBrad.Beckmann@amd.com#include "mem/protocol/${ident}_ProfileDumper.hh" 13627542SBrad.Beckmann@amd.com 13637542SBrad.Beckmann@amd.com${ident}_ProfileDumper::${ident}_ProfileDumper() 13647542SBrad.Beckmann@amd.com{ 13657542SBrad.Beckmann@amd.com} 13667542SBrad.Beckmann@amd.com 13677542SBrad.Beckmann@amd.comvoid 13687542SBrad.Beckmann@amd.com${ident}_ProfileDumper::registerProfiler(${ident}_Profiler* profiler) 13697542SBrad.Beckmann@amd.com{ 13707542SBrad.Beckmann@amd.com m_profilers.push_back(profiler); 13717542SBrad.Beckmann@amd.com} 13727542SBrad.Beckmann@amd.com 13737542SBrad.Beckmann@amd.comvoid 13747542SBrad.Beckmann@amd.com${ident}_ProfileDumper::dumpStats(std::ostream& out) const 13757542SBrad.Beckmann@amd.com{ 13767542SBrad.Beckmann@amd.com out << " --- ${ident} ---\\n"; 13777542SBrad.Beckmann@amd.com out << " - Event Counts -\\n"; 13787542SBrad.Beckmann@amd.com for (${ident}_Event event = ${ident}_Event_FIRST; 13797542SBrad.Beckmann@amd.com event < ${ident}_Event_NUM; 13807542SBrad.Beckmann@amd.com ++event) { 13817542SBrad.Beckmann@amd.com out << (${ident}_Event) event << " ["; 13827542SBrad.Beckmann@amd.com uint64 total = 0; 13837542SBrad.Beckmann@amd.com for (int i = 0; i < m_profilers.size(); i++) { 13847542SBrad.Beckmann@amd.com out << m_profilers[i]->getEventCount(event) << " "; 13857542SBrad.Beckmann@amd.com total += m_profilers[i]->getEventCount(event); 13867542SBrad.Beckmann@amd.com } 13877542SBrad.Beckmann@amd.com out << "] " << total << "\\n"; 13887542SBrad.Beckmann@amd.com } 13897542SBrad.Beckmann@amd.com out << "\\n"; 13907542SBrad.Beckmann@amd.com out << " - Transitions -\\n"; 13917542SBrad.Beckmann@amd.com for (${ident}_State state = ${ident}_State_FIRST; 13927542SBrad.Beckmann@amd.com state < ${ident}_State_NUM; 13937542SBrad.Beckmann@amd.com ++state) { 13947542SBrad.Beckmann@amd.com for (${ident}_Event event = ${ident}_Event_FIRST; 13957542SBrad.Beckmann@amd.com event < ${ident}_Event_NUM; 13967542SBrad.Beckmann@amd.com ++event) { 13977542SBrad.Beckmann@amd.com if (m_profilers[0]->isPossible(state, event)) { 13987542SBrad.Beckmann@amd.com out << (${ident}_State) state << " " 13997542SBrad.Beckmann@amd.com << (${ident}_Event) event << " ["; 14007542SBrad.Beckmann@amd.com uint64 total = 0; 14017542SBrad.Beckmann@amd.com for (int i = 0; i < m_profilers.size(); i++) { 14027542SBrad.Beckmann@amd.com out << m_profilers[i]->getTransitionCount(state, event) << " "; 14037542SBrad.Beckmann@amd.com total += m_profilers[i]->getTransitionCount(state, event); 14047542SBrad.Beckmann@amd.com } 14057542SBrad.Beckmann@amd.com out << "] " << total << "\\n"; 14067542SBrad.Beckmann@amd.com } 14077542SBrad.Beckmann@amd.com } 14087542SBrad.Beckmann@amd.com out << "\\n"; 14097542SBrad.Beckmann@amd.com } 14107542SBrad.Beckmann@amd.com} 14117542SBrad.Beckmann@amd.com''') 14127542SBrad.Beckmann@amd.com code.write(path, "%s_ProfileDumper.cc" % self.ident) 14137542SBrad.Beckmann@amd.com 14146657Snate@binkert.org def printProfilerHH(self, path): 14156999Snate@binkert.org code = self.symtab.codeFormatter() 14166657Snate@binkert.org ident = self.ident 14176657Snate@binkert.org 14186657Snate@binkert.org code(''' 14196657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 14206657Snate@binkert.org// ${ident}: ${{self.short}} 14216657Snate@binkert.org 14227542SBrad.Beckmann@amd.com#ifndef __${ident}_PROFILER_HH__ 14237542SBrad.Beckmann@amd.com#define __${ident}_PROFILER_HH__ 14246657Snate@binkert.org 14257832Snate@binkert.org#include <cassert> 14267002Snate@binkert.org#include <iostream> 14277002Snate@binkert.org 14288229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 14298229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 14308608Snilay@cs.wisc.edu#include "mem/ruby/common/TypeDefines.hh" 14316657Snate@binkert.org 14327007Snate@binkert.orgclass ${ident}_Profiler 14337007Snate@binkert.org{ 14346657Snate@binkert.org public: 14356657Snate@binkert.org ${ident}_Profiler(); 14366657Snate@binkert.org void setVersion(int version); 14376657Snate@binkert.org void countTransition(${ident}_State state, ${ident}_Event event); 14386657Snate@binkert.org void possibleTransition(${ident}_State state, ${ident}_Event event); 14397542SBrad.Beckmann@amd.com uint64 getEventCount(${ident}_Event event); 14407542SBrad.Beckmann@amd.com bool isPossible(${ident}_State state, ${ident}_Event event); 14417542SBrad.Beckmann@amd.com uint64 getTransitionCount(${ident}_State state, ${ident}_Event event); 14426657Snate@binkert.org void clearStats(); 14436657Snate@binkert.org 14446657Snate@binkert.org private: 14456657Snate@binkert.org int m_counters[${ident}_State_NUM][${ident}_Event_NUM]; 14466657Snate@binkert.org int m_event_counters[${ident}_Event_NUM]; 14476657Snate@binkert.org bool m_possible[${ident}_State_NUM][${ident}_Event_NUM]; 14486657Snate@binkert.org int m_version; 14496657Snate@binkert.org}; 14506657Snate@binkert.org 14517007Snate@binkert.org#endif // __${ident}_PROFILER_HH__ 14526657Snate@binkert.org''') 14536657Snate@binkert.org code.write(path, "%s_Profiler.hh" % self.ident) 14546657Snate@binkert.org 14556657Snate@binkert.org def printProfilerCC(self, path): 14566999Snate@binkert.org code = self.symtab.codeFormatter() 14576657Snate@binkert.org ident = self.ident 14586657Snate@binkert.org 14596657Snate@binkert.org code(''' 14606657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 14616657Snate@binkert.org// ${ident}: ${{self.short}} 14626657Snate@binkert.org 14637832Snate@binkert.org#include <cassert> 14647832Snate@binkert.org 14656657Snate@binkert.org#include "mem/protocol/${ident}_Profiler.hh" 14666657Snate@binkert.org 14676657Snate@binkert.org${ident}_Profiler::${ident}_Profiler() 14686657Snate@binkert.org{ 14696657Snate@binkert.org for (int state = 0; state < ${ident}_State_NUM; state++) { 14706657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 14716657Snate@binkert.org m_possible[state][event] = false; 14726657Snate@binkert.org m_counters[state][event] = 0; 14736657Snate@binkert.org } 14746657Snate@binkert.org } 14756657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 14766657Snate@binkert.org m_event_counters[event] = 0; 14776657Snate@binkert.org } 14786657Snate@binkert.org} 14797007Snate@binkert.org 14807007Snate@binkert.orgvoid 14817007Snate@binkert.org${ident}_Profiler::setVersion(int version) 14826657Snate@binkert.org{ 14836657Snate@binkert.org m_version = version; 14846657Snate@binkert.org} 14857007Snate@binkert.org 14867007Snate@binkert.orgvoid 14877007Snate@binkert.org${ident}_Profiler::clearStats() 14886657Snate@binkert.org{ 14896657Snate@binkert.org for (int state = 0; state < ${ident}_State_NUM; state++) { 14906657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 14916657Snate@binkert.org m_counters[state][event] = 0; 14926657Snate@binkert.org } 14936657Snate@binkert.org } 14946657Snate@binkert.org 14956657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 14966657Snate@binkert.org m_event_counters[event] = 0; 14976657Snate@binkert.org } 14986657Snate@binkert.org} 14997007Snate@binkert.orgvoid 15007007Snate@binkert.org${ident}_Profiler::countTransition(${ident}_State state, ${ident}_Event event) 15016657Snate@binkert.org{ 15026657Snate@binkert.org assert(m_possible[state][event]); 15036657Snate@binkert.org m_counters[state][event]++; 15046657Snate@binkert.org m_event_counters[event]++; 15056657Snate@binkert.org} 15067007Snate@binkert.orgvoid 15077007Snate@binkert.org${ident}_Profiler::possibleTransition(${ident}_State state, 15087007Snate@binkert.org ${ident}_Event event) 15096657Snate@binkert.org{ 15106657Snate@binkert.org m_possible[state][event] = true; 15116657Snate@binkert.org} 15127007Snate@binkert.org 15137542SBrad.Beckmann@amd.comuint64 15147542SBrad.Beckmann@amd.com${ident}_Profiler::getEventCount(${ident}_Event event) 15156657Snate@binkert.org{ 15167542SBrad.Beckmann@amd.com return m_event_counters[event]; 15177542SBrad.Beckmann@amd.com} 15187002Snate@binkert.org 15197542SBrad.Beckmann@amd.combool 15207542SBrad.Beckmann@amd.com${ident}_Profiler::isPossible(${ident}_State state, ${ident}_Event event) 15217542SBrad.Beckmann@amd.com{ 15227542SBrad.Beckmann@amd.com return m_possible[state][event]; 15236657Snate@binkert.org} 15247542SBrad.Beckmann@amd.com 15257542SBrad.Beckmann@amd.comuint64 15267542SBrad.Beckmann@amd.com${ident}_Profiler::getTransitionCount(${ident}_State state, 15277542SBrad.Beckmann@amd.com ${ident}_Event event) 15287542SBrad.Beckmann@amd.com{ 15297542SBrad.Beckmann@amd.com return m_counters[state][event]; 15307542SBrad.Beckmann@amd.com} 15317542SBrad.Beckmann@amd.com 15326657Snate@binkert.org''') 15336657Snate@binkert.org code.write(path, "%s_Profiler.cc" % self.ident) 15346657Snate@binkert.org 15356657Snate@binkert.org # ************************** 15366657Snate@binkert.org # ******* HTML Files ******* 15376657Snate@binkert.org # ************************** 15387007Snate@binkert.org def frameRef(self, click_href, click_target, over_href, over_num, text): 15396999Snate@binkert.org code = self.symtab.codeFormatter(fix_newlines=False) 15407007Snate@binkert.org code("""<A href=\"$click_href\" target=\"$click_target\" onmouseover=\" 15417007Snate@binkert.org if (parent.frames[$over_num].location != parent.location + '$over_href') { 15427007Snate@binkert.org parent.frames[$over_num].location='$over_href' 15437007Snate@binkert.org }\"> 15447007Snate@binkert.org ${{html.formatShorthand(text)}} 15457007Snate@binkert.org </A>""") 15466657Snate@binkert.org return str(code) 15476657Snate@binkert.org 15486657Snate@binkert.org def writeHTMLFiles(self, path): 15496657Snate@binkert.org # Create table with no row hilighted 15506657Snate@binkert.org self.printHTMLTransitions(path, None) 15516657Snate@binkert.org 15526657Snate@binkert.org # Generate transition tables 15536657Snate@binkert.org for state in self.states.itervalues(): 15546657Snate@binkert.org self.printHTMLTransitions(path, state) 15556657Snate@binkert.org 15566657Snate@binkert.org # Generate action descriptions 15576657Snate@binkert.org for action in self.actions.itervalues(): 15586657Snate@binkert.org name = "%s_action_%s.html" % (self.ident, action.ident) 15596657Snate@binkert.org code = html.createSymbol(action, "Action") 15606657Snate@binkert.org code.write(path, name) 15616657Snate@binkert.org 15626657Snate@binkert.org # Generate state descriptions 15636657Snate@binkert.org for state in self.states.itervalues(): 15646657Snate@binkert.org name = "%s_State_%s.html" % (self.ident, state.ident) 15656657Snate@binkert.org code = html.createSymbol(state, "State") 15666657Snate@binkert.org code.write(path, name) 15676657Snate@binkert.org 15686657Snate@binkert.org # Generate event descriptions 15696657Snate@binkert.org for event in self.events.itervalues(): 15706657Snate@binkert.org name = "%s_Event_%s.html" % (self.ident, event.ident) 15716657Snate@binkert.org code = html.createSymbol(event, "Event") 15726657Snate@binkert.org code.write(path, name) 15736657Snate@binkert.org 15746657Snate@binkert.org def printHTMLTransitions(self, path, active_state): 15756999Snate@binkert.org code = self.symtab.codeFormatter() 15766657Snate@binkert.org 15776657Snate@binkert.org code(''' 15787007Snate@binkert.org<HTML> 15797007Snate@binkert.org<BODY link="blue" vlink="blue"> 15806657Snate@binkert.org 15816657Snate@binkert.org<H1 align="center">${{html.formatShorthand(self.short)}}: 15826657Snate@binkert.org''') 15836657Snate@binkert.org code.indent() 15846657Snate@binkert.org for i,machine in enumerate(self.symtab.getAllType(StateMachine)): 15856657Snate@binkert.org mid = machine.ident 15866657Snate@binkert.org if i != 0: 15876657Snate@binkert.org extra = " - " 15886657Snate@binkert.org else: 15896657Snate@binkert.org extra = "" 15906657Snate@binkert.org if machine == self: 15916657Snate@binkert.org code('$extra$mid') 15926657Snate@binkert.org else: 15936657Snate@binkert.org code('$extra<A target="Table" href="${mid}_table.html">$mid</A>') 15946657Snate@binkert.org code.dedent() 15956657Snate@binkert.org 15966657Snate@binkert.org code(""" 15976657Snate@binkert.org</H1> 15986657Snate@binkert.org 15996657Snate@binkert.org<TABLE border=1> 16006657Snate@binkert.org<TR> 16016657Snate@binkert.org <TH> </TH> 16026657Snate@binkert.org""") 16036657Snate@binkert.org 16046657Snate@binkert.org for event in self.events.itervalues(): 16056657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 16066657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 16076657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 16086657Snate@binkert.org 16096657Snate@binkert.org code('</TR>') 16106657Snate@binkert.org # -- Body of table 16116657Snate@binkert.org for state in self.states.itervalues(): 16126657Snate@binkert.org # -- Each row 16136657Snate@binkert.org if state == active_state: 16146657Snate@binkert.org color = "yellow" 16156657Snate@binkert.org else: 16166657Snate@binkert.org color = "white" 16176657Snate@binkert.org 16186657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 16196657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 16206657Snate@binkert.org text = html.formatShorthand(state.short) 16216657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 16226657Snate@binkert.org code(''' 16236657Snate@binkert.org<TR> 16246657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 16256657Snate@binkert.org''') 16266657Snate@binkert.org 16276657Snate@binkert.org # -- One column for each event 16286657Snate@binkert.org for event in self.events.itervalues(): 16296657Snate@binkert.org trans = self.table.get((state,event), None) 16306657Snate@binkert.org if trans is None: 16316657Snate@binkert.org # This is the no transition case 16326657Snate@binkert.org if state == active_state: 16336657Snate@binkert.org color = "#C0C000" 16346657Snate@binkert.org else: 16356657Snate@binkert.org color = "lightgrey" 16366657Snate@binkert.org 16376657Snate@binkert.org code('<TD bgcolor=$color> </TD>') 16386657Snate@binkert.org continue 16396657Snate@binkert.org 16406657Snate@binkert.org next = trans.nextState 16416657Snate@binkert.org stall_action = False 16426657Snate@binkert.org 16436657Snate@binkert.org # -- Get the actions 16446657Snate@binkert.org for action in trans.actions: 16456657Snate@binkert.org if action.ident == "z_stall" or \ 16466657Snate@binkert.org action.ident == "zz_recycleMandatoryQueue": 16476657Snate@binkert.org stall_action = True 16486657Snate@binkert.org 16496657Snate@binkert.org # -- Print out "actions/next-state" 16506657Snate@binkert.org if stall_action: 16516657Snate@binkert.org if state == active_state: 16526657Snate@binkert.org color = "#C0C000" 16536657Snate@binkert.org else: 16546657Snate@binkert.org color = "lightgrey" 16556657Snate@binkert.org 16566657Snate@binkert.org elif active_state and next.ident == active_state.ident: 16576657Snate@binkert.org color = "aqua" 16586657Snate@binkert.org elif state == active_state: 16596657Snate@binkert.org color = "yellow" 16606657Snate@binkert.org else: 16616657Snate@binkert.org color = "white" 16626657Snate@binkert.org 16636657Snate@binkert.org code('<TD bgcolor=$color>') 16646657Snate@binkert.org for action in trans.actions: 16656657Snate@binkert.org href = "%s_action_%s.html" % (self.ident, action.ident) 16666657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", 16676657Snate@binkert.org action.short) 16687007Snate@binkert.org code(' $ref') 16696657Snate@binkert.org if next != state: 16706657Snate@binkert.org if trans.actions: 16716657Snate@binkert.org code('/') 16726657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, next.ident) 16736657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, next.ident) 16746657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", next.short) 16756657Snate@binkert.org code("$ref") 16767007Snate@binkert.org code("</TD>") 16776657Snate@binkert.org 16786657Snate@binkert.org # -- Each row 16796657Snate@binkert.org if state == active_state: 16806657Snate@binkert.org color = "yellow" 16816657Snate@binkert.org else: 16826657Snate@binkert.org color = "white" 16836657Snate@binkert.org 16846657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 16856657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 16866657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 16876657Snate@binkert.org code(''' 16886657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 16896657Snate@binkert.org</TR> 16906657Snate@binkert.org''') 16916657Snate@binkert.org code(''' 16927007Snate@binkert.org<!- Column footer-> 16936657Snate@binkert.org<TR> 16946657Snate@binkert.org <TH> </TH> 16956657Snate@binkert.org''') 16966657Snate@binkert.org 16976657Snate@binkert.org for event in self.events.itervalues(): 16986657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 16996657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 17006657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 17016657Snate@binkert.org code(''' 17026657Snate@binkert.org</TR> 17036657Snate@binkert.org</TABLE> 17046657Snate@binkert.org</BODY></HTML> 17056657Snate@binkert.org''') 17066657Snate@binkert.org 17076657Snate@binkert.org 17086657Snate@binkert.org if active_state: 17096657Snate@binkert.org name = "%s_table_%s.html" % (self.ident, active_state.ident) 17106657Snate@binkert.org else: 17116657Snate@binkert.org name = "%s_table.html" % self.ident 17126657Snate@binkert.org code.write(path, name) 17136657Snate@binkert.org 17146657Snate@binkert.org__all__ = [ "StateMachine" ] 1715