[Avida-SVN] r3580 - in development/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Mon Dec 28 09:13:02 PST 2009
Author: beckma24
Date: 2009-12-28 12:13:01 -0500 (Mon, 28 Dec 2009)
New Revision: 3580
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/main/cAvidaConfig.h
development/source/main/cOrganism.cc
Log:
Added instructions and config options for thread-centric version of the interrupt model. Currently, interrupts can be torn down, but not initiated.
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2009-12-28 03:26:12 UTC (rev 3579)
+++ development/source/cpu/cHardwareCPU.cc 2009-12-28 17:13:01 UTC (rev 3580)
@@ -537,6 +537,15 @@
tInstLibEntry<tMethod>("alarm-label-high", &cHardwareCPU::Inst_Alarm_Label),
tInstLibEntry<tMethod>("alarm-label-low", &cHardwareCPU::Inst_Alarm_Label),
+ // Interrupt
+ tInstLibEntry<tMethod>("send-msg-interrupt-type1", &cHardwareCPU::Inst_SendMessageInterruptType1, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("send-msg-interrupt-type2", &cHardwareCPU::Inst_SendMessageInterruptType1, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("msg-handler", &cHardwareCPU::Inst_MSG_Handler),
+ tInstLibEntry<tMethod>("msg-handler-type1", &cHardwareCPU::Inst_MSG_Handler),
+ tInstLibEntry<tMethod>("msg-handler-type2", &cHardwareCPU::Inst_MSG_Handler),
+// tInstLibEntry<tMethod>("moved-handler", &cHardwareCPU::Inst_Moved_Handler),
+ tInstLibEntry<tMethod>("end-handler", &cHardwareCPU::Inst_End_Handler),
+
// Placebo instructions
tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip),
@@ -1414,11 +1423,8 @@
// interrupt stuff
m_threads[num_threads].Reset(this,new_id);
-
m_cur_thread = num_threads;
- // move all heads to one past beginning
-
- // set all heads to same spot
+ // move all heads to one past beginning of interrupt
for(int i = 0; i < NUM_HEADS; i++) {
GetHead(i,new_id).Set(search_head.GetPosition());
}
@@ -1449,8 +1455,6 @@
if (m_cur_thread > kill_thread) m_cur_thread--;
- //TODO: it interrupt enabled and more messages to process then reinterrupt
-
return true;
}
@@ -7287,6 +7291,50 @@
return SendMessage(ctx);
}
+bool cHardwareCPU::Inst_SendMessageInterruptType1(cAvidaContext& ctx)
+{
+ return SendMessage(ctx, 1);
+}
+
+bool cHardwareCPU::Inst_SendMessageInterruptType2(cAvidaContext& ctx)
+{
+ return SendMessage(ctx, 2);
+}
+
+// jumps one instruction passed end-handler
+bool cHardwareCPU::Inst_MSG_Handler(cAvidaContext& ctx) {
+ m_advance_ip = false;
+ //Jump 1 instruction passed msg-handler
+ cInstruction label_inst = GetInstSet().GetInst("end-handler");
+
+ cHeadCPU search_head(IP());
+ int start_pos = search_head.GetPosition();
+ search_head++;
+
+ while (start_pos != search_head.GetPosition()) {
+ if (search_head.GetInst() == label_inst) {
+ // move IP to here
+ search_head++;
+ IP().Set(search_head.GetPosition());
+ return true;
+ }
+ search_head++;
+ }
+ return false;
+}
+
+bool cHardwareCPU::Inst_End_Handler(cAvidaContext& ctx) {
+ KillThread(); // return false if one thread exists or max threads has been reached... this is OK.
+ // previous thread is now restored
+
+ // if interrupt enabled and more messages to process then reinterrupt
+ if (m_organism->GetReceivedMessages().size() > 0) {
+ InterruptThread(MSG_INTERRUPT);
+ }
+ return true;
+}
+
+
bool cHardwareCPU::SendMessage(cAvidaContext& ctx, int messageType) {
const int label_reg = FindModifiedRegister(REG_BX);
const int data_reg = FindNextRegister(label_reg);
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2009-12-28 03:26:12 UTC (rev 3579)
+++ development/source/cpu/cHardwareCPU.h 2009-12-28 17:13:01 UTC (rev 3580)
@@ -762,6 +762,14 @@
bool Inst_Broadcast4(cAvidaContext& ctx);
bool Inst_Broadcast8(cAvidaContext& ctx);
+ // Active messaging //
+ bool Inst_SendMessageInterruptType1(cAvidaContext& ctx);
+ bool Inst_SendMessageInterruptType2(cAvidaContext& ctx);
+ bool Inst_MSG_Handler(cAvidaContext& ctx);
+ bool Inst_MSG_Handler_Type1(cAvidaContext& ctx);
+ bool Inst_MSG_Handler_Type2(cAvidaContext& ctx);
+ bool Inst_End_Handler(cAvidaContext& ctx);
+
//// Alarm ////
bool Inst_Alarm_MSG_local(cAvidaContext& ctx);
bool Inst_Alarm_MSG_multihop(cAvidaContext& ctx);
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2009-12-28 03:26:12 UTC (rev 3579)
+++ development/source/main/cAvidaConfig.h 2009-12-28 17:13:01 UTC (rev 3580)
@@ -504,10 +504,14 @@
CONFIG_ADD_VAR(NET_STYLE, int, 0, "Communication Style. 0 = Random Next, 1 = Receiver Facing");
CONFIG_ADD_GROUP(ORGANISM_MESSAGING_GROUP, "Organism Message-Based Communication");
- CONFIG_ADD_VAR(MESSAGE_SEND_BUFFER_SIZE, bool, 1, "Size of message send buffer (stores messages that were sent)\nTASKS NOT CHECKED ON 0!\n-1=inf, default=1.");
- CONFIG_ADD_VAR(MESSAGE_RECV_BUFFER_SIZE, bool, 8, "Size of message receive buffer (stores messages that are received); -1=inf, default=8.");
+ CONFIG_ADD_VAR(MESSAGE_SEND_BUFFER_SIZE, int, 1, "Size of message send buffer (stores messages that were sent)\nTASKS NOT CHECKED ON 0!\n-1=inf, default=1.");
+ CONFIG_ADD_VAR(MESSAGE_RECV_BUFFER_SIZE, int, 8, "Size of message receive buffer (stores messages that are received); -1=inf, default=8.");
CONFIG_ADD_VAR(MESSAGE_RECV_BUFFER_BEHAVIOR, bool, 0, "Behavior of message receive buffer; 0=drop oldest (default), 1=drop incoming");
+ CONFIG_ADD_GROUP(MESSAGING_INTERRUPT_GROUP, "Active Message Communication");
+ CONFIG_ADD_VAR(INTERRUPT_ENABLED, bool, 0, "Enable interruption of organism execution. 0/1 (off/on)");
+ CONFIG_ADD_VAR(INTERRUPT_PREEMPTION_ENABLED, bool, 0, "Enables preemption of currently executing interrupts. 0/1 (off/on)");
+
CONFIG_ADD_GROUP(BUY_SELL_GROUP, "Buying and Selling Parameters");
CONFIG_ADD_VAR(SAVE_RECEIVED, bool, 0, "Enable storage of all inputs bought from other orgs");
CONFIG_ADD_VAR(BUY_PRICE, int, 0, "price offered by organisms attempting to buy");
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2009-12-28 03:26:12 UTC (rev 3579)
+++ development/source/main/cOrganism.cc 2009-12-28 17:13:01 UTC (rev 3580)
@@ -898,6 +898,19 @@
//TODO: perform context switch
// need config option for depth of saved context stack
+
+ // if(INTERRUPT_ENABLED) {
+ // if preempt running interrupt thread and #thread < max_threads
+ // then create new thread and load its registers
+
+ // hardware->IP().Retreat();
+ // hardware->Inst_RetrieveMessage(m_world->GetDefaultContext());
+ // hardware->IP().Advance();
+
+ // else // cannot preempt
+ // do nothing since message is already buffered. It will get processed later.
+
+
}
More information about the Avida-cvs
mailing list