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);
174 app_thread_headroom(struct app_params *app,
177 uint32_t hyper_th_id)
179 struct thread_headroom_read_msg_req *req;
180 struct thread_headroom_read_msg_rsp *rsp;
187 thread_id = cpu_core_map_get_lcore_id(app->core_map,
192 if ((thread_id < 0) ||
193 ((app->core_mask & (1LLU << thread_id)) == 0))
196 req = app_msg_alloc(app);
200 req->type = THREAD_MSG_REQ_HEADROOM_READ;
202 rsp = thread_msg_send_recv(app,
203 socket_id, core_id, hyper_th_id, req, MSG_TIMEOUT_DEFAULT);
208 status = rsp->status;
213 printf("%.3f%%\n", rsp->headroom_ratio * 100);
216 app_msg_free(app, rsp);
225 struct cmd_pipeline_enable_result {
226 cmdline_fixed_string_t t_string;
227 cmdline_fixed_string_t t_id_string;
228 cmdline_fixed_string_t pipeline_string;
229 uint32_t pipeline_id;
230 cmdline_fixed_string_t enable_string;
234 cmd_pipeline_enable_parsed(
236 __rte_unused struct cmdline *cl,
239 struct cmd_pipeline_enable_result *params = parsed_result;
240 struct app_params *app = data;
242 uint32_t core_id, socket_id, hyper_th_id;
244 if (parse_pipeline_core(&socket_id,
247 params->t_id_string) != 0) {
248 printf("Command failed\n");
252 status = app_pipeline_enable(app,
256 params->pipeline_id);
259 printf("Command failed\n");
262 cmdline_parse_token_string_t cmd_pipeline_enable_t_string =
263 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, t_string, "t");
265 cmdline_parse_token_string_t cmd_pipeline_enable_t_id_string =
266 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, t_id_string,
269 cmdline_parse_token_string_t cmd_pipeline_enable_pipeline_string =
270 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, pipeline_string,
273 cmdline_parse_token_num_t cmd_pipeline_enable_pipeline_id =
274 TOKEN_NUM_INITIALIZER(struct cmd_pipeline_enable_result, pipeline_id,
277 cmdline_parse_token_string_t cmd_pipeline_enable_enable_string =
278 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, enable_string,
281 cmdline_parse_inst_t cmd_pipeline_enable = {
282 .f = cmd_pipeline_enable_parsed,
284 .help_str = "Enable pipeline on specified core",
286 (void *)&cmd_pipeline_enable_t_string,
287 (void *)&cmd_pipeline_enable_t_id_string,
288 (void *)&cmd_pipeline_enable_pipeline_string,
289 (void *)&cmd_pipeline_enable_pipeline_id,
290 (void *)&cmd_pipeline_enable_enable_string,
299 struct cmd_pipeline_disable_result {
300 cmdline_fixed_string_t t_string;
301 cmdline_fixed_string_t t_id_string;
302 cmdline_fixed_string_t pipeline_string;
303 uint32_t pipeline_id;
304 cmdline_fixed_string_t disable_string;
308 cmd_pipeline_disable_parsed(
310 __rte_unused struct cmdline *cl,
313 struct cmd_pipeline_disable_result *params = parsed_result;
314 struct app_params *app = data;
316 uint32_t core_id, socket_id, hyper_th_id;
318 if (parse_pipeline_core(&socket_id,
321 params->t_id_string) != 0) {
322 printf("Command failed\n");
326 status = app_pipeline_disable(app,
330 params->pipeline_id);
333 printf("Command failed\n");
336 cmdline_parse_token_string_t cmd_pipeline_disable_t_string =
337 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, t_string, "t");
339 cmdline_parse_token_string_t cmd_pipeline_disable_t_id_string =
340 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, t_id_string,
343 cmdline_parse_token_string_t cmd_pipeline_disable_pipeline_string =
344 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result,
345 pipeline_string, "pipeline");
347 cmdline_parse_token_num_t cmd_pipeline_disable_pipeline_id =
348 TOKEN_NUM_INITIALIZER(struct cmd_pipeline_disable_result, pipeline_id,
351 cmdline_parse_token_string_t cmd_pipeline_disable_disable_string =
352 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, disable_string,
355 cmdline_parse_inst_t cmd_pipeline_disable = {
356 .f = cmd_pipeline_disable_parsed,
358 .help_str = "Disable pipeline on specified core",
360 (void *)&cmd_pipeline_disable_t_string,
361 (void *)&cmd_pipeline_disable_t_id_string,
362 (void *)&cmd_pipeline_disable_pipeline_string,
363 (void *)&cmd_pipeline_disable_pipeline_id,
364 (void *)&cmd_pipeline_disable_disable_string,
374 struct cmd_thread_headroom_result {
375 cmdline_fixed_string_t t_string;
376 cmdline_fixed_string_t t_id_string;
377 cmdline_fixed_string_t headroom_string;
381 cmd_thread_headroom_parsed(
383 __rte_unused struct cmdline *cl,
386 struct cmd_thread_headroom_result *params = parsed_result;
387 struct app_params *app = data;
389 uint32_t core_id, socket_id, hyper_th_id;
391 if (parse_pipeline_core(&socket_id,
394 params->t_id_string) != 0) {
395 printf("Command failed\n");
399 status = app_thread_headroom(app,
405 printf("Command failed\n");
408 cmdline_parse_token_string_t cmd_thread_headroom_t_string =
409 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
412 cmdline_parse_token_string_t cmd_thread_headroom_t_id_string =
413 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
416 cmdline_parse_token_string_t cmd_thread_headroom_headroom_string =
417 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
418 headroom_string, "headroom");
420 cmdline_parse_inst_t cmd_thread_headroom = {
421 .f = cmd_thread_headroom_parsed,
423 .help_str = "Display thread headroom",
425 (void *)&cmd_thread_headroom_t_string,
426 (void *)&cmd_thread_headroom_t_id_string,
427 (void *)&cmd_thread_headroom_headroom_string,
433 static cmdline_parse_ctx_t thread_cmds[] = {
434 (cmdline_parse_inst_t *) &cmd_pipeline_enable,
435 (cmdline_parse_inst_t *) &cmd_pipeline_disable,
436 (cmdline_parse_inst_t *) &cmd_thread_headroom,
441 app_pipeline_thread_cmd_push(struct app_params *app)
445 /* Check for available slots in the application commands array */
446 n_cmds = RTE_DIM(thread_cmds) - 1;
447 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
450 /* Push thread commands into the application */
451 memcpy(&app->cmds[app->n_cmds], thread_cmds,
452 n_cmds * sizeof(cmdline_parse_ctx_t));
454 for (i = 0; i < n_cmds; i++)
455 app->cmds[app->n_cmds + i]->data = app;
457 app->n_cmds += n_cmds;
458 app->cmds[app->n_cmds] = NULL;