From 9cb736e11d82bf5cfe8085ae4bf3dccda91b5ee3 Mon Sep 17 00:00:00 2001 From: amarsri28 <38097938+amarsri28@users.noreply.github.com> Date: Thu, 3 Mar 2022 01:56:40 +0530 Subject: [PATCH] Fix division by zero crash when doing metering (#529) * Revert "Workaround for division by zero crash (#385)" This reverts commit 103b19842673b1557b47a5e103b786518cd24058. * Revert "QoS: Use params to profile map, carry pointer" This reverts commit d2c079317b8cc9878c957a101287323e0fa9f286. Co-authored-by: Maximilian Pudelko --- core/modules/qos.cc | 59 +++++++++++++-------------------------------- core/modules/qos.h | 21 +--------------- 2 files changed, 18 insertions(+), 62 deletions(-) diff --git a/core/modules/qos.cc b/core/modules/qos.cc index 84ecbf454..7eb0d6806 100644 --- a/core/modules/qos.cc +++ b/core/modules/qos.cc @@ -161,27 +161,19 @@ void Qos::ProcessBatch(Context *ctx, bess::PacketBatch *batch) { // meter if ogate is 0 if (ogate == METER_GATE) { - if (val[j]->p->cir_period == 0 || val[j]->p->pir_period == 0) { - // FIXME: https://github.com/omec-project/upf-epc/issues/376 - DLOG(INFO) << "Detected pir/cir_period zero in rte_meter_trtcm_profile," - << " BUG? Setting METER_GREEN_GATE to prevent crash" - << std::endl; + uint64_t time = rte_rdtsc(); + uint32_t pkt_len = pkt->total_len() - val[j]->deduct_len; + uint8_t color = rte_meter_trtcm_color_blind_check(&val[j]->m, &val[j]->p, + time, pkt_len); + + DLOG(INFO) << "color : " << color << std::endl; + // update ogate to color specific gate + if (color == RTE_COLOR_GREEN) { ogate = METER_GREEN_GATE; - } else { - uint64_t time = rte_rdtsc(); - uint32_t pkt_len = pkt->total_len() - val[j]->deduct_len; - uint8_t color = rte_meter_trtcm_color_blind_check(&val[j]->m, val[j]->p, - time, pkt_len); - - DLOG(INFO) << "color : " << color << std::endl; - // update ogate to color specific gate - if (color == RTE_COLOR_GREEN) { - ogate = METER_GREEN_GATE; - } else if (color == RTE_COLOR_YELLOW) { - ogate = METER_YELLOW_GATE; - } else if (color == RTE_COLOR_RED) { - ogate = METER_RED_GATE; - } + } else if (color == RTE_COLOR_YELLOW) { + ogate = METER_YELLOW_GATE; + } else if (color == RTE_COLOR_RED) { + ogate = METER_RED_GATE; } } @@ -386,28 +378,12 @@ CommandResponse Qos::CommandAdd(const bess::pb::QosCommandAddArg &arg) { struct rte_meter_trtcm_params app_trtcm_params = { .cir = cir, .pir = pir, .cbs = cbs, .pbs = pbs}; - auto *result = params_map_.Find(app_trtcm_params); - - if (result == nullptr) { - struct rte_meter_trtcm_profile p; - - int ret = rte_meter_trtcm_profile_config(&p, &app_trtcm_params); - if (ret) - return CommandFailure( - ret, - "Insert Failed - rte_meter_trtcm_profile_config creation failed"); - - result = params_map_.Insert(app_trtcm_params, p); - if (result == nullptr) { - return CommandFailure( - ret, - "Insert Failed - rte_meter_trtcm_profile_config map insert failed"); - } - } - - v.p = &result->second; + int ret = rte_meter_trtcm_profile_config(&v.p, &app_trtcm_params); + if (ret) + return CommandFailure( + ret, "Insert Failed - rte_meter_trtcm_profile_config failed"); - int ret = rte_meter_trtcm_config(&v.m, v.p); + ret = rte_meter_trtcm_config(&v.m, &v.p); if (ret) { return CommandFailure(ret, "Insert Failed - rte_meter_trtcm_config failed"); @@ -433,7 +409,6 @@ CommandResponse Qos::CommandClear(__attribute__((unused)) void Qos::Clear() { table_.Clear(); - params_map_.Clear(); } void Qos::DeInit() { diff --git a/core/modules/qos.h b/core/modules/qos.h index d5a329f7a..e2ff8be52 100644 --- a/core/modules/qos.h +++ b/core/modules/qos.h @@ -13,10 +13,8 @@ #include #include "../pb/module_msg.pb.h" -#include "../utils/cuckoo_map.h" #include "../utils/metering.h" -using bess::utils::CuckooMap; using bess::utils::Metering; using bess::utils::MeteringKey; @@ -40,7 +38,7 @@ enum { FieldType = 0, ValueType }; struct value { gate_idx_t ogate; int64_t deduct_len; - struct rte_meter_trtcm_profile *p; + struct rte_meter_trtcm_profile p; struct rte_meter_trtcm m; MeteringKey Data; } __attribute__((packed)); @@ -56,21 +54,6 @@ class Qos final : public Module { static const Commands cmds; - struct Hash { - bess::utils::HashResult operator()( - const rte_meter_trtcm_params &key) const { - return rte_hash_crc(&key, sizeof(rte_meter_trtcm_params), 0); - } - }; - - struct EqualTo { - bool operator()(const rte_meter_trtcm_params &p1, - const rte_meter_trtcm_params &p2) const { - return (p1.cir == p2.cir) && (p1.pir == p2.pir) && (p1.cbs == p2.cbs) && - (p1.pbs == p2.pbs); - } - }; - Qos() : Module(), default_gate_(), total_key_size_(), fields_() { max_allowed_workers_ = Worker::kMaxWorkers; size_t len = sizeof(mask) / sizeof(uint64_t); @@ -106,8 +89,6 @@ class Qos final : public Module { std::vector values_; Metering table_; uint64_t mask[MAX_FIELDS]; - CuckooMap - params_map_; }; #endif // BESS_MODULES_QOS_H