Commit 3f4964a6 authored by Joanne Hugé's avatar Joanne Hugé

Compute userspace timestamp after recvmsg in recvpacket

parent f09aa981
...@@ -39,9 +39,7 @@ static ingress_stat_t *stats; ...@@ -39,9 +39,7 @@ static ingress_stat_t *stats;
static uint64_t *kernel_latency_hist; static uint64_t *kernel_latency_hist;
static int use_histogram; static int use_histogram;
static uint64_t timestamps_buffer[TIMESTAMP_BUFFER_SIZE]; uint64_t post_kernel_timestamp;
static int ts_buf_read_index = 0;
static int ts_buf_write_index = 0;
// Sets the interface // Sets the interface
static int set_if() { static int set_if() {
...@@ -130,12 +128,6 @@ void recv_udp_packet() { ...@@ -130,12 +128,6 @@ void recv_udp_packet() {
struct timespec ts; struct timespec ts;
if (params->use_timestamps) {
clock_gettime(CLOCK_REALTIME, &ts);
timestamps_buffer[ts_buf_write_index] = ts_to_uint(ts);
ts_buf_write_index = (ts_buf_write_index + 1) % TIMESTAMP_BUFFER_SIZE;
}
iov.iov_base = &rx_buffer; iov.iov_base = &rx_buffer;
iov.iov_len = MAX_BUFFER_SIZE - 1; iov.iov_len = MAX_BUFFER_SIZE - 1;
...@@ -151,13 +143,19 @@ void recv_udp_packet() { ...@@ -151,13 +143,19 @@ 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 (params->use_timestamps) {
clock_gettime(CLOCK_REALTIME, &ts);
post_kernel_timestamp = ts_to_uint(ts);
}
if (params->use_timestamps) { if (params->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);
uint64_t kernel_latency = timestamps_buffer[ts_buf_read_index] - ts_to_uint(*stamp); uint64_t kernel_latency = post_kernel_timestamp - ts_to_uint(*stamp);
ts_buf_read_index = (ts_buf_read_index + 1) % TIMESTAMP_BUFFER_SIZE; ts_buf_read_index = (ts_buf_read_index + 1) % TIMESTAMP_BUFFER_SIZE;
kernel_latency /= 1000u; kernel_latency /= 1000u;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment