From eedd18183ea5b06947079984de83cd145684cd38 Mon Sep 17 00:00:00 2001 From: luwenpeng Date: Fri, 24 Nov 2023 15:17:18 +0800 Subject: perf: 优化session_ctx减少内存占用; 优化global metrics的结构 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/include/utils.h | 43 ------------------------------------------- common/src/utils.cpp | 23 ----------------------- common/test/gtest_utils.cpp | 28 ---------------------------- 3 files changed, 94 deletions(-) (limited to 'common') diff --git a/common/include/utils.h b/common/include/utils.h index b0dfbf4..c606766 100644 --- a/common/include/utils.h +++ b/common/include/utils.h @@ -52,49 +52,6 @@ int mutable_array_count_elem(struct mutable_array *array); int mutable_array_exist_elem(struct mutable_array *array, uint64_t elem); int mutable_array_index_elem(struct mutable_array *array, int index); -/****************************************************************************** - * sids - ******************************************************************************/ - -typedef uint16_t sid_t; -#define MR_SID_LIST_MAXLEN 8 - -struct sids -{ - int num; - sid_t elems[MR_SID_LIST_MAXLEN]; -}; - -void sids_copy(struct sids *dst, struct sids *src); - -/****************************************************************************** - * route_ctx - ******************************************************************************/ - -struct route_ctx -{ - char data[64]; - int len; -}; - -void route_ctx_copy(struct route_ctx *dst, struct route_ctx *src); - -/****************************************************************************** - * throughput_metrics - ******************************************************************************/ - -struct throughput_metrics -{ - uint64_t n_pkts; - uint64_t n_bytes; -}; - -static inline void throughput_metrics_inc(struct throughput_metrics *iterm, uint64_t n_pkts, uint64_t n_bytes) -{ - iterm->n_bytes += n_bytes; - iterm->n_pkts += n_pkts; -} - /****************************************************************************** * device ******************************************************************************/ diff --git a/common/src/utils.cpp b/common/src/utils.cpp index 94d644f..773b1f2 100644 --- a/common/src/utils.cpp +++ b/common/src/utils.cpp @@ -98,29 +98,6 @@ int mutable_array_index_elem(struct mutable_array *array, int index) return array->elems[index]; } -/****************************************************************************** - * sids - ******************************************************************************/ - -void sids_copy(struct sids *dst, struct sids *src) -{ - if (dst && src) - { - dst->num = src->num; - memcpy(dst->elems, src->elems, sizeof(dst->elems[0]) * dst->num); - } -} - -/****************************************************************************** - * route_ctx - ******************************************************************************/ - -void route_ctx_copy(struct route_ctx *dst, struct route_ctx *src) -{ - memcpy(dst->data, src->data, src->len); - dst->len = src->len; -} - /****************************************************************************** * device ******************************************************************************/ diff --git a/common/test/gtest_utils.cpp b/common/test/gtest_utils.cpp index 5b85acd..9b50c62 100644 --- a/common/test/gtest_utils.cpp +++ b/common/test/gtest_utils.cpp @@ -36,34 +36,6 @@ TEST(UTILS, FIXED_NUM_ARRAY) EXPECT_TRUE(mutable_array_count_elem(&array) == 0); } -TEST(UTILS, SIDS) -{ - struct sids src; - struct sids dst; - - for (int i = 0; i < MR_SID_LIST_MAXLEN; i++) - { - src.elems[i] = i; - } - src.num = MR_SID_LIST_MAXLEN; - - sids_copy(&dst, &src); - - EXPECT_TRUE(dst.num == src.num); - for (int i = 0; i < MR_SID_LIST_MAXLEN; i++) - { - EXPECT_TRUE(dst.elems[i] == i); - } -} - -TEST(UTILS, THROUGHPUT_METRICS) -{ - struct throughput_metrics iterm = {.n_pkts = 0, .n_bytes = 0}; - throughput_metrics_inc(&iterm, 1, 2); - EXPECT_TRUE(iterm.n_pkts == 1); - EXPECT_TRUE(iterm.n_bytes == 2); -} - TEST(UTILS, DEVICE) { const char *dev_name = "lo"; -- cgit v1.2.3