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>
10 #include "thread_fe.h"
12 #include "pipeline_common_fe.h"
16 thread_msg_send_recv(struct app_params *app,
17 uint32_t socket_id, uint32_t core_id, uint32_t ht_id,
21 struct rte_ring *r_req = app_thread_msgq_in_get(app,
22 socket_id, core_id, ht_id);
23 struct rte_ring *r_rsp = app_thread_msgq_out_get(app,
24 socket_id, core_id, ht_id);
25 uint64_t hz = rte_get_tsc_hz();
32 status = rte_ring_sp_enqueue(r_req, (void *) msg);
33 } while (status == -ENOBUFS);
36 deadline = (timeout_ms) ?
37 (rte_rdtsc() + ((hz * timeout_ms) / 1000)) :
41 if (rte_rdtsc() > deadline)
44 status = rte_ring_sc_dequeue(r_rsp, &msg_recv);
45 } while (status != 0);
51 app_pipeline_enable(struct app_params *app,
57 struct thread_pipeline_enable_msg_req *req;
58 struct thread_pipeline_enable_msg_rsp *rsp;
60 struct app_pipeline_data *p;
61 struct app_pipeline_params *p_params;
62 struct pipeline_type *p_type;
68 thread_id = cpu_core_map_get_lcore_id(app->core_map,
73 if ((thread_id < 0) || !app_core_is_enabled(app, thread_id))
76 if (app_pipeline_data(app, pipeline_id) == NULL)
79 p = &app->pipeline_data[pipeline_id];
80 p_params = &app->pipeline_params[pipeline_id];
81 p_type = app_pipeline_type_find(app, p_params->type);
89 req = app_msg_alloc(app);
93 req->type = THREAD_MSG_REQ_PIPELINE_ENABLE;
94 req->pipeline_id = pipeline_id;
96 req->f_run = p_type->be_ops->f_run;
97 req->f_timer = p_type->be_ops->f_timer;
98 req->timer_period = p->timer_period;
100 rsp = thread_msg_send_recv(app,
101 socket_id, core_id, hyper_th_id, req, MSG_TIMEOUT_DEFAULT);
105 status = rsp->status;
106 app_msg_free(app, rsp);
116 app_pipeline_disable(struct app_params *app,
119 uint32_t hyper_th_id,
120 uint32_t pipeline_id)
122 struct thread_pipeline_disable_msg_req *req;
123 struct thread_pipeline_disable_msg_rsp *rsp;
125 struct app_pipeline_data *p;
131 thread_id = cpu_core_map_get_lcore_id(app->core_map,
136 if ((thread_id < 0) || !app_core_is_enabled(app, thread_id))
139 if (app_pipeline_data(app, pipeline_id) == NULL)
142 p = &app->pipeline_data[pipeline_id];
147 req = app_msg_alloc(app);
151 req->type = THREAD_MSG_REQ_PIPELINE_DISABLE;
152 req->pipeline_id = pipeline_id;
154 rsp = thread_msg_send_recv(app,
155 socket_id, core_id, hyper_th_id, req, MSG_TIMEOUT_DEFAULT);
160 status = rsp->status;
161 app_msg_free(app, rsp);
171 app_thread_headroom(struct app_params *app,
174 uint32_t hyper_th_id)
176 struct thread_headroom_read_msg_req *req;
177 struct thread_headroom_read_msg_rsp *rsp;
184 thread_id = cpu_core_map_get_lcore_id(app->core_map,
189 if ((thread_id < 0) || !app_core_is_enabled(app, thread_id))
192 req = app_msg_alloc(app);
196 req->type = THREAD_MSG_REQ_HEADROOM_READ;
198 rsp = thread_msg_send_recv(app,
199 socket_id, core_id, hyper_th_id, req, MSG_TIMEOUT_DEFAULT);
204 status = rsp->status;
209 printf("%.3f%%\n", rsp->headroom_ratio * 100);
212 app_msg_free(app, rsp);
221 struct cmd_pipeline_enable_result {
222 cmdline_fixed_string_t t_string;
223 cmdline_fixed_string_t t_id_string;
224 cmdline_fixed_string_t pipeline_string;
225 uint32_t pipeline_id;
226 cmdline_fixed_string_t enable_string;
230 cmd_pipeline_enable_parsed(
232 __rte_unused struct cmdline *cl,
235 struct cmd_pipeline_enable_result *params = parsed_result;
236 struct app_params *app = data;
238 uint32_t core_id, socket_id, hyper_th_id;
240 if (parse_pipeline_core(&socket_id,
243 params->t_id_string) != 0) {
244 printf("Command failed\n");
248 status = app_pipeline_enable(app,
252 params->pipeline_id);
255 printf("Command failed\n");
258 static cmdline_parse_token_string_t cmd_pipeline_enable_t_string =
259 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, t_string, "t");
261 static cmdline_parse_token_string_t cmd_pipeline_enable_t_id_string =
262 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, t_id_string,
265 static cmdline_parse_token_string_t cmd_pipeline_enable_pipeline_string =
266 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, pipeline_string,
269 static cmdline_parse_token_num_t cmd_pipeline_enable_pipeline_id =
270 TOKEN_NUM_INITIALIZER(struct cmd_pipeline_enable_result, pipeline_id,
273 static cmdline_parse_token_string_t cmd_pipeline_enable_enable_string =
274 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, enable_string,
277 static cmdline_parse_inst_t cmd_pipeline_enable = {
278 .f = cmd_pipeline_enable_parsed,
280 .help_str = "Enable pipeline on specified core",
282 (void *)&cmd_pipeline_enable_t_string,
283 (void *)&cmd_pipeline_enable_t_id_string,
284 (void *)&cmd_pipeline_enable_pipeline_string,
285 (void *)&cmd_pipeline_enable_pipeline_id,
286 (void *)&cmd_pipeline_enable_enable_string,
295 struct cmd_pipeline_disable_result {
296 cmdline_fixed_string_t t_string;
297 cmdline_fixed_string_t t_id_string;
298 cmdline_fixed_string_t pipeline_string;
299 uint32_t pipeline_id;
300 cmdline_fixed_string_t disable_string;
304 cmd_pipeline_disable_parsed(
306 __rte_unused struct cmdline *cl,
309 struct cmd_pipeline_disable_result *params = parsed_result;
310 struct app_params *app = data;
312 uint32_t core_id, socket_id, hyper_th_id;
314 if (parse_pipeline_core(&socket_id,
317 params->t_id_string) != 0) {
318 printf("Command failed\n");
322 status = app_pipeline_disable(app,
326 params->pipeline_id);
329 printf("Command failed\n");
332 static cmdline_parse_token_string_t cmd_pipeline_disable_t_string =
333 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, t_string, "t");
335 static cmdline_parse_token_string_t cmd_pipeline_disable_t_id_string =
336 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, t_id_string,
339 static cmdline_parse_token_string_t cmd_pipeline_disable_pipeline_string =
340 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result,
341 pipeline_string, "pipeline");
343 static cmdline_parse_token_num_t cmd_pipeline_disable_pipeline_id =
344 TOKEN_NUM_INITIALIZER(struct cmd_pipeline_disable_result, pipeline_id,
347 static cmdline_parse_token_string_t cmd_pipeline_disable_disable_string =
348 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, disable_string,
351 static cmdline_parse_inst_t cmd_pipeline_disable = {
352 .f = cmd_pipeline_disable_parsed,
354 .help_str = "Disable pipeline on specified core",
356 (void *)&cmd_pipeline_disable_t_string,
357 (void *)&cmd_pipeline_disable_t_id_string,
358 (void *)&cmd_pipeline_disable_pipeline_string,
359 (void *)&cmd_pipeline_disable_pipeline_id,
360 (void *)&cmd_pipeline_disable_disable_string,
370 struct cmd_thread_headroom_result {
371 cmdline_fixed_string_t t_string;
372 cmdline_fixed_string_t t_id_string;
373 cmdline_fixed_string_t headroom_string;
377 cmd_thread_headroom_parsed(
379 __rte_unused struct cmdline *cl,
382 struct cmd_thread_headroom_result *params = parsed_result;
383 struct app_params *app = data;
385 uint32_t core_id, socket_id, hyper_th_id;
387 if (parse_pipeline_core(&socket_id,
390 params->t_id_string) != 0) {
391 printf("Command failed\n");
395 status = app_thread_headroom(app,
401 printf("Command failed\n");
404 static cmdline_parse_token_string_t cmd_thread_headroom_t_string =
405 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
408 static cmdline_parse_token_string_t cmd_thread_headroom_t_id_string =
409 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
412 static cmdline_parse_token_string_t cmd_thread_headroom_headroom_string =
413 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
414 headroom_string, "headroom");
416 static cmdline_parse_inst_t cmd_thread_headroom = {
417 .f = cmd_thread_headroom_parsed,
419 .help_str = "Display thread headroom",
421 (void *)&cmd_thread_headroom_t_string,
422 (void *)&cmd_thread_headroom_t_id_string,
423 (void *)&cmd_thread_headroom_headroom_string,
429 static cmdline_parse_ctx_t thread_cmds[] = {
430 (cmdline_parse_inst_t *) &cmd_pipeline_enable,
431 (cmdline_parse_inst_t *) &cmd_pipeline_disable,
432 (cmdline_parse_inst_t *) &cmd_thread_headroom,
437 app_pipeline_thread_cmd_push(struct app_params *app)
441 /* Check for available slots in the application commands array */
442 n_cmds = RTE_DIM(thread_cmds) - 1;
443 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
446 /* Push thread commands into the application */
447 memcpy(&app->cmds[app->n_cmds], thread_cmds,
448 n_cmds * sizeof(cmdline_parse_ctx_t));
450 for (i = 0; i < n_cmds; i++)
451 app->cmds[app->n_cmds + i]->data = app;
453 app->n_cmds += n_cmds;
454 app->cmds[app->n_cmds] = NULL;