Commit 99329e9e authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Small improvements

Move some more time related stuff to controller_time
Add code to handle skipped samples.
parent 9d9e8e0e
......@@ -77,7 +77,7 @@ CTRL_BLOCKS += $(BLOCKS) $(BLOCKS_IL)
CTRL_BLOCK_LIBS += libblock.la
TARGETS += $(BLOCK_TARGETS)
CLEAN += $(BLOCK_TARGETS) $(BLOCK_OBJS)
CLEAN += $(BLOCK_TARGETS) $(BLOCK_OBJS) $(BLOCK_OBJS:.lo=.o)
SRCS += $(BLOCK_SRCS)
CTRL_TESTS += \
......
......@@ -61,6 +61,7 @@ void il2c_program(char *program)
fprintf(il2c_cout, "#include <string.h>\n");
fprintf(il2c_cout, "#include <math.h>\n");
fprintf(il2c_cout, "#include <controller/controller_block.h>\n");
fprintf(il2c_cout, "#include <controller/controller_time.h>\n");
fprintf(il2c_cout, "\n");
}
......
......@@ -16,5 +16,5 @@ $(DIR)/blocks: $(BLOCKS_OBJS)
TARGETS += $(TEST_TARGETS)
CLEAN += $(TEST_TARGETS) $(BLOCKS_OBJS)
CLEAN += $(BLOCKS_OBJSC:.il=.il2c.c) $(BLOCKS_OBJS)
SRCS += $(BLOCKS_SRCS)
......@@ -490,11 +490,6 @@ int controller_block_link(void)
uint64_t controller_time_nseconds = 0;
uint32_t controller_time_seconds = 0;
uint32_t controller_time_samplenr = 0;
uint32_t controller_samplenr = 0;
void controller_block_calculate(void)
{
struct calculate_func *calculate;
......@@ -510,6 +505,12 @@ void controller_block_calculate(void)
calculates_sub_cur %= calculates_sub;
}
void controller_block_skip(int64_t nr)
{
nr += calculates_sub_cur;
nr %= calculates_sub;
calculates_sub_cur = nr;
}
......
......@@ -178,13 +178,6 @@ struct controller_block_link {
char *type;
};
/* 64bit continuous counter */
extern uint64_t controller_time_nseconds;
extern uint32_t controller_time_seconds;
extern uint32_t controller_time_samplenr;
extern uint32_t controller_samplenr;
int controller_block_create(char *type, char *name, va_list ap);
void controller_block_add(struct controller_block *newblock);
struct controller_block *controller_block_find(char *name);
......@@ -208,6 +201,8 @@ int controller_block_link_nr(void);
int controller_block_sample_init(void);
void controller_block_calculate(void);
void controller_block_skip(int64_t nr);
char *controller_block_context_get(void);
void controller_block_context_set(char *new_context);
......
......@@ -26,6 +26,7 @@
#include <string.h>
#include <controller/controller_block.h>
#include <controller/controller_time.h>
#include <log/log.h>
static int nr_traces = 0;
......
......@@ -272,6 +272,7 @@ static void wait_next_default(struct timespec *t)
uint64_t tnow = timestamp();
if (sample_timing_sane(controller_time_nseconds, tnow)) {
controller_block_skip((int64_t)(tnow - controller_time_nseconds)/nsec_interval);
clock_gettime(sample_clock, t);
t->tv_nsec -= (t->tv_nsec % nsec_interval);
log_send(LOG_T_WARNING,
......@@ -299,6 +300,7 @@ static void wait_next_prestart(struct timespec *t)
uint64_t tnow = timestamp();
if (sample_timing_sane(controller_time_nseconds, tnow)) {
controller_block_skip((int64_t)(tnow - controller_time_nseconds)/nsec_interval);
clock_gettime(sample_clock, t);
t->tv_nsec -= (t->tv_nsec % nsec_interval);
log_send(LOG_T_WARNING,
......@@ -496,18 +498,6 @@ int controller_sample_shell_add(void)
}
//TODO deprecated
double controller_sample_period(struct controller_block *block)
{
struct controller_time *t = NULL;
if (block)
t = block->time;
log_send(LOG_T_WARNING, "controller_sample_period() is deprecated!");
return controller_time_period_get(t);
}
void controller_sample_start_hook(void (*func)(void *arg), void *arg)
{
controller_sample_start_hooks = realloc(
......
......@@ -20,6 +20,12 @@
#include <stdlib.h>
#include <math.h>
uint64_t controller_time_nseconds = 0;
uint32_t controller_time_seconds = 0;
uint32_t controller_time_samplenr = 0;
uint32_t controller_samplenr = 0;
struct controller_time {
double frequency;
double delay;
......
......@@ -19,6 +19,16 @@
#define _INCLUDE_CONTROLLER_TIME_H_
#include <stdbool.h>
#include <stdint.h>
/* 64bit continuous counter */
extern uint64_t controller_time_nseconds;
extern uint32_t controller_time_seconds;
extern uint32_t controller_time_samplenr;
extern uint32_t controller_samplenr;
void controller_time_param_set(double frequency, double delay);
......
......@@ -23,6 +23,7 @@
#include <controller/controller_block.h>
#include <controller/controller_command.h>
#include <controller/controller_time.h>
#include <test/test_block.h>
#include <log/log.h>
......
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