gpointer worker_runSerial(WorkLoad* workload) { utility_assert(workload); Worker* worker = _worker_getPrivate(); Event* nextEvent = eventqueue_peek(worker->serialEventQueue); if(nextEvent) { worker->clock_now = SIMTIME_INVALID; worker->clock_last = 0; /* process all events in the priority queue */ while(nextEvent && (shadowevent_getTime(nextEvent) < slave_getExecuteWindowEnd(worker->slave)) && (shadowevent_getTime(nextEvent) < slave_getEndTime(worker->slave))) { /* get next event */ nextEvent = eventqueue_pop(worker->serialEventQueue); worker->cached_event = nextEvent; worker->cached_node = shadowevent_getNode(nextEvent); /* ensure priority */ worker->clock_now = shadowevent_getTime(worker->cached_event); // engine->clock = worker->clock_now; utility_assert(worker->clock_now >= worker->clock_last); gboolean complete = shadowevent_run(worker->cached_event); if(complete) { shadowevent_free(worker->cached_event); } worker->cached_event = NULL; worker->cached_node = NULL; worker->clock_last = worker->clock_now; worker->clock_now = SIMTIME_INVALID; nextEvent = eventqueue_peek(worker->serialEventQueue); } } slave_setKilled(worker->slave, TRUE); /* in single thread mode, we must free the nodes */ GList* hosts = workload->hosts; while(hosts) { worker->cached_node = hosts->data; host_freeAllApplications(worker->cached_node); worker->cached_node = NULL; hosts = hosts->next; } g_list_foreach(workload->hosts, (GFunc) host_free, NULL); return NULL; }
static guint _worker_processNode(Worker* worker, Node* node, SimulationTime barrier) { /* update cache, reset clocks */ worker->cached_node = node; worker->clock_last = SIMTIME_INVALID; worker->clock_now = SIMTIME_INVALID; worker->clock_barrier = barrier; /* lock the node */ node_lock(worker->cached_node); EventQueue* eventq = node_getEvents(worker->cached_node); Event* nextEvent = eventqueue_peek(eventq); /* process all events in the nodes local queue */ guint nEventsProcessed = 0; while(nextEvent && (nextEvent->time < worker->clock_barrier)) { worker->cached_event = eventqueue_pop(eventq); MAGIC_ASSERT(worker->cached_event); /* make sure we don't jump backward in time */ worker->clock_now = worker->cached_event->time; if(worker->clock_last != SIMTIME_INVALID) { g_assert(worker->clock_now >= worker->clock_last); } /* do the local task */ gboolean complete = shadowevent_run(worker->cached_event); /* update times */ worker->clock_last = worker->clock_now; worker->clock_now = SIMTIME_INVALID; /* finished event can now be destroyed */ if(complete) { shadowevent_free(worker->cached_event); nEventsProcessed++; } /* get the next event, or NULL will tell us to break */ nextEvent = eventqueue_peek(eventq); } /* unlock, clear cache */ node_unlock(worker->cached_node); worker->cached_node = NULL; worker->cached_event = NULL; return nEventsProcessed; }
static gint _engine_processEvents(Engine* engine) { MAGIC_ASSERT(engine); Event* next_event = asyncpriorityqueue_peek(engine->masterEventQueue); if(next_event) { Worker* worker = worker_getPrivate(); worker->clock_now = SIMTIME_INVALID; worker->clock_last = 0; worker->cached_engine = engine; /* process all events in the priority queue */ while(next_event && (next_event->time < engine->executeWindowEnd) && (next_event->time < engine->endTime)) { /* get next event */ next_event = asyncpriorityqueue_pop(engine->masterEventQueue); worker->cached_event = next_event; MAGIC_ASSERT(worker->cached_event); worker->cached_node = next_event->node; /* ensure priority */ worker->clock_now = worker->cached_event->time; engine->clock = worker->clock_now; g_assert(worker->clock_now >= worker->clock_last); gboolean complete = shadowevent_run(worker->cached_event); if(complete) { shadowevent_free(worker->cached_event); } worker->cached_event = NULL; worker->cached_node = NULL; worker->clock_last = worker->clock_now; worker->clock_now = SIMTIME_INVALID; next_event = asyncpriorityqueue_peek(engine->masterEventQueue); } } return 0; }