X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Fip_pipeline%2Fthread_fe.c;h=4590c2b58d6113ce2221e3bf8c54c04246b40c62;hb=01d0df35e732446b98acd9b9b70cebb8c5e76e27;hp=7a3bbf86b3ddd0c9e7c7b803d7bbc0d3a56843f5;hpb=b4aee0fb9c6d4fee771271d6c03a65dc27ba024a;p=dpdk.git diff --git a/examples/ip_pipeline/thread_fe.c b/examples/ip_pipeline/thread_fe.c index 7a3bbf86b3..4590c2b58d 100644 --- a/examples/ip_pipeline/thread_fe.c +++ b/examples/ip_pipeline/thread_fe.c @@ -5,10 +5,6 @@ #include #include #include -#include -#include -#include -#include #include "thread.h" #include "thread_fe.h" @@ -74,8 +70,7 @@ app_pipeline_enable(struct app_params *app, core_id, hyper_th_id); - if ((thread_id < 0) || - ((app->core_mask & (1LLU << thread_id)) == 0)) + if ((thread_id < 0) || !app_core_is_enabled(app, thread_id)) return -1; if (app_pipeline_data(app, pipeline_id) == NULL) @@ -85,6 +80,9 @@ app_pipeline_enable(struct app_params *app, p_params = &app->pipeline_params[pipeline_id]; p_type = app_pipeline_type_find(app, p_params->type); + if (p_type == NULL) + return -1; + if (p->enabled == 1) return -1; @@ -135,8 +133,7 @@ app_pipeline_disable(struct app_params *app, core_id, hyper_th_id); - if ((thread_id < 0) || - ((app->core_mask & (1LLU << thread_id)) == 0)) + if ((thread_id < 0) || !app_core_is_enabled(app, thread_id)) return -1; if (app_pipeline_data(app, pipeline_id) == NULL) @@ -170,6 +167,53 @@ app_pipeline_disable(struct app_params *app, return 0; } +int +app_thread_headroom(struct app_params *app, + uint32_t socket_id, + uint32_t core_id, + uint32_t hyper_th_id) +{ + struct thread_headroom_read_msg_req *req; + struct thread_headroom_read_msg_rsp *rsp; + int thread_id; + int status; + + if (app == NULL) + return -1; + + thread_id = cpu_core_map_get_lcore_id(app->core_map, + socket_id, + core_id, + hyper_th_id); + + if ((thread_id < 0) || !app_core_is_enabled(app, thread_id)) + return -1; + + req = app_msg_alloc(app); + if (req == NULL) + return -1; + + req->type = THREAD_MSG_REQ_HEADROOM_READ; + + rsp = thread_msg_send_recv(app, + socket_id, core_id, hyper_th_id, req, MSG_TIMEOUT_DEFAULT); + + if (rsp == NULL) + return -1; + + status = rsp->status; + + if (status != 0) + return -1; + + printf("%.3f%%\n", rsp->headroom_ratio * 100); + + + app_msg_free(app, rsp); + + return 0; +} + /* * pipeline enable */ @@ -211,26 +255,26 @@ cmd_pipeline_enable_parsed( printf("Command failed\n"); } -cmdline_parse_token_string_t cmd_pipeline_enable_t_string = +static cmdline_parse_token_string_t cmd_pipeline_enable_t_string = TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, t_string, "t"); -cmdline_parse_token_string_t cmd_pipeline_enable_t_id_string = +static cmdline_parse_token_string_t cmd_pipeline_enable_t_id_string = TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, t_id_string, NULL); -cmdline_parse_token_string_t cmd_pipeline_enable_pipeline_string = +static cmdline_parse_token_string_t cmd_pipeline_enable_pipeline_string = TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, pipeline_string, "pipeline"); -cmdline_parse_token_num_t cmd_pipeline_enable_pipeline_id = +static cmdline_parse_token_num_t cmd_pipeline_enable_pipeline_id = TOKEN_NUM_INITIALIZER(struct cmd_pipeline_enable_result, pipeline_id, UINT32); -cmdline_parse_token_string_t cmd_pipeline_enable_enable_string = +static cmdline_parse_token_string_t cmd_pipeline_enable_enable_string = TOKEN_STRING_INITIALIZER(struct cmd_pipeline_enable_result, enable_string, "enable"); -cmdline_parse_inst_t cmd_pipeline_enable = { +static cmdline_parse_inst_t cmd_pipeline_enable = { .f = cmd_pipeline_enable_parsed, .data = NULL, .help_str = "Enable pipeline on specified core", @@ -285,26 +329,26 @@ cmd_pipeline_disable_parsed( printf("Command failed\n"); } -cmdline_parse_token_string_t cmd_pipeline_disable_t_string = +static cmdline_parse_token_string_t cmd_pipeline_disable_t_string = TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, t_string, "t"); -cmdline_parse_token_string_t cmd_pipeline_disable_t_id_string = +static cmdline_parse_token_string_t cmd_pipeline_disable_t_id_string = TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, t_id_string, NULL); -cmdline_parse_token_string_t cmd_pipeline_disable_pipeline_string = +static cmdline_parse_token_string_t cmd_pipeline_disable_pipeline_string = TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, pipeline_string, "pipeline"); -cmdline_parse_token_num_t cmd_pipeline_disable_pipeline_id = +static cmdline_parse_token_num_t cmd_pipeline_disable_pipeline_id = TOKEN_NUM_INITIALIZER(struct cmd_pipeline_disable_result, pipeline_id, UINT32); -cmdline_parse_token_string_t cmd_pipeline_disable_disable_string = +static cmdline_parse_token_string_t cmd_pipeline_disable_disable_string = TOKEN_STRING_INITIALIZER(struct cmd_pipeline_disable_result, disable_string, "disable"); -cmdline_parse_inst_t cmd_pipeline_disable = { +static cmdline_parse_inst_t cmd_pipeline_disable = { .f = cmd_pipeline_disable_parsed, .data = NULL, .help_str = "Disable pipeline on specified core", @@ -318,9 +362,74 @@ cmdline_parse_inst_t cmd_pipeline_disable = { }, }; + +/* + * thread headroom + */ + +struct cmd_thread_headroom_result { + cmdline_fixed_string_t t_string; + cmdline_fixed_string_t t_id_string; + cmdline_fixed_string_t headroom_string; +}; + +static void +cmd_thread_headroom_parsed( + void *parsed_result, + __rte_unused struct cmdline *cl, + void *data) +{ + struct cmd_thread_headroom_result *params = parsed_result; + struct app_params *app = data; + int status; + uint32_t core_id, socket_id, hyper_th_id; + + if (parse_pipeline_core(&socket_id, + &core_id, + &hyper_th_id, + params->t_id_string) != 0) { + printf("Command failed\n"); + return; + } + + status = app_thread_headroom(app, + socket_id, + core_id, + hyper_th_id); + + if (status != 0) + printf("Command failed\n"); +} + +static cmdline_parse_token_string_t cmd_thread_headroom_t_string = + TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result, + t_string, "t"); + +static cmdline_parse_token_string_t cmd_thread_headroom_t_id_string = + TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result, + t_id_string, NULL); + +static cmdline_parse_token_string_t cmd_thread_headroom_headroom_string = + TOKEN_STRING_INITIALIZER(struct cmd_thread_headroom_result, + headroom_string, "headroom"); + +static cmdline_parse_inst_t cmd_thread_headroom = { + .f = cmd_thread_headroom_parsed, + .data = NULL, + .help_str = "Display thread headroom", + .tokens = { + (void *)&cmd_thread_headroom_t_string, + (void *)&cmd_thread_headroom_t_id_string, + (void *)&cmd_thread_headroom_headroom_string, + NULL, + }, +}; + + static cmdline_parse_ctx_t thread_cmds[] = { (cmdline_parse_inst_t *) &cmd_pipeline_enable, (cmdline_parse_inst_t *) &cmd_pipeline_disable, + (cmdline_parse_inst_t *) &cmd_thread_headroom, NULL, }; @@ -335,9 +444,8 @@ app_pipeline_thread_cmd_push(struct app_params *app) return -ENOMEM; /* Push thread commands into the application */ - memcpy(&app->cmds[app->n_cmds], - thread_cmds, - n_cmds * sizeof(cmdline_parse_ctx_t *)); + memcpy(&app->cmds[app->n_cmds], thread_cmds, + n_cmds * sizeof(cmdline_parse_ctx_t)); for (i = 0; i < n_cmds; i++) app->cmds[app->n_cmds + i]->data = app;