StateMachine.py revision 10305
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 359499Snilay@cs.wisc.edupython_class_map = { 369499Snilay@cs.wisc.edu "int": "Int", 379364Snilay@cs.wisc.edu "uint32_t" : "UInt32", 387055Snate@binkert.org "std::string": "String", 396882SBrad.Beckmann@amd.com "bool": "Bool", 406882SBrad.Beckmann@amd.com "CacheMemory": "RubyCache", 418191SLisa.Hsu@amd.com "WireBuffer": "RubyWireBuffer", 426882SBrad.Beckmann@amd.com "Sequencer": "RubySequencer", 436882SBrad.Beckmann@amd.com "DirectoryMemory": "RubyDirectoryMemory", 449102SNuwan.Jayasena@amd.com "MemoryControl": "MemoryControl", 459366Snilay@cs.wisc.edu "DMASequencer": "DMASequencer", 469499Snilay@cs.wisc.edu "Prefetcher":"Prefetcher", 479499Snilay@cs.wisc.edu "Cycles":"Cycles", 489499Snilay@cs.wisc.edu } 496882SBrad.Beckmann@amd.com 506657Snate@binkert.orgclass StateMachine(Symbol): 516657Snate@binkert.org def __init__(self, symtab, ident, location, pairs, config_parameters): 526657Snate@binkert.org super(StateMachine, self).__init__(symtab, ident, location, pairs) 536657Snate@binkert.org self.table = None 546657Snate@binkert.org self.config_parameters = config_parameters 559366Snilay@cs.wisc.edu self.prefetchers = [] 567839Snilay@cs.wisc.edu 576657Snate@binkert.org for param in config_parameters: 586882SBrad.Beckmann@amd.com if param.pointer: 596882SBrad.Beckmann@amd.com var = Var(symtab, param.name, location, param.type_ast.type, 606882SBrad.Beckmann@amd.com "(*m_%s_ptr)" % param.name, {}, self) 616882SBrad.Beckmann@amd.com else: 626882SBrad.Beckmann@amd.com var = Var(symtab, param.name, location, param.type_ast.type, 636882SBrad.Beckmann@amd.com "m_%s" % param.name, {}, self) 646657Snate@binkert.org self.symtab.registerSym(param.name, var) 659366Snilay@cs.wisc.edu if str(param.type_ast.type) == "Prefetcher": 669366Snilay@cs.wisc.edu self.prefetchers.append(var) 676657Snate@binkert.org 686657Snate@binkert.org self.states = orderdict() 696657Snate@binkert.org self.events = orderdict() 706657Snate@binkert.org self.actions = orderdict() 719104Shestness@cs.utexas.edu self.request_types = orderdict() 726657Snate@binkert.org self.transitions = [] 736657Snate@binkert.org self.in_ports = [] 746657Snate@binkert.org self.functions = [] 756657Snate@binkert.org self.objects = [] 767839Snilay@cs.wisc.edu self.TBEType = None 777839Snilay@cs.wisc.edu self.EntryType = None 786657Snate@binkert.org 796657Snate@binkert.org def __repr__(self): 806657Snate@binkert.org return "[StateMachine: %s]" % self.ident 816657Snate@binkert.org 826657Snate@binkert.org def addState(self, state): 836657Snate@binkert.org assert self.table is None 846657Snate@binkert.org self.states[state.ident] = state 856657Snate@binkert.org 866657Snate@binkert.org def addEvent(self, event): 876657Snate@binkert.org assert self.table is None 886657Snate@binkert.org self.events[event.ident] = event 896657Snate@binkert.org 906657Snate@binkert.org def addAction(self, action): 916657Snate@binkert.org assert self.table is None 926657Snate@binkert.org 936657Snate@binkert.org # Check for duplicate action 946657Snate@binkert.org for other in self.actions.itervalues(): 956657Snate@binkert.org if action.ident == other.ident: 966779SBrad.Beckmann@amd.com action.warning("Duplicate action definition: %s" % action.ident) 976657Snate@binkert.org action.error("Duplicate action definition: %s" % action.ident) 986657Snate@binkert.org if action.short == other.short: 996657Snate@binkert.org other.warning("Duplicate action shorthand: %s" % other.ident) 1006657Snate@binkert.org other.warning(" shorthand = %s" % other.short) 1016657Snate@binkert.org action.warning("Duplicate action shorthand: %s" % action.ident) 1026657Snate@binkert.org action.error(" shorthand = %s" % action.short) 1036657Snate@binkert.org 1046657Snate@binkert.org self.actions[action.ident] = action 1056657Snate@binkert.org 1069104Shestness@cs.utexas.edu def addRequestType(self, request_type): 1079104Shestness@cs.utexas.edu assert self.table is None 1089104Shestness@cs.utexas.edu self.request_types[request_type.ident] = request_type 1099104Shestness@cs.utexas.edu 1106657Snate@binkert.org def addTransition(self, trans): 1116657Snate@binkert.org assert self.table is None 1126657Snate@binkert.org self.transitions.append(trans) 1136657Snate@binkert.org 1146657Snate@binkert.org def addInPort(self, var): 1156657Snate@binkert.org self.in_ports.append(var) 1166657Snate@binkert.org 1176657Snate@binkert.org def addFunc(self, func): 1186657Snate@binkert.org # register func in the symbol table 1196657Snate@binkert.org self.symtab.registerSym(str(func), func) 1206657Snate@binkert.org self.functions.append(func) 1216657Snate@binkert.org 1226657Snate@binkert.org def addObject(self, obj): 1236657Snate@binkert.org self.objects.append(obj) 1246657Snate@binkert.org 1257839Snilay@cs.wisc.edu def addType(self, type): 1267839Snilay@cs.wisc.edu type_ident = '%s' % type.c_ident 1277839Snilay@cs.wisc.edu 1287839Snilay@cs.wisc.edu if type_ident == "%s_TBE" %self.ident: 1297839Snilay@cs.wisc.edu if self.TBEType != None: 1307839Snilay@cs.wisc.edu self.error("Multiple Transaction Buffer types in a " \ 1317839Snilay@cs.wisc.edu "single machine."); 1327839Snilay@cs.wisc.edu self.TBEType = type 1337839Snilay@cs.wisc.edu 1347839Snilay@cs.wisc.edu elif "interface" in type and "AbstractCacheEntry" == type["interface"]: 1357839Snilay@cs.wisc.edu if self.EntryType != None: 1367839Snilay@cs.wisc.edu self.error("Multiple AbstractCacheEntry types in a " \ 1377839Snilay@cs.wisc.edu "single machine."); 1387839Snilay@cs.wisc.edu self.EntryType = type 1397839Snilay@cs.wisc.edu 1406657Snate@binkert.org # Needs to be called before accessing the table 1416657Snate@binkert.org def buildTable(self): 1426657Snate@binkert.org assert self.table is None 1436657Snate@binkert.org 1446657Snate@binkert.org table = {} 1456657Snate@binkert.org 1466657Snate@binkert.org for trans in self.transitions: 1476657Snate@binkert.org # Track which actions we touch so we know if we use them 1486657Snate@binkert.org # all -- really this should be done for all symbols as 1496657Snate@binkert.org # part of the symbol table, then only trigger it for 1506657Snate@binkert.org # Actions, States, Events, etc. 1516657Snate@binkert.org 1526657Snate@binkert.org for action in trans.actions: 1536657Snate@binkert.org action.used = True 1546657Snate@binkert.org 1556657Snate@binkert.org index = (trans.state, trans.event) 1566657Snate@binkert.org if index in table: 1576657Snate@binkert.org table[index].warning("Duplicate transition: %s" % table[index]) 1586657Snate@binkert.org trans.error("Duplicate transition: %s" % trans) 1596657Snate@binkert.org table[index] = trans 1606657Snate@binkert.org 1616657Snate@binkert.org # Look at all actions to make sure we used them all 1626657Snate@binkert.org for action in self.actions.itervalues(): 1636657Snate@binkert.org if not action.used: 1646657Snate@binkert.org error_msg = "Unused action: %s" % action.ident 1656657Snate@binkert.org if "desc" in action: 1666657Snate@binkert.org error_msg += ", " + action.desc 1676657Snate@binkert.org action.warning(error_msg) 1686657Snate@binkert.org self.table = table 1696657Snate@binkert.org 1709219Spower.jg@gmail.com def writeCodeFiles(self, path, includes): 1716877Ssteve.reinhardt@amd.com self.printControllerPython(path) 1726657Snate@binkert.org self.printControllerHH(path) 1739219Spower.jg@gmail.com self.printControllerCC(path, includes) 1746657Snate@binkert.org self.printCSwitch(path) 1759219Spower.jg@gmail.com self.printCWakeup(path, includes) 1766657Snate@binkert.org 1776877Ssteve.reinhardt@amd.com def printControllerPython(self, path): 1786999Snate@binkert.org code = self.symtab.codeFormatter() 1796877Ssteve.reinhardt@amd.com ident = self.ident 1806877Ssteve.reinhardt@amd.com py_ident = "%s_Controller" % ident 1816877Ssteve.reinhardt@amd.com c_ident = "%s_Controller" % self.ident 1826877Ssteve.reinhardt@amd.com code(''' 1836877Ssteve.reinhardt@amd.comfrom m5.params import * 1846877Ssteve.reinhardt@amd.comfrom m5.SimObject import SimObject 1856877Ssteve.reinhardt@amd.comfrom Controller import RubyController 1866877Ssteve.reinhardt@amd.com 1876877Ssteve.reinhardt@amd.comclass $py_ident(RubyController): 1886877Ssteve.reinhardt@amd.com type = '$py_ident' 1899338SAndreas.Sandberg@arm.com cxx_header = 'mem/protocol/${c_ident}.hh' 1906877Ssteve.reinhardt@amd.com''') 1916877Ssteve.reinhardt@amd.com code.indent() 1926877Ssteve.reinhardt@amd.com for param in self.config_parameters: 1936877Ssteve.reinhardt@amd.com dflt_str = '' 1946877Ssteve.reinhardt@amd.com if param.default is not None: 1956877Ssteve.reinhardt@amd.com dflt_str = str(param.default) + ', ' 1966882SBrad.Beckmann@amd.com if python_class_map.has_key(param.type_ast.type.c_ident): 1976882SBrad.Beckmann@amd.com python_type = python_class_map[param.type_ast.type.c_ident] 1986882SBrad.Beckmann@amd.com code('${{param.name}} = Param.${{python_type}}(${dflt_str}"")') 1996882SBrad.Beckmann@amd.com else: 2006882SBrad.Beckmann@amd.com self.error("Unknown c++ to python class conversion for c++ " \ 2016882SBrad.Beckmann@amd.com "type: '%s'. Please update the python_class_map " \ 2026882SBrad.Beckmann@amd.com "in StateMachine.py", param.type_ast.type.c_ident) 2036877Ssteve.reinhardt@amd.com code.dedent() 2046877Ssteve.reinhardt@amd.com code.write(path, '%s.py' % py_ident) 2056877Ssteve.reinhardt@amd.com 2066877Ssteve.reinhardt@amd.com 2076657Snate@binkert.org def printControllerHH(self, path): 2086657Snate@binkert.org '''Output the method declarations for the class declaration''' 2096999Snate@binkert.org code = self.symtab.codeFormatter() 2106657Snate@binkert.org ident = self.ident 2116657Snate@binkert.org c_ident = "%s_Controller" % self.ident 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 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() 2369595Snilay@cs.wisc.edu has_peer = False 2376657Snate@binkert.org for var in self.objects: 2386793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 2396657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 2409595Snilay@cs.wisc.edu if "network" in var and "physical_network" in var: 2419595Snilay@cs.wisc.edu has_peer = True 2426657Snate@binkert.org seen_types.add(var.type.ident) 2436657Snate@binkert.org 2446657Snate@binkert.org # for adding information to the protocol debug trace 2456657Snate@binkert.org code(''' 2467002Snate@binkert.orgextern std::stringstream ${ident}_transitionComment; 2476657Snate@binkert.org 2487007Snate@binkert.orgclass $c_ident : public AbstractController 2497007Snate@binkert.org{ 2509271Snilay@cs.wisc.edu public: 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; 2569745Snilay@cs.wisc.edu 2577002Snate@binkert.org void print(std::ostream& out) const; 2586657Snate@binkert.org void wakeup(); 25910012Snilay@cs.wisc.edu void resetStats(); 2609745Snilay@cs.wisc.edu void regStats(); 2619745Snilay@cs.wisc.edu void collateStats(); 2629745Snilay@cs.wisc.edu 2638683Snilay@cs.wisc.edu void recordCacheTrace(int cntrl, CacheRecorder* tr); 2648683Snilay@cs.wisc.edu Sequencer* getSequencer() const; 2657007Snate@binkert.org 2669302Snilay@cs.wisc.edu bool functionalReadBuffers(PacketPtr&); 2679302Snilay@cs.wisc.edu uint32_t functionalWriteBuffers(PacketPtr&); 2689302Snilay@cs.wisc.edu 2699745Snilay@cs.wisc.edu void countTransition(${ident}_State state, ${ident}_Event event); 2709745Snilay@cs.wisc.edu void possibleTransition(${ident}_State state, ${ident}_Event event); 2719745Snilay@cs.wisc.edu uint64 getEventCount(${ident}_Event event); 2729745Snilay@cs.wisc.edu bool isPossible(${ident}_State state, ${ident}_Event event); 2739745Snilay@cs.wisc.edu uint64 getTransitionCount(${ident}_State state, ${ident}_Event event); 2749745Snilay@cs.wisc.edu 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(''' 2877007Snate@binkert.orgTransitionResult doTransition(${ident}_Event event, 2887839Snilay@cs.wisc.edu''') 2897839Snilay@cs.wisc.edu 2907839Snilay@cs.wisc.edu if self.EntryType != None: 2917839Snilay@cs.wisc.edu code(''' 2927839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}* m_cache_entry_ptr, 2937839Snilay@cs.wisc.edu''') 2947839Snilay@cs.wisc.edu if self.TBEType != None: 2957839Snilay@cs.wisc.edu code(''' 2967839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}* m_tbe_ptr, 2977839Snilay@cs.wisc.edu''') 2987839Snilay@cs.wisc.edu 2997839Snilay@cs.wisc.edu code(''' 30010010Snilay@cs.wisc.edu const Address addr); 3017007Snate@binkert.org 3027007Snate@binkert.orgTransitionResult doTransitionWorker(${ident}_Event event, 3037007Snate@binkert.org ${ident}_State state, 3047007Snate@binkert.org ${ident}_State& next_state, 3057839Snilay@cs.wisc.edu''') 3067839Snilay@cs.wisc.edu 3077839Snilay@cs.wisc.edu if self.TBEType != None: 3087839Snilay@cs.wisc.edu code(''' 3097839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}*& m_tbe_ptr, 3107839Snilay@cs.wisc.edu''') 3117839Snilay@cs.wisc.edu if self.EntryType != None: 3127839Snilay@cs.wisc.edu code(''' 3137839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, 3147839Snilay@cs.wisc.edu''') 3157839Snilay@cs.wisc.edu 3167839Snilay@cs.wisc.edu code(''' 3177007Snate@binkert.org const Address& addr); 3187007Snate@binkert.org 3199745Snilay@cs.wisc.eduint m_counters[${ident}_State_NUM][${ident}_Event_NUM]; 3209745Snilay@cs.wisc.eduint m_event_counters[${ident}_Event_NUM]; 3219745Snilay@cs.wisc.edubool m_possible[${ident}_State_NUM][${ident}_Event_NUM]; 3229745Snilay@cs.wisc.edu 3239745Snilay@cs.wisc.edustatic std::vector<Stats::Vector *> eventVec; 3249745Snilay@cs.wisc.edustatic std::vector<std::vector<Stats::Vector *> > transVec; 3256657Snate@binkert.orgstatic int m_num_controllers; 3267007Snate@binkert.org 3276657Snate@binkert.org// Internal functions 3286657Snate@binkert.org''') 3296657Snate@binkert.org 3306657Snate@binkert.org for func in self.functions: 3316657Snate@binkert.org proto = func.prototype 3326657Snate@binkert.org if proto: 3336657Snate@binkert.org code('$proto') 3346657Snate@binkert.org 3359595Snilay@cs.wisc.edu if has_peer: 3369595Snilay@cs.wisc.edu code('void getQueuesFromPeer(AbstractController *);') 3377839Snilay@cs.wisc.edu if self.EntryType != None: 3387839Snilay@cs.wisc.edu code(''' 3397839Snilay@cs.wisc.edu 3407839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable 3417839Snilay@cs.wisc.eduvoid set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry); 3427839Snilay@cs.wisc.eduvoid unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr); 3437839Snilay@cs.wisc.edu''') 3447839Snilay@cs.wisc.edu 3457839Snilay@cs.wisc.edu if self.TBEType != None: 3467839Snilay@cs.wisc.edu code(''' 3477839Snilay@cs.wisc.edu 3487839Snilay@cs.wisc.edu// Set and Reset for tbe variable 3497839Snilay@cs.wisc.eduvoid set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${ident}_TBE* m_new_tbe); 3507839Snilay@cs.wisc.eduvoid unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr); 3517839Snilay@cs.wisc.edu''') 3527839Snilay@cs.wisc.edu 35310121Snilay@cs.wisc.edu # Prototype the actions that the controller can take 3546657Snate@binkert.org code(''' 3556657Snate@binkert.org 3566657Snate@binkert.org// Actions 3576657Snate@binkert.org''') 3587839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 3597839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3607839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 36110121Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& ' 36210121Snilay@cs.wisc.edu 'm_tbe_ptr, ${{self.EntryType.c_ident}}*& ' 36310121Snilay@cs.wisc.edu 'm_cache_entry_ptr, const Address& addr);') 3647839Snilay@cs.wisc.edu elif self.TBEType != None: 3657839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3667839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 36710121Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& ' 36810121Snilay@cs.wisc.edu 'm_tbe_ptr, const Address& addr);') 3697839Snilay@cs.wisc.edu elif self.EntryType != None: 3707839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3717839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 37210121Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.EntryType.c_ident}}*& ' 37310121Snilay@cs.wisc.edu 'm_cache_entry_ptr, const Address& addr);') 3747839Snilay@cs.wisc.edu else: 3757839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3767839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3777839Snilay@cs.wisc.edu code('void ${{action.ident}}(const Address& addr);') 3786657Snate@binkert.org 3796657Snate@binkert.org # the controller internal variables 3806657Snate@binkert.org code(''' 3816657Snate@binkert.org 3827007Snate@binkert.org// Objects 3836657Snate@binkert.org''') 3846657Snate@binkert.org for var in self.objects: 3859273Snilay@cs.wisc.edu th = var.get("template", "") 38610305Snilay@cs.wisc.edu code('${{var.type.c_ident}}$th* m_${{var.ident}}_ptr;') 3876657Snate@binkert.org 3886657Snate@binkert.org code.dedent() 3896657Snate@binkert.org code('};') 3907007Snate@binkert.org code('#endif // __${ident}_CONTROLLER_H__') 3916657Snate@binkert.org code.write(path, '%s.hh' % c_ident) 3926657Snate@binkert.org 3939219Spower.jg@gmail.com def printControllerCC(self, path, includes): 3946657Snate@binkert.org '''Output the actions for performing the actions''' 3956657Snate@binkert.org 3966999Snate@binkert.org code = self.symtab.codeFormatter() 3976657Snate@binkert.org ident = self.ident 3986657Snate@binkert.org c_ident = "%s_Controller" % self.ident 3999595Snilay@cs.wisc.edu has_peer = False 4006657Snate@binkert.org 4016657Snate@binkert.org code(''' 4027007Snate@binkert.org/** \\file $c_ident.cc 4036657Snate@binkert.org * 4046657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__ 4056657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}" 4066657Snate@binkert.org */ 4076657Snate@binkert.org 4088946Sandreas.hansson@arm.com#include <sys/types.h> 4098946Sandreas.hansson@arm.com#include <unistd.h> 4108946Sandreas.hansson@arm.com 4117832Snate@binkert.org#include <cassert> 4127002Snate@binkert.org#include <sstream> 4137002Snate@binkert.org#include <string> 4147002Snate@binkert.org 4158641Snate@binkert.org#include "base/compiler.hh" 4167056Snate@binkert.org#include "base/cprintf.hh" 4178232Snate@binkert.org#include "debug/RubyGenerated.hh" 4188232Snate@binkert.org#include "debug/RubySlicc.hh" 4196657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 4208229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 4216657Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 4226657Snate@binkert.org#include "mem/protocol/Types.hh" 4237056Snate@binkert.org#include "mem/ruby/common/Global.hh" 4246657Snate@binkert.org#include "mem/ruby/system/System.hh" 4259219Spower.jg@gmail.com''') 4269219Spower.jg@gmail.com for include_path in includes: 4279219Spower.jg@gmail.com code('#include "${{include_path}}"') 4289219Spower.jg@gmail.com 4299219Spower.jg@gmail.com code(''' 4307002Snate@binkert.org 4317002Snate@binkert.orgusing namespace std; 4326657Snate@binkert.org''') 4336657Snate@binkert.org 4346657Snate@binkert.org # include object classes 4356657Snate@binkert.org seen_types = set() 4366657Snate@binkert.org for var in self.objects: 4376793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 4386657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 4396657Snate@binkert.org seen_types.add(var.type.ident) 4406657Snate@binkert.org 44110121Snilay@cs.wisc.edu num_in_ports = len(self.in_ports) 44210121Snilay@cs.wisc.edu 4436657Snate@binkert.org code(''' 4446877Ssteve.reinhardt@amd.com$c_ident * 4456877Ssteve.reinhardt@amd.com${c_ident}Params::create() 4466877Ssteve.reinhardt@amd.com{ 4476877Ssteve.reinhardt@amd.com return new $c_ident(this); 4486877Ssteve.reinhardt@amd.com} 4496877Ssteve.reinhardt@amd.com 4506657Snate@binkert.orgint $c_ident::m_num_controllers = 0; 4519745Snilay@cs.wisc.edustd::vector<Stats::Vector *> $c_ident::eventVec; 4529745Snilay@cs.wisc.edustd::vector<std::vector<Stats::Vector *> > $c_ident::transVec; 4536657Snate@binkert.org 4547007Snate@binkert.org// for adding information to the protocol debug trace 4556657Snate@binkert.orgstringstream ${ident}_transitionComment; 4569801Snilay@cs.wisc.edu 4579801Snilay@cs.wisc.edu#ifndef NDEBUG 4586657Snate@binkert.org#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str) 4599801Snilay@cs.wisc.edu#else 4609801Snilay@cs.wisc.edu#define APPEND_TRANSITION_COMMENT(str) do {} while (0) 4619801Snilay@cs.wisc.edu#endif 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{ 46710078Snilay@cs.wisc.edu m_machineID.type = MachineType_${ident}; 46810078Snilay@cs.wisc.edu m_machineID.num = m_version; 46910121Snilay@cs.wisc.edu m_num_controllers++; 47010121Snilay@cs.wisc.edu 47110121Snilay@cs.wisc.edu m_in_ports = $num_in_ports; 4726657Snate@binkert.org''') 4736657Snate@binkert.org code.indent() 4746882SBrad.Beckmann@amd.com 4756882SBrad.Beckmann@amd.com # 4766882SBrad.Beckmann@amd.com # After initializing the universal machine parameters, initialize the 47710121Snilay@cs.wisc.edu # this machines config parameters. Also if these configuration params 47810121Snilay@cs.wisc.edu # include a sequencer, connect the it to the controller. 4796882SBrad.Beckmann@amd.com # 4806877Ssteve.reinhardt@amd.com for param in self.config_parameters: 4816882SBrad.Beckmann@amd.com if param.pointer: 4826882SBrad.Beckmann@amd.com code('m_${{param.name}}_ptr = p->${{param.name}};') 4836882SBrad.Beckmann@amd.com else: 4846882SBrad.Beckmann@amd.com code('m_${{param.name}} = p->${{param.name}};') 48510121Snilay@cs.wisc.edu if re.compile("sequencer").search(param.name): 48610121Snilay@cs.wisc.edu code('m_${{param.name}}_ptr->setController(this);') 4876888SBrad.Beckmann@amd.com 4886657Snate@binkert.org for var in self.objects: 4896657Snate@binkert.org if var.ident.find("mandatoryQueue") >= 0: 4909508Snilay@cs.wisc.edu code(''' 49110305Snilay@cs.wisc.edum_${{var.ident}}_ptr = new ${{var.type.c_ident}}(); 49210305Snilay@cs.wisc.edum_${{var.ident}}_ptr->setReceiver(this); 4939508Snilay@cs.wisc.edu''') 4949595Snilay@cs.wisc.edu else: 4959595Snilay@cs.wisc.edu if "network" in var and "physical_network" in var and \ 4969595Snilay@cs.wisc.edu var["network"] == "To": 4979595Snilay@cs.wisc.edu has_peer = True 4989595Snilay@cs.wisc.edu code(''' 49910305Snilay@cs.wisc.edum_${{var.ident}}_ptr = new ${{var.type.c_ident}}(); 50010305Snilay@cs.wisc.edupeerQueueMap[${{var["physical_network"]}}] = m_${{var.ident}}_ptr; 50110305Snilay@cs.wisc.edum_${{var.ident}}_ptr->setSender(this); 5029595Snilay@cs.wisc.edu''') 5036657Snate@binkert.org 5049595Snilay@cs.wisc.edu code(''' 5059595Snilay@cs.wisc.eduif (p->peer != NULL) 5069595Snilay@cs.wisc.edu connectWithPeer(p->peer); 5079745Snilay@cs.wisc.edu 5089745Snilay@cs.wisc.edufor (int state = 0; state < ${ident}_State_NUM; state++) { 5099745Snilay@cs.wisc.edu for (int event = 0; event < ${ident}_Event_NUM; event++) { 5109745Snilay@cs.wisc.edu m_possible[state][event] = false; 5119745Snilay@cs.wisc.edu m_counters[state][event] = 0; 5129745Snilay@cs.wisc.edu } 5139745Snilay@cs.wisc.edu} 5149745Snilay@cs.wisc.edufor (int event = 0; event < ${ident}_Event_NUM; event++) { 5159745Snilay@cs.wisc.edu m_event_counters[event] = 0; 5169745Snilay@cs.wisc.edu} 5179595Snilay@cs.wisc.edu''') 5186657Snate@binkert.org code.dedent() 5196657Snate@binkert.org code(''' 5206657Snate@binkert.org} 5216657Snate@binkert.org 5227007Snate@binkert.orgvoid 5237007Snate@binkert.org$c_ident::init() 5246657Snate@binkert.org{ 5259745Snilay@cs.wisc.edu MachineType machine_type = string_to_MachineType("${{var.machine.ident}}"); 52610008Snilay@cs.wisc.edu int base M5_VAR_USED = MachineType_base_number(machine_type); 5277007Snate@binkert.org 5287007Snate@binkert.org // initialize objects 5297007Snate@binkert.org 5306657Snate@binkert.org''') 5316657Snate@binkert.org 5326657Snate@binkert.org code.indent() 5336657Snate@binkert.org for var in self.objects: 5346657Snate@binkert.org vtype = var.type 53510305Snilay@cs.wisc.edu vid = "m_%s_ptr" % var.ident 5366657Snate@binkert.org if "network" not in var: 5376657Snate@binkert.org # Not a network port object 5386657Snate@binkert.org if "primitive" in vtype: 5396657Snate@binkert.org code('$vid = new ${{vtype.c_ident}};') 5406657Snate@binkert.org if "default" in var: 5416657Snate@binkert.org code('(*$vid) = ${{var["default"]}};') 5426657Snate@binkert.org else: 5436657Snate@binkert.org # Normal Object 5449595Snilay@cs.wisc.edu if var.ident.find("mandatoryQueue") < 0: 5459273Snilay@cs.wisc.edu th = var.get("template", "") 5466657Snate@binkert.org expr = "%s = new %s%s" % (vid, vtype.c_ident, th) 5476657Snate@binkert.org args = "" 5486657Snate@binkert.org if "non_obj" not in vtype and not vtype.isEnumeration: 5499364Snilay@cs.wisc.edu args = var.get("constructor", "") 5507007Snate@binkert.org code('$expr($args);') 5516657Snate@binkert.org 5526657Snate@binkert.org code('assert($vid != NULL);') 5536657Snate@binkert.org 5546657Snate@binkert.org if "default" in var: 5557007Snate@binkert.org code('*$vid = ${{var["default"]}}; // Object default') 5566657Snate@binkert.org elif "default" in vtype: 5577007Snate@binkert.org comment = "Type %s default" % vtype.ident 5587007Snate@binkert.org code('*$vid = ${{vtype["default"]}}; // $comment') 5596657Snate@binkert.org 5606657Snate@binkert.org # Set ordering 5619508Snilay@cs.wisc.edu if "ordered" in var: 5626657Snate@binkert.org # A buffer 5636657Snate@binkert.org code('$vid->setOrdering(${{var["ordered"]}});') 5646657Snate@binkert.org 5656657Snate@binkert.org # Set randomization 5666657Snate@binkert.org if "random" in var: 5676657Snate@binkert.org # A buffer 5686657Snate@binkert.org code('$vid->setRandomization(${{var["random"]}});') 5696657Snate@binkert.org 5706657Snate@binkert.org # Set Priority 5719508Snilay@cs.wisc.edu if vtype.isBuffer and "rank" in var: 5726657Snate@binkert.org code('$vid->setPriority(${{var["rank"]}});') 5737566SBrad.Beckmann@amd.com 5749508Snilay@cs.wisc.edu # Set sender and receiver for trigger queue 5759508Snilay@cs.wisc.edu if var.ident.find("triggerQueue") >= 0: 5769508Snilay@cs.wisc.edu code('$vid->setSender(this);') 5779508Snilay@cs.wisc.edu code('$vid->setReceiver(this);') 5789508Snilay@cs.wisc.edu elif vtype.c_ident == "TimerTable": 5799508Snilay@cs.wisc.edu code('$vid->setClockObj(this);') 5809604Snilay@cs.wisc.edu elif var.ident.find("optionalQueue") >= 0: 5819604Snilay@cs.wisc.edu code('$vid->setSender(this);') 5829604Snilay@cs.wisc.edu code('$vid->setReceiver(this);') 5839508Snilay@cs.wisc.edu 5846657Snate@binkert.org else: 5856657Snate@binkert.org # Network port object 5866657Snate@binkert.org network = var["network"] 5876657Snate@binkert.org ordered = var["ordered"] 5886657Snate@binkert.org 5899595Snilay@cs.wisc.edu if "virtual_network" in var: 5909595Snilay@cs.wisc.edu vnet = var["virtual_network"] 5919595Snilay@cs.wisc.edu vnet_type = var["vnet_type"] 5929595Snilay@cs.wisc.edu 5939595Snilay@cs.wisc.edu assert var.machine is not None 5949595Snilay@cs.wisc.edu code(''' 5958308Stushar@csail.mit.edu$vid = m_net_ptr->get${network}NetQueue(m_version + base, $ordered, $vnet, "$vnet_type"); 5969595Snilay@cs.wisc.eduassert($vid != NULL); 5976657Snate@binkert.org''') 5986657Snate@binkert.org 5999595Snilay@cs.wisc.edu # Set the end 6009595Snilay@cs.wisc.edu if network == "To": 6019595Snilay@cs.wisc.edu code('$vid->setSender(this);') 6029595Snilay@cs.wisc.edu else: 6039595Snilay@cs.wisc.edu code('$vid->setReceiver(this);') 6049508Snilay@cs.wisc.edu 6056657Snate@binkert.org # Set ordering 6066657Snate@binkert.org if "ordered" in var: 6076657Snate@binkert.org # A buffer 6086657Snate@binkert.org code('$vid->setOrdering(${{var["ordered"]}});') 6096657Snate@binkert.org 6106657Snate@binkert.org # Set randomization 6116657Snate@binkert.org if "random" in var: 6126657Snate@binkert.org # A buffer 6138187SLisa.Hsu@amd.com code('$vid->setRandomization(${{var["random"]}});') 6146657Snate@binkert.org 6156657Snate@binkert.org # Set Priority 6166657Snate@binkert.org if "rank" in var: 6176657Snate@binkert.org code('$vid->setPriority(${{var["rank"]}})') 6186657Snate@binkert.org 6196657Snate@binkert.org # Set buffer size 6206657Snate@binkert.org if vtype.isBuffer: 6216657Snate@binkert.org code(''' 6226657Snate@binkert.orgif (m_buffer_size > 0) { 6237454Snate@binkert.org $vid->resize(m_buffer_size); 6246657Snate@binkert.org} 6256657Snate@binkert.org''') 6266657Snate@binkert.org 6276657Snate@binkert.org # set description (may be overriden later by port def) 6287007Snate@binkert.org code(''' 62910305Snilay@cs.wisc.edu$vid->setDescription("[Version " + to_string(m_version) + ", ${ident}, name=${{var.ident}}]"); 6307007Snate@binkert.org 6317007Snate@binkert.org''') 6326657Snate@binkert.org 6337566SBrad.Beckmann@amd.com if vtype.isBuffer: 6347566SBrad.Beckmann@amd.com if "recycle_latency" in var: 6359499Snilay@cs.wisc.edu code('$vid->setRecycleLatency( ' \ 6369499Snilay@cs.wisc.edu 'Cycles(${{var["recycle_latency"]}}));') 6377566SBrad.Beckmann@amd.com else: 6387566SBrad.Beckmann@amd.com code('$vid->setRecycleLatency(m_recycle_latency);') 6397566SBrad.Beckmann@amd.com 6409366Snilay@cs.wisc.edu # Set the prefetchers 6419366Snilay@cs.wisc.edu code() 6429366Snilay@cs.wisc.edu for prefetcher in self.prefetchers: 6439366Snilay@cs.wisc.edu code('${{prefetcher.code}}.setController(this);') 6447566SBrad.Beckmann@amd.com 6457672Snate@binkert.org code() 6466657Snate@binkert.org for port in self.in_ports: 6479465Snilay@cs.wisc.edu # Set the queue consumers 6486657Snate@binkert.org code('${{port.code}}.setConsumer(this);') 6499465Snilay@cs.wisc.edu # Set the queue descriptions 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) 6659745Snilay@cs.wisc.edu code('possibleTransition($state, $event);') 6666657Snate@binkert.org 6676657Snate@binkert.org code.dedent() 6689496Snilay@cs.wisc.edu code(''' 6699496Snilay@cs.wisc.edu AbstractController::init(); 67010012Snilay@cs.wisc.edu resetStats(); 6719496Snilay@cs.wisc.edu} 6729496Snilay@cs.wisc.edu''') 6736657Snate@binkert.org 67410121Snilay@cs.wisc.edu mq_ident = "NULL" 6756657Snate@binkert.org for port in self.in_ports: 6766657Snate@binkert.org if port.code.find("mandatoryQueue_ptr") >= 0: 67710305Snilay@cs.wisc.edu mq_ident = "m_mandatoryQueue_ptr" 6786657Snate@binkert.org 6798683Snilay@cs.wisc.edu seq_ident = "NULL" 6808683Snilay@cs.wisc.edu for param in self.config_parameters: 6818683Snilay@cs.wisc.edu if param.name == "sequencer": 6828683Snilay@cs.wisc.edu assert(param.pointer) 6838683Snilay@cs.wisc.edu seq_ident = "m_%s_ptr" % param.name 6848683Snilay@cs.wisc.edu 6856657Snate@binkert.org code(''' 6869745Snilay@cs.wisc.edu 6879745Snilay@cs.wisc.eduvoid 6889745Snilay@cs.wisc.edu$c_ident::regStats() 6899745Snilay@cs.wisc.edu{ 69010012Snilay@cs.wisc.edu AbstractController::regStats(); 69110012Snilay@cs.wisc.edu 6929745Snilay@cs.wisc.edu if (m_version == 0) { 6939745Snilay@cs.wisc.edu for (${ident}_Event event = ${ident}_Event_FIRST; 6949745Snilay@cs.wisc.edu event < ${ident}_Event_NUM; ++event) { 6959745Snilay@cs.wisc.edu Stats::Vector *t = new Stats::Vector(); 6969745Snilay@cs.wisc.edu t->init(m_num_controllers); 69710012Snilay@cs.wisc.edu t->name(g_system_ptr->name() + ".${c_ident}." + 69810012Snilay@cs.wisc.edu ${ident}_Event_to_string(event)); 6999745Snilay@cs.wisc.edu t->flags(Stats::pdf | Stats::total | Stats::oneline | 7009745Snilay@cs.wisc.edu Stats::nozero); 7019745Snilay@cs.wisc.edu 7029745Snilay@cs.wisc.edu eventVec.push_back(t); 7039745Snilay@cs.wisc.edu } 7049745Snilay@cs.wisc.edu 7059745Snilay@cs.wisc.edu for (${ident}_State state = ${ident}_State_FIRST; 7069745Snilay@cs.wisc.edu state < ${ident}_State_NUM; ++state) { 7079745Snilay@cs.wisc.edu 7089745Snilay@cs.wisc.edu transVec.push_back(std::vector<Stats::Vector *>()); 7099745Snilay@cs.wisc.edu 7109745Snilay@cs.wisc.edu for (${ident}_Event event = ${ident}_Event_FIRST; 7119745Snilay@cs.wisc.edu event < ${ident}_Event_NUM; ++event) { 7129745Snilay@cs.wisc.edu 7139745Snilay@cs.wisc.edu Stats::Vector *t = new Stats::Vector(); 7149745Snilay@cs.wisc.edu t->init(m_num_controllers); 71510012Snilay@cs.wisc.edu t->name(g_system_ptr->name() + ".${c_ident}." + 71610012Snilay@cs.wisc.edu ${ident}_State_to_string(state) + 7179745Snilay@cs.wisc.edu "." + ${ident}_Event_to_string(event)); 7189745Snilay@cs.wisc.edu 7199745Snilay@cs.wisc.edu t->flags(Stats::pdf | Stats::total | Stats::oneline | 7209745Snilay@cs.wisc.edu Stats::nozero); 7219745Snilay@cs.wisc.edu transVec[state].push_back(t); 7229745Snilay@cs.wisc.edu } 7239745Snilay@cs.wisc.edu } 7249745Snilay@cs.wisc.edu } 7259745Snilay@cs.wisc.edu} 7269745Snilay@cs.wisc.edu 7279745Snilay@cs.wisc.eduvoid 7289745Snilay@cs.wisc.edu$c_ident::collateStats() 7299745Snilay@cs.wisc.edu{ 7309745Snilay@cs.wisc.edu for (${ident}_Event event = ${ident}_Event_FIRST; 7319745Snilay@cs.wisc.edu event < ${ident}_Event_NUM; ++event) { 7329745Snilay@cs.wisc.edu for (unsigned int i = 0; i < m_num_controllers; ++i) { 7339745Snilay@cs.wisc.edu std::map<uint32_t, AbstractController *>::iterator it = 7349745Snilay@cs.wisc.edu g_abs_controls[MachineType_${ident}].find(i); 7359745Snilay@cs.wisc.edu assert(it != g_abs_controls[MachineType_${ident}].end()); 7369745Snilay@cs.wisc.edu (*eventVec[event])[i] = 7379745Snilay@cs.wisc.edu (($c_ident *)(*it).second)->getEventCount(event); 7389745Snilay@cs.wisc.edu } 7399745Snilay@cs.wisc.edu } 7409745Snilay@cs.wisc.edu 7419745Snilay@cs.wisc.edu for (${ident}_State state = ${ident}_State_FIRST; 7429745Snilay@cs.wisc.edu state < ${ident}_State_NUM; ++state) { 7439745Snilay@cs.wisc.edu 7449745Snilay@cs.wisc.edu for (${ident}_Event event = ${ident}_Event_FIRST; 7459745Snilay@cs.wisc.edu event < ${ident}_Event_NUM; ++event) { 7469745Snilay@cs.wisc.edu 7479745Snilay@cs.wisc.edu for (unsigned int i = 0; i < m_num_controllers; ++i) { 7489745Snilay@cs.wisc.edu std::map<uint32_t, AbstractController *>::iterator it = 7499745Snilay@cs.wisc.edu g_abs_controls[MachineType_${ident}].find(i); 7509745Snilay@cs.wisc.edu assert(it != g_abs_controls[MachineType_${ident}].end()); 7519745Snilay@cs.wisc.edu (*transVec[state][event])[i] = 7529745Snilay@cs.wisc.edu (($c_ident *)(*it).second)->getTransitionCount(state, event); 7539745Snilay@cs.wisc.edu } 7549745Snilay@cs.wisc.edu } 7559745Snilay@cs.wisc.edu } 7569745Snilay@cs.wisc.edu} 7579745Snilay@cs.wisc.edu 7589745Snilay@cs.wisc.eduvoid 7599745Snilay@cs.wisc.edu$c_ident::countTransition(${ident}_State state, ${ident}_Event event) 7609745Snilay@cs.wisc.edu{ 7619745Snilay@cs.wisc.edu assert(m_possible[state][event]); 7629745Snilay@cs.wisc.edu m_counters[state][event]++; 7639745Snilay@cs.wisc.edu m_event_counters[event]++; 7649745Snilay@cs.wisc.edu} 7659745Snilay@cs.wisc.eduvoid 7669745Snilay@cs.wisc.edu$c_ident::possibleTransition(${ident}_State state, 7679745Snilay@cs.wisc.edu ${ident}_Event event) 7689745Snilay@cs.wisc.edu{ 7699745Snilay@cs.wisc.edu m_possible[state][event] = true; 7709745Snilay@cs.wisc.edu} 7719745Snilay@cs.wisc.edu 7729745Snilay@cs.wisc.eduuint64 7739745Snilay@cs.wisc.edu$c_ident::getEventCount(${ident}_Event event) 7749745Snilay@cs.wisc.edu{ 7759745Snilay@cs.wisc.edu return m_event_counters[event]; 7769745Snilay@cs.wisc.edu} 7779745Snilay@cs.wisc.edu 7789745Snilay@cs.wisc.edubool 7799745Snilay@cs.wisc.edu$c_ident::isPossible(${ident}_State state, ${ident}_Event event) 7809745Snilay@cs.wisc.edu{ 7819745Snilay@cs.wisc.edu return m_possible[state][event]; 7829745Snilay@cs.wisc.edu} 7839745Snilay@cs.wisc.edu 7849745Snilay@cs.wisc.eduuint64 7859745Snilay@cs.wisc.edu$c_ident::getTransitionCount(${ident}_State state, 7869745Snilay@cs.wisc.edu ${ident}_Event event) 7879745Snilay@cs.wisc.edu{ 7889745Snilay@cs.wisc.edu return m_counters[state][event]; 7899745Snilay@cs.wisc.edu} 7909745Snilay@cs.wisc.edu 7917007Snate@binkert.orgint 7927007Snate@binkert.org$c_ident::getNumControllers() 7937007Snate@binkert.org{ 7946657Snate@binkert.org return m_num_controllers; 7956657Snate@binkert.org} 7966657Snate@binkert.org 7977007Snate@binkert.orgMessageBuffer* 7987007Snate@binkert.org$c_ident::getMandatoryQueue() const 7997007Snate@binkert.org{ 8006657Snate@binkert.org return $mq_ident; 8016657Snate@binkert.org} 8026657Snate@binkert.org 8038683Snilay@cs.wisc.eduSequencer* 8048683Snilay@cs.wisc.edu$c_ident::getSequencer() const 8058683Snilay@cs.wisc.edu{ 8068683Snilay@cs.wisc.edu return $seq_ident; 8078683Snilay@cs.wisc.edu} 8088683Snilay@cs.wisc.edu 8097007Snate@binkert.orgvoid 8107007Snate@binkert.org$c_ident::print(ostream& out) const 8117007Snate@binkert.org{ 8127007Snate@binkert.org out << "[$c_ident " << m_version << "]"; 8137007Snate@binkert.org} 8146657Snate@binkert.org 81510012Snilay@cs.wisc.eduvoid $c_ident::resetStats() 8169745Snilay@cs.wisc.edu{ 8179745Snilay@cs.wisc.edu for (int state = 0; state < ${ident}_State_NUM; state++) { 8189745Snilay@cs.wisc.edu for (int event = 0; event < ${ident}_Event_NUM; event++) { 8199745Snilay@cs.wisc.edu m_counters[state][event] = 0; 8209745Snilay@cs.wisc.edu } 8219745Snilay@cs.wisc.edu } 8226902SBrad.Beckmann@amd.com 8239745Snilay@cs.wisc.edu for (int event = 0; event < ${ident}_Event_NUM; event++) { 8249745Snilay@cs.wisc.edu m_event_counters[event] = 0; 8259745Snilay@cs.wisc.edu } 8269745Snilay@cs.wisc.edu 82710012Snilay@cs.wisc.edu AbstractController::resetStats(); 8286902SBrad.Beckmann@amd.com} 8297839Snilay@cs.wisc.edu''') 8307839Snilay@cs.wisc.edu 8317839Snilay@cs.wisc.edu if self.EntryType != None: 8327839Snilay@cs.wisc.edu code(''' 8337839Snilay@cs.wisc.edu 8347839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable 8357839Snilay@cs.wisc.eduvoid 8367839Snilay@cs.wisc.edu$c_ident::set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry) 8377839Snilay@cs.wisc.edu{ 8387839Snilay@cs.wisc.edu m_cache_entry_ptr = (${{self.EntryType.c_ident}}*)m_new_cache_entry; 8397839Snilay@cs.wisc.edu} 8407839Snilay@cs.wisc.edu 8417839Snilay@cs.wisc.eduvoid 8427839Snilay@cs.wisc.edu$c_ident::unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr) 8437839Snilay@cs.wisc.edu{ 8447839Snilay@cs.wisc.edu m_cache_entry_ptr = 0; 8457839Snilay@cs.wisc.edu} 8467839Snilay@cs.wisc.edu''') 8477839Snilay@cs.wisc.edu 8487839Snilay@cs.wisc.edu if self.TBEType != None: 8497839Snilay@cs.wisc.edu code(''' 8507839Snilay@cs.wisc.edu 8517839Snilay@cs.wisc.edu// Set and Reset for tbe variable 8527839Snilay@cs.wisc.eduvoid 8537839Snilay@cs.wisc.edu$c_ident::set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.TBEType.c_ident}}* m_new_tbe) 8547839Snilay@cs.wisc.edu{ 8557839Snilay@cs.wisc.edu m_tbe_ptr = m_new_tbe; 8567839Snilay@cs.wisc.edu} 8577839Snilay@cs.wisc.edu 8587839Snilay@cs.wisc.eduvoid 8597839Snilay@cs.wisc.edu$c_ident::unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr) 8607839Snilay@cs.wisc.edu{ 8617839Snilay@cs.wisc.edu m_tbe_ptr = NULL; 8627839Snilay@cs.wisc.edu} 8637839Snilay@cs.wisc.edu''') 8647839Snilay@cs.wisc.edu 8657839Snilay@cs.wisc.edu code(''' 8666902SBrad.Beckmann@amd.com 8678683Snilay@cs.wisc.eduvoid 8688683Snilay@cs.wisc.edu$c_ident::recordCacheTrace(int cntrl, CacheRecorder* tr) 8698683Snilay@cs.wisc.edu{ 8708683Snilay@cs.wisc.edu''') 8718683Snilay@cs.wisc.edu # 8728683Snilay@cs.wisc.edu # Record cache contents for all associated caches. 8738683Snilay@cs.wisc.edu # 8748683Snilay@cs.wisc.edu code.indent() 8758683Snilay@cs.wisc.edu for param in self.config_parameters: 8768683Snilay@cs.wisc.edu if param.type_ast.type.ident == "CacheMemory": 8778683Snilay@cs.wisc.edu assert(param.pointer) 8788683Snilay@cs.wisc.edu code('m_${{param.ident}}_ptr->recordCacheContents(cntrl, tr);') 8798683Snilay@cs.wisc.edu 8808683Snilay@cs.wisc.edu code.dedent() 8818683Snilay@cs.wisc.edu code(''' 8828683Snilay@cs.wisc.edu} 8838683Snilay@cs.wisc.edu 8846657Snate@binkert.org// Actions 8856657Snate@binkert.org''') 8867839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 8877839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 8887839Snilay@cs.wisc.edu if "c_code" not in action: 8897839Snilay@cs.wisc.edu continue 8906657Snate@binkert.org 8917839Snilay@cs.wisc.edu code(''' 8927839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 8937839Snilay@cs.wisc.eduvoid 8947839Snilay@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) 8957839Snilay@cs.wisc.edu{ 8968055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 8977839Snilay@cs.wisc.edu ${{action["c_code"]}} 8987839Snilay@cs.wisc.edu} 8996657Snate@binkert.org 9007839Snilay@cs.wisc.edu''') 9017839Snilay@cs.wisc.edu elif self.TBEType != None: 9027839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9037839Snilay@cs.wisc.edu if "c_code" not in action: 9047839Snilay@cs.wisc.edu continue 9057839Snilay@cs.wisc.edu 9067839Snilay@cs.wisc.edu code(''' 9077839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9087839Snilay@cs.wisc.eduvoid 9097839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, const Address& addr) 9107839Snilay@cs.wisc.edu{ 9118055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9127839Snilay@cs.wisc.edu ${{action["c_code"]}} 9137839Snilay@cs.wisc.edu} 9147839Snilay@cs.wisc.edu 9157839Snilay@cs.wisc.edu''') 9167839Snilay@cs.wisc.edu elif self.EntryType != None: 9177839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9187839Snilay@cs.wisc.edu if "c_code" not in action: 9197839Snilay@cs.wisc.edu continue 9207839Snilay@cs.wisc.edu 9217839Snilay@cs.wisc.edu code(''' 9227839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9237839Snilay@cs.wisc.eduvoid 9247839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr) 9257839Snilay@cs.wisc.edu{ 9268055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9277839Snilay@cs.wisc.edu ${{action["c_code"]}} 9287839Snilay@cs.wisc.edu} 9297839Snilay@cs.wisc.edu 9307839Snilay@cs.wisc.edu''') 9317839Snilay@cs.wisc.edu else: 9327839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9337839Snilay@cs.wisc.edu if "c_code" not in action: 9347839Snilay@cs.wisc.edu continue 9357839Snilay@cs.wisc.edu 9367839Snilay@cs.wisc.edu code(''' 9376657Snate@binkert.org/** \\brief ${{action.desc}} */ 9387007Snate@binkert.orgvoid 9397007Snate@binkert.org$c_ident::${{action.ident}}(const Address& addr) 9406657Snate@binkert.org{ 9418055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9426657Snate@binkert.org ${{action["c_code"]}} 9436657Snate@binkert.org} 9446657Snate@binkert.org 9456657Snate@binkert.org''') 9468478Snilay@cs.wisc.edu for func in self.functions: 9478478Snilay@cs.wisc.edu code(func.generateCode()) 9488478Snilay@cs.wisc.edu 9499302Snilay@cs.wisc.edu # Function for functional reads from messages buffered in the controller 9509302Snilay@cs.wisc.edu code(''' 9519302Snilay@cs.wisc.edubool 9529302Snilay@cs.wisc.edu$c_ident::functionalReadBuffers(PacketPtr& pkt) 9539302Snilay@cs.wisc.edu{ 9549302Snilay@cs.wisc.edu''') 9559302Snilay@cs.wisc.edu for var in self.objects: 9569302Snilay@cs.wisc.edu vtype = var.type 9579302Snilay@cs.wisc.edu if vtype.isBuffer: 95810305Snilay@cs.wisc.edu vid = "m_%s_ptr" % var.ident 9599302Snilay@cs.wisc.edu code('if ($vid->functionalRead(pkt)) { return true; }') 9609302Snilay@cs.wisc.edu code(''' 9619302Snilay@cs.wisc.edu return false; 9629302Snilay@cs.wisc.edu} 9639302Snilay@cs.wisc.edu''') 9649302Snilay@cs.wisc.edu 9659302Snilay@cs.wisc.edu # Function for functional writes to messages buffered in the controller 9669302Snilay@cs.wisc.edu code(''' 9679302Snilay@cs.wisc.eduuint32_t 9689302Snilay@cs.wisc.edu$c_ident::functionalWriteBuffers(PacketPtr& pkt) 9699302Snilay@cs.wisc.edu{ 9709302Snilay@cs.wisc.edu uint32_t num_functional_writes = 0; 9719302Snilay@cs.wisc.edu''') 9729302Snilay@cs.wisc.edu for var in self.objects: 9739302Snilay@cs.wisc.edu vtype = var.type 9749302Snilay@cs.wisc.edu if vtype.isBuffer: 97510305Snilay@cs.wisc.edu vid = "m_%s_ptr" % var.ident 9769302Snilay@cs.wisc.edu code('num_functional_writes += $vid->functionalWrite(pkt);') 9779302Snilay@cs.wisc.edu code(''' 9789302Snilay@cs.wisc.edu return num_functional_writes; 9799302Snilay@cs.wisc.edu} 9809302Snilay@cs.wisc.edu''') 9819302Snilay@cs.wisc.edu 9829595Snilay@cs.wisc.edu # Check if this controller has a peer, if yes then write the 9839595Snilay@cs.wisc.edu # function for connecting to the peer. 9849595Snilay@cs.wisc.edu if has_peer: 9859595Snilay@cs.wisc.edu code(''' 9869595Snilay@cs.wisc.edu 9879595Snilay@cs.wisc.eduvoid 9889595Snilay@cs.wisc.edu$c_ident::getQueuesFromPeer(AbstractController *peer) 9899595Snilay@cs.wisc.edu{ 9909595Snilay@cs.wisc.edu''') 9919595Snilay@cs.wisc.edu for var in self.objects: 9929595Snilay@cs.wisc.edu if "network" in var and "physical_network" in var and \ 9939595Snilay@cs.wisc.edu var["network"] == "From": 9949595Snilay@cs.wisc.edu code(''' 99510305Snilay@cs.wisc.edum_${{var.ident}}_ptr = peer->getPeerQueue(${{var["physical_network"]}}); 99610305Snilay@cs.wisc.eduassert(m_${{var.ident}}_ptr != NULL); 99710305Snilay@cs.wisc.edum_${{var.ident}}_ptr->setReceiver(this); 9989595Snilay@cs.wisc.edu 9999595Snilay@cs.wisc.edu''') 10009595Snilay@cs.wisc.edu code('}') 10019595Snilay@cs.wisc.edu 10026657Snate@binkert.org code.write(path, "%s.cc" % c_ident) 10036657Snate@binkert.org 10049219Spower.jg@gmail.com def printCWakeup(self, path, includes): 10056657Snate@binkert.org '''Output the wakeup loop for the events''' 10066657Snate@binkert.org 10076999Snate@binkert.org code = self.symtab.codeFormatter() 10086657Snate@binkert.org ident = self.ident 10096657Snate@binkert.org 10109104Shestness@cs.utexas.edu outputRequest_types = True 10119104Shestness@cs.utexas.edu if len(self.request_types) == 0: 10129104Shestness@cs.utexas.edu outputRequest_types = False 10139104Shestness@cs.utexas.edu 10146657Snate@binkert.org code(''' 10156657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 10166657Snate@binkert.org// ${ident}: ${{self.short}} 10176657Snate@binkert.org 10188946Sandreas.hansson@arm.com#include <sys/types.h> 10198946Sandreas.hansson@arm.com#include <unistd.h> 10208946Sandreas.hansson@arm.com 10217832Snate@binkert.org#include <cassert> 10227832Snate@binkert.org 10237007Snate@binkert.org#include "base/misc.hh" 10248232Snate@binkert.org#include "debug/RubySlicc.hh" 10258229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 10268229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 10278229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 10289104Shestness@cs.utexas.edu''') 10299104Shestness@cs.utexas.edu 10309104Shestness@cs.utexas.edu if outputRequest_types: 10319104Shestness@cs.utexas.edu code('''#include "mem/protocol/${ident}_RequestType.hh"''') 10329104Shestness@cs.utexas.edu 10339104Shestness@cs.utexas.edu code(''' 10348229Snate@binkert.org#include "mem/protocol/Types.hh" 10356657Snate@binkert.org#include "mem/ruby/common/Global.hh" 10366657Snate@binkert.org#include "mem/ruby/system/System.hh" 10379219Spower.jg@gmail.com''') 10389219Spower.jg@gmail.com 10399219Spower.jg@gmail.com 10409219Spower.jg@gmail.com for include_path in includes: 10419219Spower.jg@gmail.com code('#include "${{include_path}}"') 10429219Spower.jg@gmail.com 10439219Spower.jg@gmail.com code(''' 10446657Snate@binkert.org 10457055Snate@binkert.orgusing namespace std; 10467055Snate@binkert.org 10477007Snate@binkert.orgvoid 10487007Snate@binkert.org${ident}_Controller::wakeup() 10496657Snate@binkert.org{ 10506657Snate@binkert.org int counter = 0; 10516657Snate@binkert.org while (true) { 10526657Snate@binkert.org // Some cases will put us into an infinite loop without this limit 10536657Snate@binkert.org assert(counter <= m_transitions_per_cycle); 10546657Snate@binkert.org if (counter == m_transitions_per_cycle) { 10557007Snate@binkert.org // Count how often we are fully utilized 10569496Snilay@cs.wisc.edu m_fully_busy_cycles++; 10577007Snate@binkert.org 10587007Snate@binkert.org // Wakeup in another cycle and try again 10599499Snilay@cs.wisc.edu scheduleEvent(Cycles(1)); 10606657Snate@binkert.org break; 10616657Snate@binkert.org } 10626657Snate@binkert.org''') 10636657Snate@binkert.org 10646657Snate@binkert.org code.indent() 10656657Snate@binkert.org code.indent() 10666657Snate@binkert.org 10676657Snate@binkert.org # InPorts 10686657Snate@binkert.org # 10696657Snate@binkert.org for port in self.in_ports: 10706657Snate@binkert.org code.indent() 10716657Snate@binkert.org code('// ${ident}InPort $port') 10727567SBrad.Beckmann@amd.com if port.pairs.has_key("rank"): 10739996Snilay@cs.wisc.edu code('m_cur_in_port = ${{port.pairs["rank"]}};') 10747567SBrad.Beckmann@amd.com else: 10759996Snilay@cs.wisc.edu code('m_cur_in_port = 0;') 10766657Snate@binkert.org code('${{port["c_code_in_port"]}}') 10776657Snate@binkert.org code.dedent() 10786657Snate@binkert.org 10796657Snate@binkert.org code('') 10806657Snate@binkert.org 10816657Snate@binkert.org code.dedent() 10826657Snate@binkert.org code.dedent() 10836657Snate@binkert.org code(''' 10846657Snate@binkert.org break; // If we got this far, we have nothing left todo 10856657Snate@binkert.org } 10866657Snate@binkert.org} 10876657Snate@binkert.org''') 10886657Snate@binkert.org 10896657Snate@binkert.org code.write(path, "%s_Wakeup.cc" % self.ident) 10906657Snate@binkert.org 10916657Snate@binkert.org def printCSwitch(self, path): 10926657Snate@binkert.org '''Output switch statement for transition table''' 10936657Snate@binkert.org 10946999Snate@binkert.org code = self.symtab.codeFormatter() 10956657Snate@binkert.org ident = self.ident 10966657Snate@binkert.org 10976657Snate@binkert.org code(''' 10986657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 10996657Snate@binkert.org// ${ident}: ${{self.short}} 11006657Snate@binkert.org 11017832Snate@binkert.org#include <cassert> 11027832Snate@binkert.org 11037805Snilay@cs.wisc.edu#include "base/misc.hh" 11047832Snate@binkert.org#include "base/trace.hh" 11058232Snate@binkert.org#include "debug/ProtocolTrace.hh" 11068232Snate@binkert.org#include "debug/RubyGenerated.hh" 11078229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 11088229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 11098229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 11108229Snate@binkert.org#include "mem/protocol/Types.hh" 11116657Snate@binkert.org#include "mem/ruby/common/Global.hh" 11126657Snate@binkert.org#include "mem/ruby/system/System.hh" 11136657Snate@binkert.org 11146657Snate@binkert.org#define HASH_FUN(state, event) ((int(state)*${ident}_Event_NUM)+int(event)) 11156657Snate@binkert.org 11166657Snate@binkert.org#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str()) 11176657Snate@binkert.org#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str("")) 11186657Snate@binkert.org 11197007Snate@binkert.orgTransitionResult 11207007Snate@binkert.org${ident}_Controller::doTransition(${ident}_Event event, 11217839Snilay@cs.wisc.edu''') 11227839Snilay@cs.wisc.edu if self.EntryType != None: 11237839Snilay@cs.wisc.edu code(''' 11247839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}* m_cache_entry_ptr, 11257839Snilay@cs.wisc.edu''') 11267839Snilay@cs.wisc.edu if self.TBEType != None: 11277839Snilay@cs.wisc.edu code(''' 11287839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}* m_tbe_ptr, 11297839Snilay@cs.wisc.edu''') 11307839Snilay@cs.wisc.edu code(''' 113110010Snilay@cs.wisc.edu const Address addr) 11326657Snate@binkert.org{ 11337839Snilay@cs.wisc.edu''') 113410305Snilay@cs.wisc.edu code.indent() 113510305Snilay@cs.wisc.edu 11367839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 11378337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_tbe_ptr, m_cache_entry_ptr, addr);') 11387839Snilay@cs.wisc.edu elif self.TBEType != None: 11398337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_tbe_ptr, addr);') 11407839Snilay@cs.wisc.edu elif self.EntryType != None: 11418337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_cache_entry_ptr, addr);') 11427839Snilay@cs.wisc.edu else: 11438337Snilay@cs.wisc.edu code('${ident}_State state = getState(addr);') 11447839Snilay@cs.wisc.edu 11457839Snilay@cs.wisc.edu code(''' 114610305Snilay@cs.wisc.edu${ident}_State next_state = state; 11476657Snate@binkert.org 114810305Snilay@cs.wisc.eduDPRINTF(RubyGenerated, "%s, Time: %lld, state: %s, event: %s, addr: %s\\n", 114910305Snilay@cs.wisc.edu *this, curCycle(), ${ident}_State_to_string(state), 115010305Snilay@cs.wisc.edu ${ident}_Event_to_string(event), addr); 11516657Snate@binkert.org 115210305Snilay@cs.wisc.eduTransitionResult result = 11537839Snilay@cs.wisc.edu''') 11547839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 11557839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_tbe_ptr, m_cache_entry_ptr, addr);') 11567839Snilay@cs.wisc.edu elif self.TBEType != None: 11577839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_tbe_ptr, addr);') 11587839Snilay@cs.wisc.edu elif self.EntryType != None: 11597839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_cache_entry_ptr, addr);') 11607839Snilay@cs.wisc.edu else: 11617839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, addr);') 11626657Snate@binkert.org 11637839Snilay@cs.wisc.edu code(''' 11646657Snate@binkert.org 116510305Snilay@cs.wisc.eduif (result == TransitionResult_Valid) { 116610305Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "next_state: %s\\n", 116710305Snilay@cs.wisc.edu ${ident}_State_to_string(next_state)); 116810305Snilay@cs.wisc.edu countTransition(state, event); 116910305Snilay@cs.wisc.edu 117010305Snilay@cs.wisc.edu DPRINTFR(ProtocolTrace, "%15d %3s %10s%20s %6s>%-6s %s %s\\n", 117110305Snilay@cs.wisc.edu curTick(), m_version, "${ident}", 117210305Snilay@cs.wisc.edu ${ident}_Event_to_string(event), 117310305Snilay@cs.wisc.edu ${ident}_State_to_string(state), 117410305Snilay@cs.wisc.edu ${ident}_State_to_string(next_state), 117510305Snilay@cs.wisc.edu addr, GET_TRANSITION_COMMENT()); 117610305Snilay@cs.wisc.edu 117710305Snilay@cs.wisc.edu CLEAR_TRANSITION_COMMENT(); 11787839Snilay@cs.wisc.edu''') 11797839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 11808337Snilay@cs.wisc.edu code('setState(m_tbe_ptr, m_cache_entry_ptr, addr, next_state);') 11818341Snilay@cs.wisc.edu code('setAccessPermission(m_cache_entry_ptr, addr, next_state);') 11827839Snilay@cs.wisc.edu elif self.TBEType != None: 11838337Snilay@cs.wisc.edu code('setState(m_tbe_ptr, addr, next_state);') 11848341Snilay@cs.wisc.edu code('setAccessPermission(addr, next_state);') 11857839Snilay@cs.wisc.edu elif self.EntryType != None: 11868337Snilay@cs.wisc.edu code('setState(m_cache_entry_ptr, addr, next_state);') 11878341Snilay@cs.wisc.edu code('setAccessPermission(m_cache_entry_ptr, addr, next_state);') 11887839Snilay@cs.wisc.edu else: 11898337Snilay@cs.wisc.edu code('setState(addr, next_state);') 11908341Snilay@cs.wisc.edu code('setAccessPermission(addr, next_state);') 11917839Snilay@cs.wisc.edu 11927839Snilay@cs.wisc.edu code(''' 119310305Snilay@cs.wisc.edu} else if (result == TransitionResult_ResourceStall) { 119410305Snilay@cs.wisc.edu DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\\n", 119510305Snilay@cs.wisc.edu curTick(), m_version, "${ident}", 119610305Snilay@cs.wisc.edu ${ident}_Event_to_string(event), 119710305Snilay@cs.wisc.edu ${ident}_State_to_string(state), 119810305Snilay@cs.wisc.edu ${ident}_State_to_string(next_state), 119910305Snilay@cs.wisc.edu addr, "Resource Stall"); 120010305Snilay@cs.wisc.edu} else if (result == TransitionResult_ProtocolStall) { 120110305Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "stalling\\n"); 120210305Snilay@cs.wisc.edu DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\\n", 120310305Snilay@cs.wisc.edu curTick(), m_version, "${ident}", 120410305Snilay@cs.wisc.edu ${ident}_Event_to_string(event), 120510305Snilay@cs.wisc.edu ${ident}_State_to_string(state), 120610305Snilay@cs.wisc.edu ${ident}_State_to_string(next_state), 120710305Snilay@cs.wisc.edu addr, "Protocol Stall"); 120810305Snilay@cs.wisc.edu} 12096657Snate@binkert.org 121010305Snilay@cs.wisc.edureturn result; 121110305Snilay@cs.wisc.edu''') 121210305Snilay@cs.wisc.edu code.dedent() 121310305Snilay@cs.wisc.edu code(''' 12146657Snate@binkert.org} 12156657Snate@binkert.org 12167007Snate@binkert.orgTransitionResult 12177007Snate@binkert.org${ident}_Controller::doTransitionWorker(${ident}_Event event, 12187007Snate@binkert.org ${ident}_State state, 12197007Snate@binkert.org ${ident}_State& next_state, 12207839Snilay@cs.wisc.edu''') 12217839Snilay@cs.wisc.edu 12227839Snilay@cs.wisc.edu if self.TBEType != None: 12237839Snilay@cs.wisc.edu code(''' 12247839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}*& m_tbe_ptr, 12257839Snilay@cs.wisc.edu''') 12267839Snilay@cs.wisc.edu if self.EntryType != None: 12277839Snilay@cs.wisc.edu code(''' 12287839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, 12297839Snilay@cs.wisc.edu''') 12307839Snilay@cs.wisc.edu code(''' 12317007Snate@binkert.org const Address& addr) 12326657Snate@binkert.org{ 12336657Snate@binkert.org switch(HASH_FUN(state, event)) { 12346657Snate@binkert.org''') 12356657Snate@binkert.org 12366657Snate@binkert.org # This map will allow suppress generating duplicate code 12376657Snate@binkert.org cases = orderdict() 12386657Snate@binkert.org 12396657Snate@binkert.org for trans in self.transitions: 12406657Snate@binkert.org case_string = "%s_State_%s, %s_Event_%s" % \ 12416657Snate@binkert.org (self.ident, trans.state.ident, self.ident, trans.event.ident) 12426657Snate@binkert.org 12436999Snate@binkert.org case = self.symtab.codeFormatter() 12446657Snate@binkert.org # Only set next_state if it changes 12456657Snate@binkert.org if trans.state != trans.nextState: 12466657Snate@binkert.org ns_ident = trans.nextState.ident 12476657Snate@binkert.org case('next_state = ${ident}_State_${ns_ident};') 12486657Snate@binkert.org 12496657Snate@binkert.org actions = trans.actions 12509104Shestness@cs.utexas.edu request_types = trans.request_types 12516657Snate@binkert.org 12526657Snate@binkert.org # Check for resources 12536657Snate@binkert.org case_sorter = [] 12546657Snate@binkert.org res = trans.resources 12556657Snate@binkert.org for key,val in res.iteritems(): 125610228Snilay@cs.wisc.edu val = ''' 12577007Snate@binkert.orgif (!%s.areNSlotsAvailable(%s)) 12586657Snate@binkert.org return TransitionResult_ResourceStall; 12596657Snate@binkert.org''' % (key.code, val) 12606657Snate@binkert.org case_sorter.append(val) 12616657Snate@binkert.org 12629105SBrad.Beckmann@amd.com # Check all of the request_types for resource constraints 12639105SBrad.Beckmann@amd.com for request_type in request_types: 12649105SBrad.Beckmann@amd.com val = ''' 12659105SBrad.Beckmann@amd.comif (!checkResourceAvailable(%s_RequestType_%s, addr)) { 12669105SBrad.Beckmann@amd.com return TransitionResult_ResourceStall; 12679105SBrad.Beckmann@amd.com} 12689105SBrad.Beckmann@amd.com''' % (self.ident, request_type.ident) 12699105SBrad.Beckmann@amd.com case_sorter.append(val) 12706657Snate@binkert.org 12716657Snate@binkert.org # Emit the code sequences in a sorted order. This makes the 12726657Snate@binkert.org # output deterministic (without this the output order can vary 12736657Snate@binkert.org # since Map's keys() on a vector of pointers is not deterministic 12746657Snate@binkert.org for c in sorted(case_sorter): 12756657Snate@binkert.org case("$c") 12766657Snate@binkert.org 12779104Shestness@cs.utexas.edu # Record access types for this transition 12789104Shestness@cs.utexas.edu for request_type in request_types: 12799104Shestness@cs.utexas.edu case('recordRequestType(${ident}_RequestType_${{request_type.ident}}, addr);') 12809104Shestness@cs.utexas.edu 12816657Snate@binkert.org # Figure out if we stall 12826657Snate@binkert.org stall = False 12836657Snate@binkert.org for action in actions: 12846657Snate@binkert.org if action.ident == "z_stall": 12856657Snate@binkert.org stall = True 12866657Snate@binkert.org break 12876657Snate@binkert.org 12886657Snate@binkert.org if stall: 12896657Snate@binkert.org case('return TransitionResult_ProtocolStall;') 12906657Snate@binkert.org else: 12917839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 12927839Snilay@cs.wisc.edu for action in actions: 12937839Snilay@cs.wisc.edu case('${{action.ident}}(m_tbe_ptr, m_cache_entry_ptr, addr);') 12947839Snilay@cs.wisc.edu elif self.TBEType != None: 12957839Snilay@cs.wisc.edu for action in actions: 12967839Snilay@cs.wisc.edu case('${{action.ident}}(m_tbe_ptr, addr);') 12977839Snilay@cs.wisc.edu elif self.EntryType != None: 12987839Snilay@cs.wisc.edu for action in actions: 12997839Snilay@cs.wisc.edu case('${{action.ident}}(m_cache_entry_ptr, addr);') 13007839Snilay@cs.wisc.edu else: 13017839Snilay@cs.wisc.edu for action in actions: 13027839Snilay@cs.wisc.edu case('${{action.ident}}(addr);') 13036657Snate@binkert.org case('return TransitionResult_Valid;') 13046657Snate@binkert.org 13056657Snate@binkert.org case = str(case) 13066657Snate@binkert.org 13076657Snate@binkert.org # Look to see if this transition code is unique. 13086657Snate@binkert.org if case not in cases: 13096657Snate@binkert.org cases[case] = [] 13106657Snate@binkert.org 13116657Snate@binkert.org cases[case].append(case_string) 13126657Snate@binkert.org 13136657Snate@binkert.org # Walk through all of the unique code blocks and spit out the 13146657Snate@binkert.org # corresponding case statement elements 13156657Snate@binkert.org for case,transitions in cases.iteritems(): 13166657Snate@binkert.org # Iterative over all the multiple transitions that share 13176657Snate@binkert.org # the same code 13186657Snate@binkert.org for trans in transitions: 13196657Snate@binkert.org code(' case HASH_FUN($trans):') 132010305Snilay@cs.wisc.edu code(' $case\n') 13216657Snate@binkert.org 13226657Snate@binkert.org code(''' 13236657Snate@binkert.org default: 13247805Snilay@cs.wisc.edu fatal("Invalid transition\\n" 13258159SBrad.Beckmann@amd.com "%s time: %d addr: %s event: %s state: %s\\n", 13269465Snilay@cs.wisc.edu name(), curCycle(), addr, event, state); 13276657Snate@binkert.org } 132810305Snilay@cs.wisc.edu 13296657Snate@binkert.org return TransitionResult_Valid; 13306657Snate@binkert.org} 13316657Snate@binkert.org''') 13326657Snate@binkert.org code.write(path, "%s_Transitions.cc" % self.ident) 13336657Snate@binkert.org 13346657Snate@binkert.org 13356657Snate@binkert.org # ************************** 13366657Snate@binkert.org # ******* HTML Files ******* 13376657Snate@binkert.org # ************************** 13387007Snate@binkert.org def frameRef(self, click_href, click_target, over_href, over_num, text): 13396999Snate@binkert.org code = self.symtab.codeFormatter(fix_newlines=False) 13407007Snate@binkert.org code("""<A href=\"$click_href\" target=\"$click_target\" onmouseover=\" 13417007Snate@binkert.org if (parent.frames[$over_num].location != parent.location + '$over_href') { 13427007Snate@binkert.org parent.frames[$over_num].location='$over_href' 13437007Snate@binkert.org }\"> 13447007Snate@binkert.org ${{html.formatShorthand(text)}} 13457007Snate@binkert.org </A>""") 13466657Snate@binkert.org return str(code) 13476657Snate@binkert.org 13486657Snate@binkert.org def writeHTMLFiles(self, path): 13496657Snate@binkert.org # Create table with no row hilighted 13506657Snate@binkert.org self.printHTMLTransitions(path, None) 13516657Snate@binkert.org 13526657Snate@binkert.org # Generate transition tables 13536657Snate@binkert.org for state in self.states.itervalues(): 13546657Snate@binkert.org self.printHTMLTransitions(path, state) 13556657Snate@binkert.org 13566657Snate@binkert.org # Generate action descriptions 13576657Snate@binkert.org for action in self.actions.itervalues(): 13586657Snate@binkert.org name = "%s_action_%s.html" % (self.ident, action.ident) 13596657Snate@binkert.org code = html.createSymbol(action, "Action") 13606657Snate@binkert.org code.write(path, name) 13616657Snate@binkert.org 13626657Snate@binkert.org # Generate state descriptions 13636657Snate@binkert.org for state in self.states.itervalues(): 13646657Snate@binkert.org name = "%s_State_%s.html" % (self.ident, state.ident) 13656657Snate@binkert.org code = html.createSymbol(state, "State") 13666657Snate@binkert.org code.write(path, name) 13676657Snate@binkert.org 13686657Snate@binkert.org # Generate event descriptions 13696657Snate@binkert.org for event in self.events.itervalues(): 13706657Snate@binkert.org name = "%s_Event_%s.html" % (self.ident, event.ident) 13716657Snate@binkert.org code = html.createSymbol(event, "Event") 13726657Snate@binkert.org code.write(path, name) 13736657Snate@binkert.org 13746657Snate@binkert.org def printHTMLTransitions(self, path, active_state): 13756999Snate@binkert.org code = self.symtab.codeFormatter() 13766657Snate@binkert.org 13776657Snate@binkert.org code(''' 13787007Snate@binkert.org<HTML> 13797007Snate@binkert.org<BODY link="blue" vlink="blue"> 13806657Snate@binkert.org 13816657Snate@binkert.org<H1 align="center">${{html.formatShorthand(self.short)}}: 13826657Snate@binkert.org''') 13836657Snate@binkert.org code.indent() 13846657Snate@binkert.org for i,machine in enumerate(self.symtab.getAllType(StateMachine)): 13856657Snate@binkert.org mid = machine.ident 13866657Snate@binkert.org if i != 0: 13876657Snate@binkert.org extra = " - " 13886657Snate@binkert.org else: 13896657Snate@binkert.org extra = "" 13906657Snate@binkert.org if machine == self: 13916657Snate@binkert.org code('$extra$mid') 13926657Snate@binkert.org else: 13936657Snate@binkert.org code('$extra<A target="Table" href="${mid}_table.html">$mid</A>') 13946657Snate@binkert.org code.dedent() 13956657Snate@binkert.org 13966657Snate@binkert.org code(""" 13976657Snate@binkert.org</H1> 13986657Snate@binkert.org 13996657Snate@binkert.org<TABLE border=1> 14006657Snate@binkert.org<TR> 14016657Snate@binkert.org <TH> </TH> 14026657Snate@binkert.org""") 14036657Snate@binkert.org 14046657Snate@binkert.org for event in self.events.itervalues(): 14056657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 14066657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 14076657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 14086657Snate@binkert.org 14096657Snate@binkert.org code('</TR>') 14106657Snate@binkert.org # -- Body of table 14116657Snate@binkert.org for state in self.states.itervalues(): 14126657Snate@binkert.org # -- Each row 14136657Snate@binkert.org if state == active_state: 14146657Snate@binkert.org color = "yellow" 14156657Snate@binkert.org else: 14166657Snate@binkert.org color = "white" 14176657Snate@binkert.org 14186657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 14196657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 14206657Snate@binkert.org text = html.formatShorthand(state.short) 14216657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 14226657Snate@binkert.org code(''' 14236657Snate@binkert.org<TR> 14246657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 14256657Snate@binkert.org''') 14266657Snate@binkert.org 14276657Snate@binkert.org # -- One column for each event 14286657Snate@binkert.org for event in self.events.itervalues(): 14296657Snate@binkert.org trans = self.table.get((state,event), None) 14306657Snate@binkert.org if trans is None: 14316657Snate@binkert.org # This is the no transition case 14326657Snate@binkert.org if state == active_state: 14336657Snate@binkert.org color = "#C0C000" 14346657Snate@binkert.org else: 14356657Snate@binkert.org color = "lightgrey" 14366657Snate@binkert.org 14376657Snate@binkert.org code('<TD bgcolor=$color> </TD>') 14386657Snate@binkert.org continue 14396657Snate@binkert.org 14406657Snate@binkert.org next = trans.nextState 14416657Snate@binkert.org stall_action = False 14426657Snate@binkert.org 14436657Snate@binkert.org # -- Get the actions 14446657Snate@binkert.org for action in trans.actions: 14456657Snate@binkert.org if action.ident == "z_stall" or \ 14466657Snate@binkert.org action.ident == "zz_recycleMandatoryQueue": 14476657Snate@binkert.org stall_action = True 14486657Snate@binkert.org 14496657Snate@binkert.org # -- Print out "actions/next-state" 14506657Snate@binkert.org if stall_action: 14516657Snate@binkert.org if state == active_state: 14526657Snate@binkert.org color = "#C0C000" 14536657Snate@binkert.org else: 14546657Snate@binkert.org color = "lightgrey" 14556657Snate@binkert.org 14566657Snate@binkert.org elif active_state and next.ident == active_state.ident: 14576657Snate@binkert.org color = "aqua" 14586657Snate@binkert.org elif state == active_state: 14596657Snate@binkert.org color = "yellow" 14606657Snate@binkert.org else: 14616657Snate@binkert.org color = "white" 14626657Snate@binkert.org 14636657Snate@binkert.org code('<TD bgcolor=$color>') 14646657Snate@binkert.org for action in trans.actions: 14656657Snate@binkert.org href = "%s_action_%s.html" % (self.ident, action.ident) 14666657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", 14676657Snate@binkert.org action.short) 14687007Snate@binkert.org code(' $ref') 14696657Snate@binkert.org if next != state: 14706657Snate@binkert.org if trans.actions: 14716657Snate@binkert.org code('/') 14726657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, next.ident) 14736657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, next.ident) 14746657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", next.short) 14756657Snate@binkert.org code("$ref") 14767007Snate@binkert.org code("</TD>") 14776657Snate@binkert.org 14786657Snate@binkert.org # -- Each row 14796657Snate@binkert.org if state == active_state: 14806657Snate@binkert.org color = "yellow" 14816657Snate@binkert.org else: 14826657Snate@binkert.org color = "white" 14836657Snate@binkert.org 14846657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 14856657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 14866657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 14876657Snate@binkert.org code(''' 14886657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 14896657Snate@binkert.org</TR> 14906657Snate@binkert.org''') 14916657Snate@binkert.org code(''' 14927007Snate@binkert.org<!- Column footer-> 14936657Snate@binkert.org<TR> 14946657Snate@binkert.org <TH> </TH> 14956657Snate@binkert.org''') 14966657Snate@binkert.org 14976657Snate@binkert.org for event in self.events.itervalues(): 14986657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 14996657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 15006657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 15016657Snate@binkert.org code(''' 15026657Snate@binkert.org</TR> 15036657Snate@binkert.org</TABLE> 15046657Snate@binkert.org</BODY></HTML> 15056657Snate@binkert.org''') 15066657Snate@binkert.org 15076657Snate@binkert.org 15086657Snate@binkert.org if active_state: 15096657Snate@binkert.org name = "%s_table_%s.html" % (self.ident, active_state.ident) 15106657Snate@binkert.org else: 15116657Snate@binkert.org name = "%s_table.html" % self.ident 15126657Snate@binkert.org code.write(path, name) 15136657Snate@binkert.org 15146657Snate@binkert.org__all__ = [ "StateMachine" ] 1515