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
75b4ef10
Commit
75b4ef10
authored
Jun 23, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up the code
parent
10a4b9d7
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
32 deletions
+39
-32
packet-exchange/src/client.c
packet-exchange/src/client.c
+22
-19
packet-exchange/src/recv_packet.c
packet-exchange/src/recv_packet.c
+1
-1
packet-exchange/src/recv_packet.h
packet-exchange/src/recv_packet.h
+2
-1
packet-exchange/src/send_packet.c
packet-exchange/src/send_packet.c
+1
-1
packet-exchange/src/server.c
packet-exchange/src/server.c
+13
-10
No files found.
packet-exchange/src/client.c
View file @
75b4ef10
...
...
@@ -25,6 +25,8 @@
// Structs
enum
TSNTask
{
SEND_PACKET_TASK
,
RTT_TASK
};
typedef
struct
rtt_stat
{
int
min_rtt
;
...
...
@@ -62,24 +64,25 @@ static uint64_t nb_cycles;
static
main_param_t
main_params
;
static
thread_param_t
thread_params
;
static
rtt_stat_t
rtt_stats
;
static
egress_stat_t
egress_stats
;
static
egress_param_t
egress_params
;
static
ingress_stat_t
ingress_stats
;
static
ingress_param_t
ingress_params
;
static
rtt_stat_t
rtt_stats
=
{.
min_rtt
=
INT_MAX
};
static
egress_stat_t
egress_stats
=
{.
min_kernel_latency
=
INT_MAX
};
static
ingress_stat_t
ingress_stats
=
{.
min_kernel_latency
=
INT_MAX
,
.
min_interval
=
INT_MAX
};
static
int
enable_histograms
;
static
int
enable_affinity
;
static
int
enable_etf
;
static
int
enable_timestamps
;
enum
TSNTask
{
SEND_PACKET_TASK
,
RTT_TASK
};
static
enum
TSNTask
tsn_task
;
struct
timespec
measures_start
;
struct
timespec
measures_end
;
st
atic
st
ruct
timespec
measures_start
;
st
atic
st
ruct
timespec
measures_end
;
char
send_data
[
MAX_BUFFER_SIZE
];
static
char
send_data
[
MAX_BUFFER_SIZE
];
static
void
help
(
char
*
argv
[])
{
printf
(
"Usage: %s -f IF [-abthgv] [-e ETF_OFFSET] [-d BUF_LEN] [-i USEC] [-l N] [-p PRIO] [-q PACKET_PRIO] [-r USEC]
\n\n
"
,
argv
[
0
]);
...
...
@@ -100,10 +103,11 @@ static void help(char *argv[]) {
printf
(
"
\n
"
);
}
// Real-time thread
// Sends packets at a regular intervall
/*
* Real-time thread: Sends packets at a regular intervall
*/
static
void
*
packet_sending_thread
(
void
*
p
)
{
(
void
)
p
;
(
void
)
p
;
struct
timespec
next
;
uint64_t
next_txtime
;
struct
sched_param
priority
;
...
...
@@ -133,10 +137,11 @@ static void *packet_sending_thread(void *p) {
clock_gettime
(
CLOCK_MONOTONIC
,
&
next
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
measures_start
);
// Packet sending loop
for
(
nb_cycles
=
0
;;
nb_cycles
++
)
{
if
(
thread_params
.
max_cycles
)
if
(
nb_cycles
>=
((
unsigned
int
)
thread_params
.
max_cycles
))
if
(
thread_params
.
max_cycles
&&
nb_cycles
>=
((
unsigned
int
)
thread_params
.
max_cycles
))
break
;
sprintf
(
send_data
,
"%d"
,
(
int
)(
nb_cycles
%
1000
));
...
...
@@ -153,15 +158,13 @@ static void *packet_sending_thread(void *p) {
return
NULL
;
}
// Main thread, has non-real time priority
// Handles the IO and creates real time threads
/*
* Main thread, has non-real time priority
* Handles the IO and creates the real time thread
*/
int
main
(
int
argc
,
char
*
argv
[])
{
pthread_t
thread
;
egress_stats
.
min_kernel_latency
=
INT_MAX
;
egress_stats
.
avg_kernel_latency
=
0
;
egress_stats
.
max_kernel_latency
=
0
;
// Default configuration values
thread_params
.
interval
=
100000
*
1000
;
thread_params
.
max_cycles
=
0
;
...
...
packet-exchange/src/recv_packet.c
View file @
75b4ef10
...
...
@@ -161,7 +161,7 @@ void recv_udp_packet() {
stats
->
min_kernel_latency
=
min
(
kernel_latency
,
stats
->
min_kernel_latency
);
stats
->
max_kernel_latency
=
max
(
kernel_latency
,
stats
->
max_kernel_latency
);
stats
->
avg_kernel_latency
=
(
stats
->
max_kernel_latency
*
(
stats
->
packets_received
)
+
kernel_latency
)
/
(
stats
->
packets_received
+
1
);
stats
->
avg_kernel_latency
=
(
stats
->
max_kernel_latency
*
(
stats
->
packets_received
)
+
kernel_latency
)
/
(
stats
->
packets_received
+
1
);
if
(
use_histogram
)
{
if
(
kernel_latency
>
MAX_KERNEL_LATENCY
)
...
...
packet-exchange/src/recv_packet.h
View file @
75b4ef10
...
...
@@ -22,8 +22,9 @@ typedef struct ingress_stat {
int
avg_interval
;
int
max_interval
;
uint64_t
high_kernel_latency
;
uint64_t
packets_received
;
uint64_t
high_kernel_latency
;
uint64_t
high_jitter
;
int
lost_packets
;
char
data
[
MAX_BUFFER_SIZE
];
...
...
packet-exchange/src/send_packet.c
View file @
75b4ef10
...
...
@@ -224,7 +224,7 @@ static void process_error_queue() {
stats
->
min_kernel_latency
=
min
(
kernel_latency
,
stats
->
min_kernel_latency
);
stats
->
max_kernel_latency
=
max
(
kernel_latency
,
stats
->
max_kernel_latency
);
stats
->
avg_kernel_latency
=
(
stats
->
max_kernel_latency
*
packets_sent
+
kernel_latency
)
/
(
packets_sent
+
1
);
stats
->
avg_kernel_latency
=
(
stats
->
max_kernel_latency
*
packets_sent
+
kernel_latency
)
/
(
packets_sent
+
1
);
if
(
use_histogram
)
{
if
(
kernel_latency
>
MAX_KERNEL_LATENCY
)
...
...
packet-exchange/src/server.c
View file @
75b4ef10
...
...
@@ -31,6 +31,8 @@
// Structs
enum
TSNTask
{
RECV_PACKET_TASK
,
RTT_TASK
};
typedef
struct
thread_param
{
int
interval
;
int
priority
;
...
...
@@ -53,20 +55,21 @@ static uint64_t jitter_hist[MAX_JITTER];
static
main_param_t
main_params
;
static
thread_param_t
thread_params
;
static
ingress_stat_t
ingress_stats
;
static
ingress_param_t
ingress_params
;
static
egress_stat_t
egress_stats
;
static
egress_param_t
egress_params
;
static
egress_stat_t
egress_stats
=
{.
min_kernel_latency
=
INT_MAX
};
static
ingress_stat_t
ingress_stats
=
{.
min_kernel_latency
=
INT_MAX
,
.
min_interval
=
INT_MAX
};
static
int
enable_histograms
;
static
int
enable_affinity
;
static
int
enable_timestamps
;
enum
TSNTask
{
RECV_PACKET_TASK
,
RTT_TASK
};
static
enum
TSNTask
tsn_task
;
struct
timespec
measures_start
;
struct
timespec
measures_end
;
st
atic
st
ruct
timespec
measures_start
;
st
atic
st
ruct
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
]);
...
...
@@ -87,14 +90,14 @@ static void help(char *argv[]) {
// Real-time thread
// Measures intervals between packet receptions
static
void
*
packet_receiving_thread
(
void
*
p
)
{
(
void
)
p
;
(
void
)
p
;
struct
timespec
current
,
previous
;
struct
sched_param
priority
;
cpu_set_t
mask
;
int
prev_packet_id
=
0
;
if
(
enable_affinity
)
{
// Set thread CPU affinity
if
(
enable_affinity
)
{
CPU_ZERO
(
&
mask
);
CPU_SET
(
1
,
&
mask
);
if
(
sched_setaffinity
(
0
,
sizeof
(
mask
),
&
mask
))
...
...
@@ -107,6 +110,7 @@ static void *packet_receiving_thread(void *p) {
error
(
EXIT_FAILURE
,
errno
,
"Couldn't set priority"
);
clock_gettime
(
CLOCK_MONOTONIC
,
&
measures_start
);
// Packet receiving loop
for
(
ingress_stats
.
packets_received
=
0
;;
ingress_stats
.
packets_received
++
)
{
...
...
@@ -130,7 +134,7 @@ static void *packet_receiving_thread(void *p) {
ingress_stats
.
min_interval
=
min
(
interval_us
,
ingress_stats
.
min_interval
);
ingress_stats
.
max_interval
=
max
(
interval_us
,
ingress_stats
.
max_interval
);
ingress_stats
.
avg_interval
=
(
ingress_stats
.
avg_interval
*
ingress_stats
.
packets_received
+
interval_us
)
/
(
ingress_stats
.
packets_received
+
1
);
ingress_stats
.
avg_interval
=
(
ingress_stats
.
avg_interval
*
ingress_stats
.
packets_received
+
interval_us
)
/
(
ingress_stats
.
packets_received
+
1
);
// Check if packets were lost
ingress_stats
.
lost_packets
+=
(
current_packet_id
-
prev_packet_id
-
1
)
%
1000
;
...
...
@@ -140,7 +144,7 @@ static void *packet_receiving_thread(void *p) {
dist_to_interval
+=
MAX_JITTER
/
2
;
if
(
dist_to_interval
>
((
int
)
MAX_JITTER
)
||
dist_to_interval
<
0
)
fprintf
(
stderr
,
"jitter higher than MAX_JITTER: %d
\n
"
,
dist_to_interval
)
;
ingress_stats
.
high_jitter
++
;
else
jitter_hist
[
dist_to_interval
]
++
;
}
...
...
@@ -169,7 +173,6 @@ int main(int argc, char *argv[]) {
ingress_stats
.
packets_received
=
0
;
// Default configuration values
thread_params
.
interval
=
100000
*
1000
;
thread_params
.
priority
=
99
;
...
...
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