Beispiel #1
0
static void _master_registerPluginCallback(ConfigurationPluginElement* pe, Master* master) {
    utility_assert(pe);
    MAGIC_ASSERT(master);
    utility_assert(pe->id.isSet && pe->id.string);
    slave_addNewProgram(master->slave, pe->id.string->str, pe->path.string->str,
                        pe->startsymbol.isSet ? pe->startsymbol.string->str : NULL);
}
Beispiel #2
0
void worker_scheduleEvent(Event* event, SimulationTime nano_delay, GQuark receiver_node_id) {
    /* TODO create accessors, or better yet refactor the work to event class */
    utility_assert(event);

    /* get our thread-private worker */
    Worker* worker = _worker_getPrivate();

    /* when the event will execute */
    shadowevent_setTime(event, worker->clock_now + nano_delay);

    /* parties involved. sender may be NULL, receiver may not! */
    Host* sender = worker->cached_node;

    /* we MAY NOT OWN the receiver, so do not write to it! */
    Host* receiver = receiver_node_id == 0 ? sender : _slave_getHost(worker->slave, receiver_node_id);
    utility_assert(receiver);

    /* the NodeEvent needs a pointer to the correct node */
    shadowevent_setNode(event, receiver);

    /* if we are not going to execute any more events, free it and return */
    if(slave_isKilled(worker->slave)) {
        shadowevent_free(event);
        return;
    }

    /* engine is not killed, assert accurate worker clock */
    utility_assert(worker->clock_now != SIMTIME_INVALID);

    /* figure out where to push the event */
    if(worker->serialEventQueue) {
        /* single-threaded, push to global serial queue */
        eventqueue_push(worker->serialEventQueue, event);
    } else {
        /* non-local events must be properly delayed so the event wont show up at another worker
         * before the next scheduling interval. this is only a problem if the sender and
         * receivers have been assigned to different workers. */
        if(!host_isEqual(receiver, sender)) {
            SimulationTime jump = slave_getMinTimeJump(worker->slave);
            SimulationTime minTime = worker->clock_now + jump;

            /* warn and adjust time if needed */
            SimulationTime eventTime = shadowevent_getTime(event);
            if(eventTime < minTime) {
                info("Inter-node event time %"G_GUINT64_FORMAT" changed to %"G_GUINT64_FORMAT" due to minimum delay %"G_GUINT64_FORMAT,
                        eventTime, minTime, jump);
                shadowevent_setTime(event, minTime);
            }
        }

        /* multi-threaded, push event to receiver node */
        EventQueue* eventq = host_getEvents(receiver);
        eventqueue_push(eventq, event);
    }
}
Beispiel #3
0
static void _master_registerProcessCallback(ConfigurationProcessElement* pe, ProcessCallbackArgs* args) {
    utility_assert(pe && args);
    MAGIC_ASSERT(args->master);
    utility_assert(pe->plugin.isSet && pe->plugin.string);
    utility_assert(pe->arguments.isSet && pe->arguments.string);

    slave_addNewVirtualProcess(args->master->slave, args->hostParams->hostname, pe->plugin.string->str,
                        pe->preload.isSet ? pe->preload.string->str : NULL,
                        SIMTIME_ONE_SECOND * pe->starttime.integer,
                        pe->stoptime.isSet ? SIMTIME_ONE_SECOND * pe->stoptime.integer : 0,
                        pe->arguments.string->str);
}
Beispiel #4
0
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;
}
Beispiel #5
0
static void _scheduler_assignHostsToThread(Scheduler* scheduler, GQueue* hosts, pthread_t thread, uint maxAssignments) {
    MAGIC_ASSERT(scheduler);
    utility_assert(hosts);
    utility_assert(thread);

    guint numAssignments = 0;
    while((maxAssignments == 0 || numAssignments < maxAssignments) && !g_queue_is_empty(hosts)) {
        Host* host = (Host*) g_queue_pop_head(hosts);
        utility_assert(host);
        scheduler->policy->addHost(scheduler->policy, host, thread);
        numAssignments++;
    }
}
static Event* _schedulerpolicyhoststeal_popFromThread(SchedulerPolicy* policy, HostStealThreadData* tdata, GQueue* assignedHosts, SimulationTime barrier) {
    /* if there is no tdata, that means this thread didn't get any hosts assigned to it */
    if(!tdata) {
        return NULL;
    }

    HostStealPolicyData* data = policy->data;

    while(!g_queue_is_empty(assignedHosts) || tdata->runningHost) {
        /* if there's no running host, we completed the last assignment and need a new one */
        if(!tdata->runningHost) {
            tdata->runningHost = g_queue_pop_head(assignedHosts);
        }
        Host* host = tdata->runningHost;
        g_rw_lock_reader_lock(&data->lock);
        HostStealQueueData* qdata = g_hash_table_lookup(data->hostToQueueDataMap, host);
        g_rw_lock_reader_unlock(&data->lock);
        utility_assert(qdata);

        g_mutex_lock(&(qdata->lock));
        Event* nextEvent = priorityqueue_peek(qdata->pq);
        SimulationTime eventTime = (nextEvent != NULL) ? event_getTime(nextEvent) : SIMTIME_INVALID;

        if(nextEvent != NULL && eventTime < barrier) {
            utility_assert(eventTime >= qdata->lastEventTime);
            qdata->lastEventTime = eventTime;
            nextEvent = priorityqueue_pop(qdata->pq);
            qdata->nPopped++;
            /* migrate iff a migration is needed */
            _schedulerpolicyhoststeal_migrateHost(policy, host, pthread_self());
        } else {
            nextEvent = NULL;
        }

        if(nextEvent == NULL) {
            /* no more events on the runningHost, mark it as NULL so we get a new one */
            g_queue_push_tail(tdata->processedHosts, host);
            tdata->runningHost = NULL;
        }

        g_mutex_unlock(&(qdata->lock));

        if(nextEvent != NULL) {
            return nextEvent;
        }
    }

    /* if we make it here, all hosts for this thread have no more events before barrier */
    return NULL;
}
/* primarily a wrapper for dealing with TLS and the hostToThread map.
 * this does not affect unprocessedHosts/processedHosts/runningHost;
 * that migration should be done as normal (from/to the respective threads) */
static void _schedulerpolicyhoststeal_migrateHost(SchedulerPolicy* policy, Host* host, pthread_t newThread) {
    MAGIC_ASSERT(policy);
    HostStealPolicyData* data = policy->data;
    g_rw_lock_reader_lock(&data->lock);
    pthread_t oldThread = (pthread_t)g_hash_table_lookup(data->hostToThreadMap, host);
    if(oldThread == newThread) {
        g_rw_lock_reader_unlock(&data->lock);
        return;
    }
    HostStealThreadData* tdata = g_hash_table_lookup(data->threadToThreadDataMap, GUINT_TO_POINTER(oldThread));
    HostStealThreadData* tdataNew = g_hash_table_lookup(data->threadToThreadDataMap, GUINT_TO_POINTER(newThread));
    g_rw_lock_reader_unlock(&data->lock);
    /* check that there's actually a thread we're migrating from */
    if(tdata) {
        /* Sanity check that the host isn't being run on another thread while migrating.
         * Ostensibly, we could make this check on *all* threads, but this is simpler, faster,
         * and should catch most bugs (since it's presumably the thread we're stealing from
         * that would be running it).
         */
        utility_assert(tdata->runningHost != tdataNew->runningHost);
        /* migrate the TLS of all objects associated with this host */
        host_migrate(host, &oldThread, &newThread);
    }
    _schedulerpolicyhoststeal_addHost(policy, host, newThread);
}
Beispiel #8
0
gint host_epollGetEvents(Host* host, gint handle,
		struct epoll_event* eventArray, gint eventArrayLength, gint* nEvents) {
	MAGIC_ASSERT(host);

	/* EBADF  epfd is not a valid file descriptor. */
	Descriptor* descriptor = host_lookupDescriptor(host, handle);
	if(descriptor == NULL) {
		return EBADF;
	}

	DescriptorStatus status = descriptor_getStatus(descriptor);
	if(status & DS_CLOSED) {
		warning("descriptor handle '%i' not a valid open descriptor", handle);
		return EBADF;
	}

	/* EINVAL epfd is not an epoll file descriptor */
	if(descriptor_getType(descriptor) != DT_EPOLL) {
		return EINVAL;
	}

	Epoll* epoll = (Epoll*) descriptor;
	gint ret = epoll_getEvents(epoll, eventArray, eventArrayLength, nEvents);

	for(gint i = 0; i < *nEvents; i++) {
	    if(!host_isShadowDescriptor(host, eventArray[i].data.fd)) {
	        /* the fd is a file that the OS handled for us, translate to shadow fd */
	        eventArray[i].data.fd = host_getShadowHandle(host, eventArray[i].data.fd);
	        utility_assert(eventArray[i].data.fd >= 0);
	    }
	}

	return ret;
}
Beispiel #9
0
static void _main_countTLSProcessCallback(ConfigurationProcessElement* processElement, TLSCountingState* state) {
    utility_assert(processElement && state);

    /* each process must have a plugin, and can optionally have a preload lib */
    ConfigurationPluginElement* pluginElement = NULL;
    ConfigurationPluginElement* preloadElement = NULL;

    if(processElement && processElement->plugin.isSet && processElement->plugin.string) {
        gchar* pluginID = processElement->plugin.string->str;
        pluginElement = configuration_getPluginElementByID(state->config, pluginID);
    }

    if(processElement && processElement->preload.isSet && processElement->preload.string) {
        gchar* preloadID = processElement->preload.string->str;
        preloadElement = configuration_getPluginElementByID(state->config, preloadID);
    }

    /* get the TLS used by this process and store total needed by this host element */
    gulong tlsSizePerProcess = _main_getTLSUsedByProcess(state, pluginElement, preloadElement);
    if(tlsSizePerProcess == 0) {
        warning("skipping process with plugin '%s' at path '%s' "
                "and preload '%s' at path '%s' "
                "when computing total needed static TLS size",
                pluginElement ? pluginElement->id.string->str : "n/a",
                pluginElement ? pluginElement->path.string->str : "n/a",
                preloadElement ? preloadElement->id.string->str : "n/a",
                preloadElement ? preloadElement->path.string->str : "n/a");
    } else {
        state->tlsSizeTotal += (tlsSizePerProcess * state->currentHostQuantity);
    }
}
Beispiel #10
0
void master_slaveFinishedCurrentWindow(Master* master, SimulationTime minNextEventTime) {
    MAGIC_ASSERT(master);
    utility_assert(minNextEventTime != SIMTIME_INVALID);

    /* TODO: once we get multiple slaves, we have to block them here
     * until they have all notified us that they are finished */

    /* update our detected min jump time */
    master->minJumpTime = master->nextMinJumpTime;

    /* update the next interval window based on next event times */
    SimulationTime newStart = minNextEventTime;
    SimulationTime newEnd = minNextEventTime + master_getMinTimeJump(master);

    /* update the new window end as one interval past the new window start,
     * making sure we dont run over the experiment end time */
    if(newEnd > master->endTime) {
        newEnd = master->endTime;
    }

    /* if we are done, make sure the workers know about it */
    if(newStart >= newEnd) {
        master_setKilled(master, TRUE);
    }

    /* finally, set the new values */
    master->executeWindowStart = newStart;
    master->executeWindowEnd = newEnd;
}
Beispiel #11
0
guint utility_int16Hash(gconstpointer value) {
    utility_assert(value);
    /* make sure upper bits are zero */
    gint key = 0;
    key = (gint) *((gint16*)value);
    return g_int_hash(&key);
}
Beispiel #12
0
/* this func is called whenever g_logv is called, not just in our log code */
void logging_handleLog(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) {
    /* GLogLevelFlags* configuredLogLevel = user_data; */
    const gchar* logDomainStr = log_domain ? log_domain : "shadow";
    const gchar* messageStr = message ? message : "n/a";

    /* check again if the message should be filtered */
    if(worker_isFiltered(log_level)) {
        return;
    }

    gulong hours = 0, minutes = 0, seconds = 0, microseconds = 0;
    gulong elapsed = 0;
    if(worker_isAlive()) {
        elapsed = (gulong) g_timer_elapsed(worker_getRunTimer(), &microseconds);
        hours = elapsed / 3600;
        elapsed %= 3600;
        minutes = elapsed / 60;
        seconds = elapsed % 60;
    }

    g_print("%02lu:%02lu:%02lu.%06lu %s\n", hours, minutes, seconds, microseconds, messageStr);

    if(log_level & G_LOG_LEVEL_ERROR) {
        /* error level logs always abort, but glibs messages are not that useful.
         * lets override that with our own debug info and preemtively abort */
        utility_assert(FALSE && "failure due to error-level log message");
    }
}
Beispiel #13
0
gboolean priorityqueue_push(PriorityQueue *q, gpointer data) {
	utility_assert(q);
	if (q->size >= q->heapSize) {
		q->heapSize *= 2;
		gpointer *oldheap = q->heap;
		q->heap = g_renew(gpointer, q->heap, q->heapSize);
		if (q->heap != oldheap) {
			_priorityqueue_refresh_map(q);
		}
	}

	gpointer *oldentry = g_hash_table_lookup(q->map, data);
	if (oldentry != NULL) {
		gint oldindex = oldentry - q->heap;
		_priorityqueue_heapify_up(q, _priorityqueue_heapify_down(q, oldindex));
		return FALSE;
	}

	guint index = q->size;
	q->heap[index] = data;
	g_hash_table_insert(q->map, data, q->heap + index);
	q->size += 1;
	_priorityqueue_heapify_up(q, index);

	return TRUE;
}
Beispiel #14
0
gpointer priorityqueue_peek(PriorityQueue *q) {
	utility_assert(q);
	if (q->size > 0) {
		return q->heap[0];
	}
	return NULL;
}
Beispiel #15
0
Worker* worker_new(Slave* slave) {
    /* make sure this isnt called twice on the same thread! */
    utility_assert(!worker_isAlive());

    Worker* worker = g_new0(Worker, 1);
    MAGIC_INIT(worker);

    worker->slave = slave;
    worker->thread_id = slave_generateWorkerID(slave);
    worker->clock_now = SIMTIME_INVALID;
    worker->clock_last = SIMTIME_INVALID;
    worker->clock_barrier = SIMTIME_INVALID;

    /* each worker needs a private copy of each plug-in library */
    worker->privatePrograms = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, (GDestroyNotify)program_free);

    if(slave_getWorkerCount(slave) <= 1) {
        /* this will cause events to get pushed to this queue instead of host queues */
        worker->serialEventQueue = eventqueue_new();
    }

    g_private_replace(&workerKey, worker);

    return worker;
}
Beispiel #16
0
Master* master_new(Options* options) {
    utility_assert(options);

    /* Don't do anything in this function that will cause a log message. The
     * global engine is still NULL since we are creating it now, and logging
     * here will cause an assertion error.
     */

    Master* master = g_new0(Master, 1);
    MAGIC_INIT(master);

    master->options = options;
    master->random = random_new(options_getRandomSeed(options));

    gint minRunAhead = (SimulationTime)options_getMinRunAhead(options);
    master->minJumpTimeConfig = ((SimulationTime)minRunAhead) * SIMTIME_ONE_MILLISECOND;

    /* these are only avail in glib >= 2.30
     * setup signal handlers for gracefully handling shutdowns */
//  TODO
//  g_unix_signal_add(SIGTERM, (GSourceFunc)_master_handleInterruptSignal, master);
//  g_unix_signal_add(SIGHUP, (GSourceFunc)_master_handleInterruptSignal, master);
//  g_unix_signal_add(SIGINT, (GSourceFunc)_master_handleInterruptSignal, master);

    message("simulation master created");
    return master;
}
Beispiel #17
0
void priorityqueue_free(PriorityQueue *q) {
	utility_assert(q);
	priorityqueue_clear(q);
	g_hash_table_destroy(q->map);
	g_free(q->heap);
	g_slice_free(PriorityQueue, q);
}
Beispiel #18
0
gboolean master_slaveFinishedCurrentRound(Master* master, SimulationTime minNextEventTime,
        SimulationTime* executeWindowStart, SimulationTime* executeWindowEnd) {
    MAGIC_ASSERT(master);
    utility_assert(executeWindowStart && executeWindowEnd);

    /* TODO: once we get multiple slaves, we have to block them here
     * until they have all notified us that they are finished */

    /* update our detected min jump time */
    master->minJumpTime = master->nextMinJumpTime;

    /* update the next interval window based on next event times */
    SimulationTime newStart = minNextEventTime;
    SimulationTime newEnd = minNextEventTime + _master_getMinTimeJump(master);

    /* update the new window end as one interval past the new window start,
     * making sure we dont run over the experiment end time */
    if(newEnd > master->endTime) {
        newEnd = master->endTime;
    }

    /* finally, set the new values */
    master->executeWindowStart = newStart;
    master->executeWindowEnd = newEnd;

    *executeWindowStart = master->executeWindowStart;
    *executeWindowEnd = master->executeWindowEnd;

    /* return TRUE if we should keep running */
    return newStart < newEnd ? TRUE : FALSE;
}
Beispiel #19
0
gboolean utility_int16Equal(gconstpointer value1, gconstpointer value2) {
    utility_assert(value1 && value2);
    /* make sure upper bits are zero */
    gint key1 = 0, key2 = 0;
    key1 = (gint) *((gint16*)value1);
    key2 = (gint) *((gint16*)value2);
    return g_int_equal(&key1, &key2);
}
Beispiel #20
0
void scheduler_push(Scheduler* scheduler, Event* event, GQuark senderHostID, GQuark receiverHostID) {
    MAGIC_ASSERT(scheduler);

    SimulationTime eventTime = event_getTime(event);
    if(eventTime > scheduler->endTime) {
        event_unref(event);
        return;
    }

    /* parties involved. sender may be NULL, receiver may not!
     * we MAY NOT OWN the receiver, so do not write to it! */
    Host* sender = scheduler_getHost(scheduler, senderHostID);
    Host* receiver = scheduler_getHost(scheduler, receiverHostID);
    utility_assert(receiver);
    utility_assert(receiver == event_getHost(event));

    /* push to a queue based on the policy */
    scheduler->policy->push(scheduler->policy, event, sender, receiver, scheduler->currentRound.endTime);
}
Beispiel #21
0
void random_nextNBytes(Random* random, guchar* buffer, gint nbytes) {
    utility_assert(random);
    gint offset = 0;
    while(offset < nbytes) {
        gint randInt = random_nextInt(random);
        gint n = MIN((nbytes - offset), sizeof(gint));
        memmove(&buffer[offset], &randInt, n);
        offset += n;
    }
}
Beispiel #22
0
gsize socket_getOutputBufferSpace(Socket* socket) {
    MAGIC_ASSERT(socket);
    utility_assert(socket->outputBufferSize >= socket->outputBufferLength);
    gsize bufferSize = socket_getOutputBufferSize(socket);
    if(bufferSize < socket->outputBufferLength) {
        return 0;
    } else {
        return bufferSize - socket->outputBufferLength;
    }
}
Beispiel #23
0
static gint _host_monitorDescriptor(Host* host, Descriptor* descriptor) {
	MAGIC_ASSERT(host);

	/* make sure there are no collisions before inserting */
	gint* handle = descriptor_getHandleReference(descriptor);
	utility_assert(handle && !host_lookupDescriptor(host, *handle));
	g_hash_table_replace(host->descriptors, handle, descriptor);

	return *handle;
}
static void _networkinterface_scheduleNextReceive(NetworkInterface* interface) {
	/* the next packets need to be received and processed */
	SimulationTime batchTime = worker_getConfig()->interfaceBatchTime;

	/* receive packets in batches */
	while(!g_queue_is_empty(interface->inBuffer) &&
			interface->receiveNanosecondsConsumed <= batchTime) {
		/* get the next packet */
		Packet* packet = g_queue_pop_head(interface->inBuffer);
		utility_assert(packet);

		/* successfully received */
		packet_addDeliveryStatus(packet, PDS_RCV_INTERFACE_RECEIVED);
		_networkinterface_pcapWritePacket(interface, packet);

		/* free up buffer space */
		guint length = packet_getPayloadLength(packet) + packet_getHeaderSize(packet);
		interface->inBufferLength -= length;

		/* calculate how long it took to 'receive' this packet */
		interface->receiveNanosecondsConsumed += (length * interface->timePerByteDown);

		/* hand it off to the correct socket layer */
		gint key = packet_getDestinationAssociationKey(packet);
		Socket* socket = g_hash_table_lookup(interface->boundSockets, GINT_TO_POINTER(key));

		/* if the socket closed, just drop the packet */
		gint socketHandle = -1;
		if(socket) {
			socketHandle = *descriptor_getHandleReference((Descriptor*)socket);
			socket_pushInPacket(socket, packet);
		} else {
			packet_addDeliveryStatus(packet, PDS_RCV_INTERFACE_DROPPED);
		}

		packet_unref(packet);

		/* count our bandwidth usage by interface, and by socket handle if possible */
		tracker_addInputBytes(host_getTracker(worker_getCurrentHost()),(guint64)length, socketHandle);
	}

	/*
	 * we need to call back and try to receive more, even if we didnt consume all
	 * of our batch time, because we might have more packets to receive then.
	 */
	SimulationTime receiveTime = (SimulationTime) floor(interface->receiveNanosecondsConsumed);
	if(receiveTime >= SIMTIME_ONE_NANOSECOND) {
		/* we are 'receiving' the packets */
		interface->flags |= NIF_RECEIVING;
		/* call back when the packets are 'received' */
		InterfaceReceivedEvent* event = interfacereceived_new(interface);
		/* event destination is our node */
		worker_scheduleEvent((Event*)event, receiveTime, 0);
	}
}
Beispiel #25
0
Slave* slave_new(Master* master, Configuration* config, guint randomSeed) {
    Slave* slave = g_new0(Slave, 1);
    MAGIC_INIT(slave);

    g_mutex_init(&(slave->lock));
    g_mutex_init(&(slave->pluginInitLock));

    slave->master = master;
    slave->config = config;
    slave->random = random_new(randomSeed);

    slave->rawFrequencyKHz = utility_getRawCPUFrequency(CONFIG_CPU_MAX_FREQ_FILE);
    if(slave->rawFrequencyKHz == 0) {
        info("unable to read '%s' for copying", CONFIG_CPU_MAX_FREQ_FILE);
    }

    slave->hosts = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, NULL);
    slave->programs = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, (GDestroyNotify)program_free);

    slave->dns = dns_new();

    slave->nWorkers = (guint) configuration_getNWorkerThreads(config);
    slave->mainThreadWorker = worker_new(slave);

    slave->cwdPath = g_get_current_dir();
    slave->dataPath = g_build_filename(slave->cwdPath, "shadow.data", NULL);
    slave->hostsPath = g_build_filename(slave->dataPath, "hosts", NULL);

    if(g_file_test(slave->dataPath, G_FILE_TEST_EXISTS)) {
        gboolean success = utility_removeAll(slave->dataPath);
        utility_assert(success);
    }

    gchar* templateDataPath = g_build_filename(slave->cwdPath, "shadow.data.template", NULL);
    if(g_file_test(templateDataPath, G_FILE_TEST_EXISTS)) {
        gboolean success = utility_copyAll(templateDataPath, slave->dataPath);
        utility_assert(success);
    }
    g_free(templateDataPath);

    return slave;
}
Beispiel #26
0
static void _main_countTLSHostCallback(ConfigurationHostElement* hostElement, TLSCountingState* state) {
    utility_assert(hostElement && state);

    if(hostElement && hostElement->processes) {
        /* make sure to get the new quantity set of each host */
        state->currentHostQuantity = hostElement->quantity.isSet ? ((guint)hostElement->quantity.integer) : 1;

        /* now figure out the plugins that each process is using */
        g_queue_foreach(hostElement->processes, (GFunc)_main_countTLSProcessCallback, state);
    }
}
Beispiel #27
0
void priorityqueue_clear(PriorityQueue *q) {
	utility_assert(q);
	if(q->freeFunc) {
		for (guint i = 0; i < q->size; i++) {
			q->freeFunc(q->heap[i]);
			q->heap[i] = NULL;
		}
	}
	q->size = 0;
	g_hash_table_remove_all(q->map);
}
Beispiel #28
0
static void _process_callbackTimerExpired(Process* proc, ProcessCallbackData* data) {
    MAGIC_ASSERT(proc);
    utility_assert(data);

    if(process_isRunning(proc)) {
        program_swapInState(proc->prog, proc->state);
        thread_executeCallback2(proc->mainThread, data->callback, data->data, data->argument);
        program_swapOutState(proc->prog, proc->state);
    }

    g_free(data);
}
Beispiel #29
0
void master_updateMinTimeJump(Master* master, gdouble minPathLatency) {
    MAGIC_ASSERT(master);
    if(master->nextMinJumpTime == 0 || minPathLatency < master->nextMinJumpTime) {
        utility_assert(minPathLatency > 0.0f);
        SimulationTime oldJumpMS = master->nextMinJumpTime;
        master->nextMinJumpTime = ((SimulationTime)minPathLatency) * SIMTIME_ONE_MILLISECOND;
        info("updated topology minimum time jump from %"G_GUINT64_FORMAT" to %"G_GUINT64_FORMAT" nanoseconds; "
             "the minimum config override is %s (%"G_GUINT64_FORMAT" nanoseconds)",
                oldJumpMS, master->nextMinJumpTime, master->minJumpTimeConfig > 0 ? "set" : "not set",
                master->minJumpTimeConfig);
    }
}
void networkinterface_associate(NetworkInterface* interface, Socket* socket) {
	MAGIC_ASSERT(interface);

	gint key = socket_getAssociationKey(socket);

	/* make sure there is no collision */
	utility_assert(!networkinterface_isAssociated(interface, key));

	/* insert to our storage */
	g_hash_table_replace(interface->boundSockets, GINT_TO_POINTER(key), socket);
	descriptor_ref(socket);
}