From 37de87ae48617c25ae8a48ef77499e1f5b9f0267 Mon Sep 17 00:00:00 2001 From: Tom Barbette <tom.barbette@uclouvain.be> Date: Tue, 18 Jul 2023 10:01:26 +0200 Subject: [PATCH] TimestampDiff: Enable nanosecond precision --- elements/analysis/timestampdiff.cc | 7 ++++--- elements/analysis/timestampdiff.hh | 2 +- include/click/tsctimestamp.hh | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/elements/analysis/timestampdiff.cc b/elements/analysis/timestampdiff.cc index 99dd36fa7..dc1130552 100644 --- a/elements/analysis/timestampdiff.cc +++ b/elements/analysis/timestampdiff.cc @@ -56,6 +56,7 @@ int TimestampDiff::configure(Vector<String> &conf, ErrorHandler *errh) .read("OFFSET",_offset) .read("N", _limit) .read("MAXDELAY", _max_delay_ms) + .read("NANO", _nano) .read_or_set("SAMPLE", _sample, 1) .read_or_set("VERBOSE", _verbose, false) .read_or_set("TC_OFFSET", _tc_offset, -1) @@ -256,12 +257,12 @@ inline int TimestampDiff::smaction(Packet *p) } TimestampT diff = now - old; - uint32_t usec = diff.usecval(); - if ((usec > _max_delay_ms * 1000)) { + uint32_t usec = _nano? diff.nsecval() : diff.usecval(); + if ((usec > _max_delay_ms * (_nano?1000000:1000))) { if (_verbose) { click_chatter( "Packet %" PRIu64 " experienced delay %u ms > %u ms", - i, (usec)/1000, _max_delay_ms + i, (usec)/ (_nano?1000000:1000), _max_delay_ms ); } } diff --git a/elements/analysis/timestampdiff.hh b/elements/analysis/timestampdiff.hh index 649ee88a2..12c379b50 100644 --- a/elements/analysis/timestampdiff.hh +++ b/elements/analysis/timestampdiff.hh @@ -89,7 +89,7 @@ private: bool _verbose; int _tc_offset; unsigned char _tc_mask; - + bool _nano; inline int smaction(Packet *p); RecordTimestamp *get_recordtimestamp_instance(); diff --git a/include/click/tsctimestamp.hh b/include/click/tsctimestamp.hh index 906f696e4..f1c056005 100644 --- a/include/click/tsctimestamp.hh +++ b/include/click/tsctimestamp.hh @@ -76,6 +76,13 @@ class TSCTimestamp { return val / (cycles_hz_warp() / 1000000); } + /** + * @brief returns the total number of nsecs represented by this timestamp + */ + inline double nsecval() { + return (double)val / ((double)cycles_hz_warp() / 1000000000.0d); + } + inline int64_t tsc_val() { return val; } -- GitLab