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
9ed02abf
Commit
9ed02abf
authored
Jun 10, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformat code with clang-format
parent
34fbbef0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
85 deletions
+84
-85
packet-exchange/src/client.c
packet-exchange/src/client.c
+28
-27
packet-exchange/src/recv_packet.c
packet-exchange/src/recv_packet.c
+5
-5
packet-exchange/src/send_packet.c
packet-exchange/src/send_packet.c
+7
-8
packet-exchange/src/send_packet.h
packet-exchange/src/send_packet.h
+1
-1
packet-exchange/src/server.c
packet-exchange/src/server.c
+42
-42
packet-exchange/src/utilities.h
packet-exchange/src/utilities.h
+1
-2
No files found.
packet-exchange/src/client.c
View file @
9ed02abf
...
...
@@ -54,7 +54,7 @@ typedef struct network_config {
// Static functions
static
void
process_options
(
int
argc
,
char
*
argv
[]);
static
void
do_tsn_task
(
struct
thread_param
*
param
,
char
*
data
,
uint64_t
next_txtime
);
static
void
do_tsn_task
(
struct
thread_param
*
param
,
char
*
data
,
uint64_t
next_txtime
);
static
void
print_histograms
();
static
void
sighand
(
int
sig_num
);
...
...
@@ -122,13 +122,12 @@ static void *packet_sending_thread(void *p) {
if
(
sched_setscheduler
(
0
,
SCHED_FIFO
,
&
priority
))
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set priority"
);
if
(
enable_etf
)
{
if
(
enable_etf
)
{
// Measure from CLOCK_TAI to generate timestamp
clock_gettime
(
CLOCK_TAI
,
&
next
);
next_txtime
=
next
.
tv_sec
*
NSEC_PER_SEC
+
next
.
tv_nsec
;
next_txtime
+=
param
->
etf_offset
;
}
else
{
}
else
{
next_txtime
=
0
;
}
...
...
@@ -145,7 +144,7 @@ static void *packet_sending_thread(void *p) {
add_ns
(
&
next
,
param
->
interval
);
if
(
enable_etf
)
if
(
enable_etf
)
next_txtime
+=
param
->
interval
;
clock_nanosleep
(
CLOCK_MONOTONIC
,
TIMER_ABSTIME
,
&
next
,
NULL
);
...
...
@@ -240,7 +239,7 @@ int main(int argc, char *argv[]) {
}
// Critical TSN task
static
void
do_tsn_task
(
struct
thread_param
*
param
,
char
*
data
,
uint64_t
next_txtime
)
{
static
void
do_tsn_task
(
struct
thread_param
*
param
,
char
*
data
,
uint64_t
next_txtime
)
{
struct
timespec
t1
,
t2
;
int
rtt_us
;
...
...
@@ -262,9 +261,9 @@ static void do_tsn_task(struct thread_param *param, char * data, uint64_t next_t
param
->
stats
.
rtt
=
calcdiff_ns
(
t2
,
t1
);
if
(
enable_histograms
)
{
if
(
enable_histograms
)
{
rtt_us
=
param
->
stats
.
rtt
/
1000
;
if
(
rtt_us
>
MAX_HIST_VAL
)
{
if
(
rtt_us
>
MAX_HIST_VAL
)
{
fprintf
(
stderr
,
"RTT value higher than MAX_HIST_VAL : %d ( > %d)
\n
"
,
rtt_us
,
MAX_HIST_VAL
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -288,26 +287,28 @@ static void print_histograms() {
interval
=
param
->
interval
/
1000
;
if
(
tsn_task
==
SEND_PACKET_TASK
)
{
if
(
tsn_task
==
SEND_PACKET_TASK
)
{
printf
(
"{
\"
measure_sets
\"
: [{"
"
\"
measure_type
\"
:
\"
packet_send_timestamps
\"
,"
"
\"
props_names
\"
: [
\"
user_space
\"
,
\"
kernel_space
\"
],"
"
\"
units
\"
: [
\"
us
\"
,
\"
us
\"
],"
"
\"
props_type
\"
:
\"
histogram
\"
,"
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"},"
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
);
}
else
if
(
tsn_task
==
RTT_TASK
)
{
"
\"
measure_type
\"
:
\"
packet_send_timestamps
\"
,"
"
\"
props_names
\"
: [
\"
user_space
\"
,
\"
kernel_space
\"
],"
"
\"
units
\"
: [
\"
us
\"
,
\"
us
\"
],"
"
\"
props_type
\"
:
\"
histogram
\"
,"
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"},"
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
);
}
else
if
(
tsn_task
==
RTT_TASK
)
{
printf
(
"{
\"
measure_sets
\"
: [{"
"
\"
measure_type
\"
:
\"
packet_rtt
\"
,"
"
\"
props_names
\"
: [
\"
rtt
\"
],"
"
\"
units
\"
: [
\"
us
\"
],"
"
\"
props_type
\"
:
\"
histogram
\"
,"
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"},"
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
);
"
\"
measure_type
\"
:
\"
packet_rtt
\"
,"
"
\"
props_names
\"
: [
\"
rtt
\"
],"
"
\"
units
\"
: [
\"
us
\"
],"
"
\"
props_type
\"
:
\"
histogram
\"
,"
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"},"
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
);
}
nb_hists
=
tsn_task
==
SEND_PACKET_TASK
?
2
:
1
;
...
...
@@ -325,7 +326,7 @@ static void print_histograms() {
printf
(
"%s"
,
(
i
+
1
<
nb_hists
?
"], "
:
"]"
));
}
printf
(
"]}]}
\n
"
);
printf
(
"]}]}
\n
"
);
}
static
void
sighand
(
int
sig_num
)
{
...
...
packet-exchange/src/recv_packet.c
View file @
9ed02abf
...
...
@@ -107,11 +107,11 @@ packet_info_t recv_udp_packet(int use_timestamps, int use_histograms, int64_t hi
struct
cmsghdr
*
cmsg
;
struct
msghdr
msg
;
// Message hardware, sent to the socket
struct
iovec
iov
;
// The iovec structures stores the RX buffer
struct
iovec
iov
;
// The iovec structures stores the RX buffer
struct
sockaddr_in
sin
;
struct
{
struct
cmsghdr
cm
;
char
control
[
512
];
struct
cmsghdr
cm
;
char
control
[
512
];
}
control
;
int
recvmsgerr
;
...
...
@@ -144,7 +144,7 @@ packet_info_t recv_udp_packet(int use_timestamps, int use_histograms, int64_t hi
packet_info
.
userspace_enter_ts
=
ts_to_uint
(
ts
);
}
if
(
use_timestamps
)
{
if
(
use_timestamps
)
{
for
(
cmsg
=
CMSG_FIRSTHDR
(
&
msg
);
cmsg
;
cmsg
=
CMSG_NXTHDR
(
&
msg
,
cmsg
))
{
if
(
cmsg
->
cmsg_level
==
SOL_SOCKET
&&
cmsg
->
cmsg_type
==
SO_TIMESTAMPING
)
{
...
...
@@ -154,7 +154,7 @@ packet_info_t recv_udp_packet(int use_timestamps, int use_histograms, int64_t hi
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_info
.
userspace_exit_ts
=
ts_to_uint
(
ts
);
if
(
use_histograms
)
if
(
use_histograms
)
fill_histograms
(
&
packet_info
,
histograms
);
}
}
...
...
packet-exchange/src/send_packet.c
View file @
9ed02abf
...
...
@@ -128,15 +128,15 @@ void init_udp_send(int use_etf, int use_timestamps, int packet_priority,
* Sends udp packets
*/
packet_info_t
send_udp_packet
(
int
use_etf
,
int
use_timestamps
,
char
*
data
,
uint64_t
txtime
,
const
char
*
server_ip
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
char
*
data
,
uint64_t
txtime
,
const
char
*
server_ip
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
struct
msghdr
msg
;
// Message hardware, sent to the socket
struct
cmsghdr
*
cmsg
;
// Control message hardware, for txtime
struct
msghdr
msg
;
// Message hardware, sent to the socket
struct
cmsghdr
*
cmsg
;
// Control message hardware, for txtime
char
control
[
CMSG_SPACE
(
sizeof
(
txtime
))]
=
{};
// Stores txtime
struct
iovec
iov
;
// The iovec structures stores the TX buffer
struct
iovec
iov
;
// The iovec structures stores the TX buffer
// Poll file descriptor, used to poll for timestamp messages
struct
pollfd
poll_fd
=
{
sock_fd
,
POLLPRI
,
0
};
int
sendmsgerr
,
pollerr
;
...
...
@@ -260,7 +260,6 @@ static void process_timestamps(packet_info_t *packet_info, int64_t histograms[NB
fprintf
(
stderr
,
"process_timestamps: level %d type %d"
,
cmsg
->
cmsg_level
,
cmsg
->
cmsg_type
);
#endif
}
}
}
...
...
packet-exchange/src/send_packet.h
View file @
9ed02abf
...
...
@@ -4,6 +4,6 @@
#include "utilities.h"
void
init_udp_send
(
int
use_etf
,
int
use_timestamps
,
int
so_priority
,
char
*
network_if
,
size_t
tx_buffer_len
);
packet_info_t
send_udp_packet
(
int
use_etf
,
int
use_timestamps
,
char
*
data
,
uint64_t
txtime
,
const
char
*
server_ip
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
packet_info_t
send_udp_packet
(
int
use_etf
,
int
use_timestamps
,
char
*
data
,
uint64_t
txtime
,
const
char
*
server_ip
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
#endif
packet-exchange/src/server.c
View file @
9ed02abf
...
...
@@ -81,7 +81,6 @@ static enum TSNTask tsn_task;
struct
timespec
measures_start
;
struct
timespec
measures_end
;
static
void
help
(
char
*
argv
[])
{
printf
(
"Usage: %s [-aghtv] [-b CLIENT_IP] [-d BUF_LEN] [-f IF] [-i USEC] [-p PRIO] [-r USEC]
\n\n
"
,
argv
[
0
]);
printf
(
" -a Run the real time thread on CPU1
\n
"
);
...
...
@@ -137,7 +136,7 @@ static void *packet_receiving_thread(void *p) {
}
else
if
(
tsn_task
==
RECV_PACKET_TASK
)
{
int
current_packet_id
;
int
current_packet_id
;
param
->
stats
.
packet_info
=
recv_udp_packet
(
enable_timestamps
,
enable_histograms
,
histograms
);
...
...
@@ -155,14 +154,13 @@ static void *packet_receiving_thread(void *p) {
// Check if packets were lost
param
->
stats
.
lost_packets
+=
(
current_packet_id
-
prev_packet_id
-
1
)
%
1000
;
if
(
enable_histograms
)
{
if
(
enable_histograms
)
{
dist_to_interval
=
(((
int64_t
)
diff
)
-
param
->
interval
)
/
1000
;
dist_to_interval
+=
MAX_HIST_VAL
/
2
;
if
(
dist_to_interval
>
((
int
)
MAX_HIST_VAL
)
||
dist_to_interval
<
0
)
{
if
(
dist_to_interval
>
((
int
)
MAX_HIST_VAL
)
||
dist_to_interval
<
0
)
{
fprintf
(
stderr
,
"jitter higher than MAX_HIST_VAL: %"
PRIi64
"
\n
"
,
dist_to_interval
);
exit
(
EXIT_FAILURE
);
}
else
{
}
else
{
histograms
[
2
][
dist_to_interval
]
++
;
}
}
...
...
@@ -226,17 +224,17 @@ int main(int argc, char *argv[]) {
for
(;;)
{
usleep
(
main_param
.
refresh_rate
);
if
(
main_param
.
verbose
)
{
if
(
main_param
.
verbose
)
{
if
(
tsn_task
==
RECV_PACKET_TASK
)
{
if
(
tsn_task
==
RECV_PACKET_TASK
)
{
diff
=
((
int64_t
)
stats
->
max_interval
)
-
stats
->
min_interval
;
printf
(
"(%d) Jitter : %"
PRIi64
" [Packet data: %s] [Lost packets: %d]
\n
"
,
stats
->
packets_received
,
diff
,
stats
->
packet_info
.
data
,
stats
->
lost_packets
);
printf
(
"(%d) Jitter : %"
PRIi64
" [Packet data: %s] [Lost packets: %d]
\n
"
,
stats
->
packets_received
,
diff
,
stats
->
packet_info
.
data
,
stats
->
lost_packets
);
if
(
enable_timestamps
)
{
if
(
enable_timestamps
)
{
printf
(
"(%d) Enter send_udp_packet timestamp: %"
PRIu64
"
\n
"
,
stats
->
packets_received
,
stats
->
packet_info
.
userspace_enter_ts
);
...
...
@@ -267,16 +265,17 @@ static void print_histograms() {
interval
=
param
->
interval
/
1000
;
if
(
enable_timestamps
)
{
if
(
enable_timestamps
)
{
printf
(
"{
\"
measure_sets
\"
: [{"
"
\"
measure_type
\"
:
\"
packet_recv_timestamps
\"
,"
"
\"
props_names
\"
: [
\"
user_space
\"
,
\"
kernel_space
\"
],"
"
\"
units
\"
: [
\"
us
\"
,
\"
us
\"
],"
"
\"
props_type
\"
:
\"
histogram
\"
,"
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"},"
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
);
"
\"
measure_type
\"
:
\"
packet_recv_timestamps
\"
,"
"
\"
props_names
\"
: [
\"
user_space
\"
,
\"
kernel_space
\"
],"
"
\"
units
\"
: [
\"
us
\"
,
\"
us
\"
],"
"
\"
props_type
\"
:
\"
histogram
\"
,"
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"},"
"
\"
props
\"
: ["
,
interval
,
duration_hour
,
duration_minutes
);
max_hist_val
=
0
;
for
(
int
i
=
0
;
i
<
2
;
i
++
)
...
...
@@ -294,35 +293,36 @@ static void print_histograms() {
max_hist_val
=
0
;
for
(
int
j
=
0
;
j
<
MAX_HIST_VAL
;
j
++
)
if
(
histograms
[
2
][
j
])
if
(
histograms
[
2
][
j
])
max_hist_val
=
j
;
min_hist_val
=
MAX_HIST_VAL
-
1
;
for
(
int
j
=
MAX_HIST_VAL
-
1
;
j
>=
0
;
j
--
)
if
(
histograms
[
2
][
j
])
if
(
histograms
[
2
][
j
])
min_hist_val
=
j
;
if
(
!
enable_timestamps
)
if
(
!
enable_timestamps
)
printf
(
"{
\"
measure_sets
\"
: [{"
);
else
printf
(
"]}, {"
);
printf
(
"
\"
measure_type
\"
:
\"
packet_jitter
\"
,"
"
\"
props_names
\"
: [
\"
jitter
\"
],"
"
\"
units
\"
: [
\"
us
\"
],"
"
\"
props_type
\"
:
\"
histogram
\"
,"
"
\"
middle
\"
:
\"
%d
\"
,"
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"},"
"
\"
props
\"
: [["
,
MAX_HIST_VAL
/
2
-
min_hist_val
,
interval
,
duration_hour
,
duration_minutes
);
printf
(
"]}, {"
);
printf
(
"
\"
measure_type
\"
:
\"
packet_jitter
\"
,"
"
\"
props_names
\"
: [
\"
jitter
\"
],"
"
\"
units
\"
: [
\"
us
\"
],"
"
\"
props_type
\"
:
\"
histogram
\"
,"
"
\"
middle
\"
:
\"
%d
\"
,"
"
\"
metadata
\"
: {"
"
\"
i
\"
:
\"
%dus
\"
,
\"
duration
\"
:
\"
%dh%d
\"
"
"},"
"
\"
props
\"
: [["
,
MAX_HIST_VAL
/
2
-
min_hist_val
,
interval
,
duration_hour
,
duration_minutes
);
for
(
int
j
=
min_hist_val
;
j
<
max_hist_val
;
j
++
)
printf
(
"%"
PRIi64
"%s"
,
histograms
[
2
][
j
],
(
j
+
1
<
max_hist_val
?
", "
:
""
));
printf
(
"]]}]}
\n
"
);
printf
(
"]]}]}
\n
"
);
}
static
void
sighand
(
int
sig_num
)
{
...
...
@@ -330,7 +330,7 @@ static void sighand(int sig_num) {
print_histograms
();
if
(
param
->
stats
.
lost_packets
)
if
(
param
->
stats
.
lost_packets
)
fprintf
(
stderr
,
"%d packets were lost
\n
"
,
param
->
stats
.
lost_packets
);
exit
(
EXIT_SUCCESS
);
...
...
packet-exchange/src/utilities.h
View file @
9ed02abf
...
...
@@ -3,8 +3,8 @@
#define _GNU_SOURCE
#include <inttypes.h>
#include <stdint.h>
#include <signal.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
...
...
@@ -32,5 +32,4 @@ void init_signals(void (*_sighand)(int), int enable_histograms);
extern
void
(
*
previous_handlers
[
NSIG
])(
int
);
#endif
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