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
166ec762
Commit
166ec762
authored
Jun 03, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix rx_timestamps on reception
parent
8b83646b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
56 deletions
+14
-56
packet-exchange/src/recv_packet.c
packet-exchange/src/recv_packet.c
+14
-56
No files found.
packet-exchange/src/recv_packet.c
View file @
166ec762
...
...
@@ -32,7 +32,7 @@
#define BUFFER_SIZE 1024
static
void
process_timestamp
s
(
packet_timestamps_t
*
packet_ts
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
static
void
fill_histogram
s
(
packet_timestamps_t
*
packet_ts
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
]);
static
char
rx_buffer
[
BUFFER_SIZE
];
static
int
sock_fd
;
...
...
@@ -108,17 +108,17 @@ int init_udp_recv(int use_timestamps, char *network_if) {
*/
packet_timestamps_t
recv_udp_packet
(
int
use_timestamps
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
struct
cmsghdr
*
cmsg
;
struct
msghdr
msg
;
// Message hardware, sent to the socket
struct
iovec
iov
;
// The iovec structures stores the RX buffer
struct
sockaddr_in
sin
;
// Poll file descriptor, used to poll for timestamp messages
struct
pollfd
poll_fd
=
{
sock_fd
,
POLLPRI
,
0
};
int
recvmsgerr
,
pollerr
;
int
recvmsgerr
;
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
);
...
...
@@ -142,14 +142,17 @@ packet_timestamps_t recv_udp_packet(int use_timestamps, int64_t histograms[NB_HI
if
(
recvmsgerr
<
0
)
error
(
EXIT_FAILURE
,
errno
,
"recvmsg failed, ret value: %d
\n
"
,
recvmsgerr
);
if
(
use_timestamps
)
{
pollerr
=
poll
(
&
poll_fd
,
1
,
0
);
if
(
pollerr
>
0
)
process_timestamps
(
&
packet_ts
,
histograms
);
else
fprintf
(
stderr
,
"select failed
\n
"
);
}
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
);
fill_histograms
(
&
packet_ts
,
histograms
);
}
}
}
return
packet_ts
;
}
...
...
@@ -174,51 +177,6 @@ static void fill_histograms(packet_timestamps_t *packet_ts, int64_t histograms[N
histograms
[
1
][
kernel_space_time
]
++
;
}
static
void
process_timestamps
(
packet_timestamps_t
*
packet_ts
,
int64_t
histograms
[
NB_HISTOGRAMS
][
MAX_HIST_VAL
])
{
char
data
[
256
];
struct
msghdr
msg
;
struct
iovec
entry
;
struct
sockaddr_in
from_addr
;
struct
{
struct
cmsghdr
cm
;
char
control
[
512
];
}
control
;
struct
cmsghdr
*
cmsg
;
memset
(
&
msg
,
0
,
sizeof
(
msg
));
msg
.
msg_iov
=
&
entry
;
msg
.
msg_iovlen
=
1
;
entry
.
iov_base
=
data
;
entry
.
iov_len
=
sizeof
(
data
);
msg
.
msg_name
=
(
caddr_t
)
&
from_addr
;
msg
.
msg_namelen
=
sizeof
(
from_addr
);
msg
.
msg_control
=
&
control
;
msg
.
msg_controllen
=
sizeof
(
control
);
if
(
recvmsg
(
sock_fd
,
&
msg
,
MSG_ERRQUEUE
|
MSG_DONTWAIT
)
==
-
1
)
{
fprintf
(
stderr
,
"recvmsg failed
\n
"
);
return
;
}
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
);
fill_histograms
(
packet_ts
,
histograms
);
}
else
{
#ifdef DEBUG
fprintf
(
stderr
,
"process_timestamps: level %d type %d"
,
cmsg
->
cmsg_level
,
cmsg
->
cmsg_type
);
#endif
}
}
}
#ifdef DEBUG
/*
...
...
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