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
471ae88b
Commit
471ae88b
authored
May 06, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix syntax error and improve comments
parent
51e3fe90
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
46 deletions
+51
-46
latency-measure/src/main.c
latency-measure/src/main.c
+51
-46
No files found.
latency-measure/src/main.c
View file @
471ae88b
...
@@ -36,56 +36,17 @@ typedef struct main_param {
...
@@ -36,56 +36,17 @@ typedef struct main_param {
int
refresh_rate
;
int
refresh_rate
;
}
main_param_t
;
}
main_param_t
;
static
inline
int64_t
diff_ns
(
struct
timespec
t1
,
struct
timespec
t2
)
{
static
inline
int64_t
diff_ns
(
struct
timespec
t1
,
struct
timespec
t2
);
int64_t
diff
;
static
inline
int64_t
max
(
int64_t
a
,
int64_t
b
);
static
inline
int64_t
min
(
int64_t
a
,
int64_t
b
);
diff
=
NSECS_PER_SECOND
*
(
t1
.
tv_sec
-
t2
.
tv_sec
);
static
inline
struct
timespec
add_ns
(
struct
timespec
t
,
int64_t
ns
);
diff
+=
((
int64_t
)
t1
.
tv_nsec
)
-
((
int64_t
)
t2
.
tv_nsec
);
static
inline
struct
timespec
sub_ns
(
struct
timespec
t
,
int64_t
ns
);
if
(
diff
<
0
)
diff
=
-
diff
;
return
diff
;
}
static
inline
int64_t
max
(
int64_t
a
,
int64_t
b
)
{
return
a
>
b
?
a
:
b
;
}
static
inline
int64_t
min
(
int64_t
a
,
int64_t
b
)
{
return
a
<
b
?
a
:
b
;
}
static
inline
struct
timespec
add_ns
(
struct
timespec
t
,
int64_t
ns
)
{
struct
timespec
ret
;
ret
.
tv_nsec
=
t
.
tv_nsec
+
ns
;
ret
.
tv_sec
=
t
.
tv_sec
;
if
(
ret
.
tv_nsec
>=
NSECS_PER_SECOND
)
{
ret
.
tv_sec
++
;
ret
.
tv_nsec
-=
NSECS_PER_SECOND
;
}
return
ret
;
}
static
inline
struct
timespec
sub_ns
(
struct
timespec
t
,
int64_t
ns
)
{
struct
timespec
ret
;
ret
.
tv_nsec
=
t
.
tv_nsec
-
ns
;
ret
.
tv_sec
=
t
.
tv_sec
;
if
(
ret
.
tv_nsec
<
0
)
{
ret
.
tv_sec
--
;
ret
.
tv_nsec
+=
NSECS_PER_SECOND
;
}
return
ret
;
}
static
void
sleep_poll
(
struct
timespec
*
next
,
struct
timespec
*
current
)
{
static
void
sleep_poll
(
struct
timespec
*
next
,
struct
timespec
*
current
)
{
struct
timespec
pre_next
;
struct
timespec
pre_next
;
pre_next
=
sub_ns
(
next
,
3000000
);
pre_next
=
sub_ns
(
next
,
3000000
);
clock_nanosleep
(
CLOCK_ID
,
TIMER_ABSTIME
,
clock_nanosleep
(
CLOCK_ID
,
TIMER_ABSTIME
,
pre_next
);
for
(;;)
{
for
(;;)
{
clock_gettime
(
CLOCK_ID
,
current
);
clock_gettime
(
CLOCK_ID
,
current
);
if
(
current
->
tv_sec
>
next
->
tv_sec
||
(
current
->
tv_sec
==
next
->
tv_sec
&&
current
->
tv_nsec
>=
next
->
tv_nsec
)
)
if
(
current
->
tv_sec
>
next
->
tv_sec
||
(
current
->
tv_sec
==
next
->
tv_sec
&&
current
->
tv_nsec
>=
next
->
tv_nsec
)
)
...
@@ -99,7 +60,6 @@ static void sleep_nanosleep(struct timespec * next, struct timespec * current) {
...
@@ -99,7 +60,6 @@ static void sleep_nanosleep(struct timespec * next, struct timespec * current) {
}
}
// Real-time thread
// Real-time thread
// Sends packets at a regular intervall
static
void
*
timerthread
(
void
*
p
)
{
static
void
*
timerthread
(
void
*
p
)
{
struct
timespec
next
;
struct
timespec
next
;
...
@@ -240,3 +200,48 @@ int main(int argc, char *argv[]) {
...
@@ -240,3 +200,48 @@ int main(int argc, char *argv[]) {
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
}
}
static
inline
int64_t
diff_ns
(
struct
timespec
t1
,
struct
timespec
t2
)
{
int64_t
diff
;
diff
=
NSECS_PER_SECOND
*
(
t1
.
tv_sec
-
t2
.
tv_sec
);
diff
+=
((
int64_t
)
t1
.
tv_nsec
)
-
((
int64_t
)
t2
.
tv_nsec
);
if
(
diff
<
0
)
diff
=
-
diff
;
return
diff
;
}
static
inline
int64_t
max
(
int64_t
a
,
int64_t
b
)
{
return
a
>
b
?
a
:
b
;
}
static
inline
int64_t
min
(
int64_t
a
,
int64_t
b
)
{
return
a
<
b
?
a
:
b
;
}
static
inline
struct
timespec
add_ns
(
struct
timespec
t
,
int64_t
ns
)
{
struct
timespec
ret
;
ret
.
tv_nsec
=
t
.
tv_nsec
+
ns
;
ret
.
tv_sec
=
t
.
tv_sec
;
if
(
ret
.
tv_nsec
>=
NSECS_PER_SECOND
)
{
ret
.
tv_sec
++
;
ret
.
tv_nsec
-=
NSECS_PER_SECOND
;
}
return
ret
;
}
static
inline
struct
timespec
sub_ns
(
struct
timespec
t
,
int64_t
ns
)
{
struct
timespec
ret
;
ret
.
tv_nsec
=
t
.
tv_nsec
-
ns
;
ret
.
tv_sec
=
t
.
tv_sec
;
if
(
ret
.
tv_nsec
<
0
)
{
ret
.
tv_sec
--
;
ret
.
tv_nsec
+=
NSECS_PER_SECOND
;
}
return
ret
;
}
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