summaryrefslogtreecommitdiff
path: root/shaping/src
diff options
context:
space:
mode:
authorroot <[email protected]>2024-03-21 03:30:55 +0000
committerroot <[email protected]>2024-03-21 03:30:55 +0000
commitdb240b23f54bd8f419a8fb70e0dabd06fe057338 (patch)
tree440407c0cfef757b6333c765c18126588d84b1a5 /shaping/src
parentadec4a3d8eb5e826fd3c3ea340dd1143c66db75a (diff)
TSG-19771:定期刷新profile配置,在刷新周期内,配置改变造成的限速不准现象为正常情况,刷新周期为5秒
Diffstat (limited to 'shaping/src')
-rw-r--r--shaping/src/main.cpp2
-rw-r--r--shaping/src/shaper.cpp23
-rw-r--r--shaping/src/shaper_maat.cpp26
3 files changed, 40 insertions, 11 deletions
diff --git a/shaping/src/main.cpp b/shaping/src/main.cpp
index 63b7a49..597230b 100644
--- a/shaping/src/main.cpp
+++ b/shaping/src/main.cpp
@@ -41,7 +41,7 @@ static void *shaper_thread_loop(void *data)
session_table_reset_with_callback(ctx->session_table, shaper_session_data_free_cb, ctx);
__atomic_fetch_and(&ctx->session_need_reset, 0, __ATOMIC_SEQ_CST);
}
- marsio_poll_wait(ctx->marsio_info->instance, &ctx->marsio_info->mr_dev, 1, ctx->thread_index, output_interval_s * 1000);
+ marsio_poll_wait(ctx->marsio_info->instance, &ctx->marsio_info->mr_dev, 1, ctx->thread_index, output_interval_s);
}
shaper_thread_resource_clear();
diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp
index 2ff490d..91117f5 100644
--- a/shaping/src/shaper.cpp
+++ b/shaping/src/shaper.cpp
@@ -30,6 +30,8 @@ extern "C" {
#define HMGET_REQUEST_INTERVAL_MS 10
#define PRIORITY_BLOCK_MIN_TIME_MS 500
+#define PROFILE_HASH_NODE_REFRESH_SEC 5
+
#define SWARMKV_QUEUE_LEN_GET_CMD "HMGET tsg-shaping-%d priority-0 priority-1 priority-2 priority-3 priority-4 priority-5 priority-6 priority-7 priority-8 priority-9"
struct shaper {//trees in one thread
@@ -563,6 +565,23 @@ static int shaper_deposit_token_get(struct shaping_profile_info *profile, int re
return -1;
}
+static void shaper_profile_hash_node_refresh(struct shaping_thread_ctx *ctx, struct shaping_profile_hash_node *pf_hash_node)
+{
+ time_t curr_time_s = time(NULL);
+ if (curr_time_s - pf_hash_node->last_refresh_time_s < PROFILE_HASH_NODE_REFRESH_SEC) {
+ return;
+ }
+
+ struct shaping_profile *profile = shaper_maat_profile_get(ctx, pf_hash_node->id);
+ if (profile) {
+ pf_hash_node->limit_direction = profile->limit_direction;
+ pf_hash_node->aqm_type = profile->aqm_type;
+ }
+ pf_hash_node->last_refresh_time_s = curr_time_s;
+
+ return;
+}
+
static void shaper_token_get_from_profile(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, struct shaping_profile_info *pf_info, int profile_type, int req_token_bits, unsigned char direction, struct timespec *curr_timespec)
{
struct shaping_tconsume_cb_arg *arg = NULL;
@@ -572,6 +591,8 @@ static void shaper_token_get_from_profile(struct shaping_thread_ctx *ctx, struct
if (pf_hash_node->tconsume_ref_cnt > 0) {
return;
}
+
+ shaper_profile_hash_node_refresh(ctx, pf_hash_node);
if (pf_hash_node->limit_direction == PROFILE_LIMIT_DIRECTION_BIDIRECTION) {
snprintf(key, sizeof(key), "tsg-shaping-%d-bidirectional", pf_info->id);
@@ -708,7 +729,7 @@ END:
}
}
-void shaper_profile_hash_node_update(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile)
+void shaper_profile_hash_node_set(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile)
{
if (profile->hash_node == NULL) {
struct shaping_profile_hash_node *hash_node = NULL;
diff --git a/shaping/src/shaper_maat.cpp b/shaping/src/shaper_maat.cpp
index e7de972..9def069 100644
--- a/shaping/src/shaper_maat.cpp
+++ b/shaping/src/shaper_maat.cpp
@@ -352,18 +352,31 @@ void shaper_profile_update(struct shaping_thread_ctx *ctx, struct shaping_profil
{
s_pf_info->id = s_pf_ex->id;
s_pf_info->type = s_pf_ex->type;
- shaper_profile_hash_node_update(ctx, s_pf_info);
+ shaper_profile_hash_node_set(ctx, s_pf_info);
s_pf_info->hash_node->aqm_type = s_pf_ex->aqm_type;
s_pf_info->hash_node->limit_direction = s_pf_ex->limit_direction;
return;
}
+struct shaping_profile *shaper_maat_profile_get(struct shaping_thread_ctx *ctx, int profile_id)
+{
+ struct shaping_profile *s_pf = NULL;
+ char pf_id_key[8] = {0};
+
+ snprintf(pf_id_key, sizeof(pf_id_key), "%d", profile_id);
+ s_pf = (struct shaping_profile *)maat_plugin_table_get_ex_data(g_maat_instance, ctx->maat_info->profile_table_id, pf_id_key, strlen(pf_id_key));
+ if (!s_pf) {
+ LOG_ERROR("%s maat_plugin_table_get_ex_data get profile failed for key %s", LOG_TAG_MAAT, pf_id_key);
+ }
+
+ return s_pf;
+}
+
static int shaper_rule_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, struct shaping_rule_info *s_rule_info, long long rule_compile_id, int *priority_changed)
{
struct shaping_rule *s_rule = NULL;
struct shaping_profile *s_pf = NULL;
- char pf_id_key[8] = {0};
s_rule = (struct shaping_rule*)maat_plugin_table_get_ex_data(g_maat_instance, ctx->maat_info->rule_table_id, (char *)&rule_compile_id, sizeof(rule_compile_id));
if (!s_rule) {
@@ -376,10 +389,8 @@ static int shaper_rule_update(struct shaping_thread_ctx *ctx, struct shaping_flo
s_rule_info->is_enabled = 1;
- snprintf(pf_id_key, sizeof(pf_id_key), "%d", s_rule->primary_pf_id);
- s_pf = (struct shaping_profile *)maat_plugin_table_get_ex_data(g_maat_instance, ctx->maat_info->profile_table_id, pf_id_key, strlen(pf_id_key));
+ s_pf = shaper_maat_profile_get(ctx, s_rule->primary_pf_id);
if (!s_pf) {
- LOG_ERROR("%s maat_plugin_table_get_ex_data get profile failed for key %s", LOG_TAG_MAAT, pf_id_key);
return -1;
}
shaper_profile_update(ctx, &s_rule_info->primary, s_pf);
@@ -403,11 +414,8 @@ static int shaper_rule_update(struct shaping_thread_ctx *ctx, struct shaping_flo
}
for (int i = 0; i < s_rule->borrow_pf_num; i++) {
- memset(pf_id_key, 0, sizeof(pf_id_key));
- snprintf(pf_id_key, sizeof(pf_id_key), "%d", s_rule->borrow_pf_id_array[i]);
- s_pf = (struct shaping_profile *)maat_plugin_table_get_ex_data(g_maat_instance, ctx->maat_info->profile_table_id, pf_id_key, strlen(pf_id_key));
+ s_pf = shaper_maat_profile_get(ctx, s_rule->borrow_pf_id_array[i]);
if (!s_pf) {
- LOG_ERROR("%s maat_plugin_table_get_ex_data get profile failed for key %s", LOG_TAG_MAAT, pf_id_key);
return -1;
}