Skip to content

Commit ad3c438

Browse files
committed
Fix: seting rl rate on VF
Signed-off-by: Kasiewicz, Marek <marek.kasiewicz@intel.com>
1 parent 3790484 commit ad3c438

File tree

6 files changed

+73
-38
lines changed

6 files changed

+73
-38
lines changed

lib/src/dev/mt_dev.c

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -683,13 +683,8 @@ static int dev_init_ratelimit_all(struct mt_interface* inf) {
683683
shaper->shaper_profile_id);
684684
}
685685

686-
ret = rte_tm_hierarchy_commit(port_id, 1, &error);
687-
if (ret < 0)
688-
err("%s(%d), commit error (%d)%s\n", __func__, port, ret,
689-
mt_string_safe(error.message));
690-
691686
dbg("%s(%d), succ\n", __func__, port);
692-
return ret;
687+
return 0;
693688
}
694689

695690
static int dev_tx_queue_set_rl_rate(struct mt_interface* inf, uint16_t queue,
@@ -712,13 +707,22 @@ static int dev_tx_queue_set_rl_rate(struct mt_interface* inf, uint16_t queue,
712707
/* not changed */
713708
if (bps == tx_queue->bps) return 0;
714709

710+
rte_atomic32_set(&inf->resetting, true);
711+
mt_pthread_mutex_lock(&inf->vf_cmd_mutex);
712+
713+
ret = rte_eth_dev_stop(port_id);
714+
if (ret) {
715+
err("%s(%d), stop port %d fail %d\n", __func__, port, port_id, ret);
716+
goto exit;
717+
}
718+
715719
/* delete old queue node */
716720
if (tx_queue->rl_shapers_mapping >= 0) {
717721
ret = rte_tm_node_delete(port_id, queue, &error);
718722
if (ret < 0) {
719723
err("%s(%d), node %d delete fail %d(%s)\n", __func__, port, queue, ret,
720724
mt_string_safe(error.message));
721-
return ret;
725+
goto exit;
722726
}
723727
tx_queue->rl_shapers_mapping = -1;
724728
}
@@ -727,7 +731,8 @@ static int dev_tx_queue_set_rl_rate(struct mt_interface* inf, uint16_t queue,
727731
shaper = dev_rl_shaper_get(inf, bps);
728732
if (!shaper) {
729733
err("%s(%d), rl shaper get fail for q %d\n", __func__, port, queue);
730-
return -EIO;
734+
ret = -EIO;
735+
goto exit;
731736
}
732737
memset(&qp, 0, sizeof(qp));
733738
qp.shaper_profile_id = shaper->shaper_profile_id;
@@ -740,29 +745,59 @@ static int dev_tx_queue_set_rl_rate(struct mt_interface* inf, uint16_t queue,
740745
ret = rte_tm_node_add(port_id, queue, ST_TM_LAST_NONLEAF_NODE_ID_PF, 0, 1,
741746
ST_TM_NONLEAF_NODES_NUM_PF, &qp, &error);
742747
}
743-
if (ret < 0) {
748+
if (ret) {
744749
err("%s(%d), q %d add fail %d(%s)\n", __func__, port, queue, ret,
745750
mt_string_safe(error.message));
746-
return ret;
751+
goto exit;
747752
}
753+
748754
tx_queue->rl_shapers_mapping = shaper->idx;
749755
info("%s(%d), q %d link to shaper id %d(%" PRIu64 ")\n", __func__, port, queue,
750756
shaper->shaper_profile_id, shaper->rl_bps);
751757
}
752-
rte_atomic32_set(&inf->resetting, true);
753-
mt_pthread_mutex_lock(&inf->vf_cmd_mutex);
754-
ret = rte_tm_hierarchy_commit(port_id, 1, &error);
755-
mt_pthread_mutex_unlock(&inf->vf_cmd_mutex);
756-
rte_atomic32_set(&inf->resetting, false);
757-
if (ret < 0) {
758-
err("%s(%d), commit error (%d)%s\n", __func__, port, ret,
759-
mt_string_safe(error.message));
760-
return ret;
758+
759+
if (inf->drv_info.drv_type == MT_DRV_IAVF) {
760+
ret = rte_eth_dev_start(port_id);
761+
if (ret) {
762+
err("%s(%d), start port %d fail %d\n", __func__, port, port_id, ret);
763+
goto exit;
764+
}
765+
766+
ret = rte_tm_hierarchy_commit(port_id, 1, &error);
767+
if (ret) {
768+
err("%s(%d), commit error (%d)%s\n", __func__, port, ret,
769+
mt_string_safe(error.message));
770+
goto exit;
771+
}
772+
773+
ret = rte_eth_dev_stop(port_id);
774+
if (ret) {
775+
err("%s(%d), stop port %d fail %d\n", __func__, port, port_id, ret);
776+
goto exit;
777+
}
778+
779+
} else {
780+
ret = rte_tm_hierarchy_commit(port_id, 1, &error);
781+
if (ret) {
782+
err("%s(%d), commit error (%d)%s\n", __func__, port, ret,
783+
mt_string_safe(error.message));
784+
goto exit;
785+
}
786+
}
787+
788+
ret = rte_eth_dev_start(port_id);
789+
if (ret) {
790+
err("%s(%d), start port %d fail %d\n", __func__, port, port_id, ret);
791+
goto exit;
761792
}
762793

763794
tx_queue->bps = bps;
795+
ret = 0;
764796

765-
return 0;
797+
exit:
798+
mt_pthread_mutex_unlock(&inf->vf_cmd_mutex);
799+
rte_atomic32_set(&inf->resetting, false);
800+
return ret;
766801
}
767802

768803
static int dev_stop_port(struct mt_interface* inf) {
@@ -1420,13 +1455,11 @@ static int dev_if_init_pacing(struct mt_interface* inf) {
14201455
return ret;
14211456
}
14221457
/* IAVF require all q config with RL */
1423-
if (inf->drv_info.drv_type == MT_DRV_IAVF) {
1458+
if (inf->drv_info.drv_type == MT_DRV_IAVF)
14241459
ret = dev_init_ratelimit_all(inf);
1425-
} else {
1460+
else
14261461
ret = dev_tx_queue_set_rl_rate(inf, 0, ST_DEFAULT_RL_BPS);
1427-
if (ret >= 0) dev_tx_queue_set_rl_rate(inf, 0, 0);
1428-
}
1429-
if (ret < 0) { /* fallback to tsc if no rl */
1462+
if (ret) { /* fallback to tsc if no rl */
14301463
if (auto_detect) {
14311464
warn("%s(%d), fallback to tsc as rl init fail\n", __func__, port);
14321465
inf->tx_pacing_way = ST21_TX_PACING_WAY_TSC;

lib/src/mt_main.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ struct mt_sch_mgr {
617617
};
618618

619619
struct mt_pacing_train_result {
620-
uint64_t input_bps; /* input, byte per sec */
620+
uint64_t input_bps; /* input, byte per sec */
621621
uint64_t profiled_bps; /* profiled result */
622622
float pacing_pad_interval; /* result */
623623
};

lib/src/mt_util.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ int mt_build_port_map(struct mtl_main_impl* impl, char** ports, enum mtl_port* m
252252
}
253253

254254
int mt_pacing_train_pad_result_add(struct mtl_main_impl* impl, enum mtl_port port,
255-
uint64_t input_bps, float pad_interval) {
255+
uint64_t input_bps, float pad_interval) {
256256
struct mt_pacing_train_result* ptr = &mt_if(impl, port)->pt_results[0];
257257

258258
for (int i = 0; i < MT_MAX_RL_ITEMS; i++) {
@@ -267,7 +267,7 @@ int mt_pacing_train_pad_result_add(struct mtl_main_impl* impl, enum mtl_port por
267267
}
268268

269269
int mt_pacing_train_pad_result_search(struct mtl_main_impl* impl, enum mtl_port port,
270-
uint64_t rl_bps, float* pad_interval) {
270+
uint64_t rl_bps, float* pad_interval) {
271271
struct mt_pacing_train_result* ptr = &mt_if(impl, port)->pt_results[0];
272272

273273
for (int i = 0; i < MT_MAX_RL_ITEMS; i++) {
@@ -282,7 +282,7 @@ int mt_pacing_train_pad_result_search(struct mtl_main_impl* impl, enum mtl_port
282282
}
283283

284284
int mt_pacing_train_bps_result_add(struct mtl_main_impl* impl, enum mtl_port port,
285-
uint64_t input_bps, uint64_t profiled_bps) {
285+
uint64_t input_bps, uint64_t profiled_bps) {
286286
struct mt_pacing_train_result* ptr = &mt_if(impl, port)->pt_results[0];
287287

288288
for (int i = 0; i < MT_MAX_RL_ITEMS; i++) {
@@ -297,7 +297,7 @@ int mt_pacing_train_bps_result_add(struct mtl_main_impl* impl, enum mtl_port por
297297
}
298298

299299
int mt_pacing_train_bps_result_search(struct mtl_main_impl* impl, enum mtl_port port,
300-
uint64_t input_bps, uint64_t* profiled_bps) {
300+
uint64_t input_bps, uint64_t* profiled_bps) {
301301
struct mt_pacing_train_result* ptr = &mt_if(impl, port)->pt_results[0];
302302

303303
for (int i = 0; i < MT_MAX_RL_ITEMS; i++) {

lib/src/mt_util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ void mt_mbuf_sanity_check(struct rte_mbuf** mbufs, uint16_t nb, char* tag);
5959
int mt_pacing_train_pad_result_add(struct mtl_main_impl* impl, enum mtl_port port,
6060
uint64_t input_bps, float pad_interval);
6161
int mt_pacing_train_pad_result_search(struct mtl_main_impl* impl, enum mtl_port port,
62-
uint64_t input_bps, float* pad_interval);
62+
uint64_t input_bps, float* pad_interval);
6363

6464
int mt_pacing_train_bps_result_add(struct mtl_main_impl* impl, enum mtl_port port,
6565
uint64_t input_bps, uint64_t profiled_bps);
6666
int mt_pacing_train_bps_result_search(struct mtl_main_impl* impl, enum mtl_port port,
67-
uint64_t input_bps, uint64_t* profiled_bps);
67+
uint64_t input_bps, uint64_t* profiled_bps);
6868

6969
enum mtl_port mt_port_by_name(struct mtl_main_impl* impl, const char* name);
7070
int mt_build_port_map(struct mtl_main_impl* impl, char** ports, enum mtl_port* maps,

lib/src/st2110/st_tx_audio_session.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ static int tx_audio_session_init_rl(struct mtl_main_impl* impl,
12521252

12531253
uint64_t initial_bytes_per_sec = tx_audio_session_initial_rl_bps(s);
12541254
int profiled = mt_pacing_train_bps_result_search(impl, port, initial_bytes_per_sec,
1255-
&profiled_per_sec);
1255+
&profiled_per_sec);
12561256

12571257
/* pad pkt */
12581258
rl_port->pad = mt_build_pad(impl, mt_sys_tx_mempool(impl, port), port,

lib/src/st2110/st_tx_video_session.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,18 @@ static int tv_train_pacing(struct mtl_main_impl* impl, struct st_tx_video_sessio
427427
pkts_per_frame = pkts_per_frame * reactive;
428428
measured_bps = s->st20_pkt_size * pkts_per_sec * reactive;
429429

430+
/* If the measured speed is lower then expected. Set higher bps and retrain to add
431+
* padding */
430432
if (measured_bps < rl_bps) {
431-
/* The measured speed is lower then expected. Set higher bps and retrain to add padding */
432-
info("%s(%d), measured bps %ld, set bps %ld, increasing rl bps\n", __func__, idx,
433-
(uint64_t)measured_bps, rl_bps);
434-
433+
info("%s(%d), measured bps %ld is lower then set bps %ld\n", __func__, idx,
434+
(uint64_t)measured_bps, rl_bps);
435435
if (!mt_pacing_train_bps_result_search(impl, port, rl_bps, &bps_to_set)) {
436436
err("%s(%d), measured speed is too low on already trained bps\n", __func__, idx);
437437
return -EINVAL;
438438
}
439439

440440
bps_to_set = rl_bps / measured_bps * rl_bps;
441+
info("%s(%d), increase bps to %ld\n", __func__, idx, bps_to_set);
441442
mt_pacing_train_bps_result_add(impl, port, rl_bps, bps_to_set);
442443
mt_txq_set_tx_bps(queue, bps_to_set);
443444
ret = tv_train_pacing(impl, s, s_port);
@@ -3874,7 +3875,8 @@ int st20_tx_queue_fatal_error(struct mtl_main_impl* impl,
38743875
struct mt_txq_flow flow;
38753876
memset(&flow, 0, sizeof(flow));
38763877
flow.bytes_per_sec = tv_rl_bps(s);
3877-
mt_pacing_train_bps_result_search(impl, s_port, flow.bytes_per_sec, &flow.bytes_per_sec);
3878+
mt_pacing_train_bps_result_search(impl, s_port, flow.bytes_per_sec,
3879+
&flow.bytes_per_sec);
38783880
mtl_memcpy(&flow.dip_addr, &s->ops.dip_addr[s_port], MTL_IP_ADDR_LEN);
38793881
flow.dst_port = s->ops.udp_port[s_port];
38803882
s->queue[s_port] = mt_txq_get(impl, port, &flow);

0 commit comments

Comments
 (0)