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
d9ef8c97
Commit
d9ef8c97
authored
Apr 23, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store max latency only and add a refresh option
parent
70739230
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
8 deletions
+25
-8
.gitignore
.gitignore
+1
-0
latency-measure/src/main.c
latency-measure/src/main.c
+24
-8
No files found.
.gitignore
View file @
d9ef8c97
...
...
@@ -2,3 +2,4 @@
*.d
simple-server/build/main
simple-client/build/main
latency-measure/build/main
latency-measure/src/main.c
View file @
d9ef8c97
...
...
@@ -15,7 +15,7 @@
typedef
struct
thread_stat
{
int
nb_cycles
;
int64_t
diff
;
int64_t
max_
diff
;
}
thread_stat_t
;
typedef
struct
thread_param
{
...
...
@@ -25,6 +25,10 @@ typedef struct thread_param {
thread_stat_t
stat
;
}
thread_param_t
;
typedef
struct
main_param
{
int
refresh_rate
;
}
main_param_t
;
static
inline
int64_t
diff_ns
(
struct
timespec
t1
,
struct
timespec
t2
)
{
int64_t
diff
;
...
...
@@ -34,6 +38,10 @@ static inline int64_t diff_ns(struct timespec t1, struct timespec t2) {
return
diff
;
}
static
inline
int64_t
max
(
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
;
...
...
@@ -66,6 +74,8 @@ static void *timerthread(void *p) {
if
(
err
)
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set priority"
);
stat
->
max_diff
=
0
;
clock_gettime
(
CLOCK_ID
,
&
next
);
next
=
add_ns
(
next
,
param
->
interval
);
...
...
@@ -78,7 +88,7 @@ static void *timerthread(void *p) {
clock_nanosleep
(
CLOCK_ID
,
TIMER_ABSTIME
,
&
next
,
NULL
);
clock_gettime
(
CLOCK_ID
,
&
current
);
stat
->
diff
=
diff_ns
(
current
,
next
);
stat
->
max_diff
=
max
(
stat
->
max_diff
,
diff_ns
(
current
,
next
)
);
next
=
add_ns
(
current
,
param
->
interval
);
}
...
...
@@ -86,11 +96,11 @@ static void *timerthread(void *p) {
return
NULL
;
}
static
void
process_options
(
int
argc
,
char
*
argv
[],
thread_param_t
*
param
)
{
static
void
process_options
(
int
argc
,
char
*
argv
[],
thread_param_t
*
param
,
main_param_t
*
main_param
)
{
for
(;;)
{
int
c
=
getopt
(
argc
,
argv
,
"l:p:i:"
);
int
c
=
getopt
(
argc
,
argv
,
"l:p:i:
r:
"
);
if
(
c
==
-
1
)
break
;
...
...
@@ -103,7 +113,10 @@ static void process_options(int argc, char *argv[], thread_param_t * param) {
param
->
max_cycles
=
atoi
(
optarg
);
break
;
case
'i'
:
param
->
interval
=
atoi
(
optarg
);
param
->
interval
=
(
atoi
(
optarg
)
*
1000
);
break
;
case
'r'
:
main_param
->
refresh_rate
=
atoi
(
optarg
);
break
;
default:
exit
(
EXIT_FAILURE
);
...
...
@@ -118,13 +131,16 @@ int main(int argc, char *argv[]) {
pthread_t
thread
;
thread_param_t
param
;
main_param_t
main_param
;
// Default values
param
.
interval
=
NSECS_PER_SECOND
;
param
.
max_cycles
=
100
;
param
.
priority
=
80
;
process_options
(
argc
,
argv
,
&
param
);
main_param
.
refresh_rate
=
10000
;
process_options
(
argc
,
argv
,
&
param
,
&
main_param
);
int
err
=
pthread_create
(
&
thread
,
NULL
,
timerthread
,
(
void
*
)
&
param
);
...
...
@@ -134,9 +150,9 @@ int main(int argc, char *argv[]) {
for
(;;)
{
usleep
(
100000
);
usleep
(
main_param
.
refresh_rate
);
printf
(
"
Diff: %"
PRIi64
"us (%d)
\n
"
,
(
param
.
stat
.
diff
/
1000
),
param
.
stat
.
nb_cycles
);
printf
(
"
Maximum latency: %"
PRIi64
"us (%d)
\n
"
,
(
param
.
stat
.
max_
diff
/
1000
),
param
.
stat
.
nb_cycles
);
if
(
param
.
max_cycles
==
param
.
stat
.
nb_cycles
)
break
;
...
...
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