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
2e191aec
Commit
2e191aec
authored
Jun 04, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly compute userspace and kernelspace timestamps when receiving a packet
parent
b47dc228
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
24 deletions
+29
-24
packet-exchange/src/client.c
packet-exchange/src/client.c
+3
-3
packet-exchange/src/recv_packet.c
packet-exchange/src/recv_packet.c
+15
-10
packet-exchange/src/send_packet.c
packet-exchange/src/send_packet.c
+5
-5
packet-exchange/src/server.c
packet-exchange/src/server.c
+3
-3
packet-exchange/src/utilities.h
packet-exchange/src/utilities.h
+3
-3
No files found.
packet-exchange/src/client.c
View file @
2e191aec
...
...
@@ -207,13 +207,13 @@ int main(int argc, char *argv[]) {
printf
(
"(%d) Enter send_udp_packet timestamp: %"
PRIu64
"
\n
"
,
stats
->
nb_cycles
,
stats
->
packet_ts
.
enter_user_space
);
stats
->
packet_ts
.
userspace_enter_ts
);
printf
(
"(%d) Call sendmsg timestamp : %"
PRIu64
"
\n
"
,
stats
->
nb_cycles
,
stats
->
packet_ts
.
enter_kernel
);
stats
->
packet_ts
.
userspace_exit_ts
);
printf
(
"(%d) Leave kernel timestamp : %"
PRIu64
"
\n
"
,
stats
->
nb_cycles
,
stats
->
packet_ts
.
leave_kernel
);
stats
->
packet_ts
.
kernelspace_ts
);
}
}
...
...
packet-exchange/src/recv_packet.c
View file @
2e191aec
...
...
@@ -122,12 +122,6 @@ packet_timestamps_t recv_udp_packet(int use_timestamps, int use_histograms, int6
packet_timestamps_t
packet_ts
;
struct
timespec
ts
;
if
(
use_timestamps
)
{
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_ts
.
enter_user_space
=
ts_to_uint
(
ts
);
}
iov
.
iov_base
=
&
rx_buffer
;
iov
.
iov_len
=
BUFFER_SIZE
-
1
;
...
...
@@ -141,31 +135,42 @@ packet_timestamps_t recv_udp_packet(int use_timestamps, int use_histograms, int6
if
(
use_timestamps
)
{
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_ts
.
enter_kernel
=
ts_to_uint
(
ts
);
packet_ts
.
userspace_exit_ts
=
ts_to_uint
(
ts
);
}
recvmsgerr
=
recvmsg
(
sock_fd
,
&
msg
,
0
);
if
(
recvmsgerr
<
0
)
error
(
EXIT_FAILURE
,
errno
,
"recvmsg failed, ret value: %d
\n
"
,
recvmsgerr
);
if
(
use_timestamps
)
{
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_ts
.
userspace_enter_ts
=
ts_to_uint
(
ts
);
}
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
)
{
struct
timespec
*
stamp
=
(
struct
timespec
*
)
CMSG_DATA
(
cmsg
);
packet_ts
.
leave_kernel
=
ts_to_uint
(
*
stamp
);
packet_ts
.
kernelspace_ts
=
ts_to_uint
(
*
stamp
);
if
(
use_histograms
)
fill_histograms
(
&
packet_ts
,
histograms
);
}
}
}
if
(
use_timestamps
)
{
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_ts
.
userspace_exit_ts
=
ts_to_uint
(
ts
);
}
return
packet_ts
;
}
static
void
fill_histograms
(
packet_timestamps_t
*
packet_ts
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
uint64_t
user_space_time
=
packet_ts
->
enter_kernel
-
packet_ts
->
enter_user_space
;
uint64_t
kernel_space_time
=
packet_ts
->
leave_kernel
-
packet_ts
->
enter_kernel
;
uint64_t
user_space_time
=
packet_ts
->
userspace_exit_ts
-
packet_ts
->
userspace_enter_ts
;
uint64_t
kernel_space_time
=
packet_ts
->
userspace_enter_ts
-
packet_ts
->
kernelspace_ts
;
user_space_time
/=
1000u
;
kernel_space_time
/=
1000u
;
...
...
packet-exchange/src/send_packet.c
View file @
2e191aec
...
...
@@ -166,7 +166,7 @@ packet_timestamps_t send_udp_packet(int use_etf, int use_timestamps,
if
(
use_timestamps
)
{
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_ts
.
enter_user_space
=
ts_to_uint
(
ts
);
packet_ts
.
userspace_enter_ts
=
ts_to_uint
(
ts
);
}
memset
(
&
sin
,
0
,
sizeof
(
sin
));
...
...
@@ -198,7 +198,7 @@ packet_timestamps_t send_udp_packet(int use_etf, int use_timestamps,
if
(
use_timestamps
)
{
clock_gettime
(
CLOCK_REALTIME
,
&
ts
);
packet_ts
.
enter_kernel
=
ts_to_uint
(
ts
);
packet_ts
.
userspace_exit_ts
=
ts_to_uint
(
ts
);
}
sendmsgerr
=
sendmsg
(
sock_fd
,
&
msg
,
0
);
...
...
@@ -218,8 +218,8 @@ packet_timestamps_t send_udp_packet(int use_etf, int use_timestamps,
static
void
fill_histograms
(
packet_timestamps_t
*
packet_ts
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
uint64_t
user_space_time
=
packet_ts
->
enter_kernel
-
packet_ts
->
enter_user_space
;
uint64_t
kernel_space_time
=
packet_ts
->
leave_kernel
-
packet_ts
->
enter_kernel
;
uint64_t
user_space_time
=
packet_ts
->
userspace_exit_ts
-
packet_ts
->
userspace_enter_ts
;
uint64_t
kernel_space_time
=
packet_ts
->
kernelspace_ts
-
packet_ts
->
userspace_exit_ts
;
user_space_time
/=
1000u
;
kernel_space_time
/=
1000u
;
...
...
@@ -267,7 +267,7 @@ static void process_timestamps(packet_timestamps_t *packet_ts, int64_t histogram
if
(
cmsg
->
cmsg_level
==
SOL_SOCKET
&&
cmsg
->
cmsg_type
==
SO_TIMESTAMPING
)
{
struct
timespec
*
stamp
=
(
struct
timespec
*
)
CMSG_DATA
(
cmsg
);
packet_ts
->
leave_kernel
=
ts_to_uint
(
*
stamp
);
packet_ts
->
kernelspace_ts
=
ts_to_uint
(
*
stamp
);
fill_histograms
(
packet_ts
,
histograms
);
}
else
{
...
...
packet-exchange/src/server.c
View file @
2e191aec
...
...
@@ -226,13 +226,13 @@ int main(int argc, char *argv[]) {
if
(
enable_timestamps
)
{
printf
(
"(%d) Enter send_udp_packet timestamp: %"
PRIu64
"
\n
"
,
stats
->
packets_received
,
stats
->
packet_ts
.
enter_user_space
);
stats
->
packet_ts
.
userspace_enter_ts
);
printf
(
"(%d) Call sendmsg timestamp : %"
PRIu64
"
\n
"
,
stats
->
packets_received
,
stats
->
packet_ts
.
enter_kernel
);
stats
->
packet_ts
.
userspace_exit_ts
);
printf
(
"(%d) Leave kernel timestamp : %"
PRIu64
"
\n
"
,
stats
->
packets_received
,
stats
->
packet_ts
.
leave_kernel
);
stats
->
packet_ts
.
kernelspace_ts
);
}
}
}
...
...
packet-exchange/src/utilities.h
View file @
2e191aec
...
...
@@ -14,9 +14,9 @@
#define NB_HISTOGRAMS 3
typedef
struct
packet_timestamps
{
uint64_t
enter_user_space
;
uint64_t
enter_kernel
;
uint64_t
leave_kernel
;
uint64_t
userspace_enter_ts
;
uint64_t
userspace_exit_ts
;
uint64_t
kernelspace_ts
;
}
packet_timestamps_t
;
uint64_t
ts_to_uint
(
struct
timespec
t
);
...
...
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