Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tsn-measures
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
tsn-measures
Commits
558f0fa2
Commit
558f0fa2
authored
Apr 24, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add polling timerthread
parent
52325bb4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
2 deletions
+51
-2
latency-measure/build/Makefile
latency-measure/build/Makefile
+1
-1
latency-measure/src/main.c
latency-measure/src/main.c
+50
-1
No files found.
latency-measure/build/Makefile
View file @
558f0fa2
...
...
@@ -7,7 +7,7 @@ SRCS = main.c
OBJS
=
$(SRCS:%.c=%.o)
CFLAGS
=
-Og
-g
-Wall
-We
rror
-We
xtra
CFLAGS
=
-Og
-g
-Wall
-Wextra
CFLAGS
+=
-MD
-MP
CFLAGS
+=
-I
$(SRCDIR)
CFLAGS
+=
-std
=
gnu99
...
...
latency-measure/src/main.c
View file @
558f0fa2
...
...
@@ -59,6 +59,55 @@ static inline struct timespec add_ns(struct timespec t, int64_t ns) {
return
ret
;
}
// Real-time thread
// Sends packets at a regular intervall
static
void
*
timerthread_poll
(
void
*
p
)
{
struct
timespec
next
;
struct
timespec
current
;
struct
sched_param
priority
;
thread_param_t
*
param
=
(
thread_param_t
*
)
p
;
thread_stat_t
*
stat
=
&
param
->
stat
;
priority
.
sched_priority
=
param
->
priority
;
int
err
=
sched_setscheduler
(
0
,
SCHED_FIFO
,
&
priority
);
if
(
err
)
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set priority"
);
stat
->
max_diff
=
0
;
stat
->
min_diff
=
1000000
;
clock_gettime
(
CLOCK_ID
,
&
next
);
next
=
add_ns
(
next
,
param
->
interval
);
for
(
stat
->
nb_cycles
=
0
;;
stat
->
nb_cycles
++
)
{
if
(
param
->
max_cycles
)
if
(
stat
->
nb_cycles
>=
param
->
max_cycles
)
break
;
for
(;;)
{
clock_gettime
(
CLOCK_ID
,
&
current
);
if
(
current
.
tv_nsec
==
next
.
tv_nsec
)
break
;
}
int64_t
diff
=
diff_ns
(
current
,
next
);
stat
->
max_diff
=
max
(
stat
->
max_diff
,
diff
);
stat
->
min_diff
=
min
(
stat
->
min_diff
,
diff
);
next
=
add_ns
(
current
,
param
->
interval
);
}
printf
(
"Done
\n
"
);
return
NULL
;
}
// Real-time thread
// Sends packets at a regular intervall
...
...
@@ -154,7 +203,7 @@ int main(int argc, char *argv[]) {
sleep
(
1
);
pthread_create
(
&
thread
,
NULL
,
timerthread
,
(
void
*
)
&
param
);
pthread_create
(
&
thread
,
NULL
,
timerthread
_poll
,
(
void
*
)
&
param
);
sleep
(
10
);
...
...
Write
Preview
Markdown
is supported
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