1 #include <rte_common.h>
3 #include <rte_malloc.h>
4 #include <cmdline_rdline.h>
5 #include <cmdline_parse.h>
6 #include <cmdline_parse_num.h>
7 #include <cmdline_parse_string.h>
8 #include <cmdline_parse_ipaddr.h>
9 #include <cmdline_parse_etheraddr.h>
10 #include <cmdline_socket.h>
14 #include "thread_fe.h"
16 #include "pipeline_common_fe.h"
20 thread_msg_send_recv(struct app_params *app,
21 uint32_t socket_id, uint32_t core_id, uint32_t ht_id,
25 struct rte_ring *r_req = app_thread_msgq_in_get(app,
26 socket_id, core_id, ht_id);
27 struct rte_ring *r_rsp = app_thread_msgq_out_get(app,
28 socket_id, core_id, ht_id);
29 uint64_t hz = rte_get_tsc_hz();
36 status = rte_ring_sp_enqueue(r_req, (void *) msg);
37 } while (status == -ENOBUFS);
40 deadline = (timeout_ms) ?
41 (rte_rdtsc() + ((hz * timeout_ms) / 1000)) :
45 if (rte_rdtsc() > deadline)
48 status = rte_ring_sc_dequeue(r_rsp, &msg_recv);
49 } while (status != 0);
55 app_pipeline_enable(struct app_params *app,
61 struct thread_pipeline_enable_msg_req *req;
62 struct thread_pipeline_enable_msg_rsp *rsp;
64 struct app_pipeline_data *p;
65 struct app_pipeline_params *p_params;
66 struct pipeline_type *p_type;
72 thread_id = cpu_core_map_get_lcore_id(app->core_map,
77 if ((thread_id < 0) ||
78 ((app->core_mask & (1LLU << thread_id)) == 0))
81 if (app_pipeline_data(app, pipeline_id) == NULL)
84 p = &app->pipeline_data[pipeline_id];
85 p_params = &app->pipeline_params[pipeline_id];
86 p_type = app_pipeline_type_find(app, p_params->type);
91 req = app_msg_alloc(app);
95 req->type = THREAD_MSG_REQ_PIPELINE_ENABLE;
96 req->pipeline_id = pipeline_id;
98 req->f_run = p_type->be_ops->f_run;
99 req->f_timer = p_type->be_ops->f_timer;
100 req->timer_period = p->timer_period;
102 rsp = thread_msg_send_recv(app,
103 socket_id, core_id, hyper_th_id, req, MSG_TIMEOUT_DEFAULT);
107 status = rsp->status;
108 app_msg_free(app, rsp);
118 app_pipeline_disable(struct app_params *app,
121 uint32_t hyper_th_id,
122 uint32_t pipeline_id)
124 struct thread_pipeline_disable_msg_req *req;
125 struct thread_pipeline_disable_msg_rsp *rsp;
127 struct app_pipeline_data *p;
133 thread_id = cpu_core_map_get_lcore_id(app->core_map,
138 if ((thread_id < 0) ||
139 ((app->core_mask & (1LLU << thread_id)) == 0))
142 if (app_pipeline_data(app, pipeline_id) == NULL)
145 p = &app->pipeline_data[pipeline_id];
150 req = app_msg_alloc(app);
154 req->type = THREAD_MSG_REQ_PIPELINE_DISABLE;
155 req->pipeline_id = pipeline_id;
157 rsp = thread_msg_send_recv(app,
158 socket_id, core_id, hyper_th_id, req, MSG_TIMEOUT_DEFAULT);
163 status = rsp->status;
164 app_msg_free(app, rsp);
177 struct cmd_pipeline_enable_result {
178 cmdline_fixed_string_t t_string;
179 cmdline_fixed_string_t t_id_string;
180 cmdline_fixed_string_t pipeline_string;
181 uint32_t pipeline_id;
182 cmdline_fixed_string_t enable_string;
186 cmd_pipeline_enable_parsed(
188 __rte_unused struct cmdline *cl,
191 struct cmd_pipeline_enable_result *params = parsed_result;
192 struct app_params *app = data;
194 uint32_t core_id, socket_id, hyper_th_id;
196 if (parse_pipeline_core(&socket_id,
199 params->t_id_string) != 0) {
200 printf("Command failed\n");
204 status = app_pipeline_enable(app,
208 params->pipeline_id);
211 printf("Command failed\n");
214 cmdline_parse_token_string_t cmd_pipeline_enable_t_string =
215 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, t_string, "t");
217 cmdline_parse_token_string_t cmd_pipeline_enable_t_id_string =
218 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, t_id_string,
221 cmdline_parse_token_string_t cmd_pipeline_enable_pipeline_string =
222 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, pipeline_string,
225 cmdline_parse_token_num_t cmd_pipeline_enable_pipeline_id =
226 TOKEN_NUM_INITIALIZER(struct cmd_pipeline_enable_result, pipeline_id,
229 cmdline_parse_token_string_t cmd_pipeline_enable_enable_string =
230 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, enable_string,
233 cmdline_parse_inst_t cmd_pipeline_enable = {
234 .f = cmd_pipeline_enable_parsed,
236 .help_str = "Enable pipeline on specified core",
238 (void *)&cmd_pipeline_enable_t_string,
239 (void *)&cmd_pipeline_enable_t_id_string,
240 (void *)&cmd_pipeline_enable_pipeline_string,
241 (void *)&cmd_pipeline_enable_pipeline_id,
242 (void *)&cmd_pipeline_enable_enable_string,
251 struct cmd_pipeline_disable_result {
252 cmdline_fixed_string_t t_string;
253 cmdline_fixed_string_t t_id_string;
254 cmdline_fixed_string_t pipeline_string;
255 uint32_t pipeline_id;
256 cmdline_fixed_string_t disable_string;
260 cmd_pipeline_disable_parsed(
262 __rte_unused struct cmdline *cl,
265 struct cmd_pipeline_disable_result *params = parsed_result;
266 struct app_params *app = data;
268 uint32_t core_id, socket_id, hyper_th_id;
270 if (parse_pipeline_core(&socket_id,
273 params->t_id_string) != 0) {
274 printf("Command failed\n");
278 status = app_pipeline_disable(app,
282 params->pipeline_id);
285 printf("Command failed\n");
288 cmdline_parse_token_string_t cmd_pipeline_disable_t_string =
289 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, t_string, "t");
291 cmdline_parse_token_string_t cmd_pipeline_disable_t_id_string =
292 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, t_id_string,
295 cmdline_parse_token_string_t cmd_pipeline_disable_pipeline_string =
296 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result,
297 pipeline_string, "pipeline");
299 cmdline_parse_token_num_t cmd_pipeline_disable_pipeline_id =
300 TOKEN_NUM_INITIALIZER(struct cmd_pipeline_disable_result, pipeline_id,
303 cmdline_parse_token_string_t cmd_pipeline_disable_disable_string =
304 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, disable_string,
307 cmdline_parse_inst_t cmd_pipeline_disable = {
308 .f = cmd_pipeline_disable_parsed,
310 .help_str = "Disable pipeline on specified core",
312 (void *)&cmd_pipeline_disable_t_string,
313 (void *)&cmd_pipeline_disable_t_id_string,
314 (void *)&cmd_pipeline_disable_pipeline_string,
315 (void *)&cmd_pipeline_disable_pipeline_id,
316 (void *)&cmd_pipeline_disable_disable_string,
321 static cmdline_parse_ctx_t thread_cmds[] = {
322 (cmdline_parse_inst_t *) &cmd_pipeline_enable,
323 (cmdline_parse_inst_t *) &cmd_pipeline_disable,
328 app_pipeline_thread_cmd_push(struct app_params *app)
332 /* Check for available slots in the application commands array */
333 n_cmds = RTE_DIM(thread_cmds) - 1;
334 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
337 /* Push thread commands into the application */
338 memcpy(&app->cmds[app->n_cmds], thread_cmds,
339 n_cmds * sizeof(cmdline_parse_ctx_t));
341 for (i = 0; i < n_cmds; i++)
342 app->cmds[app->n_cmds + i]->data = app;
344 app->n_cmds += n_cmds;
345 app->cmds[app->n_cmds] = NULL;