Skip to content

Commit 22608e4

Browse files
authored
Merge pull request #1051 from tarun-t/fix/propagate-dpdk-rx-timestamp
Propagate DPDK mbuf RX timestamp to FreeBSD mbuf rcv_tstmp
2 parents 6d30bc6 + 7a6c075 commit 22608e4

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

lib/ff_dpdk_if.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <rte_udp.h>
5555
#include <rte_eth_bond.h>
5656
#include <rte_eth_bond_8023ad.h>
57+
#include <rte_mbuf_dyn.h>
5758

5859
#include "ff_dpdk_if.h"
5960
#include "ff_dpdk_pcap.h"
@@ -80,6 +81,8 @@ static int numa_on;
8081

8182
static unsigned idle_sleep;
8283
static unsigned pkt_tx_delay;
84+
static int timestamp_dynfield_offset = -1;
85+
static uint64_t timestamp_dynflag_mask;
8386
static uint64_t usr_cb_tsc;
8487
static int stop_loop;
8588

@@ -741,6 +744,11 @@ init_port_start(void)
741744
pconf->hw_features.rx_csum = 1;
742745
}
743746

747+
if (dev_info.rx_offload_capa & RTE_ETH_RX_OFFLOAD_TIMESTAMP) {
748+
ff_log(FF_LOG_INFO, FF_LOGTYPE_FSTACK_LIB, "RX timestamp offload supported\n");
749+
port_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_TIMESTAMP;
750+
}
751+
744752
if (ff_global_cfg.dpdk.tx_csum_offoad_skip == 0) {
745753
if ((dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM)) {
746754
ff_log(FF_LOG_INFO, FF_LOGTYPE_FSTACK_LIB, "TX ip checksum offload supported\n");
@@ -852,6 +860,20 @@ init_port_start(void)
852860
return ret;
853861
}
854862

863+
if ((port_conf.rxmode.offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) &&
864+
timestamp_dynfield_offset < 0) {
865+
ret = rte_mbuf_dyn_rx_timestamp_register(
866+
&timestamp_dynfield_offset, &timestamp_dynflag_mask);
867+
if (ret == 0) {
868+
ff_log(FF_LOG_INFO, FF_LOGTYPE_FSTACK_LIB,
869+
"RX timestamp dynfield registered, offset=%d\n",
870+
timestamp_dynfield_offset);
871+
} else {
872+
ff_log(FF_LOG_ERR, FF_LOGTYPE_FSTACK_LIB,
873+
"RX timestamp dynfield registration failed\n");
874+
}
875+
}
876+
855877
//RSS reta update will failed when enable flow isolate
856878
#if !defined(FF_FLOW_ISOLATE) && !defined(FF_FLOW_IPIP)
857879
if (nb_queues > 1) {
@@ -1460,6 +1482,13 @@ ff_veth_input(const struct ff_dpdk_if_context *ctx, struct rte_mbuf *pkt)
14601482
ff_mbuf_set_vlan_info(hdr, pkt->vlan_tci);
14611483
}
14621484

1485+
if ((pkt->ol_flags & timestamp_dynflag_mask) &&
1486+
timestamp_dynfield_offset >= 0) {
1487+
rte_mbuf_timestamp_t ts = *RTE_MBUF_DYNFIELD(
1488+
pkt, timestamp_dynfield_offset, rte_mbuf_timestamp_t *);
1489+
ff_mbuf_set_timestamp(hdr, (uint64_t)ts);
1490+
}
1491+
14631492
struct rte_mbuf *pn = pkt->next;
14641493
void *prev = hdr;
14651494
while(pn != NULL) {

lib/ff_syscall_wrapper.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
#define LINUX_SO_SNDLOWAT 19
8181
#define LINUX_SO_RCVTIMEO 20
8282
#define LINUX_SO_SNDTIMEO 21
83+
#define LINUX_SO_TIMESTAMP 29
8384
#define LINUX_SO_ACCEPTCONN 30
8485
#define LINUX_SO_PROTOCOL 38
8586

@@ -566,6 +567,8 @@ so_opt_convert(int optname)
566567
return SO_ACCEPTCONN;
567568
case LINUX_SO_PROTOCOL:
568569
return SO_PROTOCOL;
570+
case LINUX_SO_TIMESTAMP:
571+
return SO_TIMESTAMP;
569572
default:
570573
return -1;
571574
}

lib/ff_veth.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,3 +1124,10 @@ ff_mbuf_set_vlan_info(void *hdr, uint16_t vlan_tci) {
11241124
return;
11251125
}
11261126

1127+
void
1128+
ff_mbuf_set_timestamp(void *hdr, uint64_t timestamp) {
1129+
struct mbuf *m = (struct mbuf *)hdr;
1130+
m->m_pkthdr.rcv_tstmp = timestamp;
1131+
m->m_flags |= M_TSTMP | M_TSTMP_HPREC;
1132+
}
1133+

lib/ff_veth.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ void *ff_veth_get_softc(void *host_ctx);
5252
void ff_veth_free_softc(void *softc);
5353

5454
void ff_mbuf_set_vlan_info(void *hdr, uint16_t vlan_tci);
55+
void ff_mbuf_set_timestamp(void *hdr, uint64_t timestamp);
5556

5657
#endif /* ifndef _FSTACK_VETH_H */

0 commit comments

Comments
 (0)