diff options
| author | root <[email protected]> | 2023-12-19 06:32:10 +0000 |
|---|---|---|
| committer | root <[email protected]> | 2023-12-19 06:32:10 +0000 |
| commit | 26ce1b6977f5ccce38bbfc8272edf81794a634f0 (patch) | |
| tree | 4a40210971428267e9c438c9c247445ba946c9f6 | |
| parent | bf2c165e0ce29f1fa52780e62f185eb151e1d20e (diff) | |
OMPUB-1083: 由本地计数修改为使用maat的自动垃圾回收机制
| -rw-r--r-- | conf/table_info.json | 2 | ||||
| -rw-r--r-- | shaping/include/shaper_maat.h | 2 | ||||
| -rw-r--r-- | shaping/src/shaper_maat.cpp | 36 | ||||
| -rw-r--r-- | shaping/test/gtest_shaper_maat.cpp | 6 | ||||
| -rw-r--r-- | shaping/test/stub.cpp | 7 |
5 files changed, 7 insertions, 46 deletions
diff --git a/conf/table_info.json b/conf/table_info.json index a05c22c..90aebc8 100644 --- a/conf/table_info.json +++ b/conf/table_info.json @@ -5,6 +5,7 @@ "table_type": "plugin", "valid_column": 9, "custom": { + "gc_timeout_s":2, "key": 1, "key_type": "integer", "key_len": 8 @@ -16,6 +17,7 @@ "table_type": "plugin", "valid_column": 8, "custom": { + "gc_timeout_s":2, "key": 1, "key_type": "pointer" } diff --git a/shaping/include/shaper_maat.h b/shaping/include/shaper_maat.h index 51db653..b570b60 100644 --- a/shaping/include/shaper_maat.h +++ b/shaping/include/shaper_maat.h @@ -13,7 +13,6 @@ struct shaping_rule { int borrow_pf_id_array[SHAPING_REF_PROFILE_NUM_MAX]; int borrow_pf_num; int fair_factor; - int ref_cnt; }; struct shaping_profile { @@ -22,7 +21,6 @@ struct shaping_profile { int in_limit_bandwidth; int out_limit_bandwidth; int valid; - int ref_cnt; }; void shaper_rule_ex_new(const char *table_name, int table_id, const char *key, const char *table_line, void **ad, long argl, void *argp); diff --git a/shaping/src/shaper_maat.cpp b/shaping/src/shaper_maat.cpp index 7a65cee..61f2e23 100644 --- a/shaping/src/shaper_maat.cpp +++ b/shaping/src/shaper_maat.cpp @@ -53,7 +53,6 @@ void shaper_rule_ex_new(const char *table_name, int table_id, const char *key, c } s_rule = (struct shaping_rule*)calloc(1, sizeof(struct shaping_rule)); - s_rule->ref_cnt = 1; ret = sscanf(table_line, "%d\t%*d\t%*d\t%*d\t%*d\t%*s\t%s\t", &s_rule->id, user_region); if (ret != 2) { @@ -119,33 +118,22 @@ END: void shaper_rule_ex_dup(int table_id, void **to, void **from, long argl, void *argp) { - struct shaping_rule *s_rule; - if (*from == NULL) { return; } - s_rule = (struct shaping_rule*)*from; - __atomic_add_fetch(&s_rule->ref_cnt, 1, __ATOMIC_SEQ_CST); - *to = s_rule; + *to = *from; return; } void shaper_rule_ex_free(int table_id, void **ad, long argl, void *argp) { - struct shaping_rule *s_rule; - if (*ad == NULL) { return; } - s_rule = (struct shaping_rule*)*ad; - if (__atomic_sub_fetch(&s_rule->ref_cnt, 1, __ATOMIC_SEQ_CST) > 0) { - return; - } - - free(s_rule); + free(*ad); *ad = NULL; return; @@ -172,7 +160,6 @@ void shaper_profile_ex_new(const char *table_name, int table_id, const char *key } s_pf = (struct shaping_profile*)calloc(1, sizeof(struct shaping_profile)); - s_pf->ref_cnt = 1; ret = sscanf(table_line, "%d\t%63s\t%63s\t%127s\t%63s\t%63s\t%63s\t%d", &s_pf->id, profile_type, type_arg, limits, aqm_options, dscp_marking, volume_based_shaping, &s_pf->valid); @@ -245,29 +232,22 @@ END: void shaper_profile_ex_dup(int table_id, void **to, void **from, long argl, void *argp) { - struct shaping_profile *s_pf; - if (*from == NULL) { return; } - s_pf = (struct shaping_profile*)*from; - __atomic_add_fetch(&s_pf->ref_cnt, 1, __ATOMIC_SEQ_CST); - *to = s_pf; + *to = *from; return; } void shaper_profile_ex_free(int table_id, void **ad, long argl, void *argp) { - struct shaping_profile *s_pf; - - s_pf = (struct shaping_profile*)*ad; - if (__atomic_sub_fetch(&s_pf->ref_cnt, 1, __ATOMIC_SEQ_CST) > 0) { + if (*ad == NULL) { return; } - free(s_pf); + free(*ad); *ad = NULL; return; @@ -278,8 +258,6 @@ void shaper_profile_update(struct shaping_profile_info *s_pf_info, struct shapin s_pf_info->id = s_pf_ex->id; s_pf_info->type = s_pf_ex->type; - shaper_profile_ex_free(0, (void **)&s_pf_ex, 0, NULL); - return; } @@ -333,9 +311,6 @@ static void shaper_rule_update(struct shaping_thread_ctx *ctx, struct shaping_fl } END: - if (s_rule) { - shaper_rule_ex_free(ctx->maat_info->rule_table_id, (void **)&s_rule, 0, NULL); - } return; } @@ -357,7 +332,6 @@ int shaper_rule_is_enabled(struct shaping_thread_ctx *ctx, long long rule_id) struct shaping_rule *s_rule = (struct shaping_rule*)maat_plugin_table_get_ex_data(g_maat_instance, ctx->maat_info->rule_table_id, (char *)&rule_id, sizeof(rule_id)); if (s_rule) { - shaper_rule_ex_free(ctx->maat_info->rule_table_id, (void **)&s_rule, 0, NULL); return 1; } diff --git a/shaping/test/gtest_shaper_maat.cpp b/shaping/test/gtest_shaper_maat.cpp index 17a31ed..feed669 100644 --- a/shaping/test/gtest_shaper_maat.cpp +++ b/shaping/test/gtest_shaper_maat.cpp @@ -29,14 +29,11 @@ TEST(shaping_rule, parse) EXPECT_EQ(s_rule->borrow_pf_id_array[0], 2); EXPECT_EQ(s_rule->borrow_pf_id_array[1], 3); EXPECT_EQ(s_rule->priority, 1); - EXPECT_EQ(s_rule->ref_cnt, 1); shaper_rule_ex_dup(0, (void**)&s_rule_dup, (void**)&s_rule, 0, NULL); EXPECT_EQ(s_rule, s_rule_dup); - EXPECT_EQ(s_rule->ref_cnt, 2); shaper_rule_ex_free(0, (void**)&s_rule, 0, NULL); - shaper_rule_ex_free(0, (void**)&s_rule, 0, NULL); EXPECT_TRUE(s_rule == NULL); } @@ -57,14 +54,11 @@ TEST(shaping_profile, parse) EXPECT_EQ(s_pf->in_limit_bandwidth, 1024); EXPECT_EQ(s_pf->out_limit_bandwidth, 2048); EXPECT_EQ(s_pf->type, PROFILE_TYPE_MAX_MIN_HOST_FAIRNESS); - EXPECT_EQ(s_pf->ref_cnt, 1); shaper_profile_ex_dup(0, (void**)&s_pf_dup, (void**)&s_pf, 0, NULL); EXPECT_EQ(s_pf, s_pf_dup); - EXPECT_EQ(s_pf->ref_cnt, 2); shaper_profile_ex_free(0, (void**)&s_pf, 0, NULL); - shaper_profile_ex_free(0, (void**)&s_pf, 0, NULL); EXPECT_TRUE(s_pf == NULL); } diff --git a/shaping/test/stub.cpp b/shaping/test/stub.cpp index f3c89e5..45a2e55 100644 --- a/shaping/test/stub.cpp +++ b/shaping/test/stub.cpp @@ -187,17 +187,12 @@ void stub_init() memset(&matched_rules, 0, sizeof(struct stub_matched_rules)); memset(&pf_array, 0, MAX_STUB_PROFILE_NUM * sizeof(struct shaping_profile)); - for (i = 0; i < MAX_STUB_RULE_NUM; i++) { - matched_rules.rules[i].ref_cnt = 1; - } - for (i = 0; i < MAX_STUB_PROFILE_NUM; i++) { pf_curr_avl_token[i].in_limit_bandwidth = DEFAULT_AVALIABLE_TOKEN_PER_SEC; pf_curr_avl_token[i].out_limit_bandwidth = DEFAULT_AVALIABLE_TOKEN_PER_SEC; pf_array[i].id = i; pf_array[i].in_limit_bandwidth = DEFAULT_AVALIABLE_TOKEN_PER_SEC; pf_array[i].out_limit_bandwidth = DEFAULT_AVALIABLE_TOKEN_PER_SEC; - pf_array[i].ref_cnt = 1; pf_async_times[i] = 0; } return; @@ -531,11 +526,9 @@ void *maat_plugin_table_get_ex_data(struct maat *instance, int table_id, const c if (table_id == STUB_MAAT_SHAPING_RULE_TABLE_ID) { rule_id = *(int*)key; - matched_rules.rules[rule_id].ref_cnt++; return &matched_rules.rules[rule_id]; } else { profile_id = atoi(key); - pf_array[profile_id].ref_cnt++; return &pf_array[profile_id]; } } |
