StateMachine.py (7454:3a3e8e8cce1b) StateMachine.py (7542:49327b849c7f)
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)
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)
148
149 for func in self.functions:
150 func.writeCodeFiles(path)
151
152 def printControllerPython(self, path):
153 code = self.symtab.codeFormatter()
154 ident = self.ident
155 py_ident = "%s_Controller" % ident

--- 47 unchanged lines hidden (view full) ---

203#include "params/$c_ident.hh"
204
205#include "mem/ruby/common/Global.hh"
206#include "mem/ruby/common/Consumer.hh"
207#include "mem/ruby/slicc_interface/AbstractController.hh"
208#include "mem/protocol/TransitionResult.hh"
209#include "mem/protocol/Types.hh"
210#include "mem/protocol/${ident}_Profiler.hh"
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"
211''')
212
213 seen_types = set()
214 for var in self.objects:
215 if var.type.ident not in seen_types and not var.type.isPrimitive:
216 code('#include "mem/protocol/${{var.type.c_ident}}.hh"')
217 seen_types.add(var.type.ident)
218

--- 53 unchanged lines hidden (view full) ---

272int m_buffer_size;
273int m_recycle_latency;
274std::map<std::string, std::string> m_cfg;
275NodeID m_version;
276Network* m_net_ptr;
277MachineID m_machineID;
278bool m_is_blocking;
279std::map<Address, MessageBuffer*> m_block_map;
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;
280${ident}_Profiler s_profiler;
283static ${ident}_ProfileDumper s_profileDumper;
284${ident}_Profiler m_profiler;
281static int m_num_controllers;
282
283// Internal functions
284''')
285
286 for func in self.functions:
287 proto = func.prototype
288 if proto:

--- 63 unchanged lines hidden (view full) ---

352 code('''
353$c_ident *
354${c_ident}Params::create()
355{
356 return new $c_ident(this);
357}
358
359int $c_ident::m_num_controllers = 0;
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;
360
361// for adding information to the protocol debug trace
362stringstream ${ident}_transitionComment;
363#define APPEND_TRANSITION_COMMENT(str) (${ident}_transitionComment << str)
364
365/** \\brief constructor */
366$c_ident::$c_ident(const Params *p)
367 : AbstractController(p)

--- 61 unchanged lines hidden (view full) ---

429{
430 MachineType machine_type;
431 int base;
432
433 m_machineID.type = MachineType_${ident};
434 m_machineID.num = m_version;
435
436 // initialize objects
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
437 s_profiler.setVersion(m_version);
442 m_profiler.setVersion(m_version);
443 s_profileDumper.registerProfiler(&m_profiler);
438
439''')
440
441 code.indent()
442 for var in self.objects:
443 vtype = var.type
444 vid = "m_%s_ptr" % var.c_ident
445 if "network" not in var:

--- 103 unchanged lines hidden (view full) ---

549 for action in trans.actions:
550 if action.ident == "z_stall":
551 stall = True
552
553 # Only possible if it is not a 'z' case
554 if not stall:
555 state = "%s_State_%s" % (self.ident, trans.state.ident)
556 event = "%s_Event_%s" % (self.ident, trans.event.ident)
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)
557 code('s_profiler.possibleTransition($state, $event);')
563 code('m_profiler.possibleTransition($state, $event);')
558
559 # added by SS to initialize recycle_latency of message buffers
560 for buf in self.message_buffer_names:
561 code("$buf->setRecycleLatency(m_recycle_latency);")
562
563 code.dedent()
564 code('}')
565

--- 87 unchanged lines hidden (view full) ---

653 for param in self.config_parameters:
654 if param.type_ast.type.ident == "CacheMemory" or \
655 param.type_ast.type.ident == "DirectoryMemory" or \
656 param.type_ast.type.ident == "MemoryControl":
657 assert(param.pointer)
658 code(' m_${{param.ident}}_ptr->printStats(out);')
659
660 code('''
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('''
661 s_profiler.dumpStats(out);
667 if (m_version == 0) {
668 s_profileDumper.dumpStats(out);
669 }
662}
663
664void $c_ident::clearStats() {
665''')
666 #
667 # Cache and Memory Controllers have specific profilers associated with
668 # them. These stats must be cleared too.
669 #
670 for param in self.config_parameters:
671 if param.type_ast.type.ident == "CacheMemory" or \
672 param.type_ast.type.ident == "MemoryControl":
673 assert(param.pointer)
674 code(' m_${{param.ident}}_ptr->clearStats();')
675
676 code('''
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('''
677 s_profiler.clearStats();
685 m_profiler.clearStats();
678}
679
680// Actions
681''')
682
683 for action in self.actions.itervalues():
684 if "c_code" not in action:
685 continue

--- 113 unchanged lines hidden (view full) ---

799 DEBUG_EXPR(GENERATED_COMP, MedPrio,addr);
800
801 TransitionResult result =
802 doTransitionWorker(event, state, next_state, addr);
803
804 if (result == TransitionResult_Valid) {
805 DEBUG_EXPR(GENERATED_COMP, MedPrio, next_state);
806 DEBUG_NEWLINE(GENERATED_COMP, MedPrio);
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);
807 s_profiler.countTransition(state, event);
815 m_profiler.countTransition(state, event);
808 if (Debug::getProtocolTrace()) {
809 g_system_ptr->getProfiler()->profileTransition("${ident}",
810 m_version, addr,
811 ${ident}_State_to_string(state),
812 ${ident}_Event_to_string(event),
813 ${ident}_State_to_string(next_state),
814 GET_TRANSITION_COMMENT());
815 }

--- 107 unchanged lines hidden (view full) ---

923 WARN_EXPR(state);
924 ERROR_MSG(\"Invalid transition\");
925 }
926 return TransitionResult_Valid;
927}
928''')
929 code.write(path, "%s_Transitions.cc" % self.ident)
930
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
931 def printProfilerHH(self, path):
932 code = self.symtab.codeFormatter()
933 ident = self.ident
934
935 code('''
936// Auto generated C++ code started by $__file__:$__line__
937// ${ident}: ${{self.short}}
938
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
939#ifndef __${ident}_PROFILER_HH_
940#define __${ident}_PROFILER_HH_
1042#ifndef __${ident}_PROFILER_HH__
1043#define __${ident}_PROFILER_HH__
941
942#include <iostream>
943
944#include "mem/ruby/common/Global.hh"
945#include "mem/protocol/${ident}_State.hh"
946#include "mem/protocol/${ident}_Event.hh"
947
948class ${ident}_Profiler
949{
950 public:
951 ${ident}_Profiler();
952 void setVersion(int version);
953 void countTransition(${ident}_State state, ${ident}_Event event);
954 void possibleTransition(${ident}_State state, ${ident}_Event event);
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);
955 void dumpStats(std::ostream& out) const;
1058 uint64 getEventCount(${ident}_Event event);
1059 bool isPossible(${ident}_State state, ${ident}_Event event);
1060 uint64 getTransitionCount(${ident}_State state, ${ident}_Event event);
956 void clearStats();
957
958 private:
959 int m_counters[${ident}_State_NUM][${ident}_Event_NUM];
960 int m_event_counters[${ident}_Event_NUM];
961 bool m_possible[${ident}_State_NUM][${ident}_Event_NUM];
962 int m_version;
963};

--- 53 unchanged lines hidden (view full) ---

1017}
1018void
1019${ident}_Profiler::possibleTransition(${ident}_State state,
1020 ${ident}_Event event)
1021{
1022 m_possible[state][event] = true;
1023}
1024
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
1025void
1026${ident}_Profiler::dumpStats(std::ostream& out) const
1130uint64
1131${ident}_Profiler::getEventCount(${ident}_Event event)
1027{
1132{
1028 using namespace std;
1133 return m_event_counters[event];
1134}
1029
1135
1030 out << " --- ${ident} " << m_version << " ---" << endl;
1031 out << " - Event Counts -" << endl;
1032 for (int event = 0; event < ${ident}_Event_NUM; event++) {
1033 int count = m_event_counters[event];
1034 out << (${ident}_Event) event << " " << count << endl;
1035 }
1036 out << endl;
1037 out << " - Transitions -" << endl;
1038 for (int state = 0; state < ${ident}_State_NUM; state++) {
1039 for (int event = 0; event < ${ident}_Event_NUM; event++) {
1040 if (m_possible[state][event]) {
1041 int count = m_counters[state][event];
1042 out << (${ident}_State) state << " "
1043 << (${ident}_Event) event << " " << count;
1044 if (count == 0) {
1045 out << " <-- ";
1046 }
1047 out << endl;
1048 }
1049 }
1050 out << endl;
1051 }
1136bool
1137${ident}_Profiler::isPossible(${ident}_State state, ${ident}_Event event)
1138{
1139 return m_possible[state][event];
1052}
1140}
1141
1142uint64
1143${ident}_Profiler::getTransitionCount(${ident}_State state,
1144 ${ident}_Event event)
1145{
1146 return m_counters[state][event];
1147}
1148
1053''')
1054 code.write(path, "%s_Profiler.cc" % self.ident)
1055
1056 # **************************
1057 # ******* HTML Files *******
1058 # **************************
1059 def frameRef(self, click_href, click_target, over_href, over_num, text):
1060 code = self.symtab.codeFormatter(fix_newlines=False)

--- 175 unchanged lines hidden ---
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 ---