2009-06-26 21:13:17 +00:00
|
|
|
|
|
|
|
#include "task.h"
|
2009-06-27 00:21:49 +00:00
|
|
|
#include <glib/gstdio.h>
|
2009-06-26 21:13:17 +00:00
|
|
|
|
|
|
|
void task_free(task_t *task) {
|
|
|
|
if (!task) return;
|
2009-06-27 00:21:49 +00:00
|
|
|
g_slice_free1(task->in_size * sizeof(gdouble), task->in_old);
|
2009-06-26 21:13:17 +00:00
|
|
|
g_slice_free1(task->in_size * sizeof(gdouble), task->in);
|
|
|
|
g_slice_free1(task->out_size * sizeof(gdouble), task->out);
|
|
|
|
g_slice_free(task_t, task);
|
|
|
|
}
|
|
|
|
|
2009-06-27 00:21:49 +00:00
|
|
|
task_t* task_new(guint scenario) {
|
2009-06-26 21:13:17 +00:00
|
|
|
task_t *task = g_slice_new(task_t);
|
|
|
|
task->scenario = scenario;
|
2009-06-26 21:58:27 +00:00
|
|
|
task->timestamp = 0;
|
2009-06-27 00:21:49 +00:00
|
|
|
task->in_size = ovm_ins;
|
|
|
|
task->out_size = ovm_outs;
|
2009-06-26 21:13:17 +00:00
|
|
|
task->in = g_slice_alloc0(task->in_size * sizeof(gdouble));
|
2009-06-27 00:21:49 +00:00
|
|
|
task->in_old = g_slice_alloc0(task->in_size * sizeof(gdouble));
|
2009-06-26 21:13:17 +00:00
|
|
|
task->out = g_slice_alloc0(task->out_size * sizeof(gdouble));
|
|
|
|
return task;
|
|
|
|
}
|
2009-06-27 00:21:49 +00:00
|
|
|
|
|
|
|
void task_trace_start(task_t *task, const gchar *tracefile) {
|
|
|
|
guint32 buf[3];
|
|
|
|
task->tracefd = g_open(tracefile, O_CREAT | O_TRUNC | O_WRONLY, 0644);
|
|
|
|
|
|
|
|
if (-1 == task->tracefd) {
|
|
|
|
fprintf(stderr, "Couldn't open file %s: %s\n", tracefile, g_strerror(errno));
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[0] = 0xCAFEBABE;
|
|
|
|
buf[1] = 439;
|
|
|
|
buf[2] = (guint32) task->scenario;
|
|
|
|
write(task->tracefd, buf, 12);
|
|
|
|
}
|
|
|
|
|
|
|
|
void task_trace_end(task_t *task) {
|
|
|
|
guint32 buf[2];
|
|
|
|
buf[0] = task->timestamp;
|
|
|
|
buf[1] = 0;
|
|
|
|
write(task->tracefd, buf, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
void task_trace_step(task_t *task) {
|
|
|
|
gboolean ch2 = task->in_old[2] != task->in[2], ch3 = task->in_old[3] != task->in[3];
|
|
|
|
if ((0 == task->timestamp) || ch2 || ch3) {
|
|
|
|
guint32 buf[2+3*3], *cur = buf;
|
|
|
|
buf[0] = task->timestamp;
|
|
|
|
buf[1] = 0;
|
|
|
|
cur = &buf[2];
|
|
|
|
|
|
|
|
if (ch2) {
|
|
|
|
buf[1]++;
|
|
|
|
*cur++ = 2;
|
|
|
|
memcpy(cur, &task->in[2], sizeof(gdouble));
|
|
|
|
task->in_old[2] = task->in[2];
|
|
|
|
cur += 2;
|
|
|
|
}
|
|
|
|
if (ch3) {
|
|
|
|
buf[1]++;
|
|
|
|
*cur++ = 3;
|
|
|
|
memcpy(cur, &task->in[3], sizeof(gdouble));
|
|
|
|
task->in_old[3] = task->in[3];
|
|
|
|
cur += 2;
|
|
|
|
}
|
|
|
|
if (0 == task->timestamp) {
|
|
|
|
gdouble s = task->scenario;
|
|
|
|
buf[1]++;
|
|
|
|
*cur++ = 0x3e80;
|
|
|
|
memcpy(cur, &s, sizeof(gdouble));
|
|
|
|
cur += 2;
|
|
|
|
}
|
|
|
|
write(task->tracefd, buf, (cur-buf)*4);
|
|
|
|
}
|
|
|
|
}
|