1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

simplified code: smaller changes

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@133 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2014-07-04 15:58:10 +00:00
parent dda247ab53
commit 3678f6773b
5 changed files with 47 additions and 38 deletions

View file

@ -39,16 +39,19 @@ struct path
/** A pointer to the last received message */
struct msg *last;
/** Counter for received messages */
unsigned int received;
/** Counter for messages which arrived reordered */
unsigned int delayed;
/** Counter for messages which arrived multiple times */
unsigned int duplicated;
/** Last known message number */
unsigned int sequence;
/** Counter for sent messages */
unsigned long sent;
/** Counter for received messages */
unsigned long received;
/** Counter for messages which arrived reordered */
unsigned long delayed;
/** Counter for messages which arrived multiple times */
unsigned long duplicated;
/** Counter for received messages with invalid device id or data */
unsigned int invalid;
unsigned long invalid;
/** The thread id for this path */
pthread_t tid;

View file

@ -22,6 +22,7 @@
/** Send messages */
static void * path_send(void *arg)
{
int sig;
struct path *p = (struct path *) arg;
timer_t tmr;
sigset_t set;
@ -49,10 +50,12 @@ static void * path_send(void *arg)
perror("Failed to start timer");
while (1) {
int sig;
sigwait(&set, &sig);
msg_send(p->last, p->out);
if (p->last) {
msg_send(p->last, p->out);
p->last = NULL;
p->sent++;
}
}
return NULL;
@ -64,39 +67,42 @@ static void * path_run(void *arg)
struct path *p = (struct path *) arg;
struct msg m;
p->last = &m;
/* Main thread loop */
while (1) {
msg_recv(&m, p->in); /* Receive message */
/* Check message sequence number */
if (m.sequence < p->sequence) {
p->delayed++;
p->received++;
/* Delayed messages will be skipped */
continue;
if (m.sequence == 0 && p->sequence > 0) {
path_stats(p);
info("Simulation restarted");
p->sequence = 0;
p->received = 0;
p->sent = 0;
p->delayed = 0;
p->duplicated = 0;
p->invalid = 0;
}
else if (m.sequence < p->sequence) {
p->delayed++;
}
else if (m.sequence == p->sequence) {
p->duplicated++;
}
p->sequence = m.sequence;
p->received++;
/* Call hook */
if (p->hook && p->hook(&m)) {
/* The hook can act as a simple filter
* Returning a non-zero value will skip
* the message from being forwarded */
if (p->hook && p->hook(&m))
continue;
}
/* At fixed rate mode, messages are send by another thread */
if (p->rate)
continue;
p->last = &m;
else
msg_send(p->last, p->out);
msg_send(p->last, p->out);
p->sequence = m.sequence;
p->sent++;
}
return NULL;
@ -126,8 +132,9 @@ int path_stop(struct path *p)
void path_stats(struct path *p)
{
info("%12s " MAG("=>") " %-12s: %-8u %-8u %-8u",
info("%12s " MAG("=>") " %-12s: %-8u %-8u %-8u %-8u %-8u",
p->in->name, p->out->name,
p->received, p->delayed,
p->duplicated);
p->sent, p->received, p->delayed,
p->duplicated, p->invalid
);
}

View file

@ -81,7 +81,7 @@ int main(int argc, char *argv[])
timer_create(CLOCKID, &sev, &t);
timer_settime(t, 0, &its, NULL);
while(1) pause();
while (1) pause();
timer_delete(t);

View file

@ -40,13 +40,13 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
struct node n;
struct node n = {
.name = "node"
};
struct msg m = {
.length = atoi(argv[1]) * sizeof(double)
};
memset(&n, 0, sizeof(struct node));
/* Setup signals */
struct sigaction sa_quit = {
.sa_flags = SA_SIGINFO,

View file

@ -85,7 +85,6 @@ static void stop()
/* Join all threads and print statistics */
for (struct path *p = paths; p; p = p->next) {
path_stop(p);
path_stats(p);
info("Stopping path: %12s " RED("=>") " %-12s",
p->in->name, p->out->name);
@ -181,9 +180,9 @@ int main(int argc, char *argv[])
info("");
info("Runtime Statistics:");
info("%12s " MAG("=>") " %-12s: %-8s %-8s %-8s",
"Source", "Destination", "#Recv", "#Delay", "#Duplicated");
info("--------------------------------------------------------------");
info("%12s " MAG("=>") " %-12s: %-8s %-8s %-8s %-8s %-8s",
"Source", "Destination", "#Sent", "#Recv", "#Delay", "#Dupl", "#Inval");
info("---------------------------------------------------------------------------");
while (1) {
sleep(5);