StateMachine.py revision 9595
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 self.printProfilerCC(path) 1776657Snate@binkert.org self.printProfilerHH(path) 1787542SBrad.Beckmann@amd.com self.printProfileDumperCC(path) 1797542SBrad.Beckmann@amd.com self.printProfileDumperHH(path) 1806657Snate@binkert.org 1816877Ssteve.reinhardt@amd.com def printControllerPython(self, path): 1826999Snate@binkert.org code = self.symtab.codeFormatter() 1836877Ssteve.reinhardt@amd.com ident = self.ident 1846877Ssteve.reinhardt@amd.com py_ident = "%s_Controller" % ident 1856877Ssteve.reinhardt@amd.com c_ident = "%s_Controller" % self.ident 1866877Ssteve.reinhardt@amd.com code(''' 1876877Ssteve.reinhardt@amd.comfrom m5.params import * 1886877Ssteve.reinhardt@amd.comfrom m5.SimObject import SimObject 1896877Ssteve.reinhardt@amd.comfrom Controller import RubyController 1906877Ssteve.reinhardt@amd.com 1916877Ssteve.reinhardt@amd.comclass $py_ident(RubyController): 1926877Ssteve.reinhardt@amd.com type = '$py_ident' 1939338SAndreas.Sandberg@arm.com cxx_header = 'mem/protocol/${c_ident}.hh' 1946877Ssteve.reinhardt@amd.com''') 1956877Ssteve.reinhardt@amd.com code.indent() 1966877Ssteve.reinhardt@amd.com for param in self.config_parameters: 1976877Ssteve.reinhardt@amd.com dflt_str = '' 1986877Ssteve.reinhardt@amd.com if param.default is not None: 1996877Ssteve.reinhardt@amd.com dflt_str = str(param.default) + ', ' 2006882SBrad.Beckmann@amd.com if python_class_map.has_key(param.type_ast.type.c_ident): 2016882SBrad.Beckmann@amd.com python_type = python_class_map[param.type_ast.type.c_ident] 2026882SBrad.Beckmann@amd.com code('${{param.name}} = Param.${{python_type}}(${dflt_str}"")') 2036882SBrad.Beckmann@amd.com else: 2046882SBrad.Beckmann@amd.com self.error("Unknown c++ to python class conversion for c++ " \ 2056882SBrad.Beckmann@amd.com "type: '%s'. Please update the python_class_map " \ 2066882SBrad.Beckmann@amd.com "in StateMachine.py", param.type_ast.type.c_ident) 2076877Ssteve.reinhardt@amd.com code.dedent() 2086877Ssteve.reinhardt@amd.com code.write(path, '%s.py' % py_ident) 2096877Ssteve.reinhardt@amd.com 2106877Ssteve.reinhardt@amd.com 2116657Snate@binkert.org def printControllerHH(self, path): 2126657Snate@binkert.org '''Output the method declarations for the class declaration''' 2136999Snate@binkert.org code = self.symtab.codeFormatter() 2146657Snate@binkert.org ident = self.ident 2156657Snate@binkert.org c_ident = "%s_Controller" % self.ident 2166657Snate@binkert.org 2176657Snate@binkert.org code(''' 2187007Snate@binkert.org/** \\file $c_ident.hh 2196657Snate@binkert.org * 2206657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__ 2216657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}" 2226657Snate@binkert.org */ 2236657Snate@binkert.org 2247007Snate@binkert.org#ifndef __${ident}_CONTROLLER_HH__ 2257007Snate@binkert.org#define __${ident}_CONTROLLER_HH__ 2266657Snate@binkert.org 2277002Snate@binkert.org#include <iostream> 2287002Snate@binkert.org#include <sstream> 2297002Snate@binkert.org#include <string> 2307002Snate@binkert.org 2318229Snate@binkert.org#include "mem/protocol/${ident}_ProfileDumper.hh" 2328229Snate@binkert.org#include "mem/protocol/${ident}_Profiler.hh" 2336657Snate@binkert.org#include "mem/protocol/TransitionResult.hh" 2346657Snate@binkert.org#include "mem/protocol/Types.hh" 2358229Snate@binkert.org#include "mem/ruby/common/Consumer.hh" 2368229Snate@binkert.org#include "mem/ruby/common/Global.hh" 2378229Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh" 2388229Snate@binkert.org#include "params/$c_ident.hh" 2396657Snate@binkert.org''') 2406657Snate@binkert.org 2416657Snate@binkert.org seen_types = set() 2429595Snilay@cs.wisc.edu has_peer = False 2436657Snate@binkert.org for var in self.objects: 2446793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 2456657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 2469595Snilay@cs.wisc.edu if "network" in var and "physical_network" in var: 2479595Snilay@cs.wisc.edu has_peer = True 2486657Snate@binkert.org seen_types.add(var.type.ident) 2496657Snate@binkert.org 2506657Snate@binkert.org # for adding information to the protocol debug trace 2516657Snate@binkert.org code(''' 2527002Snate@binkert.orgextern std::stringstream ${ident}_transitionComment; 2536657Snate@binkert.org 2547007Snate@binkert.orgclass $c_ident : public AbstractController 2557007Snate@binkert.org{ 2569271Snilay@cs.wisc.edu public: 2576877Ssteve.reinhardt@amd.com typedef ${c_ident}Params Params; 2586877Ssteve.reinhardt@amd.com $c_ident(const Params *p); 2596657Snate@binkert.org static int getNumControllers(); 2606877Ssteve.reinhardt@amd.com void init(); 2616657Snate@binkert.org MessageBuffer* getMandatoryQueue() const; 2626657Snate@binkert.org const int & getVersion() const; 2637002Snate@binkert.org const std::string toString() const; 2647002Snate@binkert.org const std::string getName() const; 2657567SBrad.Beckmann@amd.com void stallBuffer(MessageBuffer* buf, Address addr); 2667567SBrad.Beckmann@amd.com void wakeUpBuffers(Address addr); 2677922SBrad.Beckmann@amd.com void wakeUpAllBuffers(); 2686881SBrad.Beckmann@amd.com void initNetworkPtr(Network* net_ptr) { m_net_ptr = net_ptr; } 2697002Snate@binkert.org void print(std::ostream& out) const; 2706657Snate@binkert.org void wakeup(); 2717002Snate@binkert.org void printStats(std::ostream& out) const; 2726902SBrad.Beckmann@amd.com void clearStats(); 2736863Sdrh5@cs.wisc.edu void blockOnQueue(Address addr, MessageBuffer* port); 2746863Sdrh5@cs.wisc.edu void unblock(Address addr); 2758683Snilay@cs.wisc.edu void recordCacheTrace(int cntrl, CacheRecorder* tr); 2768683Snilay@cs.wisc.edu Sequencer* getSequencer() const; 2777007Snate@binkert.org 2789302Snilay@cs.wisc.edu bool functionalReadBuffers(PacketPtr&); 2799302Snilay@cs.wisc.edu uint32_t functionalWriteBuffers(PacketPtr&); 2809302Snilay@cs.wisc.edu 2816657Snate@binkert.orgprivate: 2826657Snate@binkert.org''') 2836657Snate@binkert.org 2846657Snate@binkert.org code.indent() 2856657Snate@binkert.org # added by SS 2866657Snate@binkert.org for param in self.config_parameters: 2876882SBrad.Beckmann@amd.com if param.pointer: 2886882SBrad.Beckmann@amd.com code('${{param.type_ast.type}}* m_${{param.ident}}_ptr;') 2896882SBrad.Beckmann@amd.com else: 2906882SBrad.Beckmann@amd.com code('${{param.type_ast.type}} m_${{param.ident}};') 2916657Snate@binkert.org 2926657Snate@binkert.org code(''' 2937007Snate@binkert.orgTransitionResult doTransition(${ident}_Event event, 2947839Snilay@cs.wisc.edu''') 2957839Snilay@cs.wisc.edu 2967839Snilay@cs.wisc.edu if self.EntryType != None: 2977839Snilay@cs.wisc.edu code(''' 2987839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}* m_cache_entry_ptr, 2997839Snilay@cs.wisc.edu''') 3007839Snilay@cs.wisc.edu if self.TBEType != None: 3017839Snilay@cs.wisc.edu code(''' 3027839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}* m_tbe_ptr, 3037839Snilay@cs.wisc.edu''') 3047839Snilay@cs.wisc.edu 3057839Snilay@cs.wisc.edu code(''' 3067007Snate@binkert.org const Address& addr); 3077007Snate@binkert.org 3087007Snate@binkert.orgTransitionResult doTransitionWorker(${ident}_Event event, 3097007Snate@binkert.org ${ident}_State state, 3107007Snate@binkert.org ${ident}_State& next_state, 3117839Snilay@cs.wisc.edu''') 3127839Snilay@cs.wisc.edu 3137839Snilay@cs.wisc.edu if self.TBEType != None: 3147839Snilay@cs.wisc.edu code(''' 3157839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}*& m_tbe_ptr, 3167839Snilay@cs.wisc.edu''') 3177839Snilay@cs.wisc.edu if self.EntryType != None: 3187839Snilay@cs.wisc.edu code(''' 3197839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, 3207839Snilay@cs.wisc.edu''') 3217839Snilay@cs.wisc.edu 3227839Snilay@cs.wisc.edu code(''' 3237007Snate@binkert.org const Address& addr); 3247007Snate@binkert.org 3257542SBrad.Beckmann@amd.comstatic ${ident}_ProfileDumper s_profileDumper; 3267542SBrad.Beckmann@amd.com${ident}_Profiler m_profiler; 3276657Snate@binkert.orgstatic int m_num_controllers; 3287007Snate@binkert.org 3296657Snate@binkert.org// Internal functions 3306657Snate@binkert.org''') 3316657Snate@binkert.org 3326657Snate@binkert.org for func in self.functions: 3336657Snate@binkert.org proto = func.prototype 3346657Snate@binkert.org if proto: 3356657Snate@binkert.org code('$proto') 3366657Snate@binkert.org 3379595Snilay@cs.wisc.edu if has_peer: 3389595Snilay@cs.wisc.edu code('void getQueuesFromPeer(AbstractController *);') 3397839Snilay@cs.wisc.edu if self.EntryType != None: 3407839Snilay@cs.wisc.edu code(''' 3417839Snilay@cs.wisc.edu 3427839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable 3437839Snilay@cs.wisc.eduvoid set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry); 3447839Snilay@cs.wisc.eduvoid unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr); 3457839Snilay@cs.wisc.edu''') 3467839Snilay@cs.wisc.edu 3477839Snilay@cs.wisc.edu if self.TBEType != None: 3487839Snilay@cs.wisc.edu code(''' 3497839Snilay@cs.wisc.edu 3507839Snilay@cs.wisc.edu// Set and Reset for tbe variable 3517839Snilay@cs.wisc.eduvoid set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${ident}_TBE* m_new_tbe); 3527839Snilay@cs.wisc.eduvoid unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr); 3537839Snilay@cs.wisc.edu''') 3547839Snilay@cs.wisc.edu 3556657Snate@binkert.org code(''' 3566657Snate@binkert.org 3576657Snate@binkert.org// Actions 3586657Snate@binkert.org''') 3597839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 3607839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3617839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3627839Snilay@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);') 3637839Snilay@cs.wisc.edu elif self.TBEType != None: 3647839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3657839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3667839Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, const Address& addr);') 3677839Snilay@cs.wisc.edu elif self.EntryType != None: 3687839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3697839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3707839Snilay@cs.wisc.edu code('void ${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr);') 3717839Snilay@cs.wisc.edu else: 3727839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 3737839Snilay@cs.wisc.edu code('/** \\brief ${{action.desc}} */') 3747839Snilay@cs.wisc.edu code('void ${{action.ident}}(const Address& addr);') 3756657Snate@binkert.org 3766657Snate@binkert.org # the controller internal variables 3776657Snate@binkert.org code(''' 3786657Snate@binkert.org 3797007Snate@binkert.org// Objects 3806657Snate@binkert.org''') 3816657Snate@binkert.org for var in self.objects: 3829273Snilay@cs.wisc.edu th = var.get("template", "") 3836657Snate@binkert.org code('${{var.type.c_ident}}$th* m_${{var.c_ident}}_ptr;') 3846657Snate@binkert.org 3856657Snate@binkert.org code.dedent() 3866657Snate@binkert.org code('};') 3877007Snate@binkert.org code('#endif // __${ident}_CONTROLLER_H__') 3886657Snate@binkert.org code.write(path, '%s.hh' % c_ident) 3896657Snate@binkert.org 3909219Spower.jg@gmail.com def printControllerCC(self, path, includes): 3916657Snate@binkert.org '''Output the actions for performing the actions''' 3926657Snate@binkert.org 3936999Snate@binkert.org code = self.symtab.codeFormatter() 3946657Snate@binkert.org ident = self.ident 3956657Snate@binkert.org c_ident = "%s_Controller" % self.ident 3969595Snilay@cs.wisc.edu has_peer = False 3976657Snate@binkert.org 3986657Snate@binkert.org code(''' 3997007Snate@binkert.org/** \\file $c_ident.cc 4006657Snate@binkert.org * 4016657Snate@binkert.org * Auto generated C++ code started by $__file__:$__line__ 4026657Snate@binkert.org * Created by slicc definition of Module "${{self.short}}" 4036657Snate@binkert.org */ 4046657Snate@binkert.org 4058946Sandreas.hansson@arm.com#include <sys/types.h> 4068946Sandreas.hansson@arm.com#include <unistd.h> 4078946Sandreas.hansson@arm.com 4087832Snate@binkert.org#include <cassert> 4097002Snate@binkert.org#include <sstream> 4107002Snate@binkert.org#include <string> 4117002Snate@binkert.org 4128641Snate@binkert.org#include "base/compiler.hh" 4137056Snate@binkert.org#include "base/cprintf.hh" 4148232Snate@binkert.org#include "debug/RubyGenerated.hh" 4158232Snate@binkert.org#include "debug/RubySlicc.hh" 4166657Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 4178229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 4186657Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 4196657Snate@binkert.org#include "mem/protocol/Types.hh" 4207056Snate@binkert.org#include "mem/ruby/common/Global.hh" 4216657Snate@binkert.org#include "mem/ruby/system/System.hh" 4229219Spower.jg@gmail.com''') 4239219Spower.jg@gmail.com for include_path in includes: 4249219Spower.jg@gmail.com code('#include "${{include_path}}"') 4259219Spower.jg@gmail.com 4269219Spower.jg@gmail.com code(''' 4277002Snate@binkert.org 4287002Snate@binkert.orgusing namespace std; 4296657Snate@binkert.org''') 4306657Snate@binkert.org 4316657Snate@binkert.org # include object classes 4326657Snate@binkert.org seen_types = set() 4336657Snate@binkert.org for var in self.objects: 4346793SBrad.Beckmann@amd.com if var.type.ident not in seen_types and not var.type.isPrimitive: 4356657Snate@binkert.org code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 4366657Snate@binkert.org seen_types.add(var.type.ident) 4376657Snate@binkert.org 4386657Snate@binkert.org code(''' 4396877Ssteve.reinhardt@amd.com$c_ident * 4406877Ssteve.reinhardt@amd.com${c_ident}Params::create() 4416877Ssteve.reinhardt@amd.com{ 4426877Ssteve.reinhardt@amd.com return new $c_ident(this); 4436877Ssteve.reinhardt@amd.com} 4446877Ssteve.reinhardt@amd.com 4456657Snate@binkert.orgint $c_ident::m_num_controllers = 0; 4467542SBrad.Beckmann@amd.com${ident}_ProfileDumper $c_ident::s_profileDumper; 4476657Snate@binkert.org 4487007Snate@binkert.org// for adding information to the protocol debug trace 4496657Snate@binkert.orgstringstream ${ident}_transitionComment; 4506657Snate@binkert.org#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str) 4517007Snate@binkert.org 4526657Snate@binkert.org/** \\brief constructor */ 4536877Ssteve.reinhardt@amd.com$c_ident::$c_ident(const Params *p) 4546877Ssteve.reinhardt@amd.com : AbstractController(p) 4556657Snate@binkert.org{ 4568532SLisa.Hsu@amd.com m_name = "${ident}"; 4576657Snate@binkert.org''') 4587567SBrad.Beckmann@amd.com # 4597567SBrad.Beckmann@amd.com # max_port_rank is used to size vectors and thus should be one plus the 4607567SBrad.Beckmann@amd.com # largest port rank 4617567SBrad.Beckmann@amd.com # 4627567SBrad.Beckmann@amd.com max_port_rank = self.in_ports[0].pairs["max_port_rank"] + 1 4637567SBrad.Beckmann@amd.com code(' m_max_in_port_rank = $max_port_rank;') 4646657Snate@binkert.org code.indent() 4656882SBrad.Beckmann@amd.com 4666882SBrad.Beckmann@amd.com # 4676882SBrad.Beckmann@amd.com # After initializing the universal machine parameters, initialize the 4686882SBrad.Beckmann@amd.com # this machines config parameters. Also detemine if these configuration 4696882SBrad.Beckmann@amd.com # params include a sequencer. This information will be used later for 4706882SBrad.Beckmann@amd.com # contecting the sequencer back to the L1 cache controller. 4716882SBrad.Beckmann@amd.com # 4728189SLisa.Hsu@amd.com contains_dma_sequencer = False 4738189SLisa.Hsu@amd.com sequencers = [] 4746877Ssteve.reinhardt@amd.com for param in self.config_parameters: 4758189SLisa.Hsu@amd.com if param.name == "dma_sequencer": 4768189SLisa.Hsu@amd.com contains_dma_sequencer = True 4778189SLisa.Hsu@amd.com elif re.compile("sequencer").search(param.name): 4788189SLisa.Hsu@amd.com sequencers.append(param.name) 4796882SBrad.Beckmann@amd.com if param.pointer: 4806882SBrad.Beckmann@amd.com code('m_${{param.name}}_ptr = p->${{param.name}};') 4816882SBrad.Beckmann@amd.com else: 4826882SBrad.Beckmann@amd.com code('m_${{param.name}} = p->${{param.name}};') 4836882SBrad.Beckmann@amd.com 4846882SBrad.Beckmann@amd.com # 4856882SBrad.Beckmann@amd.com # For the l1 cache controller, add the special atomic support which 4866882SBrad.Beckmann@amd.com # includes passing the sequencer a pointer to the controller. 4876882SBrad.Beckmann@amd.com # 4886882SBrad.Beckmann@amd.com if self.ident == "L1Cache": 4898189SLisa.Hsu@amd.com if not sequencers: 4906882SBrad.Beckmann@amd.com self.error("The L1Cache controller must include the sequencer " \ 4916882SBrad.Beckmann@amd.com "configuration parameter") 4926882SBrad.Beckmann@amd.com 4938189SLisa.Hsu@amd.com for seq in sequencers: 4948189SLisa.Hsu@amd.com code(''' 4958189SLisa.Hsu@amd.comm_${{seq}}_ptr->setController(this); 4968189SLisa.Hsu@amd.com ''') 4978938SLisa.Hsu@amd.com 4988938SLisa.Hsu@amd.com else: 4998938SLisa.Hsu@amd.com for seq in sequencers: 5008938SLisa.Hsu@amd.com code(''' 5018938SLisa.Hsu@amd.comm_${{seq}}_ptr->setController(this); 5028938SLisa.Hsu@amd.com ''') 5038938SLisa.Hsu@amd.com 5046888SBrad.Beckmann@amd.com # 5056888SBrad.Beckmann@amd.com # For the DMA controller, pass the sequencer a pointer to the 5066888SBrad.Beckmann@amd.com # controller. 5076888SBrad.Beckmann@amd.com # 5086888SBrad.Beckmann@amd.com if self.ident == "DMA": 5098189SLisa.Hsu@amd.com if not contains_dma_sequencer: 5106888SBrad.Beckmann@amd.com self.error("The DMA controller must include the sequencer " \ 5116888SBrad.Beckmann@amd.com "configuration parameter") 5126657Snate@binkert.org 5136888SBrad.Beckmann@amd.com code(''' 5146888SBrad.Beckmann@amd.comm_dma_sequencer_ptr->setController(this); 5156888SBrad.Beckmann@amd.com''') 5166888SBrad.Beckmann@amd.com 5176657Snate@binkert.org code('m_num_controllers++;') 5186657Snate@binkert.org for var in self.objects: 5196657Snate@binkert.org if var.ident.find("mandatoryQueue") >= 0: 5209508Snilay@cs.wisc.edu code(''' 5219508Snilay@cs.wisc.edum_${{var.c_ident}}_ptr = new ${{var.type.c_ident}}(); 5229508Snilay@cs.wisc.edum_${{var.c_ident}}_ptr->setReceiver(this); 5239508Snilay@cs.wisc.edu''') 5249595Snilay@cs.wisc.edu else: 5259595Snilay@cs.wisc.edu if "network" in var and "physical_network" in var and \ 5269595Snilay@cs.wisc.edu var["network"] == "To": 5279595Snilay@cs.wisc.edu has_peer = True 5289595Snilay@cs.wisc.edu code(''' 5299595Snilay@cs.wisc.edum_${{var.c_ident}}_ptr = new ${{var.type.c_ident}}(); 5309595Snilay@cs.wisc.edupeerQueueMap[${{var["physical_network"]}}] = m_${{var.c_ident}}_ptr; 5319595Snilay@cs.wisc.edum_${{var.c_ident}}_ptr->setSender(this); 5329595Snilay@cs.wisc.edu''') 5336657Snate@binkert.org 5349595Snilay@cs.wisc.edu code(''' 5359595Snilay@cs.wisc.eduif (p->peer != NULL) 5369595Snilay@cs.wisc.edu connectWithPeer(p->peer); 5379595Snilay@cs.wisc.edu''') 5386657Snate@binkert.org code.dedent() 5396657Snate@binkert.org code(''' 5406657Snate@binkert.org} 5416657Snate@binkert.org 5427007Snate@binkert.orgvoid 5437007Snate@binkert.org$c_ident::init() 5446657Snate@binkert.org{ 5457007Snate@binkert.org MachineType machine_type; 5467007Snate@binkert.org int base; 5479465Snilay@cs.wisc.edu machine_type = string_to_MachineType("${{var.machine.ident}}"); 5489465Snilay@cs.wisc.edu base = MachineType_base_number(machine_type); 5497007Snate@binkert.org 5506657Snate@binkert.org m_machineID.type = MachineType_${ident}; 5516657Snate@binkert.org m_machineID.num = m_version; 5526657Snate@binkert.org 5537007Snate@binkert.org // initialize objects 5547542SBrad.Beckmann@amd.com m_profiler.setVersion(m_version); 5557542SBrad.Beckmann@amd.com s_profileDumper.registerProfiler(&m_profiler); 5567007Snate@binkert.org 5576657Snate@binkert.org''') 5586657Snate@binkert.org 5596657Snate@binkert.org code.indent() 5606657Snate@binkert.org for var in self.objects: 5616657Snate@binkert.org vtype = var.type 5626657Snate@binkert.org vid = "m_%s_ptr" % var.c_ident 5636657Snate@binkert.org if "network" not in var: 5646657Snate@binkert.org # Not a network port object 5656657Snate@binkert.org if "primitive" in vtype: 5666657Snate@binkert.org code('$vid = new ${{vtype.c_ident}};') 5676657Snate@binkert.org if "default" in var: 5686657Snate@binkert.org code('(*$vid) = ${{var["default"]}};') 5696657Snate@binkert.org else: 5706657Snate@binkert.org # Normal Object 5719595Snilay@cs.wisc.edu if var.ident.find("mandatoryQueue") < 0: 5729273Snilay@cs.wisc.edu th = var.get("template", "") 5736657Snate@binkert.org expr = "%s = new %s%s" % (vid, vtype.c_ident, th) 5746657Snate@binkert.org args = "" 5756657Snate@binkert.org if "non_obj" not in vtype and not vtype.isEnumeration: 5769364Snilay@cs.wisc.edu args = var.get("constructor", "") 5777007Snate@binkert.org code('$expr($args);') 5786657Snate@binkert.org 5796657Snate@binkert.org code('assert($vid != NULL);') 5806657Snate@binkert.org 5816657Snate@binkert.org if "default" in var: 5827007Snate@binkert.org code('*$vid = ${{var["default"]}}; // Object default') 5836657Snate@binkert.org elif "default" in vtype: 5847007Snate@binkert.org comment = "Type %s default" % vtype.ident 5857007Snate@binkert.org code('*$vid = ${{vtype["default"]}}; // $comment') 5866657Snate@binkert.org 5876657Snate@binkert.org # Set ordering 5889508Snilay@cs.wisc.edu if "ordered" in var: 5896657Snate@binkert.org # A buffer 5906657Snate@binkert.org code('$vid->setOrdering(${{var["ordered"]}});') 5916657Snate@binkert.org 5926657Snate@binkert.org # Set randomization 5936657Snate@binkert.org if "random" in var: 5946657Snate@binkert.org # A buffer 5956657Snate@binkert.org code('$vid->setRandomization(${{var["random"]}});') 5966657Snate@binkert.org 5976657Snate@binkert.org # Set Priority 5989508Snilay@cs.wisc.edu if vtype.isBuffer and "rank" in var: 5996657Snate@binkert.org code('$vid->setPriority(${{var["rank"]}});') 6007566SBrad.Beckmann@amd.com 6019508Snilay@cs.wisc.edu # Set sender and receiver for trigger queue 6029508Snilay@cs.wisc.edu if var.ident.find("triggerQueue") >= 0: 6039508Snilay@cs.wisc.edu code('$vid->setSender(this);') 6049508Snilay@cs.wisc.edu code('$vid->setReceiver(this);') 6059508Snilay@cs.wisc.edu elif vtype.c_ident == "TimerTable": 6069508Snilay@cs.wisc.edu code('$vid->setClockObj(this);') 6079508Snilay@cs.wisc.edu 6086657Snate@binkert.org else: 6096657Snate@binkert.org # Network port object 6106657Snate@binkert.org network = var["network"] 6116657Snate@binkert.org ordered = var["ordered"] 6126657Snate@binkert.org 6139595Snilay@cs.wisc.edu if "virtual_network" in var: 6149595Snilay@cs.wisc.edu vnet = var["virtual_network"] 6159595Snilay@cs.wisc.edu vnet_type = var["vnet_type"] 6169595Snilay@cs.wisc.edu 6179595Snilay@cs.wisc.edu assert var.machine is not None 6189595Snilay@cs.wisc.edu code(''' 6198308Stushar@csail.mit.edu$vid = m_net_ptr->get${network}NetQueue(m_version + base, $ordered, $vnet, "$vnet_type"); 6209595Snilay@cs.wisc.eduassert($vid != NULL); 6216657Snate@binkert.org''') 6226657Snate@binkert.org 6239595Snilay@cs.wisc.edu # Set the end 6249595Snilay@cs.wisc.edu if network == "To": 6259595Snilay@cs.wisc.edu code('$vid->setSender(this);') 6269595Snilay@cs.wisc.edu else: 6279595Snilay@cs.wisc.edu code('$vid->setReceiver(this);') 6289508Snilay@cs.wisc.edu 6296657Snate@binkert.org # Set ordering 6306657Snate@binkert.org if "ordered" in var: 6316657Snate@binkert.org # A buffer 6326657Snate@binkert.org code('$vid->setOrdering(${{var["ordered"]}});') 6336657Snate@binkert.org 6346657Snate@binkert.org # Set randomization 6356657Snate@binkert.org if "random" in var: 6366657Snate@binkert.org # A buffer 6378187SLisa.Hsu@amd.com code('$vid->setRandomization(${{var["random"]}});') 6386657Snate@binkert.org 6396657Snate@binkert.org # Set Priority 6406657Snate@binkert.org if "rank" in var: 6416657Snate@binkert.org code('$vid->setPriority(${{var["rank"]}})') 6426657Snate@binkert.org 6436657Snate@binkert.org # Set buffer size 6446657Snate@binkert.org if vtype.isBuffer: 6456657Snate@binkert.org code(''' 6466657Snate@binkert.orgif (m_buffer_size > 0) { 6477454Snate@binkert.org $vid->resize(m_buffer_size); 6486657Snate@binkert.org} 6496657Snate@binkert.org''') 6506657Snate@binkert.org 6516657Snate@binkert.org # set description (may be overriden later by port def) 6527007Snate@binkert.org code(''' 6537056Snate@binkert.org$vid->setDescription("[Version " + to_string(m_version) + ", ${ident}, name=${{var.c_ident}}]"); 6547007Snate@binkert.org 6557007Snate@binkert.org''') 6566657Snate@binkert.org 6577566SBrad.Beckmann@amd.com if vtype.isBuffer: 6587566SBrad.Beckmann@amd.com if "recycle_latency" in var: 6599499Snilay@cs.wisc.edu code('$vid->setRecycleLatency( ' \ 6609499Snilay@cs.wisc.edu 'Cycles(${{var["recycle_latency"]}}));') 6617566SBrad.Beckmann@amd.com else: 6627566SBrad.Beckmann@amd.com code('$vid->setRecycleLatency(m_recycle_latency);') 6637566SBrad.Beckmann@amd.com 6649366Snilay@cs.wisc.edu # Set the prefetchers 6659366Snilay@cs.wisc.edu code() 6669366Snilay@cs.wisc.edu for prefetcher in self.prefetchers: 6679366Snilay@cs.wisc.edu code('${{prefetcher.code}}.setController(this);') 6687566SBrad.Beckmann@amd.com 6697672Snate@binkert.org code() 6706657Snate@binkert.org for port in self.in_ports: 6719465Snilay@cs.wisc.edu # Set the queue consumers 6726657Snate@binkert.org code('${{port.code}}.setConsumer(this);') 6739465Snilay@cs.wisc.edu # Set the queue descriptions 6747056Snate@binkert.org code('${{port.code}}.setDescription("[Version " + to_string(m_version) + ", $ident, $port]");') 6756657Snate@binkert.org 6766657Snate@binkert.org # Initialize the transition profiling 6777672Snate@binkert.org code() 6786657Snate@binkert.org for trans in self.transitions: 6796657Snate@binkert.org # Figure out if we stall 6806657Snate@binkert.org stall = False 6816657Snate@binkert.org for action in trans.actions: 6826657Snate@binkert.org if action.ident == "z_stall": 6836657Snate@binkert.org stall = True 6846657Snate@binkert.org 6856657Snate@binkert.org # Only possible if it is not a 'z' case 6866657Snate@binkert.org if not stall: 6876657Snate@binkert.org state = "%s_State_%s" % (self.ident, trans.state.ident) 6886657Snate@binkert.org event = "%s_Event_%s" % (self.ident, trans.event.ident) 6897542SBrad.Beckmann@amd.com code('m_profiler.possibleTransition($state, $event);') 6906657Snate@binkert.org 6916657Snate@binkert.org code.dedent() 6929496Snilay@cs.wisc.edu code(''' 6939496Snilay@cs.wisc.edu AbstractController::init(); 6949496Snilay@cs.wisc.edu clearStats(); 6959496Snilay@cs.wisc.edu} 6969496Snilay@cs.wisc.edu''') 6976657Snate@binkert.org 6986657Snate@binkert.org has_mandatory_q = False 6996657Snate@binkert.org for port in self.in_ports: 7006657Snate@binkert.org if port.code.find("mandatoryQueue_ptr") >= 0: 7016657Snate@binkert.org has_mandatory_q = True 7026657Snate@binkert.org 7036657Snate@binkert.org if has_mandatory_q: 7046657Snate@binkert.org mq_ident = "m_%s_mandatoryQueue_ptr" % self.ident 7056657Snate@binkert.org else: 7066657Snate@binkert.org mq_ident = "NULL" 7076657Snate@binkert.org 7088683Snilay@cs.wisc.edu seq_ident = "NULL" 7098683Snilay@cs.wisc.edu for param in self.config_parameters: 7108683Snilay@cs.wisc.edu if param.name == "sequencer": 7118683Snilay@cs.wisc.edu assert(param.pointer) 7128683Snilay@cs.wisc.edu seq_ident = "m_%s_ptr" % param.name 7138683Snilay@cs.wisc.edu 7146657Snate@binkert.org code(''' 7157007Snate@binkert.orgint 7167007Snate@binkert.org$c_ident::getNumControllers() 7177007Snate@binkert.org{ 7186657Snate@binkert.org return m_num_controllers; 7196657Snate@binkert.org} 7206657Snate@binkert.org 7217007Snate@binkert.orgMessageBuffer* 7227007Snate@binkert.org$c_ident::getMandatoryQueue() const 7237007Snate@binkert.org{ 7246657Snate@binkert.org return $mq_ident; 7256657Snate@binkert.org} 7266657Snate@binkert.org 7278683Snilay@cs.wisc.eduSequencer* 7288683Snilay@cs.wisc.edu$c_ident::getSequencer() const 7298683Snilay@cs.wisc.edu{ 7308683Snilay@cs.wisc.edu return $seq_ident; 7318683Snilay@cs.wisc.edu} 7328683Snilay@cs.wisc.edu 7337007Snate@binkert.orgconst int & 7347007Snate@binkert.org$c_ident::getVersion() const 7357007Snate@binkert.org{ 7366657Snate@binkert.org return m_version; 7376657Snate@binkert.org} 7386657Snate@binkert.org 7397007Snate@binkert.orgconst string 7407007Snate@binkert.org$c_ident::toString() const 7417007Snate@binkert.org{ 7426657Snate@binkert.org return "$c_ident"; 7436657Snate@binkert.org} 7446657Snate@binkert.org 7457007Snate@binkert.orgconst string 7467007Snate@binkert.org$c_ident::getName() const 7477007Snate@binkert.org{ 7486657Snate@binkert.org return m_name; 7496657Snate@binkert.org} 7507007Snate@binkert.org 7517007Snate@binkert.orgvoid 7527567SBrad.Beckmann@amd.com$c_ident::stallBuffer(MessageBuffer* buf, Address addr) 7537567SBrad.Beckmann@amd.com{ 7547567SBrad.Beckmann@amd.com if (m_waiting_buffers.count(addr) == 0) { 7557567SBrad.Beckmann@amd.com MsgVecType* msgVec = new MsgVecType; 7567567SBrad.Beckmann@amd.com msgVec->resize(m_max_in_port_rank, NULL); 7577567SBrad.Beckmann@amd.com m_waiting_buffers[addr] = msgVec; 7587567SBrad.Beckmann@amd.com } 7597567SBrad.Beckmann@amd.com (*(m_waiting_buffers[addr]))[m_cur_in_port_rank] = buf; 7607567SBrad.Beckmann@amd.com} 7617567SBrad.Beckmann@amd.com 7627567SBrad.Beckmann@amd.comvoid 7637567SBrad.Beckmann@amd.com$c_ident::wakeUpBuffers(Address addr) 7647567SBrad.Beckmann@amd.com{ 7658155Snilay@cs.wisc.edu if (m_waiting_buffers.count(addr) > 0) { 7668155Snilay@cs.wisc.edu // 7678155Snilay@cs.wisc.edu // Wake up all possible lower rank (i.e. lower priority) buffers that could 7688155Snilay@cs.wisc.edu // be waiting on this message. 7698155Snilay@cs.wisc.edu // 7708155Snilay@cs.wisc.edu for (int in_port_rank = m_cur_in_port_rank - 1; 7718155Snilay@cs.wisc.edu in_port_rank >= 0; 7728155Snilay@cs.wisc.edu in_port_rank--) { 7738155Snilay@cs.wisc.edu if ((*(m_waiting_buffers[addr]))[in_port_rank] != NULL) { 7748155Snilay@cs.wisc.edu (*(m_waiting_buffers[addr]))[in_port_rank]->reanalyzeMessages(addr); 7758155Snilay@cs.wisc.edu } 7767567SBrad.Beckmann@amd.com } 7778155Snilay@cs.wisc.edu delete m_waiting_buffers[addr]; 7788155Snilay@cs.wisc.edu m_waiting_buffers.erase(addr); 7797567SBrad.Beckmann@amd.com } 7807567SBrad.Beckmann@amd.com} 7817567SBrad.Beckmann@amd.com 7827567SBrad.Beckmann@amd.comvoid 7837922SBrad.Beckmann@amd.com$c_ident::wakeUpAllBuffers() 7847922SBrad.Beckmann@amd.com{ 7857922SBrad.Beckmann@amd.com // 7867922SBrad.Beckmann@amd.com // Wake up all possible buffers that could be waiting on any message. 7877922SBrad.Beckmann@amd.com // 7887922SBrad.Beckmann@amd.com 7897922SBrad.Beckmann@amd.com std::vector<MsgVecType*> wokeUpMsgVecs; 7907922SBrad.Beckmann@amd.com 7918154Snilay@cs.wisc.edu if(m_waiting_buffers.size() > 0) { 7928154Snilay@cs.wisc.edu for (WaitingBufType::iterator buf_iter = m_waiting_buffers.begin(); 7938154Snilay@cs.wisc.edu buf_iter != m_waiting_buffers.end(); 7948154Snilay@cs.wisc.edu ++buf_iter) { 7958154Snilay@cs.wisc.edu for (MsgVecType::iterator vec_iter = buf_iter->second->begin(); 7968154Snilay@cs.wisc.edu vec_iter != buf_iter->second->end(); 7978154Snilay@cs.wisc.edu ++vec_iter) { 7988154Snilay@cs.wisc.edu if (*vec_iter != NULL) { 7998154Snilay@cs.wisc.edu (*vec_iter)->reanalyzeAllMessages(); 8008154Snilay@cs.wisc.edu } 8018154Snilay@cs.wisc.edu } 8028154Snilay@cs.wisc.edu wokeUpMsgVecs.push_back(buf_iter->second); 8038154Snilay@cs.wisc.edu } 8048154Snilay@cs.wisc.edu 8058154Snilay@cs.wisc.edu for (std::vector<MsgVecType*>::iterator wb_iter = wokeUpMsgVecs.begin(); 8068154Snilay@cs.wisc.edu wb_iter != wokeUpMsgVecs.end(); 8078154Snilay@cs.wisc.edu ++wb_iter) { 8088154Snilay@cs.wisc.edu delete (*wb_iter); 8098154Snilay@cs.wisc.edu } 8108154Snilay@cs.wisc.edu 8118154Snilay@cs.wisc.edu m_waiting_buffers.clear(); 8127922SBrad.Beckmann@amd.com } 8137922SBrad.Beckmann@amd.com} 8147922SBrad.Beckmann@amd.com 8157922SBrad.Beckmann@amd.comvoid 8167007Snate@binkert.org$c_ident::blockOnQueue(Address addr, MessageBuffer* port) 8177007Snate@binkert.org{ 8186863Sdrh5@cs.wisc.edu m_is_blocking = true; 8196863Sdrh5@cs.wisc.edu m_block_map[addr] = port; 8206863Sdrh5@cs.wisc.edu} 8217007Snate@binkert.org 8227007Snate@binkert.orgvoid 8237007Snate@binkert.org$c_ident::unblock(Address addr) 8247007Snate@binkert.org{ 8256863Sdrh5@cs.wisc.edu m_block_map.erase(addr); 8266863Sdrh5@cs.wisc.edu if (m_block_map.size() == 0) { 8276863Sdrh5@cs.wisc.edu m_is_blocking = false; 8286863Sdrh5@cs.wisc.edu } 8296863Sdrh5@cs.wisc.edu} 8306863Sdrh5@cs.wisc.edu 8317007Snate@binkert.orgvoid 8327007Snate@binkert.org$c_ident::print(ostream& out) const 8337007Snate@binkert.org{ 8347007Snate@binkert.org out << "[$c_ident " << m_version << "]"; 8357007Snate@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(); 8729496Snilay@cs.wisc.edu AbstractController::clearStats(); 8736902SBrad.Beckmann@amd.com} 8747839Snilay@cs.wisc.edu''') 8757839Snilay@cs.wisc.edu 8767839Snilay@cs.wisc.edu if self.EntryType != None: 8777839Snilay@cs.wisc.edu code(''' 8787839Snilay@cs.wisc.edu 8797839Snilay@cs.wisc.edu// Set and Reset for cache_entry variable 8807839Snilay@cs.wisc.eduvoid 8817839Snilay@cs.wisc.edu$c_ident::set_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, AbstractCacheEntry* m_new_cache_entry) 8827839Snilay@cs.wisc.edu{ 8837839Snilay@cs.wisc.edu m_cache_entry_ptr = (${{self.EntryType.c_ident}}*)m_new_cache_entry; 8847839Snilay@cs.wisc.edu} 8857839Snilay@cs.wisc.edu 8867839Snilay@cs.wisc.eduvoid 8877839Snilay@cs.wisc.edu$c_ident::unset_cache_entry(${{self.EntryType.c_ident}}*& m_cache_entry_ptr) 8887839Snilay@cs.wisc.edu{ 8897839Snilay@cs.wisc.edu m_cache_entry_ptr = 0; 8907839Snilay@cs.wisc.edu} 8917839Snilay@cs.wisc.edu''') 8927839Snilay@cs.wisc.edu 8937839Snilay@cs.wisc.edu if self.TBEType != None: 8947839Snilay@cs.wisc.edu code(''' 8957839Snilay@cs.wisc.edu 8967839Snilay@cs.wisc.edu// Set and Reset for tbe variable 8977839Snilay@cs.wisc.eduvoid 8987839Snilay@cs.wisc.edu$c_ident::set_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr, ${{self.TBEType.c_ident}}* m_new_tbe) 8997839Snilay@cs.wisc.edu{ 9007839Snilay@cs.wisc.edu m_tbe_ptr = m_new_tbe; 9017839Snilay@cs.wisc.edu} 9027839Snilay@cs.wisc.edu 9037839Snilay@cs.wisc.eduvoid 9047839Snilay@cs.wisc.edu$c_ident::unset_tbe(${{self.TBEType.c_ident}}*& m_tbe_ptr) 9057839Snilay@cs.wisc.edu{ 9067839Snilay@cs.wisc.edu m_tbe_ptr = NULL; 9077839Snilay@cs.wisc.edu} 9087839Snilay@cs.wisc.edu''') 9097839Snilay@cs.wisc.edu 9107839Snilay@cs.wisc.edu code(''' 9116902SBrad.Beckmann@amd.com 9128683Snilay@cs.wisc.eduvoid 9138683Snilay@cs.wisc.edu$c_ident::recordCacheTrace(int cntrl, CacheRecorder* tr) 9148683Snilay@cs.wisc.edu{ 9158683Snilay@cs.wisc.edu''') 9168683Snilay@cs.wisc.edu # 9178683Snilay@cs.wisc.edu # Record cache contents for all associated caches. 9188683Snilay@cs.wisc.edu # 9198683Snilay@cs.wisc.edu code.indent() 9208683Snilay@cs.wisc.edu for param in self.config_parameters: 9218683Snilay@cs.wisc.edu if param.type_ast.type.ident == "CacheMemory": 9228683Snilay@cs.wisc.edu assert(param.pointer) 9238683Snilay@cs.wisc.edu code('m_${{param.ident}}_ptr->recordCacheContents(cntrl, tr);') 9248683Snilay@cs.wisc.edu 9258683Snilay@cs.wisc.edu code.dedent() 9268683Snilay@cs.wisc.edu code(''' 9278683Snilay@cs.wisc.edu} 9288683Snilay@cs.wisc.edu 9296657Snate@binkert.org// Actions 9306657Snate@binkert.org''') 9317839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 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 9356657Snate@binkert.org 9367839Snilay@cs.wisc.edu code(''' 9377839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9387839Snilay@cs.wisc.eduvoid 9397839Snilay@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) 9407839Snilay@cs.wisc.edu{ 9418055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9427839Snilay@cs.wisc.edu ${{action["c_code"]}} 9437839Snilay@cs.wisc.edu} 9446657Snate@binkert.org 9457839Snilay@cs.wisc.edu''') 9467839Snilay@cs.wisc.edu elif self.TBEType != None: 9477839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9487839Snilay@cs.wisc.edu if "c_code" not in action: 9497839Snilay@cs.wisc.edu continue 9507839Snilay@cs.wisc.edu 9517839Snilay@cs.wisc.edu code(''' 9527839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9537839Snilay@cs.wisc.eduvoid 9547839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.TBEType.c_ident}}*& m_tbe_ptr, const Address& addr) 9557839Snilay@cs.wisc.edu{ 9568055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9577839Snilay@cs.wisc.edu ${{action["c_code"]}} 9587839Snilay@cs.wisc.edu} 9597839Snilay@cs.wisc.edu 9607839Snilay@cs.wisc.edu''') 9617839Snilay@cs.wisc.edu elif self.EntryType != None: 9627839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9637839Snilay@cs.wisc.edu if "c_code" not in action: 9647839Snilay@cs.wisc.edu continue 9657839Snilay@cs.wisc.edu 9667839Snilay@cs.wisc.edu code(''' 9677839Snilay@cs.wisc.edu/** \\brief ${{action.desc}} */ 9687839Snilay@cs.wisc.eduvoid 9697839Snilay@cs.wisc.edu$c_ident::${{action.ident}}(${{self.EntryType.c_ident}}*& m_cache_entry_ptr, const Address& addr) 9707839Snilay@cs.wisc.edu{ 9718055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9727839Snilay@cs.wisc.edu ${{action["c_code"]}} 9737839Snilay@cs.wisc.edu} 9747839Snilay@cs.wisc.edu 9757839Snilay@cs.wisc.edu''') 9767839Snilay@cs.wisc.edu else: 9777839Snilay@cs.wisc.edu for action in self.actions.itervalues(): 9787839Snilay@cs.wisc.edu if "c_code" not in action: 9797839Snilay@cs.wisc.edu continue 9807839Snilay@cs.wisc.edu 9817839Snilay@cs.wisc.edu code(''' 9826657Snate@binkert.org/** \\brief ${{action.desc}} */ 9837007Snate@binkert.orgvoid 9847007Snate@binkert.org$c_ident::${{action.ident}}(const Address& addr) 9856657Snate@binkert.org{ 9868055Sksewell@umich.edu DPRINTF(RubyGenerated, "executing ${{action.ident}}\\n"); 9876657Snate@binkert.org ${{action["c_code"]}} 9886657Snate@binkert.org} 9896657Snate@binkert.org 9906657Snate@binkert.org''') 9918478Snilay@cs.wisc.edu for func in self.functions: 9928478Snilay@cs.wisc.edu code(func.generateCode()) 9938478Snilay@cs.wisc.edu 9949302Snilay@cs.wisc.edu # Function for functional reads from messages buffered in the controller 9959302Snilay@cs.wisc.edu code(''' 9969302Snilay@cs.wisc.edubool 9979302Snilay@cs.wisc.edu$c_ident::functionalReadBuffers(PacketPtr& pkt) 9989302Snilay@cs.wisc.edu{ 9999302Snilay@cs.wisc.edu''') 10009302Snilay@cs.wisc.edu for var in self.objects: 10019302Snilay@cs.wisc.edu vtype = var.type 10029302Snilay@cs.wisc.edu if vtype.isBuffer: 10039302Snilay@cs.wisc.edu vid = "m_%s_ptr" % var.c_ident 10049302Snilay@cs.wisc.edu code('if ($vid->functionalRead(pkt)) { return true; }') 10059302Snilay@cs.wisc.edu code(''' 10069302Snilay@cs.wisc.edu return false; 10079302Snilay@cs.wisc.edu} 10089302Snilay@cs.wisc.edu''') 10099302Snilay@cs.wisc.edu 10109302Snilay@cs.wisc.edu # Function for functional writes to messages buffered in the controller 10119302Snilay@cs.wisc.edu code(''' 10129302Snilay@cs.wisc.eduuint32_t 10139302Snilay@cs.wisc.edu$c_ident::functionalWriteBuffers(PacketPtr& pkt) 10149302Snilay@cs.wisc.edu{ 10159302Snilay@cs.wisc.edu uint32_t num_functional_writes = 0; 10169302Snilay@cs.wisc.edu''') 10179302Snilay@cs.wisc.edu for var in self.objects: 10189302Snilay@cs.wisc.edu vtype = var.type 10199302Snilay@cs.wisc.edu if vtype.isBuffer: 10209302Snilay@cs.wisc.edu vid = "m_%s_ptr" % var.c_ident 10219302Snilay@cs.wisc.edu code('num_functional_writes += $vid->functionalWrite(pkt);') 10229302Snilay@cs.wisc.edu code(''' 10239302Snilay@cs.wisc.edu return num_functional_writes; 10249302Snilay@cs.wisc.edu} 10259302Snilay@cs.wisc.edu''') 10269302Snilay@cs.wisc.edu 10279595Snilay@cs.wisc.edu # Check if this controller has a peer, if yes then write the 10289595Snilay@cs.wisc.edu # function for connecting to the peer. 10299595Snilay@cs.wisc.edu if has_peer: 10309595Snilay@cs.wisc.edu code(''' 10319595Snilay@cs.wisc.edu 10329595Snilay@cs.wisc.eduvoid 10339595Snilay@cs.wisc.edu$c_ident::getQueuesFromPeer(AbstractController *peer) 10349595Snilay@cs.wisc.edu{ 10359595Snilay@cs.wisc.edu''') 10369595Snilay@cs.wisc.edu for var in self.objects: 10379595Snilay@cs.wisc.edu if "network" in var and "physical_network" in var and \ 10389595Snilay@cs.wisc.edu var["network"] == "From": 10399595Snilay@cs.wisc.edu code(''' 10409595Snilay@cs.wisc.edum_${{var.c_ident}}_ptr = peer->getPeerQueue(${{var["physical_network"]}}); 10419595Snilay@cs.wisc.eduassert(m_${{var.c_ident}}_ptr != NULL); 10429595Snilay@cs.wisc.edum_${{var.c_ident}}_ptr->setReceiver(this); 10439595Snilay@cs.wisc.edu 10449595Snilay@cs.wisc.edu''') 10459595Snilay@cs.wisc.edu code('}') 10469595Snilay@cs.wisc.edu 10476657Snate@binkert.org code.write(path, "%s.cc" % c_ident) 10486657Snate@binkert.org 10499219Spower.jg@gmail.com def printCWakeup(self, path, includes): 10506657Snate@binkert.org '''Output the wakeup loop for the events''' 10516657Snate@binkert.org 10526999Snate@binkert.org code = self.symtab.codeFormatter() 10536657Snate@binkert.org ident = self.ident 10546657Snate@binkert.org 10559104Shestness@cs.utexas.edu outputRequest_types = True 10569104Shestness@cs.utexas.edu if len(self.request_types) == 0: 10579104Shestness@cs.utexas.edu outputRequest_types = False 10589104Shestness@cs.utexas.edu 10596657Snate@binkert.org code(''' 10606657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 10616657Snate@binkert.org// ${ident}: ${{self.short}} 10626657Snate@binkert.org 10638946Sandreas.hansson@arm.com#include <sys/types.h> 10648946Sandreas.hansson@arm.com#include <unistd.h> 10658946Sandreas.hansson@arm.com 10667832Snate@binkert.org#include <cassert> 10677832Snate@binkert.org 10687007Snate@binkert.org#include "base/misc.hh" 10698232Snate@binkert.org#include "debug/RubySlicc.hh" 10708229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 10718229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 10728229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 10739104Shestness@cs.utexas.edu''') 10749104Shestness@cs.utexas.edu 10759104Shestness@cs.utexas.edu if outputRequest_types: 10769104Shestness@cs.utexas.edu code('''#include "mem/protocol/${ident}_RequestType.hh"''') 10779104Shestness@cs.utexas.edu 10789104Shestness@cs.utexas.edu code(''' 10798229Snate@binkert.org#include "mem/protocol/Types.hh" 10806657Snate@binkert.org#include "mem/ruby/common/Global.hh" 10816657Snate@binkert.org#include "mem/ruby/system/System.hh" 10829219Spower.jg@gmail.com''') 10839219Spower.jg@gmail.com 10849219Spower.jg@gmail.com 10859219Spower.jg@gmail.com for include_path in includes: 10869219Spower.jg@gmail.com code('#include "${{include_path}}"') 10879219Spower.jg@gmail.com 10889219Spower.jg@gmail.com code(''' 10896657Snate@binkert.org 10907055Snate@binkert.orgusing namespace std; 10917055Snate@binkert.org 10927007Snate@binkert.orgvoid 10937007Snate@binkert.org${ident}_Controller::wakeup() 10946657Snate@binkert.org{ 10956657Snate@binkert.org int counter = 0; 10966657Snate@binkert.org while (true) { 10976657Snate@binkert.org // Some cases will put us into an infinite loop without this limit 10986657Snate@binkert.org assert(counter <= m_transitions_per_cycle); 10996657Snate@binkert.org if (counter == m_transitions_per_cycle) { 11007007Snate@binkert.org // Count how often we are fully utilized 11019496Snilay@cs.wisc.edu m_fully_busy_cycles++; 11027007Snate@binkert.org 11037007Snate@binkert.org // Wakeup in another cycle and try again 11049499Snilay@cs.wisc.edu scheduleEvent(Cycles(1)); 11056657Snate@binkert.org break; 11066657Snate@binkert.org } 11076657Snate@binkert.org''') 11086657Snate@binkert.org 11096657Snate@binkert.org code.indent() 11106657Snate@binkert.org code.indent() 11116657Snate@binkert.org 11126657Snate@binkert.org # InPorts 11136657Snate@binkert.org # 11146657Snate@binkert.org for port in self.in_ports: 11156657Snate@binkert.org code.indent() 11166657Snate@binkert.org code('// ${ident}InPort $port') 11177567SBrad.Beckmann@amd.com if port.pairs.has_key("rank"): 11187567SBrad.Beckmann@amd.com code('m_cur_in_port_rank = ${{port.pairs["rank"]}};') 11197567SBrad.Beckmann@amd.com else: 11207567SBrad.Beckmann@amd.com code('m_cur_in_port_rank = 0;') 11216657Snate@binkert.org code('${{port["c_code_in_port"]}}') 11226657Snate@binkert.org code.dedent() 11236657Snate@binkert.org 11246657Snate@binkert.org code('') 11256657Snate@binkert.org 11266657Snate@binkert.org code.dedent() 11276657Snate@binkert.org code.dedent() 11286657Snate@binkert.org code(''' 11296657Snate@binkert.org break; // If we got this far, we have nothing left todo 11306657Snate@binkert.org } 11316657Snate@binkert.org} 11326657Snate@binkert.org''') 11336657Snate@binkert.org 11346657Snate@binkert.org code.write(path, "%s_Wakeup.cc" % self.ident) 11356657Snate@binkert.org 11366657Snate@binkert.org def printCSwitch(self, path): 11376657Snate@binkert.org '''Output switch statement for transition table''' 11386657Snate@binkert.org 11396999Snate@binkert.org code = self.symtab.codeFormatter() 11406657Snate@binkert.org ident = self.ident 11416657Snate@binkert.org 11426657Snate@binkert.org code(''' 11436657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 11446657Snate@binkert.org// ${ident}: ${{self.short}} 11456657Snate@binkert.org 11467832Snate@binkert.org#include <cassert> 11477832Snate@binkert.org 11487805Snilay@cs.wisc.edu#include "base/misc.hh" 11497832Snate@binkert.org#include "base/trace.hh" 11508232Snate@binkert.org#include "debug/ProtocolTrace.hh" 11518232Snate@binkert.org#include "debug/RubyGenerated.hh" 11528229Snate@binkert.org#include "mem/protocol/${ident}_Controller.hh" 11538229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 11548229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 11558229Snate@binkert.org#include "mem/protocol/Types.hh" 11566657Snate@binkert.org#include "mem/ruby/common/Global.hh" 11576657Snate@binkert.org#include "mem/ruby/system/System.hh" 11586657Snate@binkert.org 11596657Snate@binkert.org#define HASH_FUN(state, event) ((int(state)*${ident}_Event_NUM)+int(event)) 11606657Snate@binkert.org 11616657Snate@binkert.org#define GET_TRANSITION_COMMENT() (${ident}_transitionComment.str()) 11626657Snate@binkert.org#define CLEAR_TRANSITION_COMMENT() (${ident}_transitionComment.str("")) 11636657Snate@binkert.org 11647007Snate@binkert.orgTransitionResult 11657007Snate@binkert.org${ident}_Controller::doTransition(${ident}_Event event, 11667839Snilay@cs.wisc.edu''') 11677839Snilay@cs.wisc.edu if self.EntryType != None: 11687839Snilay@cs.wisc.edu code(''' 11697839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}* m_cache_entry_ptr, 11707839Snilay@cs.wisc.edu''') 11717839Snilay@cs.wisc.edu if self.TBEType != None: 11727839Snilay@cs.wisc.edu code(''' 11737839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}* m_tbe_ptr, 11747839Snilay@cs.wisc.edu''') 11757839Snilay@cs.wisc.edu code(''' 11767007Snate@binkert.org const Address &addr) 11776657Snate@binkert.org{ 11787839Snilay@cs.wisc.edu''') 11797839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 11808337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_tbe_ptr, m_cache_entry_ptr, addr);') 11817839Snilay@cs.wisc.edu elif self.TBEType != None: 11828337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_tbe_ptr, addr);') 11837839Snilay@cs.wisc.edu elif self.EntryType != None: 11848337Snilay@cs.wisc.edu code('${ident}_State state = getState(m_cache_entry_ptr, addr);') 11857839Snilay@cs.wisc.edu else: 11868337Snilay@cs.wisc.edu code('${ident}_State state = getState(addr);') 11877839Snilay@cs.wisc.edu 11887839Snilay@cs.wisc.edu code(''' 11896657Snate@binkert.org ${ident}_State next_state = state; 11906657Snate@binkert.org 11917780Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "%s, Time: %lld, state: %s, event: %s, addr: %s\\n", 11929465Snilay@cs.wisc.edu *this, curCycle(), ${ident}_State_to_string(state), 11939171Snilay@cs.wisc.edu ${ident}_Event_to_string(event), addr); 11946657Snate@binkert.org 11957007Snate@binkert.org TransitionResult result = 11967839Snilay@cs.wisc.edu''') 11977839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 11987839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_tbe_ptr, m_cache_entry_ptr, addr);') 11997839Snilay@cs.wisc.edu elif self.TBEType != None: 12007839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_tbe_ptr, addr);') 12017839Snilay@cs.wisc.edu elif self.EntryType != None: 12027839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, m_cache_entry_ptr, addr);') 12037839Snilay@cs.wisc.edu else: 12047839Snilay@cs.wisc.edu code('doTransitionWorker(event, state, next_state, addr);') 12056657Snate@binkert.org 12067839Snilay@cs.wisc.edu code(''' 12076657Snate@binkert.org if (result == TransitionResult_Valid) { 12087780Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "next_state: %s\\n", 12097780Snilay@cs.wisc.edu ${ident}_State_to_string(next_state)); 12107542SBrad.Beckmann@amd.com m_profiler.countTransition(state, event); 12118266Sksewell@umich.edu DPRINTFR(ProtocolTrace, "%15d %3s %10s%20s %6s>%-6s %s %s\\n", 12128266Sksewell@umich.edu curTick(), m_version, "${ident}", 12138266Sksewell@umich.edu ${ident}_Event_to_string(event), 12148266Sksewell@umich.edu ${ident}_State_to_string(state), 12158266Sksewell@umich.edu ${ident}_State_to_string(next_state), 12168266Sksewell@umich.edu addr, GET_TRANSITION_COMMENT()); 12176657Snate@binkert.org 12187832Snate@binkert.org CLEAR_TRANSITION_COMMENT(); 12197839Snilay@cs.wisc.edu''') 12207839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 12218337Snilay@cs.wisc.edu code('setState(m_tbe_ptr, m_cache_entry_ptr, addr, next_state);') 12228341Snilay@cs.wisc.edu code('setAccessPermission(m_cache_entry_ptr, addr, next_state);') 12237839Snilay@cs.wisc.edu elif self.TBEType != None: 12248337Snilay@cs.wisc.edu code('setState(m_tbe_ptr, addr, next_state);') 12258341Snilay@cs.wisc.edu code('setAccessPermission(addr, next_state);') 12267839Snilay@cs.wisc.edu elif self.EntryType != None: 12278337Snilay@cs.wisc.edu code('setState(m_cache_entry_ptr, addr, next_state);') 12288341Snilay@cs.wisc.edu code('setAccessPermission(m_cache_entry_ptr, addr, next_state);') 12297839Snilay@cs.wisc.edu else: 12308337Snilay@cs.wisc.edu code('setState(addr, next_state);') 12318341Snilay@cs.wisc.edu code('setAccessPermission(addr, next_state);') 12327839Snilay@cs.wisc.edu 12337839Snilay@cs.wisc.edu code(''' 12346657Snate@binkert.org } else if (result == TransitionResult_ResourceStall) { 12358266Sksewell@umich.edu DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\\n", 12368266Sksewell@umich.edu curTick(), m_version, "${ident}", 12378266Sksewell@umich.edu ${ident}_Event_to_string(event), 12388266Sksewell@umich.edu ${ident}_State_to_string(state), 12398266Sksewell@umich.edu ${ident}_State_to_string(next_state), 12408266Sksewell@umich.edu addr, "Resource Stall"); 12416657Snate@binkert.org } else if (result == TransitionResult_ProtocolStall) { 12427780Snilay@cs.wisc.edu DPRINTF(RubyGenerated, "stalling\\n"); 12438266Sksewell@umich.edu DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\\n", 12448266Sksewell@umich.edu curTick(), m_version, "${ident}", 12458266Sksewell@umich.edu ${ident}_Event_to_string(event), 12468266Sksewell@umich.edu ${ident}_State_to_string(state), 12478266Sksewell@umich.edu ${ident}_State_to_string(next_state), 12488266Sksewell@umich.edu addr, "Protocol Stall"); 12496657Snate@binkert.org } 12506657Snate@binkert.org 12516657Snate@binkert.org return result; 12526657Snate@binkert.org} 12536657Snate@binkert.org 12547007Snate@binkert.orgTransitionResult 12557007Snate@binkert.org${ident}_Controller::doTransitionWorker(${ident}_Event event, 12567007Snate@binkert.org ${ident}_State state, 12577007Snate@binkert.org ${ident}_State& next_state, 12587839Snilay@cs.wisc.edu''') 12597839Snilay@cs.wisc.edu 12607839Snilay@cs.wisc.edu if self.TBEType != None: 12617839Snilay@cs.wisc.edu code(''' 12627839Snilay@cs.wisc.edu ${{self.TBEType.c_ident}}*& m_tbe_ptr, 12637839Snilay@cs.wisc.edu''') 12647839Snilay@cs.wisc.edu if self.EntryType != None: 12657839Snilay@cs.wisc.edu code(''' 12667839Snilay@cs.wisc.edu ${{self.EntryType.c_ident}}*& m_cache_entry_ptr, 12677839Snilay@cs.wisc.edu''') 12687839Snilay@cs.wisc.edu code(''' 12697007Snate@binkert.org const Address& addr) 12706657Snate@binkert.org{ 12716657Snate@binkert.org switch(HASH_FUN(state, event)) { 12726657Snate@binkert.org''') 12736657Snate@binkert.org 12746657Snate@binkert.org # This map will allow suppress generating duplicate code 12756657Snate@binkert.org cases = orderdict() 12766657Snate@binkert.org 12776657Snate@binkert.org for trans in self.transitions: 12786657Snate@binkert.org case_string = "%s_State_%s, %s_Event_%s" % \ 12796657Snate@binkert.org (self.ident, trans.state.ident, self.ident, trans.event.ident) 12806657Snate@binkert.org 12816999Snate@binkert.org case = self.symtab.codeFormatter() 12826657Snate@binkert.org # Only set next_state if it changes 12836657Snate@binkert.org if trans.state != trans.nextState: 12846657Snate@binkert.org ns_ident = trans.nextState.ident 12856657Snate@binkert.org case('next_state = ${ident}_State_${ns_ident};') 12866657Snate@binkert.org 12876657Snate@binkert.org actions = trans.actions 12889104Shestness@cs.utexas.edu request_types = trans.request_types 12896657Snate@binkert.org 12906657Snate@binkert.org # Check for resources 12916657Snate@binkert.org case_sorter = [] 12926657Snate@binkert.org res = trans.resources 12936657Snate@binkert.org for key,val in res.iteritems(): 12946657Snate@binkert.org if key.type.ident != "DNUCAStopTable": 12956657Snate@binkert.org val = ''' 12967007Snate@binkert.orgif (!%s.areNSlotsAvailable(%s)) 12976657Snate@binkert.org return TransitionResult_ResourceStall; 12986657Snate@binkert.org''' % (key.code, val) 12996657Snate@binkert.org case_sorter.append(val) 13006657Snate@binkert.org 13019105SBrad.Beckmann@amd.com # Check all of the request_types for resource constraints 13029105SBrad.Beckmann@amd.com for request_type in request_types: 13039105SBrad.Beckmann@amd.com val = ''' 13049105SBrad.Beckmann@amd.comif (!checkResourceAvailable(%s_RequestType_%s, addr)) { 13059105SBrad.Beckmann@amd.com return TransitionResult_ResourceStall; 13069105SBrad.Beckmann@amd.com} 13079105SBrad.Beckmann@amd.com''' % (self.ident, request_type.ident) 13089105SBrad.Beckmann@amd.com case_sorter.append(val) 13096657Snate@binkert.org 13106657Snate@binkert.org # Emit the code sequences in a sorted order. This makes the 13116657Snate@binkert.org # output deterministic (without this the output order can vary 13126657Snate@binkert.org # since Map's keys() on a vector of pointers is not deterministic 13136657Snate@binkert.org for c in sorted(case_sorter): 13146657Snate@binkert.org case("$c") 13156657Snate@binkert.org 13169104Shestness@cs.utexas.edu # Record access types for this transition 13179104Shestness@cs.utexas.edu for request_type in request_types: 13189104Shestness@cs.utexas.edu case('recordRequestType(${ident}_RequestType_${{request_type.ident}}, addr);') 13199104Shestness@cs.utexas.edu 13206657Snate@binkert.org # Figure out if we stall 13216657Snate@binkert.org stall = False 13226657Snate@binkert.org for action in actions: 13236657Snate@binkert.org if action.ident == "z_stall": 13246657Snate@binkert.org stall = True 13256657Snate@binkert.org break 13266657Snate@binkert.org 13276657Snate@binkert.org if stall: 13286657Snate@binkert.org case('return TransitionResult_ProtocolStall;') 13296657Snate@binkert.org else: 13307839Snilay@cs.wisc.edu if self.TBEType != None and self.EntryType != None: 13317839Snilay@cs.wisc.edu for action in actions: 13327839Snilay@cs.wisc.edu case('${{action.ident}}(m_tbe_ptr, m_cache_entry_ptr, addr);') 13337839Snilay@cs.wisc.edu elif self.TBEType != None: 13347839Snilay@cs.wisc.edu for action in actions: 13357839Snilay@cs.wisc.edu case('${{action.ident}}(m_tbe_ptr, addr);') 13367839Snilay@cs.wisc.edu elif self.EntryType != None: 13377839Snilay@cs.wisc.edu for action in actions: 13387839Snilay@cs.wisc.edu case('${{action.ident}}(m_cache_entry_ptr, addr);') 13397839Snilay@cs.wisc.edu else: 13407839Snilay@cs.wisc.edu for action in actions: 13417839Snilay@cs.wisc.edu case('${{action.ident}}(addr);') 13426657Snate@binkert.org case('return TransitionResult_Valid;') 13436657Snate@binkert.org 13446657Snate@binkert.org case = str(case) 13456657Snate@binkert.org 13466657Snate@binkert.org # Look to see if this transition code is unique. 13476657Snate@binkert.org if case not in cases: 13486657Snate@binkert.org cases[case] = [] 13496657Snate@binkert.org 13506657Snate@binkert.org cases[case].append(case_string) 13516657Snate@binkert.org 13526657Snate@binkert.org # Walk through all of the unique code blocks and spit out the 13536657Snate@binkert.org # corresponding case statement elements 13546657Snate@binkert.org for case,transitions in cases.iteritems(): 13556657Snate@binkert.org # Iterative over all the multiple transitions that share 13566657Snate@binkert.org # the same code 13576657Snate@binkert.org for trans in transitions: 13586657Snate@binkert.org code(' case HASH_FUN($trans):') 13596657Snate@binkert.org code(' $case') 13606657Snate@binkert.org 13616657Snate@binkert.org code(''' 13626657Snate@binkert.org default: 13637805Snilay@cs.wisc.edu fatal("Invalid transition\\n" 13648159SBrad.Beckmann@amd.com "%s time: %d addr: %s event: %s state: %s\\n", 13659465Snilay@cs.wisc.edu name(), curCycle(), addr, event, state); 13666657Snate@binkert.org } 13676657Snate@binkert.org return TransitionResult_Valid; 13686657Snate@binkert.org} 13696657Snate@binkert.org''') 13706657Snate@binkert.org code.write(path, "%s_Transitions.cc" % self.ident) 13716657Snate@binkert.org 13727542SBrad.Beckmann@amd.com def printProfileDumperHH(self, path): 13737542SBrad.Beckmann@amd.com code = self.symtab.codeFormatter() 13747542SBrad.Beckmann@amd.com ident = self.ident 13757542SBrad.Beckmann@amd.com 13767542SBrad.Beckmann@amd.com code(''' 13777542SBrad.Beckmann@amd.com// Auto generated C++ code started by $__file__:$__line__ 13787542SBrad.Beckmann@amd.com// ${ident}: ${{self.short}} 13797542SBrad.Beckmann@amd.com 13807542SBrad.Beckmann@amd.com#ifndef __${ident}_PROFILE_DUMPER_HH__ 13817542SBrad.Beckmann@amd.com#define __${ident}_PROFILE_DUMPER_HH__ 13827542SBrad.Beckmann@amd.com 13837832Snate@binkert.org#include <cassert> 13847542SBrad.Beckmann@amd.com#include <iostream> 13857542SBrad.Beckmann@amd.com#include <vector> 13867542SBrad.Beckmann@amd.com 13878229Snate@binkert.org#include "${ident}_Event.hh" 13887542SBrad.Beckmann@amd.com#include "${ident}_Profiler.hh" 13897542SBrad.Beckmann@amd.com 13907542SBrad.Beckmann@amd.comtypedef std::vector<${ident}_Profiler *> ${ident}_profilers; 13917542SBrad.Beckmann@amd.com 13927542SBrad.Beckmann@amd.comclass ${ident}_ProfileDumper 13937542SBrad.Beckmann@amd.com{ 13947542SBrad.Beckmann@amd.com public: 13957542SBrad.Beckmann@amd.com ${ident}_ProfileDumper(); 13967542SBrad.Beckmann@amd.com void registerProfiler(${ident}_Profiler* profiler); 13977542SBrad.Beckmann@amd.com void dumpStats(std::ostream& out) const; 13987542SBrad.Beckmann@amd.com 13997542SBrad.Beckmann@amd.com private: 14007542SBrad.Beckmann@amd.com ${ident}_profilers m_profilers; 14017542SBrad.Beckmann@amd.com}; 14027542SBrad.Beckmann@amd.com 14037542SBrad.Beckmann@amd.com#endif // __${ident}_PROFILE_DUMPER_HH__ 14047542SBrad.Beckmann@amd.com''') 14057542SBrad.Beckmann@amd.com code.write(path, "%s_ProfileDumper.hh" % self.ident) 14067542SBrad.Beckmann@amd.com 14077542SBrad.Beckmann@amd.com def printProfileDumperCC(self, path): 14087542SBrad.Beckmann@amd.com code = self.symtab.codeFormatter() 14097542SBrad.Beckmann@amd.com ident = self.ident 14107542SBrad.Beckmann@amd.com 14117542SBrad.Beckmann@amd.com code(''' 14127542SBrad.Beckmann@amd.com// Auto generated C++ code started by $__file__:$__line__ 14137542SBrad.Beckmann@amd.com// ${ident}: ${{self.short}} 14147542SBrad.Beckmann@amd.com 14157542SBrad.Beckmann@amd.com#include "mem/protocol/${ident}_ProfileDumper.hh" 14167542SBrad.Beckmann@amd.com 14177542SBrad.Beckmann@amd.com${ident}_ProfileDumper::${ident}_ProfileDumper() 14187542SBrad.Beckmann@amd.com{ 14197542SBrad.Beckmann@amd.com} 14207542SBrad.Beckmann@amd.com 14217542SBrad.Beckmann@amd.comvoid 14227542SBrad.Beckmann@amd.com${ident}_ProfileDumper::registerProfiler(${ident}_Profiler* profiler) 14237542SBrad.Beckmann@amd.com{ 14247542SBrad.Beckmann@amd.com m_profilers.push_back(profiler); 14257542SBrad.Beckmann@amd.com} 14267542SBrad.Beckmann@amd.com 14277542SBrad.Beckmann@amd.comvoid 14287542SBrad.Beckmann@amd.com${ident}_ProfileDumper::dumpStats(std::ostream& out) const 14297542SBrad.Beckmann@amd.com{ 14307542SBrad.Beckmann@amd.com out << " --- ${ident} ---\\n"; 14317542SBrad.Beckmann@amd.com out << " - Event Counts -\\n"; 14327542SBrad.Beckmann@amd.com for (${ident}_Event event = ${ident}_Event_FIRST; 14337542SBrad.Beckmann@amd.com event < ${ident}_Event_NUM; 14347542SBrad.Beckmann@amd.com ++event) { 14357542SBrad.Beckmann@amd.com out << (${ident}_Event) event << " ["; 14367542SBrad.Beckmann@amd.com uint64 total = 0; 14377542SBrad.Beckmann@amd.com for (int i = 0; i < m_profilers.size(); i++) { 14387542SBrad.Beckmann@amd.com out << m_profilers[i]->getEventCount(event) << " "; 14397542SBrad.Beckmann@amd.com total += m_profilers[i]->getEventCount(event); 14407542SBrad.Beckmann@amd.com } 14417542SBrad.Beckmann@amd.com out << "] " << total << "\\n"; 14427542SBrad.Beckmann@amd.com } 14437542SBrad.Beckmann@amd.com out << "\\n"; 14447542SBrad.Beckmann@amd.com out << " - Transitions -\\n"; 14457542SBrad.Beckmann@amd.com for (${ident}_State state = ${ident}_State_FIRST; 14467542SBrad.Beckmann@amd.com state < ${ident}_State_NUM; 14477542SBrad.Beckmann@amd.com ++state) { 14487542SBrad.Beckmann@amd.com for (${ident}_Event event = ${ident}_Event_FIRST; 14497542SBrad.Beckmann@amd.com event < ${ident}_Event_NUM; 14507542SBrad.Beckmann@amd.com ++event) { 14517542SBrad.Beckmann@amd.com if (m_profilers[0]->isPossible(state, event)) { 14527542SBrad.Beckmann@amd.com out << (${ident}_State) state << " " 14537542SBrad.Beckmann@amd.com << (${ident}_Event) event << " ["; 14547542SBrad.Beckmann@amd.com uint64 total = 0; 14557542SBrad.Beckmann@amd.com for (int i = 0; i < m_profilers.size(); i++) { 14567542SBrad.Beckmann@amd.com out << m_profilers[i]->getTransitionCount(state, event) << " "; 14577542SBrad.Beckmann@amd.com total += m_profilers[i]->getTransitionCount(state, event); 14587542SBrad.Beckmann@amd.com } 14597542SBrad.Beckmann@amd.com out << "] " << total << "\\n"; 14607542SBrad.Beckmann@amd.com } 14617542SBrad.Beckmann@amd.com } 14627542SBrad.Beckmann@amd.com out << "\\n"; 14637542SBrad.Beckmann@amd.com } 14647542SBrad.Beckmann@amd.com} 14657542SBrad.Beckmann@amd.com''') 14667542SBrad.Beckmann@amd.com code.write(path, "%s_ProfileDumper.cc" % self.ident) 14677542SBrad.Beckmann@amd.com 14686657Snate@binkert.org def printProfilerHH(self, path): 14696999Snate@binkert.org code = self.symtab.codeFormatter() 14706657Snate@binkert.org ident = self.ident 14716657Snate@binkert.org 14726657Snate@binkert.org code(''' 14736657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 14746657Snate@binkert.org// ${ident}: ${{self.short}} 14756657Snate@binkert.org 14767542SBrad.Beckmann@amd.com#ifndef __${ident}_PROFILER_HH__ 14777542SBrad.Beckmann@amd.com#define __${ident}_PROFILER_HH__ 14786657Snate@binkert.org 14797832Snate@binkert.org#include <cassert> 14807002Snate@binkert.org#include <iostream> 14817002Snate@binkert.org 14828229Snate@binkert.org#include "mem/protocol/${ident}_Event.hh" 14838229Snate@binkert.org#include "mem/protocol/${ident}_State.hh" 14848608Snilay@cs.wisc.edu#include "mem/ruby/common/TypeDefines.hh" 14856657Snate@binkert.org 14867007Snate@binkert.orgclass ${ident}_Profiler 14877007Snate@binkert.org{ 14886657Snate@binkert.org public: 14896657Snate@binkert.org ${ident}_Profiler(); 14906657Snate@binkert.org void setVersion(int version); 14916657Snate@binkert.org void countTransition(${ident}_State state, ${ident}_Event event); 14926657Snate@binkert.org void possibleTransition(${ident}_State state, ${ident}_Event event); 14937542SBrad.Beckmann@amd.com uint64 getEventCount(${ident}_Event event); 14947542SBrad.Beckmann@amd.com bool isPossible(${ident}_State state, ${ident}_Event event); 14957542SBrad.Beckmann@amd.com uint64 getTransitionCount(${ident}_State state, ${ident}_Event event); 14966657Snate@binkert.org void clearStats(); 14976657Snate@binkert.org 14986657Snate@binkert.org private: 14996657Snate@binkert.org int m_counters[${ident}_State_NUM][${ident}_Event_NUM]; 15006657Snate@binkert.org int m_event_counters[${ident}_Event_NUM]; 15016657Snate@binkert.org bool m_possible[${ident}_State_NUM][${ident}_Event_NUM]; 15026657Snate@binkert.org int m_version; 15036657Snate@binkert.org}; 15046657Snate@binkert.org 15057007Snate@binkert.org#endif // __${ident}_PROFILER_HH__ 15066657Snate@binkert.org''') 15076657Snate@binkert.org code.write(path, "%s_Profiler.hh" % self.ident) 15086657Snate@binkert.org 15096657Snate@binkert.org def printProfilerCC(self, path): 15106999Snate@binkert.org code = self.symtab.codeFormatter() 15116657Snate@binkert.org ident = self.ident 15126657Snate@binkert.org 15136657Snate@binkert.org code(''' 15146657Snate@binkert.org// Auto generated C++ code started by $__file__:$__line__ 15156657Snate@binkert.org// ${ident}: ${{self.short}} 15166657Snate@binkert.org 15177832Snate@binkert.org#include <cassert> 15187832Snate@binkert.org 15196657Snate@binkert.org#include "mem/protocol/${ident}_Profiler.hh" 15206657Snate@binkert.org 15216657Snate@binkert.org${ident}_Profiler::${ident}_Profiler() 15226657Snate@binkert.org{ 15236657Snate@binkert.org for (int state = 0; state < ${ident}_State_NUM; state++) { 15246657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 15256657Snate@binkert.org m_possible[state][event] = false; 15266657Snate@binkert.org m_counters[state][event] = 0; 15276657Snate@binkert.org } 15286657Snate@binkert.org } 15296657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 15306657Snate@binkert.org m_event_counters[event] = 0; 15316657Snate@binkert.org } 15326657Snate@binkert.org} 15337007Snate@binkert.org 15347007Snate@binkert.orgvoid 15357007Snate@binkert.org${ident}_Profiler::setVersion(int version) 15366657Snate@binkert.org{ 15376657Snate@binkert.org m_version = version; 15386657Snate@binkert.org} 15397007Snate@binkert.org 15407007Snate@binkert.orgvoid 15417007Snate@binkert.org${ident}_Profiler::clearStats() 15426657Snate@binkert.org{ 15436657Snate@binkert.org for (int state = 0; state < ${ident}_State_NUM; state++) { 15446657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 15456657Snate@binkert.org m_counters[state][event] = 0; 15466657Snate@binkert.org } 15476657Snate@binkert.org } 15486657Snate@binkert.org 15496657Snate@binkert.org for (int event = 0; event < ${ident}_Event_NUM; event++) { 15506657Snate@binkert.org m_event_counters[event] = 0; 15516657Snate@binkert.org } 15526657Snate@binkert.org} 15537007Snate@binkert.orgvoid 15547007Snate@binkert.org${ident}_Profiler::countTransition(${ident}_State state, ${ident}_Event event) 15556657Snate@binkert.org{ 15566657Snate@binkert.org assert(m_possible[state][event]); 15576657Snate@binkert.org m_counters[state][event]++; 15586657Snate@binkert.org m_event_counters[event]++; 15596657Snate@binkert.org} 15607007Snate@binkert.orgvoid 15617007Snate@binkert.org${ident}_Profiler::possibleTransition(${ident}_State state, 15627007Snate@binkert.org ${ident}_Event event) 15636657Snate@binkert.org{ 15646657Snate@binkert.org m_possible[state][event] = true; 15656657Snate@binkert.org} 15667007Snate@binkert.org 15677542SBrad.Beckmann@amd.comuint64 15687542SBrad.Beckmann@amd.com${ident}_Profiler::getEventCount(${ident}_Event event) 15696657Snate@binkert.org{ 15707542SBrad.Beckmann@amd.com return m_event_counters[event]; 15717542SBrad.Beckmann@amd.com} 15727002Snate@binkert.org 15737542SBrad.Beckmann@amd.combool 15747542SBrad.Beckmann@amd.com${ident}_Profiler::isPossible(${ident}_State state, ${ident}_Event event) 15757542SBrad.Beckmann@amd.com{ 15767542SBrad.Beckmann@amd.com return m_possible[state][event]; 15776657Snate@binkert.org} 15787542SBrad.Beckmann@amd.com 15797542SBrad.Beckmann@amd.comuint64 15807542SBrad.Beckmann@amd.com${ident}_Profiler::getTransitionCount(${ident}_State state, 15817542SBrad.Beckmann@amd.com ${ident}_Event event) 15827542SBrad.Beckmann@amd.com{ 15837542SBrad.Beckmann@amd.com return m_counters[state][event]; 15847542SBrad.Beckmann@amd.com} 15857542SBrad.Beckmann@amd.com 15866657Snate@binkert.org''') 15876657Snate@binkert.org code.write(path, "%s_Profiler.cc" % self.ident) 15886657Snate@binkert.org 15896657Snate@binkert.org # ************************** 15906657Snate@binkert.org # ******* HTML Files ******* 15916657Snate@binkert.org # ************************** 15927007Snate@binkert.org def frameRef(self, click_href, click_target, over_href, over_num, text): 15936999Snate@binkert.org code = self.symtab.codeFormatter(fix_newlines=False) 15947007Snate@binkert.org code("""<A href=\"$click_href\" target=\"$click_target\" onmouseover=\" 15957007Snate@binkert.org if (parent.frames[$over_num].location != parent.location + '$over_href') { 15967007Snate@binkert.org parent.frames[$over_num].location='$over_href' 15977007Snate@binkert.org }\"> 15987007Snate@binkert.org ${{html.formatShorthand(text)}} 15997007Snate@binkert.org </A>""") 16006657Snate@binkert.org return str(code) 16016657Snate@binkert.org 16026657Snate@binkert.org def writeHTMLFiles(self, path): 16036657Snate@binkert.org # Create table with no row hilighted 16046657Snate@binkert.org self.printHTMLTransitions(path, None) 16056657Snate@binkert.org 16066657Snate@binkert.org # Generate transition tables 16076657Snate@binkert.org for state in self.states.itervalues(): 16086657Snate@binkert.org self.printHTMLTransitions(path, state) 16096657Snate@binkert.org 16106657Snate@binkert.org # Generate action descriptions 16116657Snate@binkert.org for action in self.actions.itervalues(): 16126657Snate@binkert.org name = "%s_action_%s.html" % (self.ident, action.ident) 16136657Snate@binkert.org code = html.createSymbol(action, "Action") 16146657Snate@binkert.org code.write(path, name) 16156657Snate@binkert.org 16166657Snate@binkert.org # Generate state descriptions 16176657Snate@binkert.org for state in self.states.itervalues(): 16186657Snate@binkert.org name = "%s_State_%s.html" % (self.ident, state.ident) 16196657Snate@binkert.org code = html.createSymbol(state, "State") 16206657Snate@binkert.org code.write(path, name) 16216657Snate@binkert.org 16226657Snate@binkert.org # Generate event descriptions 16236657Snate@binkert.org for event in self.events.itervalues(): 16246657Snate@binkert.org name = "%s_Event_%s.html" % (self.ident, event.ident) 16256657Snate@binkert.org code = html.createSymbol(event, "Event") 16266657Snate@binkert.org code.write(path, name) 16276657Snate@binkert.org 16286657Snate@binkert.org def printHTMLTransitions(self, path, active_state): 16296999Snate@binkert.org code = self.symtab.codeFormatter() 16306657Snate@binkert.org 16316657Snate@binkert.org code(''' 16327007Snate@binkert.org<HTML> 16337007Snate@binkert.org<BODY link="blue" vlink="blue"> 16346657Snate@binkert.org 16356657Snate@binkert.org<H1 align="center">${{html.formatShorthand(self.short)}}: 16366657Snate@binkert.org''') 16376657Snate@binkert.org code.indent() 16386657Snate@binkert.org for i,machine in enumerate(self.symtab.getAllType(StateMachine)): 16396657Snate@binkert.org mid = machine.ident 16406657Snate@binkert.org if i != 0: 16416657Snate@binkert.org extra = " - " 16426657Snate@binkert.org else: 16436657Snate@binkert.org extra = "" 16446657Snate@binkert.org if machine == self: 16456657Snate@binkert.org code('$extra$mid') 16466657Snate@binkert.org else: 16476657Snate@binkert.org code('$extra<A target="Table" href="${mid}_table.html">$mid</A>') 16486657Snate@binkert.org code.dedent() 16496657Snate@binkert.org 16506657Snate@binkert.org code(""" 16516657Snate@binkert.org</H1> 16526657Snate@binkert.org 16536657Snate@binkert.org<TABLE border=1> 16546657Snate@binkert.org<TR> 16556657Snate@binkert.org <TH> </TH> 16566657Snate@binkert.org""") 16576657Snate@binkert.org 16586657Snate@binkert.org for event in self.events.itervalues(): 16596657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 16606657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 16616657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 16626657Snate@binkert.org 16636657Snate@binkert.org code('</TR>') 16646657Snate@binkert.org # -- Body of table 16656657Snate@binkert.org for state in self.states.itervalues(): 16666657Snate@binkert.org # -- Each row 16676657Snate@binkert.org if state == active_state: 16686657Snate@binkert.org color = "yellow" 16696657Snate@binkert.org else: 16706657Snate@binkert.org color = "white" 16716657Snate@binkert.org 16726657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 16736657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 16746657Snate@binkert.org text = html.formatShorthand(state.short) 16756657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 16766657Snate@binkert.org code(''' 16776657Snate@binkert.org<TR> 16786657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 16796657Snate@binkert.org''') 16806657Snate@binkert.org 16816657Snate@binkert.org # -- One column for each event 16826657Snate@binkert.org for event in self.events.itervalues(): 16836657Snate@binkert.org trans = self.table.get((state,event), None) 16846657Snate@binkert.org if trans is None: 16856657Snate@binkert.org # This is the no transition case 16866657Snate@binkert.org if state == active_state: 16876657Snate@binkert.org color = "#C0C000" 16886657Snate@binkert.org else: 16896657Snate@binkert.org color = "lightgrey" 16906657Snate@binkert.org 16916657Snate@binkert.org code('<TD bgcolor=$color> </TD>') 16926657Snate@binkert.org continue 16936657Snate@binkert.org 16946657Snate@binkert.org next = trans.nextState 16956657Snate@binkert.org stall_action = False 16966657Snate@binkert.org 16976657Snate@binkert.org # -- Get the actions 16986657Snate@binkert.org for action in trans.actions: 16996657Snate@binkert.org if action.ident == "z_stall" or \ 17006657Snate@binkert.org action.ident == "zz_recycleMandatoryQueue": 17016657Snate@binkert.org stall_action = True 17026657Snate@binkert.org 17036657Snate@binkert.org # -- Print out "actions/next-state" 17046657Snate@binkert.org if stall_action: 17056657Snate@binkert.org if state == active_state: 17066657Snate@binkert.org color = "#C0C000" 17076657Snate@binkert.org else: 17086657Snate@binkert.org color = "lightgrey" 17096657Snate@binkert.org 17106657Snate@binkert.org elif active_state and next.ident == active_state.ident: 17116657Snate@binkert.org color = "aqua" 17126657Snate@binkert.org elif state == active_state: 17136657Snate@binkert.org color = "yellow" 17146657Snate@binkert.org else: 17156657Snate@binkert.org color = "white" 17166657Snate@binkert.org 17176657Snate@binkert.org code('<TD bgcolor=$color>') 17186657Snate@binkert.org for action in trans.actions: 17196657Snate@binkert.org href = "%s_action_%s.html" % (self.ident, action.ident) 17206657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", 17216657Snate@binkert.org action.short) 17227007Snate@binkert.org code(' $ref') 17236657Snate@binkert.org if next != state: 17246657Snate@binkert.org if trans.actions: 17256657Snate@binkert.org code('/') 17266657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, next.ident) 17276657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, next.ident) 17286657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", next.short) 17296657Snate@binkert.org code("$ref") 17307007Snate@binkert.org code("</TD>") 17316657Snate@binkert.org 17326657Snate@binkert.org # -- Each row 17336657Snate@binkert.org if state == active_state: 17346657Snate@binkert.org color = "yellow" 17356657Snate@binkert.org else: 17366657Snate@binkert.org color = "white" 17376657Snate@binkert.org 17386657Snate@binkert.org click = "%s_table_%s.html" % (self.ident, state.ident) 17396657Snate@binkert.org over = "%s_State_%s.html" % (self.ident, state.ident) 17406657Snate@binkert.org ref = self.frameRef(click, "Table", over, "1", state.short) 17416657Snate@binkert.org code(''' 17426657Snate@binkert.org <TH bgcolor=$color>$ref</TH> 17436657Snate@binkert.org</TR> 17446657Snate@binkert.org''') 17456657Snate@binkert.org code(''' 17467007Snate@binkert.org<!- Column footer-> 17476657Snate@binkert.org<TR> 17486657Snate@binkert.org <TH> </TH> 17496657Snate@binkert.org''') 17506657Snate@binkert.org 17516657Snate@binkert.org for event in self.events.itervalues(): 17526657Snate@binkert.org href = "%s_Event_%s.html" % (self.ident, event.ident) 17536657Snate@binkert.org ref = self.frameRef(href, "Status", href, "1", event.short) 17546657Snate@binkert.org code('<TH bgcolor=white>$ref</TH>') 17556657Snate@binkert.org code(''' 17566657Snate@binkert.org</TR> 17576657Snate@binkert.org</TABLE> 17586657Snate@binkert.org</BODY></HTML> 17596657Snate@binkert.org''') 17606657Snate@binkert.org 17616657Snate@binkert.org 17626657Snate@binkert.org if active_state: 17636657Snate@binkert.org name = "%s_table_%s.html" % (self.ident, active_state.ident) 17646657Snate@binkert.org else: 17656657Snate@binkert.org name = "%s_table.html" % self.ident 17666657Snate@binkert.org code.write(path, name) 17676657Snate@binkert.org 17686657Snate@binkert.org__all__ = [ "StateMachine" ] 1769