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
70739230
Commit
70739230
authored
Apr 23, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish basic version of the latency measure module
parent
7dff3f4b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
29 deletions
+47
-29
latency-measure/build/Makefile
latency-measure/build/Makefile
+0
-2
latency-measure/src/main.c
latency-measure/src/main.c
+47
-27
No files found.
latency-measure/build/Makefile
View file @
70739230
...
@@ -4,8 +4,6 @@ PROG = main
...
@@ -4,8 +4,6 @@ PROG = main
SRCDIR
=
../src
SRCDIR
=
../src
SRCS
=
main.c
SRCS
=
main.c
SRCS
+=
getip.c
SRCS
+=
send_packet.c
OBJS
=
$(SRCS:%.c=%.o)
OBJS
=
$(SRCS:%.c=%.o)
...
...
latency-measure/src/main.c
View file @
70739230
...
@@ -7,33 +7,57 @@
...
@@ -7,33 +7,57 @@
#include <string.h>
#include <string.h>
#include <time.h>
#include <time.h>
#include <unistd.h>
#include <unistd.h>
#include <stdint.h>
#include "getip.h"
#include <inttypes.h>
#include "send_packet.h"
#define CLOCK_ID CLOCK_MONOTONIC
#define CLOCK_ID CLOCK_MONOTONIC
#define NSECS_PER_SECOND INT64_C(1000000000)
typedef
struct
thread_stat
{
typedef
struct
thread_stat
{
int
nb_cycles
;
int
nb_cycles
;
int64_t
diff
;
}
thread_stat_t
;
}
thread_stat_t
;
typedef
struct
thread_param
{
typedef
struct
thread_param
{
int
interval
;
int
64_t
interval
;
int
priority
;
int
priority
;
int
max_cycles
;
int
max_cycles
;
const
char
*
ip_address
;
thread_stat_t
stat
;
thread_stat_t
stats
;
}
thread_param_t
;
}
thread_param_t
;
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
);
return
diff
;
}
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
;
}
// Real-time thread
// Real-time thread
// Sends packets at a regular intervall
// Sends packets at a regular intervall
static
void
*
packet_sending_
thread
(
void
*
p
)
{
static
void
*
timer
thread
(
void
*
p
)
{
struct
timespec
next
;
struct
timespec
next
;
struct
timespec
current
;
struct
sched_param
priority
;
struct
sched_param
priority
;
thread_param_t
*
param
=
(
thread_param_t
*
)
p
;
thread_param_t
*
param
=
(
thread_param_t
*
)
p
;
thread_stat_t
*
stat
=
&
param
->
stat
;
priority
.
sched_priority
=
param
->
priority
;
priority
.
sched_priority
=
param
->
priority
;
...
@@ -42,19 +66,21 @@ static void *packet_sending_thread(void *p) {
...
@@ -42,19 +66,21 @@ static void *packet_sending_thread(void *p) {
if
(
err
)
if
(
err
)
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set priority"
);
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set priority"
);
for
(
param
->
stats
.
nb_cycles
=
0
;;
param
->
stats
.
nb_cycles
++
)
{
clock_gettime
(
CLOCK_ID
,
&
next
);
next
=
add_ns
(
next
,
param
->
interval
);
for
(
stat
->
nb_cycles
=
0
;;
stat
->
nb_cycles
++
)
{
if
(
param
->
max_cycles
)
if
(
param
->
max_cycles
)
if
(
param
->
stats
.
nb_cycles
>=
param
->
max_cycles
)
if
(
stat
->
nb_cycles
>=
param
->
max_cycles
)
break
;
break
;
clock_gettime
(
CLOCK_ID
,
&
next
);
next
.
tv_sec
+=
param
->
interval
;
send_udp_packet
(
param
->
ip_address
);
clock_nanosleep
(
CLOCK_ID
,
TIMER_ABSTIME
,
&
next
,
NULL
);
clock_nanosleep
(
CLOCK_ID
,
TIMER_ABSTIME
,
&
next
,
NULL
);
clock_gettime
(
CLOCK_ID
,
&
current
);
stat
->
diff
=
diff_ns
(
current
,
next
);
next
=
add_ns
(
current
,
param
->
interval
);
}
}
return
NULL
;
return
NULL
;
...
@@ -84,12 +110,6 @@ static void process_options(int argc, char *argv[], thread_param_t * param) {
...
@@ -84,12 +110,6 @@ static void process_options(int argc, char *argv[], thread_param_t * param) {
break
;
break
;
}
}
}
}
if
(
argc
!=
optind
+
1
)
{
printf
(
"Usage: %s server_ip
\n
"
,
argv
[
0
]);
exit
(
EXIT_FAILURE
);
}
param
->
ip_address
=
argv
[
optind
];
}
}
// Main thread, has non-real time priority
// Main thread, has non-real time priority
...
@@ -100,25 +120,25 @@ int main(int argc, char *argv[]) {
...
@@ -100,25 +120,25 @@ int main(int argc, char *argv[]) {
thread_param_t
param
;
thread_param_t
param
;
// Default values
// Default values
param
.
interval
=
1
;
param
.
interval
=
NSECS_PER_SECOND
;
param
.
max_cycles
=
-
1
;
param
.
max_cycles
=
100
;
param
.
priority
=
80
;
param
.
priority
=
80
;
process_options
(
argc
,
argv
,
&
param
);
process_options
(
argc
,
argv
,
&
param
);
int
err
=
int
err
=
pthread_create
(
&
thread
,
NULL
,
packet_sending_
thread
,
(
void
*
)
&
param
);
pthread_create
(
&
thread
,
NULL
,
timer
thread
,
(
void
*
)
&
param
);
if
(
err
)
if
(
err
)
error
(
EXIT_FAILURE
,
errno
,
"Couldn't create thread"
);
error
(
EXIT_FAILURE
,
errno
,
"Couldn't create thread"
);
for
(;;)
{
for
(;;)
{
usleep
(
100000
);
usleep
(
100000
);
printf
(
"
Nb cycles: %d
\n
"
,
param
.
stats
.
nb_cycles
);
printf
(
"
Diff: %"
PRIi64
"us (%d)
\n
"
,
(
param
.
stat
.
diff
/
1000
),
param
.
stat
.
nb_cycles
);
if
(
param
.
max_cycles
==
param
.
stat
s
.
nb_cycles
)
if
(
param
.
max_cycles
==
param
.
stat
.
nb_cycles
)
break
;
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