1# Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 2# Copyright (c) 2009 The Hewlett-Packard Development Company 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer; --- 131 unchanged lines hidden (view full) --- 140 def writeCodeFiles(self, path): 141 self.printControllerPython(path) 142 self.printControllerHH(path) 143 self.printControllerCC(path) 144 self.printCSwitch(path) 145 self.printCWakeup(path) 146 self.printProfilerCC(path) 147 self.printProfilerHH(path) |
148 self.printProfileDumperCC(path) 149 self.printProfileDumperHH(path) |
150 151 for func in self.functions: 152 func.writeCodeFiles(path) 153 154 def printControllerPython(self, path): 155 code = self.symtab.codeFormatter() 156 ident = self.ident 157 py_ident = "%s_Controller" % ident --- 47 unchanged lines hidden (view full) --- 205#include "params/$c_ident.hh" 206 207#include "mem/ruby/common/Global.hh" 208#include "mem/ruby/common/Consumer.hh" 209#include "mem/ruby/slicc_interface/AbstractController.hh" 210#include "mem/protocol/TransitionResult.hh" 211#include "mem/protocol/Types.hh" 212#include "mem/protocol/${ident}_Profiler.hh" |
213#include "mem/protocol/${ident}_ProfileDumper.hh" |
214''') 215 216 seen_types = set() 217 for var in self.objects: 218 if var.type.ident not in seen_types and not var.type.isPrimitive: 219 code('#include "mem/protocol/${{var.type.c_ident}}.hh"') 220 seen_types.add(var.type.ident) 221 --- 53 unchanged lines hidden (view full) --- 275int m_buffer_size; 276int m_recycle_latency; 277std::map<std::string, std::string> m_cfg; 278NodeID m_version; 279Network* m_net_ptr; 280MachineID m_machineID; 281bool m_is_blocking; 282std::map<Address, MessageBuffer*> m_block_map; |
283static ${ident}_ProfileDumper s_profileDumper; 284${ident}_Profiler m_profiler; |
285static int m_num_controllers; 286 287// Internal functions 288''') 289 290 for func in self.functions: 291 proto = func.prototype 292 if proto: --- 63 unchanged lines hidden (view full) --- 356 code(''' 357$c_ident * 358${c_ident}Params::create() 359{ 360 return new $c_ident(this); 361} 362 363int $c_ident::m_num_controllers = 0; |
364${ident}_ProfileDumper $c_ident::s_profileDumper; |
365 366// for adding information to the protocol debug trace 367stringstream ${ident}_transitionComment; 368#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str) 369 370/** \\brief constructor */ 371$c_ident::$c_ident(const Params *p) 372 : AbstractController(p) --- 61 unchanged lines hidden (view full) --- 434{ 435 MachineType machine_type; 436 int base; 437 438 m_machineID.type = MachineType_${ident}; 439 m_machineID.num = m_version; 440 441 // initialize objects |
442 m_profiler.setVersion(m_version); 443 s_profileDumper.registerProfiler(&m_profiler); |
444 445''') 446 447 code.indent() 448 for var in self.objects: 449 vtype = var.type 450 vid = "m_%s_ptr" % var.c_ident 451 if "network" not in var: --- 103 unchanged lines hidden (view full) --- 555 for action in trans.actions: 556 if action.ident == "z_stall": 557 stall = True 558 559 # Only possible if it is not a 'z' case 560 if not stall: 561 state = "%s_State_%s" % (self.ident, trans.state.ident) 562 event = "%s_Event_%s" % (self.ident, trans.event.ident) |
563 code('m_profiler.possibleTransition($state, $event);') |
564 565 # added by SS to initialize recycle_latency of message buffers 566 for buf in self.message_buffer_names: 567 code("$buf->setRecycleLatency(m_recycle_latency);") 568 569 code.dedent() 570 code('}') 571 --- 87 unchanged lines hidden (view full) --- 659 for param in self.config_parameters: 660 if param.type_ast.type.ident == "CacheMemory" or \ 661 param.type_ast.type.ident == "DirectoryMemory" or \ 662 param.type_ast.type.ident == "MemoryControl": 663 assert(param.pointer) 664 code(' m_${{param.ident}}_ptr->printStats(out);') 665 666 code(''' |
667 if (m_version == 0) { 668 s_profileDumper.dumpStats(out); 669 } |
670} 671 672void $c_ident::clearStats() { 673''') 674 # 675 # Cache and Memory Controllers have specific profilers associated with 676 # them. These stats must be cleared too. 677 # 678 for param in self.config_parameters: 679 if param.type_ast.type.ident == "CacheMemory" or \ 680 param.type_ast.type.ident == "MemoryControl": 681 assert(param.pointer) 682 code(' m_${{param.ident}}_ptr->clearStats();') 683 684 code(''' |
685 m_profiler.clearStats(); |
686} 687 688// Actions 689''') 690 691 for action in self.actions.itervalues(): 692 if "c_code" not in action: 693 continue --- 113 unchanged lines hidden (view full) --- 807 DEBUG_EXPR(GENERATED_COMP, MedPrio,addr); 808 809 TransitionResult result = 810 doTransitionWorker(event, state, next_state, addr); 811 812 if (result == TransitionResult_Valid) { 813 DEBUG_EXPR(GENERATED_COMP, MedPrio, next_state); 814 DEBUG_NEWLINE(GENERATED_COMP, MedPrio); |
815 m_profiler.countTransition(state, event); |
816 if (Debug::getProtocolTrace()) { 817 g_system_ptr->getProfiler()->profileTransition("${ident}", 818 m_version, addr, 819 ${ident}_State_to_string(state), 820 ${ident}_Event_to_string(event), 821 ${ident}_State_to_string(next_state), 822 GET_TRANSITION_COMMENT()); 823 } --- 107 unchanged lines hidden (view full) --- 931 WARN_EXPR(state); 932 ERROR_MSG(\"Invalid transition\"); 933 } 934 return TransitionResult_Valid; 935} 936''') 937 code.write(path, "%s_Transitions.cc" % self.ident) 938 |
939 def printProfileDumperHH(self, path): 940 code = self.symtab.codeFormatter() 941 ident = self.ident 942 943 code(''' 944// Auto generated C++ code started by $__file__:$__line__ 945// ${ident}: ${{self.short}} 946 947#ifndef __${ident}_PROFILE_DUMPER_HH__ 948#define __${ident}_PROFILE_DUMPER_HH__ 949 950#include <iostream> 951#include <vector> 952 953#include "${ident}_Profiler.hh" 954#include "${ident}_Event.hh" 955 956typedef std::vector<${ident}_Profiler *> ${ident}_profilers; 957 958class ${ident}_ProfileDumper 959{ 960 public: 961 ${ident}_ProfileDumper(); 962 void registerProfiler(${ident}_Profiler* profiler); 963 void dumpStats(std::ostream& out) const; 964 965 private: 966 ${ident}_profilers m_profilers; 967}; 968 969#endif // __${ident}_PROFILE_DUMPER_HH__ 970''') 971 code.write(path, "%s_ProfileDumper.hh" % self.ident) 972 973 def printProfileDumperCC(self, path): 974 code = self.symtab.codeFormatter() 975 ident = self.ident 976 977 code(''' 978// Auto generated C++ code started by $__file__:$__line__ 979// ${ident}: ${{self.short}} 980 981#include "mem/protocol/${ident}_ProfileDumper.hh" 982 983${ident}_ProfileDumper::${ident}_ProfileDumper() 984{ 985} 986 987void 988${ident}_ProfileDumper::registerProfiler(${ident}_Profiler* profiler) 989{ 990 m_profilers.push_back(profiler); 991} 992 993void 994${ident}_ProfileDumper::dumpStats(std::ostream& out) const 995{ 996 out << " --- ${ident} ---\\n"; 997 out << " - Event Counts -\\n"; 998 for (${ident}_Event event = ${ident}_Event_FIRST; 999 event < ${ident}_Event_NUM; 1000 ++event) { 1001 out << (${ident}_Event) event << " ["; 1002 uint64 total = 0; 1003 for (int i = 0; i < m_profilers.size(); i++) { 1004 out << m_profilers[i]->getEventCount(event) << " "; 1005 total += m_profilers[i]->getEventCount(event); 1006 } 1007 out << "] " << total << "\\n"; 1008 } 1009 out << "\\n"; 1010 out << " - Transitions -\\n"; 1011 for (${ident}_State state = ${ident}_State_FIRST; 1012 state < ${ident}_State_NUM; 1013 ++state) { 1014 for (${ident}_Event event = ${ident}_Event_FIRST; 1015 event < ${ident}_Event_NUM; 1016 ++event) { 1017 if (m_profilers[0]->isPossible(state, event)) { 1018 out << (${ident}_State) state << " " 1019 << (${ident}_Event) event << " ["; 1020 uint64 total = 0; 1021 for (int i = 0; i < m_profilers.size(); i++) { 1022 out << m_profilers[i]->getTransitionCount(state, event) << " "; 1023 total += m_profilers[i]->getTransitionCount(state, event); 1024 } 1025 out << "] " << total << "\\n"; 1026 } 1027 } 1028 out << "\\n"; 1029 } 1030} 1031''') 1032 code.write(path, "%s_ProfileDumper.cc" % self.ident) 1033 |
1034 def printProfilerHH(self, path): 1035 code = self.symtab.codeFormatter() 1036 ident = self.ident 1037 1038 code(''' 1039// Auto generated C++ code started by $__file__:$__line__ 1040// ${ident}: ${{self.short}} 1041 |
1042#ifndef __${ident}_PROFILER_HH__ 1043#define __${ident}_PROFILER_HH__ |
1044 1045#include <iostream> 1046 1047#include "mem/ruby/common/Global.hh" 1048#include "mem/protocol/${ident}_State.hh" 1049#include "mem/protocol/${ident}_Event.hh" 1050 1051class ${ident}_Profiler 1052{ 1053 public: 1054 ${ident}_Profiler(); 1055 void setVersion(int version); 1056 void countTransition(${ident}_State state, ${ident}_Event event); 1057 void possibleTransition(${ident}_State state, ${ident}_Event event); |
1058 uint64 getEventCount(${ident}_Event event); 1059 bool isPossible(${ident}_State state, ${ident}_Event event); 1060 uint64 getTransitionCount(${ident}_State state, ${ident}_Event event); |
1061 void clearStats(); 1062 1063 private: 1064 int m_counters[${ident}_State_NUM][${ident}_Event_NUM]; 1065 int m_event_counters[${ident}_Event_NUM]; 1066 bool m_possible[${ident}_State_NUM][${ident}_Event_NUM]; 1067 int m_version; 1068}; --- 53 unchanged lines hidden (view full) --- 1122} 1123void 1124${ident}_Profiler::possibleTransition(${ident}_State state, 1125 ${ident}_Event event) 1126{ 1127 m_possible[state][event] = true; 1128} 1129 |
1130uint64 1131${ident}_Profiler::getEventCount(${ident}_Event event) |
1132{ |
1133 return m_event_counters[event]; 1134} |
1135 |
1136bool 1137${ident}_Profiler::isPossible(${ident}_State state, ${ident}_Event event) 1138{ 1139 return m_possible[state][event]; |
1140} |
1141 1142uint64 1143${ident}_Profiler::getTransitionCount(${ident}_State state, 1144 ${ident}_Event event) 1145{ 1146 return m_counters[state][event]; 1147} 1148 |
1149''') 1150 code.write(path, "%s_Profiler.cc" % self.ident) 1151 1152 # ************************** 1153 # ******* HTML Files ******* 1154 # ************************** 1155 def frameRef(self, click_href, click_target, over_href, over_num, text): 1156 code = self.symtab.codeFormatter(fix_newlines=False) --- 175 unchanged lines hidden --- |