Skip to content

Commit

Permalink
Merge pull request #219 from CESNET/dpdk-ring-metadata-timestamp
Browse files Browse the repository at this point in the history
dpdk-ring - read timestamp from hw metadata if available
  • Loading branch information
SiskaPavel authored Sep 30, 2024
2 parents 7d51f88 + 5adbd36 commit 9d4f9aa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
46 changes: 46 additions & 0 deletions input/dpdk-ring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,30 @@ void DpdkRingReader::init(const char* params)
} else {
is_reader_ready = true;
}
getDynfieldInfo();
}

struct timeval DpdkRingReader::getTimestamp(rte_mbuf* mbuf)
{
struct timeval tv;
if (m_nfbMetadataEnabled) {
uint64_t nfb_dynflag_mask = (1ULL << m_nfbMetadataDynfieldInfo.dynflag_bit_index);

if (mbuf->ol_flags & nfb_dynflag_mask) {
const uint16_t ct_hdr_offset = *RTE_MBUF_DYNFIELD(
mbuf, m_nfbMetadataDynfieldInfo.dynfield_byte_index, uint16_t*
);

struct NfbMetadata *ct_hdr = (struct NfbMetadata*)
((uint8_t*)mbuf->buf_addr + ct_hdr_offset);

tv.tv_sec = ct_hdr->timestamp.timestamp_s;
tv.tv_usec = ct_hdr->timestamp.timestamp_ns / 1000;
return tv;
}
}

// fallback to software timestamp
auto now = std::chrono::system_clock::now();
auto now_t = std::chrono::system_clock::to_time_t(now);

Expand Down Expand Up @@ -210,4 +229,31 @@ void DpdkRingReader::configure_telemetry_dirs(
register_file(queues_dir, "input-stats", statsOps);
}

void DpdkRingReader::getDynfieldInfo()
{
struct rte_mbuf_dynfield dynfield_params;
struct rte_mbuf_dynflag dynflag_param;
int ret;
bool dynflag_found = false;
bool dynfield_found = false;

rte_errno = 0;
ret = rte_mbuf_dynflag_lookup("rte_net_nfb_dynflag_header_vld", &dynflag_param);
if (ret >= 0) {
m_nfbMetadataDynfieldInfo.dynflag_bit_index = ret;
dynflag_found = true;
}

rte_errno = 0;
ret = rte_mbuf_dynfield_lookup("rte_net_nfb_dynfield_header_offset", &dynfield_params);
if (ret >= 0) {
m_nfbMetadataDynfieldInfo.dynfield_byte_index = ret;
dynfield_found = true;
}

if (dynflag_found && dynfield_found) {
m_nfbMetadataEnabled = true;
}
}

} // namespace ipxp
19 changes: 19 additions & 0 deletions input/dpdk-ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,24 @@ class DpdkRingReader : public InputPlugin {
uint64_t receivedBytes;
};

struct NfbMetadataDynfieldInfo {
int dynflag_bit_index;
int dynfield_byte_index;
};

struct NfbTimestamp {
uint32_t timestamp_ns;
uint32_t timestamp_s;
} __rte_packed;

struct NfbMetadata {
NfbTimestamp timestamp;
uint16_t matched;
uint32_t hash;
} __rte_packed;

telemetry::Content get_queue_telemetry();
void getDynfieldInfo();

std::vector<rte_mbuf *> mbufs_;
std::uint16_t pkts_read_;
Expand All @@ -145,6 +162,8 @@ class DpdkRingReader : public InputPlugin {
rte_ring *m_ring;
bool is_reader_ready = false;
DpdkRingStats m_stats = {};
bool m_nfbMetadataEnabled = false;
NfbMetadataDynfieldInfo m_nfbMetadataDynfieldInfo = {};
};
} // namespace ipxp

Expand Down

0 comments on commit 9d4f9aa

Please sign in to comment.