Skip to content

Commit e9d9209

Browse files
committed
tasklet: support unregister (#619)
todo: add runtime register support Signed-off-by: Du, Frank <[email protected]> (cherry picked from commit ab84dbaa764025b20d305ea94db9fcdae2da2fcc)
1 parent fcaf503 commit e9d9209

13 files changed

+209
-76
lines changed

lib/src/st_ancillary_transmitter.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int st_ancillary_trs_tasklet_handler(void* priv) {
102102
int st_ancillary_transmitter_init(struct st_main_impl* impl, struct st_sch_impl* sch,
103103
struct st_tx_ancillary_sessions_mgr* mgr,
104104
struct st_ancillary_transmitter_impl* trs) {
105-
int ret, idx = sch->idx;
105+
int idx = sch->idx;
106106
struct st_sch_tasklet_ops ops;
107107

108108
trs->parnet = impl;
@@ -116,10 +116,10 @@ int st_ancillary_transmitter_init(struct st_main_impl* impl, struct st_sch_impl*
116116
ops.stop = st_ancillary_trs_tasklet_stop;
117117
ops.handler = st_ancillary_trs_tasklet_handler;
118118

119-
ret = st_sch_register_tasklet(sch, &ops);
120-
if (ret < 0) {
121-
info("%s(%d), st_sch_register_tasklet fail %d\n", __func__, idx, ret);
122-
return ret;
119+
trs->tasklet = st_sch_register_tasklet(sch, &ops);
120+
if (!trs->tasklet) {
121+
err("%s(%d), st_sch_register_tasklet fail\n", __func__, idx);
122+
return -EIO;
123123
}
124124

125125
info("%s(%d), succ\n", __func__, idx);
@@ -129,6 +129,12 @@ int st_ancillary_transmitter_init(struct st_main_impl* impl, struct st_sch_impl*
129129
int st_ancillary_transmitter_uinit(struct st_ancillary_transmitter_impl* trs) {
130130
int idx = trs->idx;
131131

132-
info("%s(%d), succ\n", __func__, idx);
132+
if (trs->tasklet) {
133+
st_sch_unregister_tasklet(trs->tasklet);
134+
trs->tasklet = NULL;
135+
}
136+
137+
info("%s(%d), succ, inflight %d:%d\n", __func__, idx, trs->inflight_cnt[ST_PORT_P],
138+
trs->inflight_cnt[ST_PORT_R]);
133139
return 0;
134140
}

lib/src/st_audio_transmitter.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static int st_audio_trs_tasklet_handler(void* priv) {
107107
int st_audio_transmitter_init(struct st_main_impl* impl, struct st_sch_impl* sch,
108108
struct st_tx_audio_sessions_mgr* mgr,
109109
struct st_audio_transmitter_impl* trs) {
110-
int ret, idx = sch->idx;
110+
int idx = sch->idx;
111111
struct st_sch_tasklet_ops ops;
112112

113113
trs->parnet = impl;
@@ -121,10 +121,10 @@ int st_audio_transmitter_init(struct st_main_impl* impl, struct st_sch_impl* sch
121121
ops.stop = st_audio_trs_tasklet_stop;
122122
ops.handler = st_audio_trs_tasklet_handler;
123123

124-
ret = st_sch_register_tasklet(sch, &ops);
125-
if (ret < 0) {
126-
info("%s(%d), st_sch_register_tasklet fail %d\n", __func__, idx, ret);
127-
return ret;
124+
trs->tasklet = st_sch_register_tasklet(sch, &ops);
125+
if (!trs->tasklet) {
126+
err("%s(%d), st_sch_register_tasklet fail\n", __func__, idx);
127+
return -EIO;
128128
}
129129

130130
info("%s(%d), succ\n", __func__, idx);
@@ -133,6 +133,12 @@ int st_audio_transmitter_init(struct st_main_impl* impl, struct st_sch_impl* sch
133133

134134
int st_audio_transmitter_uinit(struct st_audio_transmitter_impl* trs) {
135135
int idx = trs->idx;
136+
137+
if (trs->tasklet) {
138+
st_sch_unregister_tasklet(trs->tasklet);
139+
trs->tasklet = NULL;
140+
}
141+
136142
info("%s(%d), succ, inflight %d:%d\n", __func__, idx, trs->inflight_cnt[ST_PORT_P],
137143
trs->inflight_cnt[ST_PORT_R]);
138144
return 0;

lib/src/st_cni.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ int st_cni_init(struct st_main_impl* impl) {
247247
ops.stop = cni_tasklet_stop;
248248
ops.handler = cni_tasklet_handlder;
249249

250-
ret = st_sch_register_tasklet(impl->main_sch, &ops);
251-
if (ret < 0) {
252-
info("%s, st_sch_register_tasklet fail %d\n", __func__, ret);
250+
cni->tasklet = st_sch_register_tasklet(impl->main_sch, &ops);
251+
if (!cni->tasklet) {
252+
err("%s, st_sch_register_tasklet fail\n", __func__);
253253
st_cni_uinit(impl);
254-
return ret;
254+
return -EIO;
255255
}
256256
}
257257

@@ -266,6 +266,13 @@ int st_cni_init(struct st_main_impl* impl) {
266266
}
267267

268268
int st_cni_uinit(struct st_main_impl* impl) {
269+
struct st_cni_impl* cni = st_get_cni(impl);
270+
271+
if (cni->tasklet) {
272+
st_sch_unregister_tasklet(cni->tasklet);
273+
cni->tasklet = NULL;
274+
}
275+
269276
st_cni_stop(impl);
270277

271278
cni_queues_uinit(impl);

lib/src/st_main.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ struct st_cni_impl {
264264
pthread_t tid; /* thread id for rx */
265265
rte_atomic32_t stop_thread;
266266
bool lcore_tasklet;
267+
struct st_sch_tasklet_impl* tasklet;
267268
/* stat */
268269
int eth_rx_cnt[ST_PORT_MAX];
269270
#ifdef ST_HAS_KNI
@@ -312,6 +313,7 @@ struct st_sch_tasklet_ops {
312313
struct st_sch_tasklet_impl {
313314
struct st_sch_tasklet_ops ops;
314315
char name[ST_MAX_NAME_LEN];
316+
struct st_sch_impl* sch;
315317

316318
int idx;
317319
};
@@ -523,6 +525,7 @@ struct st_tx_video_sessions_mgr {
523525
struct st_main_impl* parnet;
524526
int idx; /* index for current session mgr */
525527
int max_idx; /* max session index */
528+
struct st_sch_tasklet_impl* tasklet;
526529

527530
struct st_tx_video_session_impl* sessions[ST_SCH_MAX_TX_VIDEO_SESSIONS];
528531
/* protect session, spin(fast) lock as it call from tasklet aslo */
@@ -532,6 +535,7 @@ struct st_tx_video_sessions_mgr {
532535
struct st_video_transmitter_impl {
533536
struct st_main_impl* parnet;
534537
struct st_tx_video_sessions_mgr* mgr;
538+
struct st_sch_tasklet_impl* tasklet;
535539
int idx; /* index for current transmitter */
536540
};
537541

@@ -795,6 +799,7 @@ struct st_rx_video_sessions_mgr {
795799
struct st_main_impl* parnet;
796800
int idx; /* index for current session mgr */
797801
int max_idx; /* max session index */
802+
struct st_sch_tasklet_impl* tasklet;
798803

799804
struct st_rx_video_session_impl* sessions[ST_SCH_MAX_RX_VIDEO_SESSIONS];
800805
/* protect session, spin(fast) lock as it call from tasklet aslo */
@@ -809,8 +814,8 @@ enum st_sch_type {
809814

810815
struct st_sch_impl {
811816
pthread_mutex_t mutex; /* protect sch context */
812-
struct st_sch_tasklet_impl tasklet[ST_MAX_TASKLET_PER_SCH];
813-
int num_tasklet;
817+
struct st_sch_tasklet_impl* tasklet[ST_MAX_TASKLET_PER_SCH];
818+
int max_tasklet_idx; /* max tasklet index */
814819
unsigned int lcore;
815820

816821
int data_quota_mbs_total; /* total data quota(mb/s) for current sch */
@@ -897,6 +902,7 @@ struct st_tx_audio_sessions_mgr {
897902
struct st_main_impl* parnet;
898903
int idx; /* index for current sessions mgr */
899904
int max_idx; /* max session index */
905+
struct st_sch_tasklet_impl* tasklet;
900906

901907
/* all audio sessions share same ring/queue */
902908
struct rte_ring* ring[ST_PORT_MAX];
@@ -915,6 +921,7 @@ struct st_tx_audio_sessions_mgr {
915921
struct st_audio_transmitter_impl {
916922
struct st_main_impl* parnet;
917923
struct st_tx_audio_sessions_mgr* mgr;
924+
struct st_sch_tasklet_impl* tasklet;
918925
int idx; /* index for current transmitter */
919926

920927
struct rte_mbuf* inflight[ST_PORT_MAX]; /* inflight mbuf */
@@ -1009,6 +1016,7 @@ struct st_rx_audio_sessions_mgr {
10091016
struct st_main_impl* parnet;
10101017
int idx; /* index for current session mgr */
10111018
int max_idx; /* max session index */
1019+
struct st_sch_tasklet_impl* tasklet;
10121020

10131021
struct st_rx_audio_session_impl* sessions[ST_MAX_RX_AUDIO_SESSIONS];
10141022
/* protect session, spin(fast) lock as it call from tasklet aslo */
@@ -1065,6 +1073,7 @@ struct st_tx_ancillary_sessions_mgr {
10651073
struct st_main_impl* parnet;
10661074
int idx; /* index for current sessions mgr */
10671075
int max_idx; /* max session index */
1076+
struct st_sch_tasklet_impl* tasklet;
10681077

10691078
/* all anc sessions share same ring/queue */
10701079
struct rte_ring* ring[ST_PORT_MAX];
@@ -1109,6 +1118,7 @@ struct st_rx_ancillary_sessions_mgr {
11091118
struct st_main_impl* parnet;
11101119
int idx; /* index for current session mgr */
11111120
int max_idx; /* max session index */
1121+
struct st_sch_tasklet_impl* tasklet;
11121122

11131123
struct st_rx_ancillary_session_impl* sessions[ST_MAX_RX_ANC_SESSIONS];
11141124
/* protect session, spin(fast) lock as it call from tasklet aslo */
@@ -1118,6 +1128,7 @@ struct st_rx_ancillary_sessions_mgr {
11181128
struct st_ancillary_transmitter_impl {
11191129
struct st_main_impl* parnet;
11201130
struct st_tx_ancillary_sessions_mgr* mgr;
1131+
struct st_sch_tasklet_impl* tasklet;
11211132
int idx; /* index for current transmitter */
11221133

11231134
struct rte_mbuf* inflight[ST_PORT_MAX]; /* inflight mbuf */

lib/src/st_rx_ancillary_session.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,6 @@ int st_rx_ancillary_sessions_mgr_update_src(struct st_rx_ancillary_sessions_mgr*
433433
int st_rx_ancillary_sessions_mgr_init(struct st_main_impl* impl, struct st_sch_impl* sch,
434434
struct st_rx_ancillary_sessions_mgr* mgr) {
435435
int idx = sch->idx;
436-
int ret;
437436
struct st_sch_tasklet_ops ops;
438437

439438
mgr->parnet = impl;
@@ -450,10 +449,10 @@ int st_rx_ancillary_sessions_mgr_init(struct st_main_impl* impl, struct st_sch_i
450449
ops.stop = rx_ancillary_sessions_tasklet_stop;
451450
ops.handler = rx_ancillary_sessions_tasklet_handler;
452451

453-
ret = st_sch_register_tasklet(sch, &ops);
454-
if (ret < 0) {
455-
err("%s(%d), st_sch_register_tasklet fail %d\n", __func__, idx, ret);
456-
return ret;
452+
mgr->tasklet = st_sch_register_tasklet(sch, &ops);
453+
if (!mgr->tasklet) {
454+
err("%s(%d), st_sch_register_tasklet fail\n", __func__, idx);
455+
return -EIO;
457456
}
458457

459458
info("%s(%d), succ\n", __func__, idx);
@@ -464,6 +463,11 @@ int st_rx_ancillary_sessions_mgr_uinit(struct st_rx_ancillary_sessions_mgr* mgr)
464463
int m_idx = mgr->idx;
465464
struct st_rx_ancillary_session_impl* s;
466465

466+
if (mgr->tasklet) {
467+
st_sch_unregister_tasklet(mgr->tasklet);
468+
mgr->tasklet = NULL;
469+
}
470+
467471
for (int i = 0; i < ST_MAX_RX_ANC_SESSIONS; i++) {
468472
s = rx_ancillary_session_get(mgr, i);
469473
if (!s) continue;

lib/src/st_rx_audio_session.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,6 @@ int st_rx_audio_sessions_mgr_update_src(struct st_rx_audio_sessions_mgr* mgr,
832832
int st_rx_audio_sessions_mgr_init(struct st_main_impl* impl, struct st_sch_impl* sch,
833833
struct st_rx_audio_sessions_mgr* mgr) {
834834
int idx = sch->idx;
835-
int ret;
836835
struct st_sch_tasklet_ops ops;
837836

838837
mgr->parnet = impl;
@@ -849,10 +848,10 @@ int st_rx_audio_sessions_mgr_init(struct st_main_impl* impl, struct st_sch_impl*
849848
ops.stop = rx_audio_sessions_tasklet_stop;
850849
ops.handler = rx_audio_sessions_tasklet_handler;
851850

852-
ret = st_sch_register_tasklet(sch, &ops);
853-
if (ret < 0) {
854-
err("%s(%d), st_sch_register_tasklet fail %d\n", __func__, idx, ret);
855-
return ret;
851+
mgr->tasklet = st_sch_register_tasklet(sch, &ops);
852+
if (!mgr->tasklet) {
853+
err("%s(%d), st_sch_register_tasklet fail\n", __func__, idx);
854+
return -EIO;
856855
}
857856

858857
info("%s(%d), succ\n", __func__, idx);
@@ -871,6 +870,11 @@ int st_rx_audio_sessions_mgr_uinit(struct st_rx_audio_sessions_mgr* mgr) {
871870
int m_idx = mgr->idx;
872871
struct st_rx_audio_session_impl* s;
873872

873+
if (mgr->tasklet) {
874+
st_sch_unregister_tasklet(mgr->tasklet);
875+
mgr->tasklet = NULL;
876+
}
877+
874878
for (int i = 0; i < ST_MAX_RX_AUDIO_SESSIONS; i++) {
875879
s = rx_audio_session_get(mgr, i);
876880
if (!s) continue;

lib/src/st_rx_video_session.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,7 +2572,6 @@ int st_rx_video_sessions_mgr_update_src(struct st_rx_video_sessions_mgr* mgr,
25722572
static int rx_video_sessions_mgr_init(struct st_main_impl* impl, struct st_sch_impl* sch,
25732573
struct st_rx_video_sessions_mgr* mgr) {
25742574
int idx = sch->idx;
2575-
int ret;
25762575
struct st_sch_tasklet_ops ops;
25772576

25782577
mgr->parnet = impl;
@@ -2589,10 +2588,10 @@ static int rx_video_sessions_mgr_init(struct st_main_impl* impl, struct st_sch_i
25892588
ops.stop = rx_video_sessions_tasklet_stop;
25902589
ops.handler = rx_video_sessions_tasklet_handler;
25912590

2592-
ret = st_sch_register_tasklet(sch, &ops);
2593-
if (ret < 0) {
2594-
err("%s(%d), st_sch_register_tasklet fail %d\n", __func__, idx, ret);
2595-
return ret;
2591+
mgr->tasklet = st_sch_register_tasklet(sch, &ops);
2592+
if (!mgr->tasklet) {
2593+
err("%s(%d), st_sch_register_tasklet fail\n", __func__, idx);
2594+
return -EIO;
25962595
}
25972596

25982597
info("%s(%d), succ\n", __func__, idx);
@@ -2611,6 +2610,11 @@ static int rx_video_sessions_mgr_uinit(struct st_rx_video_sessions_mgr* mgr) {
26112610
int m_idx = mgr->idx;
26122611
struct st_rx_video_session_impl* s;
26132612

2613+
if (mgr->tasklet) {
2614+
st_sch_unregister_tasklet(mgr->tasklet);
2615+
mgr->tasklet = NULL;
2616+
}
2617+
26142618
for (int i = 0; i < ST_SCH_MAX_RX_VIDEO_SESSIONS; i++) {
26152619
s = rx_video_session_get(mgr, i);
26162620
if (!s) continue;

0 commit comments

Comments
 (0)