diff --git a/core/modules/measure.cc b/core/modules/measure.cc index ceef891832..5fca8d13d8 100644 --- a/core/modules/measure.cc +++ b/core/modules/measure.cc @@ -110,9 +110,6 @@ void Measure::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { uint64_t now_ns = tsc_to_ns(rdtsc()); size_t offset = offset_; - mcslock_node_t mynode; - mcs_lock(&lock_, &mynode); - pkt_cnt_ += batch->cnt(); int cnt = batch->cnt(); @@ -132,21 +129,20 @@ void Measure::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { bytes_cnt_ += batch->pkts()[i]->total_len(); - rtt_hist_.Insert(diff); + rtt_hist_.AtomicInsert(diff); if (rand_.GetRealNonzero() <= jitter_sample_prob_) { if (unlikely(!last_rtt_ns_)) { last_rtt_ns_ = diff; continue; } - uint64_t jitter = absdiff(diff, last_rtt_ns_); - jitter_hist_.Insert(jitter); + int64_t jitter = diff - last_rtt_ns_; + jitter = jitter * ((jitter>0) - (jitter<0)); + jitter_hist_.AtomicInsert(jitter); last_rtt_ns_ = diff; } } } - mcs_unlock(&lock_, &mynode); - RunNextModule(ctx, batch); } diff --git a/core/modules/measure.h b/core/modules/measure.h index d4934fbae3..99ceac8066 100644 --- a/core/modules/measure.h +++ b/core/modules/measure.h @@ -38,7 +38,7 @@ #include "../utils/histogram.h" #include "../utils/mcslock.h" #include "../utils/random.h" - +#include class Measure final : public Module { public: Measure(uint64_t ns_per_bucket = 1, uint64_t max_ns = 0) @@ -69,22 +69,18 @@ class Measure final : public Module { static const uint64_t kDefaultNsPerBucket = 100; static const uint64_t kDefaultMaxNs = 100'000'000; // 100 ms static constexpr double kDefaultIpDvSampleProb = 0.05; - void Clear(); - Histogram rtt_hist_; Histogram jitter_hist_; Random rand_; double jitter_sample_prob_; - uint64_t last_rtt_ns_; - + std::atomic last_rtt_ns_; size_t offset_; // in bytes int attr_id_; - uint64_t pkt_cnt_; - uint64_t bytes_cnt_; - + std::atomic pkt_cnt_; + std::atomic bytes_cnt_; mcslock lock_; };