Skip to content

Commit

Permalink
packet drop resolution (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
amarsri28 authored Feb 27, 2024
1 parent 07ad76f commit 7e8d814
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
18 changes: 3 additions & 15 deletions core/modules/measure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,52 +101,40 @@ CommandResponse Measure::Init(const bess::pb::MeasureArg &arg) {
}

mcs_lock_init(&lock_);

return CommandSuccess();
}

void Measure::ProcessBatch(Context *ctx, bess::PacketBatch *batch) {
// We don't use ctx->current_ns here for better accuracy
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();
for (int i = 0; i < cnt; i++) {
uint64_t pkt_time = 0;
if (attr_id_ != -1)
pkt_time = get_attr<uint64_t>(this, attr_id_, batch->pkts()[i]);
if (pkt_time || IsTimestamped(batch->pkts()[i], offset, &pkt_time)) {
uint64_t diff;

if (now_ns >= pkt_time) {
diff = now_ns - pkt_time;
} else {
// The magic number matched, but timestamp doesn't seem correct
continue;
}

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);
uint64_t jitter = absdiff(diff, last_rtt_ns_.load());
jitter_hist_.AtomicInsert(jitter);
last_rtt_ns_ = diff;
}
}
}

mcs_unlock(&lock_, &mynode);

RunNextModule(ctx, batch);
}

Expand Down
11 changes: 4 additions & 7 deletions core/modules/measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "../utils/histogram.h"
#include "../utils/mcslock.h"
#include "../utils/random.h"
#include <atomic>

class Measure final : public Module {
public:
Expand Down Expand Up @@ -69,22 +70,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<uint64_t> rtt_hist_;
Histogram<uint64_t> jitter_hist_;

Random rand_;
double jitter_sample_prob_;
uint64_t last_rtt_ns_;

std::atomic<std::uint64_t> last_rtt_ns_;
size_t offset_; // in bytes
int attr_id_;

uint64_t pkt_cnt_;
uint64_t bytes_cnt_;

std::atomic<std::uint64_t> pkt_cnt_;
std::atomic<std::uint64_t> bytes_cnt_;
mcslock lock_;
};

Expand Down

0 comments on commit 7e8d814

Please sign in to comment.