[Avida-SVN] r3582 - in development/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Mon Dec 28 14:06:06 PST 2009
Author: beckma24
Date: 2009-12-28 17:06:06 -0500 (Mon, 28 Dec 2009)
New Revision: 3582
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/main/cDeme.h
development/source/main/cOrganism.cc
development/source/main/cOrganism.h
development/source/main/cStats.cc
Log:
Added a few more message types, 6 total. Fixed INTERRUPT_PREEMPTION_ENABLED config option. Add Interrupted string to organism trace when it is interrupted.
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2009-12-28 20:25:53 UTC (rev 3581)
+++ development/source/cpu/cHardwareCPU.cc 2009-12-28 22:06:06 UTC (rev 3582)
@@ -540,10 +540,16 @@
// Interrupt
tInstLibEntry<tMethod>("send-msg-interrupt-type0", &cHardwareCPU::Inst_SendMessageInterruptType0, nInstFlag::STALL),
tInstLibEntry<tMethod>("send-msg-interrupt-type1", &cHardwareCPU::Inst_SendMessageInterruptType1, nInstFlag::STALL),
- tInstLibEntry<tMethod>("send-msg-interrupt-type2", &cHardwareCPU::Inst_SendMessageInterruptType1, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("send-msg-interrupt-type2", &cHardwareCPU::Inst_SendMessageInterruptType2, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("send-msg-interrupt-type3", &cHardwareCPU::Inst_SendMessageInterruptType3, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("send-msg-interrupt-type4", &cHardwareCPU::Inst_SendMessageInterruptType4, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("send-msg-interrupt-type5", &cHardwareCPU::Inst_SendMessageInterruptType5, nInstFlag::STALL),
tInstLibEntry<tMethod>("msg-handler-type0", &cHardwareCPU::Inst_START_Handler),
tInstLibEntry<tMethod>("msg-handler-type1", &cHardwareCPU::Inst_START_Handler),
tInstLibEntry<tMethod>("msg-handler-type2", &cHardwareCPU::Inst_START_Handler),
+ tInstLibEntry<tMethod>("msg-handler-type3", &cHardwareCPU::Inst_START_Handler),
+ tInstLibEntry<tMethod>("msg-handler-type4", &cHardwareCPU::Inst_START_Handler),
+ tInstLibEntry<tMethod>("msg-handler-type5", &cHardwareCPU::Inst_START_Handler),
tInstLibEntry<tMethod>("moved-handler", &cHardwareCPU::Inst_START_Handler),
tInstLibEntry<tMethod>("end-handler", &cHardwareCPU::Inst_End_Handler),
@@ -963,11 +969,15 @@
fp << setbase(16) << "[0x" << GetRegister(i) << "] " << setbase(10);
}
+ if (m_organism->IsInterrupted()) {
+ fp << " Interrupted";
+ }
+
// Add some extra information if additional time costs are used for instructions,
// leave this out if there are no differences to keep it cleaner
if ( m_organism->GetPhenotype().GetTimeUsed() != m_organism->GetPhenotype().GetCPUCyclesUsed() )
{
- fp << " EnergyUsed:" << m_organism->GetPhenotype().GetTimeUsed();
+ fp << " EnergyUsed:" << m_organism->GetPhenotype().GetTimeUsed(); // this is not energy that is used by the energy model
}
fp << endl;
@@ -1435,7 +1445,7 @@
break;
}
- m_organism->GetOrgInterface().GetDeme()->IncOrgInterruptedCount();
+ m_organism->SetInterrupted(true);
return true;
}
@@ -7301,21 +7311,14 @@
}
// Same as cHardwareCPU::Inst_SendMessage. Added for clearity
-bool cHardwareCPU::Inst_SendMessageInterruptType0(cAvidaContext& ctx)
-{
- return SendMessage(ctx, 0);
-}
+bool cHardwareCPU::Inst_SendMessageInterruptType0(cAvidaContext& ctx) { return SendMessage(ctx, 0); }
-bool cHardwareCPU::Inst_SendMessageInterruptType1(cAvidaContext& ctx)
-{
- return SendMessage(ctx, 1);
-}
+bool cHardwareCPU::Inst_SendMessageInterruptType1(cAvidaContext& ctx) { return SendMessage(ctx, 1); }
+bool cHardwareCPU::Inst_SendMessageInterruptType2(cAvidaContext& ctx) { return SendMessage(ctx, 2); }
+bool cHardwareCPU::Inst_SendMessageInterruptType3(cAvidaContext& ctx) { return SendMessage(ctx, 3); }
+bool cHardwareCPU::Inst_SendMessageInterruptType4(cAvidaContext& ctx) { return SendMessage(ctx, 4); }
+bool cHardwareCPU::Inst_SendMessageInterruptType5(cAvidaContext& ctx) { return SendMessage(ctx, 5); }
-bool cHardwareCPU::Inst_SendMessageInterruptType2(cAvidaContext& ctx)
-{
- return SendMessage(ctx, 2);
-}
-
// jumps one instruction passed end-handler
bool cHardwareCPU::Inst_START_Handler(cAvidaContext& ctx) {
m_advance_ip = false;
@@ -7340,7 +7343,7 @@
bool cHardwareCPU::Inst_End_Handler(cAvidaContext& ctx) {
if(KillThread()) { // return false if one thread exists or max threads has been reached... this is OK.
- m_organism->GetOrgInterface().GetDeme()->DecOrgInterruptedCount();
+ m_organism->SetInterrupted(false);
} // previous thread is now restored
// if interrupt enabled and more messages to process then reinterrupt
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2009-12-28 20:25:53 UTC (rev 3581)
+++ development/source/cpu/cHardwareCPU.h 2009-12-28 22:06:06 UTC (rev 3582)
@@ -766,6 +766,9 @@
bool Inst_SendMessageInterruptType0(cAvidaContext& ctx);
bool Inst_SendMessageInterruptType1(cAvidaContext& ctx);
bool Inst_SendMessageInterruptType2(cAvidaContext& ctx);
+ bool Inst_SendMessageInterruptType3(cAvidaContext& ctx);
+ bool Inst_SendMessageInterruptType4(cAvidaContext& ctx);
+ bool Inst_SendMessageInterruptType5(cAvidaContext& ctx);
bool Inst_START_Handler(cAvidaContext& ctx);
bool Inst_End_Handler(cAvidaContext& ctx);
Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h 2009-12-28 20:25:53 UTC (rev 3581)
+++ development/source/main/cDeme.h 2009-12-28 22:06:06 UTC (rev 3582)
@@ -345,11 +345,6 @@
unsigned int GetMessageSuccessfullySent() { return MSG_SuccessfullySent; }
unsigned int GetMessageDropped() { return MSG_dropped; }
unsigned int GetMessageSendFailed() { return MSG_sendFailed; }
-
- // --- Organism Interrupted Stats --- //
- void IncOrgInterruptedCount() { ++numOrgsInterruted; }
- void DecOrgInterruptedCount() { --numOrgsInterruted; }
- int GetOrgInterruptedCount() { return numOrgsInterruted; }
// --- Pheromones --- //
void AddPheromone(int absolute_cell_id, double value);
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2009-12-28 20:25:53 UTC (rev 3581)
+++ development/source/main/cOrganism.cc 2009-12-28 22:06:06 UTC (rev 3582)
@@ -77,6 +77,7 @@
, m_is_running(false)
, m_is_sleeping(false)
, m_is_dead(false)
+ , m_is_interrupted(false)
, killed_event(false)
, m_net(NULL)
, m_msg(0)
@@ -118,6 +119,7 @@
, m_is_running(false)
, m_is_sleeping(false)
, m_is_dead(false)
+ , m_is_interrupted(false)
, killed_event(false)
, m_net(NULL)
, m_msg(0)
@@ -159,6 +161,7 @@
, m_is_running(false)
, m_is_sleeping(false)
, m_is_dead(false)
+ , m_is_interrupted(false)
, killed_event(false)
, m_net(NULL)
, m_msg(0)
@@ -899,12 +902,11 @@
if (m_world->GetConfig().INTERRUPT_ENABLED.Get()) {
// if preempt running interrupt thread and #thread < max_threads
-// if (m_world->GetConfig().INTERRUPT_PREEMPTION_ENABLED.Get() && m_world->GetConfig().MAX_CPU_THREADS.Get() >= m_hardware->GetNumThreads()) {
+ if (!IsInterrupted() || m_world->GetConfig().INTERRUPT_PREEMPTION_ENABLED.Get()) {
// then create new thread and load its registers
m_hardware->InterruptThread(cHardwareBase::MSG_INTERRUPT);
-// }
- // else cannot preempt!
- // do nothing since message is already buffered. It will get processed later.
+ }
+ // Else cannot preempt! Do nothing since message is already buffered. It will get processed later.
}
}
@@ -928,7 +930,6 @@
return ret;
}
-
void cOrganism::Move(cAvidaContext& ctx)
{
assert(m_interface);
@@ -936,7 +937,7 @@
if (m_world->GetConfig().INTERRUPT_ENABLED.Get()) {
// if preempt running interrupt thread and #thread < max_threads
- if (m_world->GetConfig().INTERRUPT_PREEMPTION_ENABLED.Get() && m_world->GetConfig().MAX_CPU_THREADS.Get() >= m_hardware->GetNumThreads()) {
+ if (!IsInterrupted() || m_world->GetConfig().INTERRUPT_PREEMPTION_ENABLED.Get()) {
// then create new thread and load its registers
m_hardware->InterruptThread(cHardwareBase::MOVE_INTERRUPT);
}
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2009-12-28 20:25:53 UTC (rev 3581)
+++ development/source/main/cOrganism.h 2009-12-28 22:06:06 UTC (rev 3582)
@@ -129,8 +129,9 @@
int m_max_executed; // Max number of instruction executed before death.
bool m_is_running; // Does this organism have the CPU?
- bool m_is_sleeping; // Is this organisms sleeping?
+ bool m_is_sleeping; // Is this organism sleeping?
bool m_is_dead; // Is this organism dead?
+ bool m_is_interrupted; // Is this organism interrupted?
bool killed_event;
@@ -221,6 +222,9 @@
bool IsDead() { return m_is_dead; }
+ void SetInterrupted(bool value) { m_is_interrupted = value; }
+ bool IsInterrupted() { return m_is_interrupted; }
+
bool GetPheromoneStatus() { return m_pher_drop; }
void TogglePheromone() { m_pher_drop = (m_pher_drop == true) ? false : true; }
void SetPheromone(bool newval) { m_pher_drop = newval; }
Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc 2009-12-28 20:25:53 UTC (rev 3581)
+++ development/source/main/cStats.cc 2009-12-28 22:06:06 UTC (rev 3582)
@@ -28,6 +28,7 @@
#include "cDataFile.h"
#include "cEnvironment.h"
#include "cGenotype.h"
+#include "cHardwareBase.h"
#include "cHardwareManager.h"
#include "cInstSet.h"
#include "cPopulation.h"
@@ -905,13 +906,23 @@
int numDemes = pop.GetNumDemes();
unsigned int totalOrgsInterrupted(0);
+ unsigned int totalThreads(0);
- for( int i=0; i < numDemes; i++ ){
- totalOrgsInterrupted += pop.GetDeme(i).GetOrgInterruptedCount();
- }
+ for( int i = 0; i < numDemes; ++i ){
+ const cDeme & cur_deme = m_world->GetPopulation().GetDeme(i);;
+ for (int j = 0; j < cur_deme.GetSize(); ++j) {
+ cPopulationCell& cur_cell = cur_deme.GetCell(j);
+ if (cur_cell.IsOccupied() == false) {
+ continue;
+ } else if (cur_cell.GetOrganism()->IsInterrupted()) {
+ ++totalOrgsInterrupted;
+ totalThreads += cur_cell.GetOrganism()->GetHardware().GetNumThreads();
+ }
+ }
+ }
df.Write(totalOrgsInterrupted, "Total organisms interrupted");
-
+ df.Write(totalThreads, "Total threads");
df.Endl();
}
More information about the Avida-cvs
mailing list