Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
dt_ctrl
Commits
e247dcae
Commit
e247dcae
authored
Apr 29, 2014
by
Jeroen Vreeken
Browse files
Merge branch 'jeroen' into ui
parents
c56fc591
6606002f
Changes
2
Show whitespace changes
Inline
Side-by-side
controller/controller/controller_sample.c
View file @
e247dcae
...
...
@@ -29,6 +29,7 @@
#include
<string.h>
#include
<sys/mman.h>
#include
<errno.h>
#include
<signal.h>
#include
"controller_block.h"
#include
"controller_sample.h"
...
...
@@ -125,6 +126,34 @@ static ssize_t sample_timing_snprintf(struct sample_timing *st,
}
static
int
sample_timing_sane
(
struct
timespec
*
t_exp
,
struct
timespec
*
t_act
)
{
long
s_diff
;
long
n_diff
;
s_diff
=
t_act
->
tv_sec
-
t_exp
->
tv_sec
;
if
(
s_diff
<
0
)
{
return
-
1
;
}
if
(
s_diff
>
1
)
{
return
1
;
}
n_diff
=
s_diff
*
1000
*
1000
*
1000
;
n_diff
+=
t_act
->
tv_nsec
-
t_exp
->
tv_nsec
;
if
(
n_diff
>
nsec_interval
*
10
)
{
return
1
;
}
return
0
;
}
static
void
alarm_handler
(
int
d
)
{
log_send
(
LOG_T_ERROR
,
"Sample has been inactive to long!"
);
}
/*
This thread should be realtime....
*/
...
...
@@ -142,6 +171,16 @@ static void *sample_thread(void *arg)
pthread_mutex_t
lock
;
pthread_cond_t
cv
;
#endif
sigset_t
sigset
;
struct
sigaction
sigact
;
sigemptyset
(
&
sigset
);
sigaddset
(
&
sigset
,
SIGALRM
);
sigprocmask
(
SIG_UNBLOCK
,
&
sigset
,
NULL
);
sigact
.
sa_handler
=
alarm_handler
;
sigemptyset
(
&
sigact
.
sa_mask
);
sigact
.
sa_flags
=
0
;
sigaction
(
SIGALRM
,
&
sigact
,
NULL
);
log_send
(
LOG_T_DEBUG
,
"Starting sample thread"
);
controller_sample_thread_running
=
true
;
...
...
@@ -206,14 +245,26 @@ static void *sample_thread(void *arg)
clock_gettime
(
clock
,
&
t_end
);
if
(
sample_timing_diff_nsec
(
&
t
,
&
t_end
)
>
nsec_interval
)
{
controller_sampleoverruns
++
;
}
if
(
sample_timing_sane
(
&
t
,
&
t_start
))
{
log_send
(
LOG_T_ERROR
,
"Time sanity check triggered: %lld.%09ld %lld.%09ld"
,
(
long
long
)
t
.
tv_sec
,
t
.
tv_nsec
,
(
long
long
)
t_start
.
tv_sec
,
t_start
.
tv_nsec
);
t
.
tv_sec
=
t_start
.
tv_sec
;
t
.
tv_nsec
=
(
t_start
.
tv_nsec
/
nsec_interval
)
*
nsec_interval
;
log_send
(
LOG_T_WARNING
,
"Using current time for next sampe: %lld.%09ld"
,
(
long
long
)
t
.
tv_sec
,
t
.
tv_nsec
);
}
else
{
sample_timing_add
(
&
st_start
,
&
t
,
&
t_start
);
sample_timing_add
(
&
st_io
,
&
t_start
,
&
t_io
);
sample_timing_add
(
&
st_end
,
&
t
,
&
t_end
);
sample_timing_add
(
&
st_sample
,
&
t_start
,
&
t_end
);
if
(
sample_timing_diff_nsec
(
&
t
,
&
t_end
)
>
nsec_interval
)
{
controller_sampleoverruns
++
;
}
alarm
(
1
);
}
return
NULL
;
}
...
...
controller/dt_ctrl.c
View file @
e247dcae
...
...
@@ -33,6 +33,7 @@
#include
<string.h>
#include
<unistd.h>
#include
<math.h>
#include
<signal.h>
#include
"dynarg.h"
...
...
@@ -53,6 +54,11 @@ int main(int argc, char **argv)
{
char
*
ctrl_filename
;
char
*
dot_filename
;
sigset_t
sigset
;
sigemptyset
(
&
sigset
);
sigaddset
(
&
sigset
,
SIGALRM
);
sigprocmask
(
SIG_BLOCK
,
&
sigset
,
NULL
);
log_server_start
(
CTRL_LOG_PORT
,
LOG_T_DEBUG
,
LOG_T_INFO
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment