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
52325bb4
Commit
52325bb4
authored
Apr 23, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add minimum latency measurement
parent
7c106519
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
latency-measure/src/main.c
latency-measure/src/main.c
+11
-2
No files found.
latency-measure/src/main.c
View file @
52325bb4
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
typedef
struct
thread_stat
{
typedef
struct
thread_stat
{
int
nb_cycles
;
int
nb_cycles
;
int64_t
max_diff
;
int64_t
max_diff
;
int64_t
min_diff
;
}
thread_stat_t
;
}
thread_stat_t
;
typedef
struct
thread_param
{
typedef
struct
thread_param
{
...
@@ -41,6 +42,9 @@ static inline int64_t diff_ns(struct timespec t1, struct timespec t2) {
...
@@ -41,6 +42,9 @@ static inline int64_t diff_ns(struct timespec t1, struct timespec t2) {
static
inline
int64_t
max
(
int64_t
a
,
int64_t
b
)
{
static
inline
int64_t
max
(
int64_t
a
,
int64_t
b
)
{
return
a
>
b
?
a
:
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
)
{
static
inline
struct
timespec
add_ns
(
struct
timespec
t
,
int64_t
ns
)
{
struct
timespec
ret
;
struct
timespec
ret
;
...
@@ -75,6 +79,7 @@ static void *timerthread(void *p) {
...
@@ -75,6 +79,7 @@ static void *timerthread(void *p) {
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set priority"
);
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set priority"
);
stat
->
max_diff
=
0
;
stat
->
max_diff
=
0
;
stat
->
min_diff
=
1000000
;
clock_gettime
(
CLOCK_ID
,
&
next
);
clock_gettime
(
CLOCK_ID
,
&
next
);
next
=
add_ns
(
next
,
param
->
interval
);
next
=
add_ns
(
next
,
param
->
interval
);
...
@@ -88,7 +93,10 @@ static void *timerthread(void *p) {
...
@@ -88,7 +93,10 @@ static void *timerthread(void *p) {
clock_nanosleep
(
CLOCK_ID
,
TIMER_ABSTIME
,
&
next
,
NULL
);
clock_nanosleep
(
CLOCK_ID
,
TIMER_ABSTIME
,
&
next
,
NULL
);
clock_gettime
(
CLOCK_ID
,
&
current
);
clock_gettime
(
CLOCK_ID
,
&
current
);
stat
->
max_diff
=
max
(
stat
->
max_diff
,
diff_ns
(
current
,
next
));
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
);
next
=
add_ns
(
current
,
param
->
interval
);
}
}
...
@@ -144,13 +152,14 @@ int main(int argc, char *argv[]) {
...
@@ -144,13 +152,14 @@ int main(int argc, char *argv[]) {
process_options
(
argc
,
argv
,
&
param
,
&
main_param
);
process_options
(
argc
,
argv
,
&
param
,
&
main_param
);
sleep
(
3
);
sleep
(
1
);
pthread_create
(
&
thread
,
NULL
,
timerthread
,
(
void
*
)
&
param
);
pthread_create
(
&
thread
,
NULL
,
timerthread
,
(
void
*
)
&
param
);
sleep
(
10
);
sleep
(
10
);
printf
(
"Maximum latency: %"
PRIi64
"us (%d)
\n
"
,
(
param
.
stat
.
max_diff
/
1000
),
param
.
stat
.
nb_cycles
);
printf
(
"Maximum latency: %"
PRIi64
"us (%d)
\n
"
,
(
param
.
stat
.
max_diff
/
1000
),
param
.
stat
.
nb_cycles
);
printf
(
"Minimum latency: %"
PRIi64
"us (%d)
\n
"
,
(
param
.
stat
.
min_diff
/
1000
),
param
.
stat
.
nb_cycles
);
//if(err)
//if(err)
// error(EXIT_FAILURE, errno, "Couldn't create thread");
// error(EXIT_FAILURE, errno, "Couldn't create thread");
...
...
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