Commit 779473bf authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Fix log code to better handle full queue.

Fix time code to properly recognize invallid combinations and return -1
Add new lowest common multiple calculation.
(Subsample number now has a maximum of 10000, but this is an arbitrary limit)
Add code to add frequency domain to .dot dump files.
parent f1619d45
......@@ -139,6 +139,9 @@ void log_send(enum log_type type, char *fmt, ...)
log_lost = true;
}
if (log_lost) {
/* Reset msg_wr to this value to make sure we don't get
to far lost in the queue */
msgs_wr = msg;
__sync_fetch_and_add(&lost_counter, 1);
}
......
......@@ -23,13 +23,16 @@
#include <controller/controller_block.h>
#include <controller/controller_trace.h>
#include <controller/controller_bus.h>
#include <controller/controller_time.h>
void controller_dumpdot(char *filename)
{
FILE *fddot;
int i, j, contextnr;
int i, j, contextnr, timenr;
char **contextlist = NULL;
int contextlist_size = 0;
struct controller_time **timelist = NULL;
int timelist_size = 0;
fddot = fopen(filename, "w");
if (!fddot)
......@@ -68,74 +71,116 @@ void controller_dumpdot(char *filename)
fprintf(fddot, "\t\tlabel=\"%s\";\n", contextlist[contextnr]);
fprintf(fddot, "\n");
/* find all time domains */
for (i = 0; i < controller_block_nr(); i++) {
struct controller_block *block;
int rows = 1;
block = controller_block_get(i);
struct controller_block *block = controller_block_get(i);
bool newtime = true;
if (strcmp(block->context, contextlist[contextnr]))
continue;
for (j = 0; j < timelist_size; j++) {
if (block->time == timelist[j])
newtime = false;
}
if (newtime) {
timelist_size++;
timelist = realloc(timelist, sizeof(struct controller_time *) * timelist_size);
timelist[timelist_size - 1] = block->time;
}
}
for (timenr = 0; timenr < timelist_size; timenr++) {
fprintf(fddot, "\t\tsubgraph cluster_%d_%d {\n", contextnr, timenr);
fprintf(fddot, "\t\t\tlabel=\"%f Hz, %f sec delay\";\n",
controller_time_frequency_get(timelist[timenr]),
controller_time_delay_get(timelist[timenr]));
fprintf(fddot, "\n");
for (i = 0; i < controller_block_nr(); i++) {
struct controller_block *block;
int rows = 1;
block = controller_block_get(i);
if (strcmp(block->context, contextlist[contextnr]))
continue;
if (block->time != timelist[timenr])
continue;
if (block->inputs > rows)
rows = block->inputs;
if (block->outputs > rows)
rows = block->outputs;
fprintf(fddot, "\t\t%s [label=<\n", block->name);
fprintf(fddot,
"\t\t\t<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\">\n");
if (block->inputs > rows)
rows = block->inputs;
if (block->outputs > rows)
rows = block->outputs;
fprintf(fddot, "\t\t%s [label=<\n", block->name);
fprintf(fddot,
"\t\t\t<TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\">\n");
for (j = 0; j < rows; j++) {
fprintf(fddot, "\t\t\t<TR>\n");
for (j = 0; j < rows; j++) {
fprintf(fddot, "\t\t\t<TR>\n");
if (block->inputs > j) {
fprintf(fddot,
"\t\t\t\t<TD PORT=\"in_%s\" BGCOLOR=\"lightblue\">%s</TD>\n",
block->input[j].name, block->input[j].name);
} else if (block->outputs > j) {
fprintf(fddot, "\t\t\t\t<TD BORDER=\"0\"></TD>\n");
}
if (block->inputs > j) {
fprintf(fddot,
"\t\t\t\t<TD PORT=\"in_%s\" BGCOLOR=\"lightblue\">%s</TD>\n",
block->input[j].name, block->input[j].name);
} else if (block->outputs > j) {
fprintf(fddot, "\t\t\t\t<TD BORDER=\"0\"></TD>\n");
}
if (j == 0) {
fprintf(fddot,
"\t\t\t\t<TD PORT=\"block_port\" ROWSPAN=\"%d\" BGCOLOR=\"yellow\">%s<BR/><I>%s</I></TD>\n",
rows, block->name, block->type);
}
if (j == 0) {
fprintf(fddot,
"\t\t\t\t<TD PORT=\"block_port\" ROWSPAN=\"%d\" BGCOLOR=\"yellow\">%s<BR/><I>%s</I></TD>\n",
rows, block->name, block->type);
}
if (block->outputs > j) {
fprintf(fddot,
"\t\t\t\t<TD PORT=\"out_%s\" BGCOLOR=\"lightblue\">%s</TD>\n",
block->output[j].name, block->output[j].name);
if (block->outputs > j) {
fprintf(fddot,
"\t\t\t\t<TD PORT=\"out_%s\" BGCOLOR=\"lightblue\">%s</TD>\n",
block->output[j].name, block->output[j].name);
}
fprintf(fddot, "\t\t\t\t</TR>\n");
}
fprintf(fddot, "\t\t\t\t</TR>\n");
}
fprintf(fddot, "\t\t\t</TABLE>>];\n");
fprintf(fddot, "\n");
fprintf(fddot, "\t\t\t</TABLE>>];\n");
fprintf(fddot, "\n");
for (j = 0; j < block->inputs; j++) {
if (block->input[j].ghostof) {
fprintf(fddot,
"\t\t%s:in_%s:e -> %s:in_%s:w [color=\"grey\"]\n",
block->name, block->input[j].name,
block->input[j].ghostof->block->name,
block->input[j].ghostof->name);
for (j = 0; j < block->inputs; j++) {
if (block->input[j].ghostof) {
fprintf(fddot,
"\t\t%s:in_%s:e -> %s:in_%s:w [color=\"grey\"]\n",
block->name, block->input[j].name,
block->input[j].ghostof->block->name,
block->input[j].ghostof->name);
}
}
}
for (j = 0; j < block->outputs; j++) {
if (block->output[j].source != block) {
fprintf(fddot,
"\t\t%s:out_%s:e -> %s:out_%s:w [color=\"grey\"]\n",
block->output[j].source->name,
block->output[j].sourceterm->name,
block->name, block->output[j].name);
for (j = 0; j < block->outputs; j++) {
if (block->output[j].source != block) {
fprintf(fddot,
"\t\t%s:out_%s:e -> %s:out_%s:w [color=\"grey\"]\n",
block->output[j].source->name,
block->output[j].sourceterm->name,
block->name, block->output[j].name);
}
}
}
fprintf(fddot, "\n");
fprintf(fddot, "\t\t};\n");
fprintf(fddot, "\n");
}
free(timelist);
timelist = NULL;
timelist_size = 0;
fprintf(fddot, "\n");
......
......@@ -92,16 +92,41 @@ double controller_time_period_get(struct controller_time *t)
return t->period;
for (entry = time_list; entry; entry = entry->next) {
period = fmax(period, entry->period);
period = fmin(period, entry->period);
}
return period;
}
double controller_time_frequency_get(struct controller_time *t)
{
struct controller_time *entry;
double frequency = param_frequency;
if (t)
return t->frequency;
for (entry = time_list; entry; entry = entry->next) {
frequency = fmax(frequency, entry->frequency);
}
return frequency;
}
double controller_time_delay_get(struct controller_time *t)
{
if (t)
return t->delay;
return param_delay;
}
static double processed_frequency = 1.0;
static double processed_period = 0.0;
static int processed_sub = 1;
#define PROCESSED_SUB_MAX 10000
int controller_time_process(void)
{
struct controller_time *entry;
......@@ -122,24 +147,43 @@ int controller_time_process(void)
off = entry->delay / processed_period;
if (fmod(processed_frequency, entry->frequency) != 0.0) {
log_send(LOG_T_DEBUG, "Frequencies not divisable");
log_send(LOG_T_ERROR,
"Frequencies %g Hz and %g Hz not divisable",
processed_frequency, entry->frequency);
return -1;
}
if (fmod(entry->delay, processed_period) != 0.0) {
log_send(LOG_T_DEBUG,
if (entry->delay && round(off) != off) {
log_send(LOG_T_ERROR,
"Period (%g) and delay (%g) not divisable",
processed_period, entry->delay);
return -1;
}
log_send(LOG_T_DEBUG,
"\tfrequency: %g Hz, period: %g sec, delay: %g sec, subsample: %g, offset: %g",
entry->frequency, entry->period, entry->delay, sub, off);
if (fmod(fmax(sub, processed_sub), fmin(sub, processed_sub)) != 0.0) {
processed_sub = sub * processed_sub;
} else if (sub > processed_sub) {
processed_sub = sub;
}
entry->sub = sub;
entry->off = off;
}
for (processed_sub = 1; processed_sub < PROCESSED_SUB_MAX; processed_sub++) {
bool lcm = true;
for (entry = time_list; entry; entry = entry->next) {
double factor = processed_sub / (double)entry->sub;
/* Take offset into account, LCM migh not be enough */
if (entry->off >= processed_sub)
lcm = false;
if (round(factor) != factor)
lcm = false;
}
if (lcm)
break;
}
if (processed_sub == PROCESSED_SUB_MAX) {
log_send(LOG_T_ERROR,
"No subsample number below maximum (%d) found",
PROCESSED_SUB_MAX);
return -1;
}
log_send(LOG_T_DEBUG,
"Sample frequency: %g Hz, period: %g sec, subsample: %d",
......
......@@ -35,6 +35,8 @@ void controller_time_param_set(double frequency, double delay);
struct controller_time *controller_time_get();
double controller_time_period_get(struct controller_time *t);
double controller_time_frequency_get(struct controller_time *t);
double controller_time_delay_get(struct controller_time *t);
int controller_time_process(void);
double controller_time_sample_frequency_get(void);
......
......@@ -132,7 +132,7 @@ static struct controller_block * block_test_command_create(char *name, int argc,
{
struct controller_block *block;
if (!(block = controller_block_alloc("test_input_bool", name,
if (!(block = controller_block_alloc("test_command", name,
sizeof(struct controller_block_private))))
return NULL;
......
......@@ -108,7 +108,7 @@ static struct controller_block * block_test_output_bool_create(char *name, int a
{
struct controller_block *block;
if (!(block = controller_block_alloc("test_input_bool", name,
if (!(block = controller_block_alloc("test_output_bool", name,
sizeof(struct controller_block_private))))
return NULL;
......
......@@ -118,7 +118,7 @@ static struct controller_block * block_test_output_float_create(char *name, int
{
struct controller_block *block;
if (!(block = controller_block_alloc("test_input_float", name,
if (!(block = controller_block_alloc("test_output_float", name,
sizeof(struct controller_block_private))))
return NULL;
......
......@@ -114,7 +114,7 @@ static struct controller_block * block_test_output_uint32_create(char *name, int
{
struct controller_block *block;
if (!(block = controller_block_alloc("test_input_uint32", name,
if (!(block = controller_block_alloc("test_output_uint32", name,
sizeof(struct controller_block_private))))
return NULL;
......
trigger {
{ "default" }
}
blocks (1.0, 0.0) {
{ "value_bool", "b1" }
}
blocks (2.0, 0.0) {
{ "value_bool", "b2" }
}
blocks (4.0, 0.0) {
{ "value_bool", "b4" }
}
blocks (8.0, 0.0) {
{ "value_bool", "b8" }
}
blocks (10.0, 0.0) {
{ "value_bool", "b10" }
}
blocks (50.0, 0.0) {
{ "value_bool", "b50" }
}
blocks (200.0, 0.0) {
{ "value_bool", "b200" }
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment