summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author刘畅 <[email protected]>2023-04-06 02:58:28 +0000
committer刘畅 <[email protected]>2023-04-06 02:58:28 +0000
commit121cc045981f27de604ba7b6cebdf2a5efe1b868 (patch)
tree4db0f449f2edd3f3e1e747216fe164a0f1beafef
parent3200d56255caf1b3c8d2ba1782da8c3f61bf96c5 (diff)
parent3a4c942bf1c57c800bf7a4513f22d29e3a7c0bd0 (diff)
Merge branch 'merge_from_bytes_to_bits' into 'rel'v1.1.7
merge from shaping_master, get token unit from tybes to bits See merge request tango/shaping-engine!9
-rw-r--r--shaping/src/shaper.cpp15
-rw-r--r--shaping/test/stub.cpp8
2 files changed, 12 insertions, 11 deletions
diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp
index 95277f1..a8a955a 100644
--- a/shaping/src/shaper.cpp
+++ b/shaping/src/shaper.cpp
@@ -426,7 +426,7 @@ static int shaper_deposit_token_is_enough(struct shaping_profile_info *pf_info,
}
}
-static int shaper_token_get_from_profile(struct swarmkv *db, struct shaping_flow *sf, struct shaping_profile_info *pf_info, int profile_type, int req_token, unsigned char direction)
+static int shaper_token_get_from_profile(struct swarmkv *db, struct shaping_flow *sf, struct shaping_profile_info *pf_info, int profile_type, int req_token_bits, unsigned char direction)
{
struct shaping_async_cb_arg *arg;
char key[32] = {0};
@@ -440,9 +440,9 @@ static int shaper_token_get_from_profile(struct swarmkv *db, struct shaping_flow
arg->sf = sf;
arg->direction = direction;
- swarmkv_tconsume(db, key, strlen(key), req_token, shaper_token_get_cb, arg);
+ swarmkv_tconsume(db, key, strlen(key), req_token_bits, shaper_token_get_cb, arg);
if (__atomic_load_n(&pf_info->async_token_ref_count, __ATOMIC_SEQ_CST) != 0) {//has async operation not completed
- shaper_deposit_token_sub(pf_info, req_token, direction);
+ shaper_deposit_token_sub(pf_info, req_token_bits, direction);
return 0;
}
@@ -454,8 +454,8 @@ static int shaper_token_get_from_profile(struct swarmkv *db, struct shaping_flow
}
}
- if (shaper_deposit_token_is_enough(pf_info, req_token, direction)) {
- shaper_deposit_token_sub(pf_info, req_token, direction);
+ if (shaper_deposit_token_is_enough(pf_info, req_token_bits, direction)) {
+ shaper_deposit_token_sub(pf_info, req_token_bits, direction);
return 0;
}
@@ -517,13 +517,14 @@ static int shaper_profile_is_priority_blocked(struct swarmkv *db, struct shaping
}
}
-static int shaper_token_consume(struct swarmkv *db, struct shaping_flow *sf, int req_token,
+static int shaper_token_consume(struct swarmkv *db, struct shaping_flow *sf, int req_token_bytes,
struct shaping_profile_info *profile, int profile_type, unsigned char direction)
{
if (shaper_profile_is_priority_blocked(db, sf, profile)) {
return -1;
} else {
- return shaper_token_get_from_profile(db, sf, profile, profile_type, req_token, direction);
+ int req_token_bits = req_token_bytes * 8;
+ return shaper_token_get_from_profile(db, sf, profile, profile_type, req_token_bits, direction);
}
}
diff --git a/shaping/test/stub.cpp b/shaping/test/stub.cpp
index f16d351..3af3cf9 100644
--- a/shaping/test/stub.cpp
+++ b/shaping/test/stub.cpp
@@ -84,11 +84,11 @@ void * stub_get_token_thread_func(void *data)
void stub_set_token_bucket_avl_per_sec(int profile_id, unsigned int tokens, unsigned char direction)
{
if (direction == SHAPING_DIR_IN) {
- pf_array[profile_id].in_limit_bandwidth = tokens;
- pf_curr_avl_token[profile_id].in_limit_bandwidth = tokens;
+ pf_array[profile_id].in_limit_bandwidth = tokens * 8;
+ pf_curr_avl_token[profile_id].in_limit_bandwidth = tokens * 8;
} else {
- pf_array[profile_id].out_limit_bandwidth = tokens;
- pf_curr_avl_token[profile_id].out_limit_bandwidth = tokens;
+ pf_array[profile_id].out_limit_bandwidth = tokens * 8;
+ pf_curr_avl_token[profile_id].out_limit_bandwidth = tokens * 8;
}
return;