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) ||
74 ((app
->core_mask
& (1LLU << thread_id
)) == 0))
77 if (app_pipeline_data(app
, pipeline_id
) == NULL
)
80 p
= &app
->pipeline_data
[pipeline_id
];
81 p_params
= &app
->pipeline_params
[pipeline_id
];
82 p_type
= app_pipeline_type_find(app
, p_params
->type
);
90 req
= app_msg_alloc(app
);
94 req
->type
= THREAD_MSG_REQ_PIPELINE_ENABLE
;
95 req
->pipeline_id
= pipeline_id
;
97 req
->f_run
= p_type
->be_ops
->f_run
;
98 req
->f_timer
= p_type
->be_ops
->f_timer
;
99 req
->timer_period
= p
->timer_period
;
101 rsp
= thread_msg_send_recv(app
,
102 socket_id
, core_id
, hyper_th_id
, req
, MSG_TIMEOUT_DEFAULT
);
106 status
= rsp
->status
;
107 app_msg_free(app
, rsp
);
117 app_pipeline_disable(struct app_params
*app
,
120 uint32_t hyper_th_id
,
121 uint32_t pipeline_id
)
123 struct thread_pipeline_disable_msg_req
*req
;
124 struct thread_pipeline_disable_msg_rsp
*rsp
;
126 struct app_pipeline_data
*p
;
132 thread_id
= cpu_core_map_get_lcore_id(app
->core_map
,
137 if ((thread_id
< 0) ||
138 ((app
->core_mask
& (1LLU << thread_id
)) == 0))
141 if (app_pipeline_data(app
, pipeline_id
) == NULL
)
144 p
= &app
->pipeline_data
[pipeline_id
];
149 req
= app_msg_alloc(app
);
153 req
->type
= THREAD_MSG_REQ_PIPELINE_DISABLE
;
154 req
->pipeline_id
= pipeline_id
;
156 rsp
= thread_msg_send_recv(app
,
157 socket_id
, core_id
, hyper_th_id
, req
, MSG_TIMEOUT_DEFAULT
);
162 status
= rsp
->status
;
163 app_msg_free(app
, rsp
);
173 app_thread_headroom(struct app_params
*app
,
176 uint32_t hyper_th_id
)
178 struct thread_headroom_read_msg_req
*req
;
179 struct thread_headroom_read_msg_rsp
*rsp
;
186 thread_id
= cpu_core_map_get_lcore_id(app
->core_map
,
191 if ((thread_id
< 0) ||
192 ((app
->core_mask
& (1LLU << thread_id
)) == 0))
195 req
= app_msg_alloc(app
);
199 req
->type
= THREAD_MSG_REQ_HEADROOM_READ
;
201 rsp
= thread_msg_send_recv(app
,
202 socket_id
, core_id
, hyper_th_id
, req
, MSG_TIMEOUT_DEFAULT
);
207 status
= rsp
->status
;
212 printf("%.3f%%\n", rsp
->headroom_ratio
* 100);
215 app_msg_free(app
, rsp
);
224 struct cmd_pipeline_enable_result
{
225 cmdline_fixed_string_t t_string
;
226 cmdline_fixed_string_t t_id_string
;
227 cmdline_fixed_string_t pipeline_string
;
228 uint32_t pipeline_id
;
229 cmdline_fixed_string_t enable_string
;
233 cmd_pipeline_enable_parsed(
235 __rte_unused
struct cmdline
*cl
,
238 struct cmd_pipeline_enable_result
*params
= parsed_result
;
239 struct app_params
*app
= data
;
241 uint32_t core_id
, socket_id
, hyper_th_id
;
243 if (parse_pipeline_core(&socket_id
,
246 params
->t_id_string
) != 0) {
247 printf("Command failed\n");
251 status
= app_pipeline_enable(app
,
255 params
->pipeline_id
);
258 printf("Command failed\n");
261 static cmdline_parse_token_string_t cmd_pipeline_enable_t_string
=
262 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result
, t_string
, "t");
264 static cmdline_parse_token_string_t cmd_pipeline_enable_t_id_string
=
265 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result
, t_id_string
,
268 static cmdline_parse_token_string_t cmd_pipeline_enable_pipeline_string
=
269 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result
, pipeline_string
,
272 static cmdline_parse_token_num_t cmd_pipeline_enable_pipeline_id
=
273 TOKEN_NUM_INITIALIZER(struct cmd_pipeline_enable_result
, pipeline_id
,
276 static cmdline_parse_token_string_t cmd_pipeline_enable_enable_string
=
277 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result
, enable_string
,
280 static cmdline_parse_inst_t cmd_pipeline_enable
= {
281 .f
= cmd_pipeline_enable_parsed
,
283 .help_str
= "Enable pipeline on specified core",
285 (void *)&cmd_pipeline_enable_t_string
,
286 (void *)&cmd_pipeline_enable_t_id_string
,
287 (void *)&cmd_pipeline_enable_pipeline_string
,
288 (void *)&cmd_pipeline_enable_pipeline_id
,
289 (void *)&cmd_pipeline_enable_enable_string
,
298 struct cmd_pipeline_disable_result
{
299 cmdline_fixed_string_t t_string
;
300 cmdline_fixed_string_t t_id_string
;
301 cmdline_fixed_string_t pipeline_string
;
302 uint32_t pipeline_id
;
303 cmdline_fixed_string_t disable_string
;
307 cmd_pipeline_disable_parsed(
309 __rte_unused
struct cmdline
*cl
,
312 struct cmd_pipeline_disable_result
*params
= parsed_result
;
313 struct app_params
*app
= data
;
315 uint32_t core_id
, socket_id
, hyper_th_id
;
317 if (parse_pipeline_core(&socket_id
,
320 params
->t_id_string
) != 0) {
321 printf("Command failed\n");
325 status
= app_pipeline_disable(app
,
329 params
->pipeline_id
);
332 printf("Command failed\n");
335 static cmdline_parse_token_string_t cmd_pipeline_disable_t_string
=
336 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result
, t_string
, "t");
338 static cmdline_parse_token_string_t cmd_pipeline_disable_t_id_string
=
339 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result
, t_id_string
,
342 static cmdline_parse_token_string_t cmd_pipeline_disable_pipeline_string
=
343 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result
,
344 pipeline_string
, "pipeline");
346 static cmdline_parse_token_num_t cmd_pipeline_disable_pipeline_id
=
347 TOKEN_NUM_INITIALIZER(struct cmd_pipeline_disable_result
, pipeline_id
,
350 static cmdline_parse_token_string_t cmd_pipeline_disable_disable_string
=
351 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result
, disable_string
,
354 static cmdline_parse_inst_t cmd_pipeline_disable
= {
355 .f
= cmd_pipeline_disable_parsed
,
357 .help_str
= "Disable pipeline on specified core",
359 (void *)&cmd_pipeline_disable_t_string
,
360 (void *)&cmd_pipeline_disable_t_id_string
,
361 (void *)&cmd_pipeline_disable_pipeline_string
,
362 (void *)&cmd_pipeline_disable_pipeline_id
,
363 (void *)&cmd_pipeline_disable_disable_string
,
373 struct cmd_thread_headroom_result
{
374 cmdline_fixed_string_t t_string
;
375 cmdline_fixed_string_t t_id_string
;
376 cmdline_fixed_string_t headroom_string
;
380 cmd_thread_headroom_parsed(
382 __rte_unused
struct cmdline
*cl
,
385 struct cmd_thread_headroom_result
*params
= parsed_result
;
386 struct app_params
*app
= data
;
388 uint32_t core_id
, socket_id
, hyper_th_id
;
390 if (parse_pipeline_core(&socket_id
,
393 params
->t_id_string
) != 0) {
394 printf("Command failed\n");
398 status
= app_thread_headroom(app
,
404 printf("Command failed\n");
407 static cmdline_parse_token_string_t cmd_thread_headroom_t_string
=
408 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result
,
411 static cmdline_parse_token_string_t cmd_thread_headroom_t_id_string
=
412 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result
,
415 static cmdline_parse_token_string_t cmd_thread_headroom_headroom_string
=
416 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result
,
417 headroom_string
, "headroom");
419 static cmdline_parse_inst_t cmd_thread_headroom
= {
420 .f
= cmd_thread_headroom_parsed
,
422 .help_str
= "Display thread headroom",
424 (void *)&cmd_thread_headroom_t_string
,
425 (void *)&cmd_thread_headroom_t_id_string
,
426 (void *)&cmd_thread_headroom_headroom_string
,
432 static cmdline_parse_ctx_t thread_cmds
[] = {
433 (cmdline_parse_inst_t
*) &cmd_pipeline_enable
,
434 (cmdline_parse_inst_t
*) &cmd_pipeline_disable
,
435 (cmdline_parse_inst_t
*) &cmd_thread_headroom
,
440 app_pipeline_thread_cmd_push(struct app_params
*app
)
444 /* Check for available slots in the application commands array */
445 n_cmds
= RTE_DIM(thread_cmds
) - 1;
446 if (n_cmds
> APP_MAX_CMDS
- app
->n_cmds
)
449 /* Push thread commands into the application */
450 memcpy(&app
->cmds
[app
->n_cmds
], thread_cmds
,
451 n_cmds
* sizeof(cmdline_parse_ctx_t
));
453 for (i
= 0; i
< n_cmds
; i
++)
454 app
->cmds
[app
->n_cmds
+ i
]->data
= app
;
456 app
->n_cmds
+= n_cmds
;
457 app
->cmds
[app
->n_cmds
] = NULL
;