2 // Copyright (c) 2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #include <rte_common.h>
19 #include <rte_malloc.h>
20 #include <cmdline_rdline.h>
21 #include <cmdline_parse.h>
22 #include <cmdline_parse_num.h>
23 #include <cmdline_parse_string.h>
24 #include <cmdline_parse_ipaddr.h>
25 #include <cmdline_parse_etheraddr.h>
26 #include <cmdline_socket.h>
30 #include "thread_fe.h"
32 #include "pipeline_common_fe.h"
36 thread_msg_send_recv(struct app_params *app,
37 uint32_t socket_id, uint32_t core_id, uint32_t ht_id,
41 struct rte_ring *r_req = app_thread_msgq_in_get(app,
42 socket_id, core_id, ht_id);
45 struct rte_ring *r_rsp = app_thread_msgq_out_get(app,
46 socket_id, core_id, ht_id);
49 uint64_t hz = rte_get_tsc_hz();
56 status = rte_ring_sp_enqueue(r_req, (void *) msg);
57 } while (status == -ENOBUFS);
60 deadline = (timeout_ms) ?
61 (rte_rdtsc() + ((hz * timeout_ms) / 1000)) :
65 if (rte_rdtsc() > deadline)
68 status = rte_ring_sc_dequeue(r_rsp, &msg_recv);
69 } while (status != 0);
75 app_pipeline_enable(struct app_params *app,
81 struct thread_pipeline_enable_msg_req *req;
82 struct thread_pipeline_enable_msg_rsp *rsp;
84 struct app_pipeline_data *p;
85 struct app_pipeline_params *p_params;
86 struct pipeline_type *p_type;
92 thread_id = cpu_core_map_get_lcore_id(app->core_map,
97 if ((thread_id < 0) || !app_core_is_enabled(app, thread_id))
100 if (app_pipeline_data(app, pipeline_id) == NULL)
103 p = &app->pipeline_data[pipeline_id];
104 p_params = &app->pipeline_params[pipeline_id];
105 p_type = app_pipeline_type_find(app, p_params->type);
112 req = app_msg_alloc(app);
116 req->type = THREAD_MSG_REQ_PIPELINE_ENABLE;
117 req->pipeline_id = pipeline_id;
119 req->f_run = p_type->be_ops->f_run;
120 req->f_timer = p_type->be_ops->f_timer;
121 req->timer_period = p->timer_period;
123 rsp = thread_msg_send_recv(app,
124 socket_id, core_id, hyper_th_id, req, MSG_TIMEOUT_DEFAULT);
128 status = rsp->status;
129 app_msg_free(app, rsp);
139 app_pipeline_disable(struct app_params *app,
142 uint32_t hyper_th_id,
143 uint32_t pipeline_id)
145 struct thread_pipeline_disable_msg_req *req;
146 struct thread_pipeline_disable_msg_rsp *rsp;
148 struct app_pipeline_data *p;
154 thread_id = cpu_core_map_get_lcore_id(app->core_map,
159 if ((thread_id < 0) || !app_core_is_enabled(app, thread_id))
162 if (app_pipeline_data(app, pipeline_id) == NULL)
165 p = &app->pipeline_data[pipeline_id];
170 req = app_msg_alloc(app);
174 req->type = THREAD_MSG_REQ_PIPELINE_DISABLE;
175 req->pipeline_id = pipeline_id;
177 rsp = thread_msg_send_recv(app,
178 socket_id, core_id, hyper_th_id, req, MSG_TIMEOUT_DEFAULT);
183 status = rsp->status;
184 app_msg_free(app, rsp);
194 app_thread_headroom(struct app_params *app,
197 uint32_t hyper_th_id)
199 struct thread_headroom_read_msg_req *req;
200 struct thread_headroom_read_msg_rsp *rsp;
207 thread_id = cpu_core_map_get_lcore_id(app->core_map,
212 if ((thread_id < 0) || !app_core_is_enabled(app, thread_id))
215 req = app_msg_alloc(app);
219 req->type = THREAD_MSG_REQ_HEADROOM_READ;
221 rsp = thread_msg_send_recv(app,
222 socket_id, core_id, hyper_th_id, req, MSG_TIMEOUT_DEFAULT);
227 status = rsp->status;
232 printf("%.3f%%\n", rsp->headroom_ratio * 100);
235 app_msg_free(app, rsp);
244 struct cmd_pipeline_enable_result {
245 cmdline_fixed_string_t t_string;
246 cmdline_fixed_string_t t_id_string;
247 cmdline_fixed_string_t pipeline_string;
248 uint32_t pipeline_id;
249 cmdline_fixed_string_t enable_string;
253 cmd_pipeline_enable_parsed(
255 __rte_unused struct cmdline *cl,
258 struct cmd_pipeline_enable_result *params = parsed_result;
259 struct app_params *app = data;
261 uint32_t core_id, socket_id, hyper_th_id;
263 if (parse_pipeline_core(&socket_id,
266 params->t_id_string) != 0) {
267 printf("Command failed\n");
271 status = app_pipeline_enable(app,
275 params->pipeline_id);
278 printf("Command failed\n");
281 cmdline_parse_token_string_t cmd_pipeline_enable_t_string =
282 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, t_string, "t");
284 cmdline_parse_token_string_t cmd_pipeline_enable_t_id_string =
285 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, t_id_string,
288 cmdline_parse_token_string_t cmd_pipeline_enable_pipeline_string =
289 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, pipeline_string,
292 cmdline_parse_token_num_t cmd_pipeline_enable_pipeline_id =
293 TOKEN_NUM_INITIALIZER(struct cmd_pipeline_enable_result, pipeline_id,
296 cmdline_parse_token_string_t cmd_pipeline_enable_enable_string =
297 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, enable_string,
300 cmdline_parse_inst_t cmd_pipeline_enable = {
301 .f = cmd_pipeline_enable_parsed,
303 .help_str = "Enable pipeline on specified core",
305 (void *)&cmd_pipeline_enable_t_string,
306 (void *)&cmd_pipeline_enable_t_id_string,
307 (void *)&cmd_pipeline_enable_pipeline_string,
308 (void *)&cmd_pipeline_enable_pipeline_id,
309 (void *)&cmd_pipeline_enable_enable_string,
318 struct cmd_pipeline_disable_result {
319 cmdline_fixed_string_t t_string;
320 cmdline_fixed_string_t t_id_string;
321 cmdline_fixed_string_t pipeline_string;
322 uint32_t pipeline_id;
323 cmdline_fixed_string_t disable_string;
327 cmd_pipeline_disable_parsed(
329 __rte_unused struct cmdline *cl,
332 struct cmd_pipeline_disable_result *params = parsed_result;
333 struct app_params *app = data;
335 uint32_t core_id, socket_id, hyper_th_id;
337 if (parse_pipeline_core(&socket_id,
340 params->t_id_string) != 0) {
341 printf("Command failed\n");
345 status = app_pipeline_disable(app,
349 params->pipeline_id);
352 printf("Command failed\n");
355 cmdline_parse_token_string_t cmd_pipeline_disable_t_string =
356 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, t_string, "t");
358 cmdline_parse_token_string_t cmd_pipeline_disable_t_id_string =
359 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, t_id_string,
362 cmdline_parse_token_string_t cmd_pipeline_disable_pipeline_string =
363 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result,
364 pipeline_string, "pipeline");
366 cmdline_parse_token_num_t cmd_pipeline_disable_pipeline_id =
367 TOKEN_NUM_INITIALIZER(struct cmd_pipeline_disable_result, pipeline_id,
370 cmdline_parse_token_string_t cmd_pipeline_disable_disable_string =
371 TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, disable_string,
374 cmdline_parse_inst_t cmd_pipeline_disable = {
375 .f = cmd_pipeline_disable_parsed,
377 .help_str = "Disable pipeline on specified core",
379 (void *)&cmd_pipeline_disable_t_string,
380 (void *)&cmd_pipeline_disable_t_id_string,
381 (void *)&cmd_pipeline_disable_pipeline_string,
382 (void *)&cmd_pipeline_disable_pipeline_id,
383 (void *)&cmd_pipeline_disable_disable_string,
393 struct cmd_thread_headroom_result {
394 cmdline_fixed_string_t t_string;
395 cmdline_fixed_string_t t_id_string;
396 cmdline_fixed_string_t headroom_string;
400 cmd_thread_headroom_parsed(
402 __rte_unused struct cmdline *cl,
405 struct cmd_thread_headroom_result *params = parsed_result;
406 struct app_params *app = data;
408 uint32_t core_id, socket_id, hyper_th_id;
410 if (parse_pipeline_core(&socket_id,
413 params->t_id_string) != 0) {
414 printf("Command failed\n");
418 status = app_thread_headroom(app,
424 printf("Command failed\n");
427 cmdline_parse_token_string_t cmd_thread_headroom_t_string =
428 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
431 cmdline_parse_token_string_t cmd_thread_headroom_t_id_string =
432 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
435 cmdline_parse_token_string_t cmd_thread_headroom_headroom_string =
436 TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result,
437 headroom_string, "headroom");
439 cmdline_parse_inst_t cmd_thread_headroom = {
440 .f = cmd_thread_headroom_parsed,
442 .help_str = "Display thread headroom",
444 (void *)&cmd_thread_headroom_t_string,
445 (void *)&cmd_thread_headroom_t_id_string,
446 (void *)&cmd_thread_headroom_headroom_string,
452 static cmdline_parse_ctx_t thread_cmds[] = {
453 (cmdline_parse_inst_t *) &cmd_pipeline_enable,
454 (cmdline_parse_inst_t *) &cmd_pipeline_disable,
455 (cmdline_parse_inst_t *) &cmd_thread_headroom,
460 app_pipeline_thread_cmd_push(struct app_params *app)
464 /* Check for available slots in the application commands array */
465 n_cmds = RTE_DIM(thread_cmds) - 1;
466 if (n_cmds > APP_MAX_CMDS - app->n_cmds)
469 /* Push thread commands into the application */
470 memcpy(&app->cmds[app->n_cmds], thread_cmds,
471 n_cmds * sizeof(cmdline_parse_ctx_t));
473 for (i = 0; i < n_cmds; i++)
474 app->cmds[app->n_cmds + i]->data = app;
476 app->n_cmds += n_cmds;
477 app->cmds[app->n_cmds] = NULL;