Changed the state machine to generate code such that multiple processors can make...
authorPolina Dudnik <pdudnik@gmail.com>
Mon, 13 Jul 2009 23:39:32 +0000 (18:39 -0500)
committerPolina Dudnik <pdudnik@gmail.com>
Mon, 13 Jul 2009 23:39:32 +0000 (18:39 -0500)
src/mem/slicc/symbols/StateMachine.cc

index 896b37a91dfde0c46dfaf67ca0439215b823ebe8..64c7ae24a7b618b19026a7247bdd3725c7d64933 100644 (file)
@@ -282,13 +282,16 @@ void StateMachine::printControllerH(ostream& out, string component)
   out << "  void printStats(ostream& out) const { s_profiler.dumpStats(out); }" << endl;
   out << "  void clearStats() { s_profiler.clearStats(); }" << endl;
   out << "private:" << endl;
-
 //added by SS
 //  found_to_mem = 0;
   std::vector<std::string*>::const_iterator it;
   for(it=m_latency_vector.begin();it!=m_latency_vector.end();it++){
         out << "  int m_" << (*it)->c_str() << ";" << endl;
   }
+  if (strncmp(component.c_str(), "L1Cache", 7) == 0) {
+    out << "  bool servicing_atomic;" << endl;
+    out << "  Address locked_read_request;" << endl;
+  }
   out << "  int m_number_of_TBEs;" << endl;
 
   out << "  TransitionResult doTransition(" << component << "_Event event, " << component
@@ -399,7 +402,11 @@ void StateMachine::printControllerC(ostream& out, string component)
       << "_Controller(const string & name)" << endl;
   out << " : m_name(name)" << endl;
   out << "{ " << endl;
-  out << "   m_num_controllers++; " << endl;
+  if (strncmp(component.c_str(), "L1Cache", 7) == 0) {
+    out << "  servicing_atomic = false;" << endl;
+    out << "  locked_read_request = Address(-1);" << endl;
+  }
+  out << "  m_num_controllers++; " << endl;
   for(int i=0; i < numObjects(); i++) {
     const Var* var = m_objs[i];
     if ( var->cIdent().find("mandatoryQueue") != string::npos)
@@ -738,6 +745,23 @@ void StateMachine::printControllerC(ostream& out, string component)
         }
       }
 
+      // add here:
+      if (strncmp(component.c_str(), "L1Cache", 7) == 0) {
+        if (c_code_string.find("writeCallback") != string::npos) {
+          string::size_type pos = c_code_string.find("(((*m_L1Cache_sequencer_ptr)).writeCallback");
+          assert(pos != string::npos);
+          string atomics_string = "\n  if (servicing_atomic) { \n \
+   servicing_atomic = false; \n \
+   locked_read_request = Address(-1); \n \
+ } \n \
+ else if (!servicing_atomic) { \n \
+   if (addr == locked_read_request) { \n \
+     servicing_atomic = true; \n \
+   } \n \
+ } \n  ";
+          c_code_string.insert(pos, atomics_string);
+        }
+      }
       out << c_code_string;
 
       out << "}" << endl;
@@ -759,17 +783,6 @@ void StateMachine::printCWakeup(ostream& out, string component)
   out << "#include \"mem/protocol/Types.hh\"" << endl;
   out << "#include \"mem/ruby/system/System.hh\"" << endl;
   out << endl;
-  if (strncmp(component.c_str(), "L1Cache", 7) == 0) {
-    out << "NodeID servicing_atomic = -1;" << endl;
-    out << endl;
-    out << "Address locked_read_request = Address(-1);" << endl;
-    out << endl;
-    out << "NodeID servicing_locked_read = -1;" << endl;
-    out << endl;
-  }
-  else {
-    cout << component << endl << flush;
-  }
   out << "void " << component << "_Controller::wakeup()" << endl;
   out << "{" << endl;
   //  out << "  DEBUG_EXPR(GENERATED_COMP, MedPrio,*this);" << endl;
@@ -814,42 +827,38 @@ void StateMachine::printCWakeup(ostream& out, string component)
     string::size_type pos = output.find("TransitionResult result = doTransition((L1Cache_mandatory_request_type_to_event(((*in_msg_ptr)).m_Type)), L1Cache_getState(addr), addr);");
     assert(pos != string::npos);
     string atomics_string = "\n \
-                           bool postpone = false; \n \
-                           if ((((*in_msg_ptr)).m_Type) == CacheRequestType_ATOMIC) { \n \
-                             if (servicing_atomic == -1) { \n \
-                                if (locked_read_request == Address(-1) && (servicing_locked_read == -1)) { \n \
-                                  assert(addr != Address(-1)); \n \
-                                  locked_read_request = addr;  \n \
-                                  servicing_locked_read = m_version; \n \
-                                } \n \
-                                else if ((addr == locked_read_request) && (servicing_locked_read == m_version)) { \n \
-                                  assert (servicing_atomic == -1); \n \
-                                  servicing_atomic = m_version; \n \
-                                } \n \
-                                else { \n \ 
-                                  postpone = true; \n \
-                                  g_eventQueue_ptr->scheduleEvent(this, 1); \n \
-                                } \n \
-                             } \n \
-                             else { \n \
-                               postpone = true; \n \
-                                g_eventQueue_ptr->scheduleEvent(this, 1); \n \
-                             } \n \
-                           } \n \
-                           if (servicing_atomic == m_version) { \n \
-                                servicing_atomic = -1; \n \
-                                locked_read_request = Address(-1); \n \
-                                servicing_locked_read = -1; \n \
-                           } \n \
-                           if (!postpone) { \n \
-                             ";
+             bool postpone = false; \n \
+             if ((((*in_msg_ptr)).m_Type) == CacheRequestType_ATOMIC) { \n \
+               if (!servicing_atomic) { \n \
+                  if (locked_read_request == Address(-1)) { \n \
+                    locked_read_request = addr;  \n \
+                  } \n \
+                  else if (addr == locked_read_request) { \n \
+                    assert (servicing_atomic); \n \
+                    //servicing_atomic = m_version; \n \
+                  } \n \
+                  else { \n \ 
+                    postpone = true; \n \
+                    g_eventQueue_ptr->scheduleEvent(this, 1); \n \
+                  } \n \
+               } \n \
+               else if (addr != locked_read_request) { \n \
+                 postpone = true; \n \
+                 g_eventQueue_ptr->scheduleEvent(this, 1); \n \
+               } \n \
+             } \n \
+           if (!postpone) { \n \
+               ";
 
 
 
     output.insert(pos, atomics_string);
-    string::size_type next_pos = output.find("// Cannot do anything with this transition, go check next doable transition (mostly likely of next port)", pos);
+    string foo = "// Cannot do anything with this transition, go check next doable transition (mostly likely of next port)\n";
+    string::size_type next_pos = output.find(foo, pos);
+    next_pos = next_pos + foo.length();
+
     assert(next_pos != string::npos);
-    string complete = "\n}";
+    string complete = "              }\n";
     output.insert(next_pos, complete);
     //out << port->lookupPair("c_code_in_port");
     out << output;
@@ -861,11 +870,15 @@ void StateMachine::printCWakeup(ostream& out, string component)
     if (i != j) {
       if (strncmp(component.c_str(), "L1Cache", 7) == 0) {
         if (port->toString().find("forwardRequestNetwork_in") != string::npos) {
-         out << "if (servicing_atomic != m_version && servicing_locked_read != m_version) {" << endl;
-        }
-        else if (port->toString().find("responseNetwork_in") != string::npos) {
-         out << "// NOTE: this will only work if the WB_ACK always comes before issuing a request for which this line was replaced" << endl;
-         out << "if (servicing_atomic == -1 || servicing_atomic == m_version) {" << endl;
+          out << "    bool postpone = false;" << endl;
+          out << "    if ((((*m_L1Cache_forwardToCache_ptr)).isReady())) {" << endl;
+          out << "      const RequestMsg* in_msg_ptr;" << endl;
+          out << "      in_msg_ptr = dynamic_cast<const RequestMsg*>(((*m_L1Cache_forwardToCache_ptr)).peek());" << endl;
+          out << "      if ((servicing_atomic && locked_read_request == ((*in_msg_ptr)).m_Address)) {" << endl;
+          out << "        postpone = true;" << endl;
+          out << "      }" << endl;
+          out << "    }" << endl;
+          out << "    if (!postpone) {" << endl;
         }
       }
       assert(port->existPair("c_code_in_port"));
@@ -877,9 +890,6 @@ void StateMachine::printCWakeup(ostream& out, string component)
         if (port->toString().find("forwardRequestNetwork_in") != string::npos) {
           out << "}" << endl;
         }
-        else if (port->toString().find("responseNetwork_in") != string::npos) {
-          out << "}" << endl;
-        }
       }
       out << endl;
     }