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
52742c4d
Commit
52742c4d
authored
Jun 22, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: rewrite and clean up code
parent
b4ea36fe
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
57 additions
and
53 deletions
+57
-53
packet-exchange/src/client.c
packet-exchange/src/client.c
+18
-16
packet-exchange/src/recv_packet.c
packet-exchange/src/recv_packet.c
+15
-17
packet-exchange/src/recv_packet.h
packet-exchange/src/recv_packet.h
+1
-3
packet-exchange/src/send_packet.c
packet-exchange/src/send_packet.c
+9
-9
packet-exchange/src/send_packet.h
packet-exchange/src/send_packet.h
+0
-2
packet-exchange/src/server.c
packet-exchange/src/server.c
+14
-6
No files found.
packet-exchange/src/client.c
View file @
52742c4d
...
@@ -62,8 +62,8 @@ static int nb_cycles;
...
@@ -62,8 +62,8 @@ static int nb_cycles;
static
main_param_t
main_params
;
static
main_param_t
main_params
;
static
thread_param_t
thread_params
;
static
thread_param_t
thread_params
;
static
rtt_stat_t
rtt_stats
;
static
rtt_stat_t
rtt_stats
;
static
egress_stat_t
*
egress_stats
;
static
egress_stat_t
egress_stats
;
static
egress_param_t
*
egress_params
;
static
egress_param_t
egress_params
;
static
int
enable_histograms
;
static
int
enable_histograms
;
static
int
enable_affinity
;
static
int
enable_affinity
;
...
@@ -168,14 +168,14 @@ int main(int argc, char *argv[]) {
...
@@ -168,14 +168,14 @@ int main(int argc, char *argv[]) {
enable_histograms
=
0
;
enable_histograms
=
0
;
tsn_task
=
SEND_PACKET_TASK
;
tsn_task
=
SEND_PACKET_TASK
;
egress_params
->
packet_priority
=
3
;
egress_params
.
packet_priority
=
3
;
egress_params
->
tx_buffer_len
=
1024
;
egress_params
.
tx_buffer_len
=
1024
;
// Process bash options
// Process bash options
process_options
(
argc
,
argv
);
process_options
(
argc
,
argv
);
egress_params
->
use_etf
=
enable_etf
;
egress_params
.
use_etf
=
enable_etf
;
egress_params
->
use_timestamps
=
enable_timestamps
;
egress_params
.
use_timestamps
=
enable_timestamps
;
if
(
enable_histograms
)
{
if
(
enable_histograms
)
{
// Init histograms
// Init histograms
...
@@ -187,8 +187,10 @@ int main(int argc, char *argv[]) {
...
@@ -187,8 +187,10 @@ int main(int argc, char *argv[]) {
init_signals
(
sighand
,
enable_histograms
);
init_signals
(
sighand
,
enable_histograms
);
// Initialize the UDP packet sending socket
// Initialize the UDP packet sending socket
init_udp_send
(
egress_params
,
init_udp_send
(
&
egress_params
,
thread_params
,
&
egress_stats
,
&
thread_params
,
enable_histograms
,
kernel_latency_hist
);
kernel_latency_hist
);
// Initialize the UDP packet receiving socket if RTT is measured
// Initialize the UDP packet receiving socket if RTT is measured
...
@@ -213,9 +215,9 @@ int main(int argc, char *argv[]) {
...
@@ -213,9 +215,9 @@ int main(int argc, char *argv[]) {
}
else
if
(
enable_timestamps
)
{
}
else
if
(
enable_timestamps
)
{
printf
(
"%10d: K: %4d %4d %4d
\n
"
,
printf
(
"%10d: K: %4d %4d %4d
\n
"
,
nb_cycles
,
egress_stats
->
min_kernel_latency
,
nb_cycles
,
egress_stats
.
min_kernel_latency
,
egress_stats
->
avg_kernel_latency
,
egress_stats
.
avg_kernel_latency
,
egress_stats
->
max_kernel_latency
);
egress_stats
.
max_kernel_latency
);
printf
(
"
\033
[%dA"
,
1
);
printf
(
"
\033
[%dA"
,
1
);
}
}
}
}
...
@@ -345,8 +347,8 @@ static void process_options(int argc, char *argv[]) {
...
@@ -345,8 +347,8 @@ static void process_options(int argc, char *argv[]) {
tsn_task
=
RTT_TASK
;
tsn_task
=
RTT_TASK
;
break
;
break
;
case
'd'
:
case
'd'
:
egress_params
->
tx_buffer_len
=
atoi
(
optarg
);
egress_params
.
tx_buffer_len
=
atoi
(
optarg
);
if
(
egress_params
->
tx_buffer_len
<
1
)
{
if
(
egress_params
.
tx_buffer_len
<
1
)
{
fprintf
(
stderr
,
"BUF_LEN should be greater than 1
\n
"
);
fprintf
(
stderr
,
"BUF_LEN should be greater than 1
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -357,7 +359,7 @@ static void process_options(int argc, char *argv[]) {
...
@@ -357,7 +359,7 @@ static void process_options(int argc, char *argv[]) {
break
;
break
;
case
'f'
:
case
'f'
:
network_if_specified
=
1
;
network_if_specified
=
1
;
strcpy
(
egress_params
->
network_if
,
optarg
);
strcpy
(
egress_params
.
network_if
,
optarg
);
break
;
break
;
case
'g'
:
case
'g'
:
enable_histograms
=
1
;
enable_histograms
=
1
;
...
@@ -376,7 +378,7 @@ static void process_options(int argc, char *argv[]) {
...
@@ -376,7 +378,7 @@ static void process_options(int argc, char *argv[]) {
thread_params
.
priority
=
atoi
(
optarg
);
thread_params
.
priority
=
atoi
(
optarg
);
break
;
break
;
case
'q'
:
case
'q'
:
egress_params
->
packet_priority
=
atoi
(
optarg
);
egress_params
.
packet_priority
=
atoi
(
optarg
);
break
;
break
;
case
'r'
:
case
'r'
:
main_params
.
refresh_rate
=
atoi
(
optarg
);
main_params
.
refresh_rate
=
atoi
(
optarg
);
...
@@ -404,5 +406,5 @@ static void process_options(int argc, char *argv[]) {
...
@@ -404,5 +406,5 @@ static void process_options(int argc, char *argv[]) {
help
(
argv
);
help
(
argv
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
strcpy
(
egress_params
->
ip_address
,
argv
[
optind
]);
strcpy
(
egress_params
.
ip_address
,
argv
[
optind
]);
}
}
packet-exchange/src/recv_packet.c
View file @
52742c4d
...
@@ -52,7 +52,6 @@ static int set_if() {
...
@@ -52,7 +52,6 @@ static int set_if() {
}
}
void
init_udp_recv
(
struct
ingress_param
*
_params
,
void
init_udp_recv
(
struct
ingress_param
*
_params
,
struct
thread_param
*
_thread_params
,
int
use_histogram
,
int
use_histogram
,
uint64_t
*
_kernel_latency_hist
)
{
uint64_t
*
_kernel_latency_hist
)
{
int
getaddrinfo_err
;
int
getaddrinfo_err
;
...
@@ -60,7 +59,6 @@ void init_udp_recv(struct ingress_param * _params,
...
@@ -60,7 +59,6 @@ void init_udp_recv(struct ingress_param * _params,
struct
addrinfo
hints
,
*
servinfo
,
*
servinfo_it
;
struct
addrinfo
hints
,
*
servinfo
,
*
servinfo_it
;
params
=
_params
;
params
=
_params
;
thread_params
=
_thread_params
;
use_histogram
=
_use_histogram
;
use_histogram
=
_use_histogram
;
kernel_latency_hist
=
_kernel_latency_hist
;
kernel_latency_hist
=
_kernel_latency_hist
;
...
@@ -110,7 +108,7 @@ void init_udp_recv(struct ingress_param * _params,
...
@@ -110,7 +108,7 @@ void init_udp_recv(struct ingress_param * _params,
/*
/*
* Receives udp packets
* Receives udp packets
*/
*/
void
recv_udp_packet
()
{
void
recv_udp_packet
(
int
nb_cycles
)
{
struct
cmsghdr
*
cmsg
;
struct
cmsghdr
*
cmsg
;
struct
msghdr
msg
;
// Message hardware, sent to the socket
struct
msghdr
msg
;
// Message hardware, sent to the socket
...
@@ -145,30 +143,30 @@ void recv_udp_packet() {
...
@@ -145,30 +143,30 @@ void recv_udp_packet() {
if
(
recvmsgerr
<
0
)
if
(
recvmsgerr
<
0
)
error
(
EXIT_FAILURE
,
errno
,
"recvmsg failed, ret value: %d
\n
"
,
recvmsgerr
);
error
(
EXIT_FAILURE
,
errno
,
"recvmsg failed, ret value: %d
\n
"
,
recvmsgerr
);
if
(
use_timestamps
)
{
if
(
params
->
use_timestamps
)
{
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_info
.
userspace_enter_ts
=
ts_to_uint
(
ts
);
}
if
(
use_timestamps
)
{
for
(
cmsg
=
CMSG_FIRSTHDR
(
&
msg
);
cmsg
;
cmsg
=
CMSG_NXTHDR
(
&
msg
,
cmsg
))
{
for
(
cmsg
=
CMSG_FIRSTHDR
(
&
msg
);
cmsg
;
cmsg
=
CMSG_NXTHDR
(
&
msg
,
cmsg
))
{
if
(
cmsg
->
cmsg_level
==
SOL_SOCKET
&&
cmsg
->
cmsg_type
==
SO_TIMESTAMPING
)
{
if
(
cmsg
->
cmsg_level
==
SOL_SOCKET
&&
cmsg
->
cmsg_type
==
SO_TIMESTAMPING
)
{
struct
timespec
*
stamp
=
(
struct
timespec
*
)
CMSG_DATA
(
cmsg
);
struct
timespec
*
stamp
=
(
struct
timespec
*
)
CMSG_DATA
(
cmsg
);
packet_info
.
kernelspace_ts
=
ts_to_uint
(
*
stamp
);
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
uint64_t
kernel_latency
=
timestamps_buffer
[
ts_buf_read_index
++
]
-
ts_to_uint
(
*
stamp
);
packet_info
.
userspace_exit_ts
=
ts_to_uint
(
ts
)
;
kernel_latency
/=
1000u
;
if
(
use_histograms
)
ingress_stats
->
min_kernel_latency
=
min
(
kernel_latency
,
ingress_stats
->
min_kernel_latency
);
fill_histograms
(
&
packet_info
,
histograms
);
ingress_stats
->
max_kernel_latency
=
max
(
kernel_latency
,
ingress_stats
->
max_kernel_latency
);
ingress_stats
->
avg_kernel_latency
=
(
ingress_stats
->
max_kernel_latency
*
(
nb_cycles
-
1
)
+
kernel_latency
)
/
nb_cycles
;
if
(
use_histogram
)
{
if
(
kernel_latency
>
MAX_KERNEL_LATENCY
)
stats
.
high_kernel_latency
++
;
else
kernel_latency_hist
[
kernel_latency
]
++
;
}
}
}
}
}
}
}
strcpy
(
packet_info
.
data
,
rx_buffer
);
strcpy
(
stats
->
data
,
rx_buffer
);
return
packet_info
;
}
}
static
void
fill_histograms
(
packet_info_t
*
packet_info
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
static
void
fill_histograms
(
packet_info_t
*
packet_info
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
...
...
packet-exchange/src/recv_packet.h
View file @
52742c4d
...
@@ -4,14 +4,12 @@
...
@@ -4,14 +4,12 @@
#include "utilities.h"
#include "utilities.h"
void
init_udp_recv
(
struct
ingress_param
*
_params
,
void
init_udp_recv
(
struct
ingress_param
*
_params
,
struct
thread_param
*
_thread_params
,
int
use_histogram
,
int
use_histogram
,
uint64_t
*
_kernel_latency_hist
);
uint64_t
*
_kernel_latency_hist
);
packet_info_t
recv_udp_packet
(
int
use_timestamps
,
int
use_histograms
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]
);
void
recv_udp_packet
(
int
nb_cycles
);
void
init_udp_recv
(
ingress_param_t
*
params
,
void
init_udp_recv
(
ingress_param_t
*
params
,
thread_param_t
*
thread_params
,
uint64_t
*
kernel_latency_hist
);
uint64_t
*
kernel_latency_hist
);
void
recv_udp_packet
(
int
nb_cycles
);
void
recv_udp_packet
(
int
nb_cycles
);
...
...
packet-exchange/src/send_packet.c
View file @
52742c4d
...
@@ -47,7 +47,7 @@ static int so_timestamping_flags =
...
@@ -47,7 +47,7 @@ static int so_timestamping_flags =
SOF_TIMESTAMPING_TX_SOFTWARE
|
SOF_TIMESTAMPING_SOFTWARE
;
SOF_TIMESTAMPING_TX_SOFTWARE
|
SOF_TIMESTAMPING_SOFTWARE
;
egress_param_t
*
params
;
egress_param_t
*
params
;
struct
thread_param
*
thread_param
s
;
egress_stat_t
*
stat
s
;
uint64_t
*
kernel_latency_hist
;
uint64_t
*
kernel_latency_hist
;
int
use_histogram
;
int
use_histogram
;
...
@@ -63,7 +63,7 @@ static int ts_buf_write_index = 0;
...
@@ -63,7 +63,7 @@ static int ts_buf_write_index = 0;
* Init UDP socket
* Init UDP socket
*/
*/
void
init_udp_send
(
egress_param_t
*
_params
,
void
init_udp_send
(
egress_param_t
*
_params
,
thread_param_t
*
_thread_param
s
,
egress_stat_t
*
_stat
s
,
int
_use_histogram
,
int
_use_histogram
,
uint64_t
*
_kernel_latency_hist
)
{
uint64_t
*
_kernel_latency_hist
)
{
...
@@ -71,7 +71,7 @@ void init_udp_send(egress_param_t * _params,
...
@@ -71,7 +71,7 @@ void init_udp_send(egress_param_t * _params,
pthread_t
thread
;
pthread_t
thread
;
params
=
_params
;
params
=
_params
;
thread_params
=
_thread_param
s
;
stats
=
_stat
s
;
kernel_latency_hist
=
_kernel_latency_hist
;
kernel_latency_hist
=
_kernel_latency_hist
;
use_histogram
=
_use_histogram
use_histogram
=
_use_histogram
...
@@ -216,13 +216,13 @@ static void process_error_queue(int nb_cycles) {
...
@@ -216,13 +216,13 @@ static void process_error_queue(int nb_cycles) {
uint64_t
kernel_latency
=
ts_to_uint
(
stamp
)
-
timestamps_buffer
[
ts_buf_read_index
++
];
uint64_t
kernel_latency
=
ts_to_uint
(
stamp
)
-
timestamps_buffer
[
ts_buf_read_index
++
];
kernel_latency
/=
1000u
;
kernel_latency
/=
1000u
;
egress_stats
->
min_kernel_latency
=
min
(
kernel_latency
,
egress_
stats
->
min_kernel_latency
);
stats
->
min_kernel_latency
=
min
(
kernel_latency
,
stats
->
min_kernel_latency
);
egress_stats
->
max_kernel_latency
=
max
(
kernel_latency
,
egress_
stats
->
max_kernel_latency
);
stats
->
max_kernel_latency
=
max
(
kernel_latency
,
stats
->
max_kernel_latency
);
egress_stats
->
avg_kernel_latency
=
(
egress_
stats
->
max_kernel_latency
*
(
nb_cycles
-
1
)
+
kernel_latency
)
/
nb_cycles
;
stats
->
avg_kernel_latency
=
(
stats
->
max_kernel_latency
*
(
nb_cycles
-
1
)
+
kernel_latency
)
/
nb_cycles
;
if
(
use_histogram
)
{
if
(
use_histogram
)
{
if
(
kernel_latency
>
MAX_KERNEL_LATENCY
)
if
(
kernel_latency
>
MAX_KERNEL_LATENCY
)
stats
.
high_kernel_latency
++
;
stats
->
high_kernel_latency
++
;
else
else
kernel_latency_hist
[
kernel_latency
]
++
;
kernel_latency_hist
[
kernel_latency
]
++
;
}
}
...
@@ -238,10 +238,10 @@ static void process_error_queue(int nb_cycles) {
...
@@ -238,10 +238,10 @@ static void process_error_queue(int nb_cycles) {
switch
(
serr
->
ee_code
)
{
switch
(
serr
->
ee_code
)
{
case
SO_EE_CODE_TXTIME_INVALID_PARAM
:
case
SO_EE_CODE_TXTIME_INVALID_PARAM
:
stats
.
invalid_parameter
++
;
stats
->
invalid_parameter
++
;
break
;
break
;
case
SO_EE_CODE_TXTIME_MISSED
:
case
SO_EE_CODE_TXTIME_MISSED
:
stats
.
missed_deadline
++
;
stats
->
missed_deadline
++
;
break
;
break
;
default:
default:
fprintf
(
stderr
,
"Uknown TxTime error
\n
"
);
fprintf
(
stderr
,
"Uknown TxTime error
\n
"
);
...
...
packet-exchange/src/send_packet.h
View file @
52742c4d
...
@@ -4,7 +4,6 @@
...
@@ -4,7 +4,6 @@
#include "common.h"
#include "common.h"
void
init_udp_send
(
egress_param_t
*
_params
,
void
init_udp_send
(
egress_param_t
*
_params
,
thread_param_t
*
_thread_params
,
int
_use_histogram
,
int
_use_histogram
,
uint64_t
*
_kernel_latency_hist
);
uint64_t
*
_kernel_latency_hist
);
void
send_udp_packet
(
char
*
data
,
uint64_t
txtime
,
int
nb_cycles
);
void
send_udp_packet
(
char
*
data
,
uint64_t
txtime
,
int
nb_cycles
);
...
@@ -30,7 +29,6 @@ typedef struct egress_stat {
...
@@ -30,7 +29,6 @@ typedef struct egress_stat {
int
avg_kernel_latency
;
int
avg_kernel_latency
;
int
max_kernel_latency
;
int
max_kernel_latency
;
char
data
[
MAX_BUFFER_SIZE
];
}
thread_stat_t
;
}
thread_stat_t
;
#endif
#endif
packet-exchange/src/server.c
View file @
52742c4d
...
@@ -31,8 +31,11 @@
...
@@ -31,8 +31,11 @@
// Structs
// Structs
typedef
struct
thread_stat
{
typedef
struct
thread_stat
{
uint64_t
min_interval
;
uint64_t
min_interval
;
uint64_t
avg_interval
;
uint64_t
max_interval
;
uint64_t
max_interval
;
int
packets_received
;
int
packets_received
;
int
lost_packets
;
int
lost_packets
;
}
thread_stat_t
;
}
thread_stat_t
;
...
@@ -171,6 +174,8 @@ int main(int argc, char *argv[]) {
...
@@ -171,6 +174,8 @@ int main(int argc, char *argv[]) {
// Default configuration values
// Default configuration values
thread_params
.
interval
=
100000
*
1000
;
thread_params
.
interval
=
100000
*
1000
;
thread_params
.
priority
=
99
;
thread_params
.
priority
=
99
;
main_params
.
refresh_rate
=
50000
;
main_params
.
verbose
=
0
;
enable_affinity
=
0
;
enable_affinity
=
0
;
enable_timestamps
=
0
;
enable_timestamps
=
0
;
...
@@ -179,9 +184,6 @@ int main(int argc, char *argv[]) {
...
@@ -179,9 +184,6 @@ int main(int argc, char *argv[]) {
network_config
.
tx_buffer_len
=
1024
;
network_config
.
tx_buffer_len
=
1024
;
main_params
.
refresh_rate
=
50000
;
main_params
.
verbose
=
0
;
// Process bash options
// Process bash options
process_options
(
argc
,
argv
);
process_options
(
argc
,
argv
);
...
@@ -194,11 +196,17 @@ int main(int argc, char *argv[]) {
...
@@ -194,11 +196,17 @@ int main(int argc, char *argv[]) {
init_signals
(
sighand
,
enable_histograms
);
init_signals
(
sighand
,
enable_histograms
);
// Initialize the UDP packet receiving socket
// Initialize the UDP packet receiving socket
init_udp_recv
(
enable_timestamps
,
network_config
.
network_if
);
init_udp_recv
(
&
ingress_params
,
&
ingress_stats
,
enable_histograms
,
kernel_latency_hist
);
// Initialize the UDP packet sending socket if RTT is measured
// Initialize the UDP packet sending socket if RTT is measured
if
(
tsn_task
==
RTT_TASK
)
if
(
tsn_task
==
RTT_TASK
)
init_udp_send
(
0
,
0
,
1
,
network_config
.
network_if
,
network_config
.
tx_buffer_len
);
init_udp_send
(
&
egress_params
,
&
egress_stats
,
0
,
NULL
);
// Create the real time thread
// Create the real time thread
if
(
pthread_create
(
&
thread
,
NULL
,
packet_receiving_thread
,
NULL
))
if
(
pthread_create
(
&
thread
,
NULL
,
packet_receiving_thread
,
NULL
))
...
@@ -212,7 +220,7 @@ int main(int argc, char *argv[]) {
...
@@ -212,7 +220,7 @@ int main(int argc, char *argv[]) {
if
(
tsn_task
==
RECV_PACKET_TASK
)
{
if
(
tsn_task
==
RECV_PACKET_TASK
)
{
int64_t
jitter
=
((
int64_t
)
stats
->
max_interval
)
-
stats
->
min_interval
;
u
int64_t
jitter
=
((
int64_t
)
stats
->
max_interval
)
-
stats
->
min_interval
;
printf
(
"%*d: J: %*"
PRIi64
,
printf
(
"%*d: J: %*"
PRIi64
,
10
,
stats
->
packets_received
,
10
,
stats
->
packets_received
,
...
...
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