From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> This series of update is to refactor functions for manipulating info of worker thread previously called as component. Yasufumi Ogawa (6): shared/sec: refactor func for deleting comp info shared/sec: revise types of spp worker shared/sec: rename funcs of flush cmd shared/sec: rename file spp_proc to cmd_utils shared/sec: refactor name of funcs for exec cmd shared/sec: rename struct spp_command src/mirror/Makefile | 2 +- src/mirror/spp_mirror.c | 51 +++--- src/pcap/Makefile | 2 +- src/pcap/{spp_proc.c => cmd_utils.c} | 2 +- src/pcap/{spp_proc.h => cmd_utils.h} | 6 +- src/pcap/command_dec.h | 2 +- src/pcap/command_proc.h | 2 +- src/pcap/spp_pcap.c | 2 +- src/pcap/spp_pcap.h | 2 +- .../secondary/spp_worker_th/cmd_parser.c | 63 +++---- .../secondary/spp_worker_th/cmd_parser.h | 12 +- .../secondary/spp_worker_th/cmd_runner.c | 159 +++++++++--------- .../secondary/spp_worker_th/cmd_runner.h | 10 +- .../spp_worker_th/{spp_proc.c => cmd_utils.c} | 87 +++++----- .../spp_worker_th/{spp_proc.h => cmd_utils.h} | 70 ++++---- .../secondary/spp_worker_th/command_conn.h | 2 +- .../secondary/spp_worker_th/mirror_deps.h | 2 +- .../spp_worker_th/ringlatencystats.c | 2 +- src/shared/secondary/spp_worker_th/spp_port.h | 8 +- src/shared/secondary/spp_worker_th/vf_deps.h | 8 +- src/vf/Makefile | 2 +- src/vf/classifier_mac.c | 2 +- src/vf/spp_forward.c | 23 ++- src/vf/spp_vf.c | 6 +- 24 files changed, 263 insertions(+), 264 deletions(-) rename src/pcap/{spp_proc.c => cmd_utils.c} (99%) rename src/pcap/{spp_proc.h => cmd_utils.h} (99%) rename src/shared/secondary/spp_worker_th/{spp_proc.c => cmd_utils.c} (94%) rename src/shared/secondary/spp_worker_th/{spp_proc.h => cmd_utils.h} (92%) -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> This update is to rename function misspelled `del_componet_info()` to `del_comp_info()` to be simple, and revise name of vars and comments for refactoring. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- .../secondary/spp_worker_th/cmd_runner.c | 19 +++++++---- src/shared/secondary/spp_worker_th/spp_proc.c | 33 ++++++++++--------- src/shared/secondary/spp_worker_th/spp_proc.h | 19 ++++++----- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c index 613e924..cf86a6a 100644 --- a/src/shared/secondary/spp_worker_th/cmd_runner.c +++ b/src/shared/secondary/spp_worker_th/cmd_runner.c @@ -207,18 +207,21 @@ update_cls_table(enum sppwk_action wk_action, } /* Assign worker thread or remove on specified lcore. */ +/* TODO(yasufum) revise func name for removing the term `component`. */ static int update_comp(enum sppwk_action wk_action, const char *name, unsigned int lcore_id, enum spp_component_type type) { - int ret = SPP_RET_NG; - int ret_del = -1; + int ret; + int ret_del; int comp_lcore_id = 0; unsigned int tmp_lcore_id = 0; struct spp_component_info *comp_info = NULL; + /* TODO(yasufum) revise `core` to be more specific. */ struct core_info *core = NULL; struct core_mng_info *info = NULL; struct spp_component_info *comp_info_base = NULL; + /* TODO(yasufum) revise `core_info` which is same as struct name. */ struct core_mng_info *core_info = NULL; int *change_core = NULL; int *change_component = NULL; @@ -277,23 +280,27 @@ update_comp(enum sppwk_action wk_action, const char *name, info = (core_info + tmp_lcore_id); core = &info->core[info->upd_index]; + /** + * TODO(yasufum) check if this ifdef is simply removed by + * running other than spp_vf. + */ #ifdef SPP_VF_MODULE /* initialize classifier information */ if (comp_info->type == SPP_COMPONENT_CLASSIFIER_MAC) init_classifier_info(comp_lcore_id); #endif /* SPP_VF_MODULE */ - ret_del = del_component_info(comp_lcore_id, - core->num, core->id); + /* The latest lcore is released if worker thread is stopped. */ + ret_del = del_comp_info(comp_lcore_id, core->num, core->id); if (ret_del >= 0) - /* If deleted, decrement number. */ core->num--; ret = SPP_RET_OK; *(change_component + comp_lcore_id) = 0; break; - default: + default: /* Unexpected case. */ + ret = SPP_RET_NG; break; } diff --git a/src/shared/secondary/spp_worker_th/spp_proc.c b/src/shared/secondary/spp_worker_th/spp_proc.c index 9c62bab..386144f 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.c +++ b/src/shared/secondary/spp_worker_th/spp_proc.c @@ -742,30 +742,33 @@ sppwk_get_lcore_id(const char *comp_name) } /* Delete component information */ +/** + * TODO(yasufum) consider to move to cmd_runner because this func is only + * used in. + */ int -del_component_info(int component_id, int component_num, int *componet_array) +del_comp_info(int lcore_id, int nof_comps, int *comp_ary) { + int idx; /* The index of comp_ary to be deleted. */ int cnt; - int match = -1; - int max = component_num; - for (cnt = 0; cnt < max; cnt++) { - if (component_id == componet_array[cnt]) - match = cnt; + /* Find the index. */ + for (cnt = 0; cnt < nof_comps; cnt++) { + if (lcore_id == comp_ary[cnt]) + idx = cnt; } - - if (match < 0) + if (idx < 0) return SPP_RET_NG; - /* Last element is excluded from movement. */ - max--; + /* Overwrite the deleted entry, and shift the remained. */ + nof_comps--; + for (cnt = idx; cnt < nof_comps; cnt++) + comp_ary[cnt] = comp_ary[cnt + 1]; - for (cnt = match; cnt < max; cnt++) - componet_array[cnt] = componet_array[cnt+1]; + /* Clean the unused last entry. */ + comp_ary[cnt] = 0; - /* Last element is cleared. */ - componet_array[cnt] = 0; - return 0; + return SPP_RET_OK; } /** diff --git a/src/shared/secondary/spp_worker_th/spp_proc.h b/src/shared/secondary/spp_worker_th/spp_proc.h index bdd628e..61f3597 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.h +++ b/src/shared/secondary/spp_worker_th/spp_proc.h @@ -555,18 +555,19 @@ int sppwk_get_lcore_id(const char *comp_name); /** * Delete component information. * - * @param component_id - * check data - * @param component_num - * array check count - * @param componet_array - * check array address + * @param[in] lcore_id The lcore ID of deleted comp. + * @param[in] nof_comps The num of elements in comp_ary. + * @param[in] *comp_ary Set of comps from which an comp is deleted. * - * @retval 0 succeeded. - * @retval -1 failed. + * @retval SPP_RET_OK If succeeded. + * @retval SPP_RET_NG If failed. + */ +/** + * TODO(yasufum) consider to move to cmd_runner because this func is only + * used in. */ int -del_component_info(int component_id, int component_num, int *componet_array); +del_comp_info(int lcore_id, int nof_comps, int *comp_ary); /** * Get index of given entry in given port info array. It returns the index, -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> This update is to revise SPP worker types to be more specific. enum `spp_component_type` is changed to `sppwk_worker_type` and the member of the enum is also changed as following. * SPPWK_TYPE_NONE which has no roles. * SPPWK_TYPE_CLS for classifier. * SPPWK_TYPE_MRG for merger. * SPPWK_TYPE_FWD for forwarder. * SPPWK_TYPE_MIR for mirror. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/mirror/spp_mirror.c | 47 +++++++++---------- .../secondary/spp_worker_th/cmd_parser.c | 16 +++---- .../secondary/spp_worker_th/cmd_parser.h | 2 +- .../secondary/spp_worker_th/cmd_runner.c | 24 +++++----- src/shared/secondary/spp_worker_th/spp_proc.c | 18 +++---- src/shared/secondary/spp_worker_th/spp_proc.h | 18 +++---- src/vf/classifier_mac.c | 2 +- src/vf/spp_forward.c | 23 +++++---- src/vf/spp_vf.c | 2 +- 9 files changed, 74 insertions(+), 78 deletions(-) diff --git a/src/mirror/spp_mirror.c b/src/mirror/spp_mirror.c index 202475a..26c250b 100644 --- a/src/mirror/spp_mirror.c +++ b/src/mirror/spp_mirror.c @@ -24,8 +24,8 @@ #define SPP_MIRROR_POOL_NAME_MAX 32 #define MAX_PKT_MIRROR 4096 #define MEMPOOL_CACHE_SIZE 256 -#define RTE_TEST_RX_DESC_DEFAULT 1024 -#define RTE_TEST_TX_DESC_DEFAULT 1024 +#define MIR_RX_DESC_DEFAULT 1024 +#define MIR_TX_DESC_DEFAULT 1024 /* A set of port info of rx and tx */ struct mirror_rxtx { @@ -35,13 +35,11 @@ struct mirror_rxtx { /* Information on the path used for mirror. */ struct mirror_path { - char name[SPP_NAME_STR_LEN]; /* component name */ - volatile enum spp_component_type type; - /* component type */ - int num_rx; /* number of receive ports */ - int num_tx; /* number of mirror ports */ - struct mirror_rxtx ports[RTE_MAX_ETHPORTS]; - /* port used for mirror */ + char name[SPP_NAME_STR_LEN]; /* component name */ + volatile enum sppwk_worker_type wk_type; + int nof_rx; /* number of receive ports */ + int nof_tx; /* number of mirror ports */ + struct mirror_rxtx ports[RTE_MAX_ETHPORTS]; /* used for mirror */ }; /* Information for mirror. */ @@ -52,9 +50,8 @@ struct mirror_info { /* Information of data path */ }; -/* */ -static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT; -static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; +static uint16_t nb_rxd = MIR_RX_DESC_DEFAULT; +static uint16_t nb_txd = MIR_TX_DESC_DEFAULT; /* Logical core ID for main process */ static unsigned int g_main_lcore_id = 0xffffffff; @@ -292,7 +289,7 @@ spp_mirror_update(struct spp_component_info *component) if (unlikely(num_rx > 1)) { RTE_LOG(ERR, MIRROR, "Component[%d] Setting error. (type = %d, rx = %d)\n", - component->component_id, component->type, num_rx); + component->component_id, component->wk_type, num_rx); return SPP_RET_NG; } @@ -300,7 +297,7 @@ spp_mirror_update(struct spp_component_info *component) if (unlikely(num_tx > 2)) { RTE_LOG(ERR, MIRROR, "Component[%d] Setting error. (type = %d, tx = %d)\n", - component->component_id, component->type, num_tx); + component->component_id, component->wk_type, num_tx); return SPP_RET_NG; } @@ -311,12 +308,12 @@ spp_mirror_update(struct spp_component_info *component) "(name = %s, type = %d)\n", component->component_id, component->name, - component->type); + component->wk_type); memcpy(&path->name, component->name, SPP_NAME_STR_LEN); - path->type = component->type; - path->num_rx = component->num_rx_port; - path->num_tx = component->num_tx_port; + path->wk_type = component->wk_type; + path->nof_rx = component->num_rx_port; + path->nof_tx = component->num_tx_port; for (cnt = 0; cnt < num_rx; cnt++) memcpy(&path->ports[cnt].rx, component->rx_ports[cnt], sizeof(struct sppwk_port_info)); @@ -335,7 +332,7 @@ spp_mirror_update(struct spp_component_info *component) "(name = %s, type = %d)\n", component->component_id, component->name, - component->type); + component->wk_type); return SPP_RET_OK; } @@ -378,7 +375,7 @@ mirror_proc(int id) path = &info->path[info->ref_index]; /* Practice condition check */ - if (!(path->num_tx == 2 && path->num_rx == 1)) + if (!(path->nof_tx == 2 && path->nof_rx == 1)) return SPP_RET_OK; rx = &path->ports[0].rx; @@ -481,24 +478,24 @@ spp_mirror_get_component_status( struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS]; struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS]; - if (unlikely(path->type == SPP_COMPONENT_UNUSE)) { + if (unlikely(path->wk_type == SPPWK_TYPE_NONE)) { RTE_LOG(ERR, MIRROR, "Component[%d] Not used. " "(status)(core = %d, type = %d)\n", - id, lcore_id, path->type); + id, lcore_id, path->wk_type); return SPP_RET_NG; } component_type = SPP_TYPE_MIRROR_STR; memset(rx_ports, 0x00, sizeof(rx_ports)); - for (cnt = 0; cnt < path->num_rx; cnt++) { + for (cnt = 0; cnt < path->nof_rx; cnt++) { rx_ports[cnt].iface_type = path->ports[cnt].rx.iface_type; rx_ports[cnt].iface_no = path->ports[cnt].rx.iface_no; } memset(tx_ports, 0x00, sizeof(tx_ports)); - for (cnt = 0; cnt < path->num_tx; cnt++) { + for (cnt = 0; cnt < path->nof_tx; cnt++) { tx_ports[cnt].iface_type = path->ports[cnt].tx.iface_type; tx_ports[cnt].iface_no = path->ports[cnt].tx.iface_no; } @@ -507,7 +504,7 @@ spp_mirror_get_component_status( ret = (*params->element_proc)( params, lcore_id, path->name, component_type, - path->num_rx, rx_ports, path->num_tx, tx_ports); + path->nof_rx, rx_ports, path->nof_tx, tx_ports); if (unlikely(ret != 0)) return SPP_RET_NG; diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.c b/src/shared/secondary/spp_worker_th/cmd_parser.c index 77efbd7..0f0e64c 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.c +++ b/src/shared/secondary/spp_worker_th/cmd_parser.c @@ -178,7 +178,7 @@ parse_resource_uid(const char *res_uid, /* Get component type from string of its name. */ /* TODO(yasufum) should be worker local, separated for vf and mirror. */ -static enum spp_component_type +static enum sppwk_worker_type get_comp_type_from_str(const char *type_str) { RTE_LOG(DEBUG, WK_CMD_PARSER, "type_str is %s\n", type_str); @@ -186,23 +186,23 @@ get_comp_type_from_str(const char *type_str) #ifdef SPP_VF_MODULE if (strncmp(type_str, CORE_TYPE_CLASSIFIER_MAC_STR, strlen(CORE_TYPE_CLASSIFIER_MAC_STR)+1) == 0) { - return SPP_COMPONENT_CLASSIFIER_MAC; + return SPPWK_TYPE_CLS; } else if (strncmp(type_str, CORE_TYPE_MERGE_STR, strlen(CORE_TYPE_MERGE_STR)+1) == 0) { - return SPP_COMPONENT_MERGE; + return SPPWK_TYPE_MRG; } else if (strncmp(type_str, CORE_TYPE_FORWARD_STR, strlen(CORE_TYPE_FORWARD_STR)+1) == 0) { - return SPP_COMPONENT_FORWARD; + return SPPWK_TYPE_FWD; } #endif /* SPP_VF_MODULE */ #ifdef SPP_MIRROR_MODULE if (strncmp(type_str, SPP_TYPE_MIRROR_STR, strlen(SPP_TYPE_MIRROR_STR)+1) == 0) - return SPP_COMPONENT_MIRROR; + return SPPWK_TYPE_MIR; #endif /* SPP_MIRROR_MODULE */ - return SPP_COMPONENT_UNUSE; + return SPPWK_TYPE_NONE; } /* Format error message object and return error code for an error case. */ @@ -418,7 +418,7 @@ static int parse_comp_type(void *output, const char *arg_val, int allow_override __attribute__ ((unused))) { - enum spp_component_type comp_type; + enum sppwk_worker_type comp_type; struct sppwk_cmd_comp *component = output; /* Parsing comp type is required only for action `start`. */ @@ -433,7 +433,7 @@ parse_comp_type(void *output, const char *arg_val, return SPP_RET_NG; } - component->type = comp_type; + component->wk_type = comp_type; return SPP_RET_OK; } diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index b90f52a..c8839f1 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -95,7 +95,7 @@ struct sppwk_cmd_comp { enum sppwk_action wk_action; /**< start or stop */ char name[SPPWK_NAME_BUFSZ]; /**< component name */ unsigned int core; /**< logical core number */ - enum spp_component_type type; /**< component type */ + enum sppwk_worker_type wk_type; /**< worker thread type */ }; /* `port` command parameters. */ diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c index cf86a6a..5df7b92 100644 --- a/src/shared/secondary/spp_worker_th/cmd_runner.c +++ b/src/shared/secondary/spp_worker_th/cmd_runner.c @@ -210,7 +210,7 @@ update_cls_table(enum sppwk_action wk_action, /* TODO(yasufum) revise func name for removing the term `component`. */ static int update_comp(enum sppwk_action wk_action, const char *name, - unsigned int lcore_id, enum spp_component_type type) + unsigned int lcore_id, enum sppwk_worker_type wk_type) { int ret; int ret_del; @@ -257,7 +257,7 @@ update_comp(enum sppwk_action wk_action, const char *name, comp_info = (comp_info_base + comp_lcore_id); memset(comp_info, 0x00, sizeof(struct spp_component_info)); strcpy(comp_info->name, name); - comp_info->type = type; + comp_info->wk_type = wk_type; comp_info->lcore_id = lcore_id; comp_info->component_id = comp_lcore_id; @@ -286,7 +286,7 @@ update_comp(enum sppwk_action wk_action, const char *name, */ #ifdef SPP_VF_MODULE /* initialize classifier information */ - if (comp_info->type == SPP_COMPONENT_CLASSIFIER_MAC) + if (comp_info->wk_type == SPPWK_TYPE_CLS) init_classifier_info(comp_lcore_id); #endif /* SPP_VF_MODULE */ @@ -324,22 +324,22 @@ check_port_count(int component_type, enum spp_port_rxtx rxtx, int num_rx, " port_type=%d, rx=%d, tx=%d\n", rxtx, num_rx, num_tx); switch (component_type) { - case SPP_COMPONENT_FORWARD: + case SPPWK_TYPE_FWD: if (num_rx > 1 || num_tx > 1) return SPP_RET_NG; break; - case SPP_COMPONENT_MERGE: + case SPPWK_TYPE_MRG: if (num_tx > 1) return SPP_RET_NG; break; - case SPP_COMPONENT_CLASSIFIER_MAC: + case SPPWK_TYPE_CLS: if (num_rx > 1) return SPP_RET_NG; break; - case SPP_COMPONENT_MIRROR: + case SPPWK_TYPE_MIR: if (num_rx > 1 || num_tx > 2) return SPP_RET_NG; break; @@ -393,7 +393,7 @@ update_port(enum sppwk_action wk_action, switch (wk_action) { case SPPWK_ACT_ADD: /* Check if over the maximum num of ports of component. */ - if (check_port_count(comp_info->type, rxtx, + if (check_port_count(comp_info->wk_type, rxtx, comp_info->num_rx_port, comp_info->num_tx_port) != SPP_RET_OK) return SPP_RET_NG; @@ -524,7 +524,7 @@ spp_iterate_core_info(struct spp_iterate_core_params *params) RTE_LOG(ERR, WK_CMD_RUNNER, "Cannot iterate core " "information. " "(core = %d, type = %d)\n", - lcore_id, SPP_COMPONENT_UNUSE); + lcore_id, SPPWK_TYPE_NONE); return SPP_RET_NG; } continue; @@ -535,7 +535,7 @@ spp_iterate_core_info(struct spp_iterate_core_params *params) NULL, NULL, NULL, NULL); comp_info = (comp_info_base + core->id[cnt]); #ifdef SPP_VF_MODULE - if (comp_info->type == SPP_COMPONENT_CLASSIFIER_MAC) { + if (comp_info->wk_type == SPPWK_TYPE_CLS) { ret = spp_classifier_get_component_status( lcore_id, core->id[cnt], @@ -557,7 +557,7 @@ spp_iterate_core_info(struct spp_iterate_core_params *params) RTE_LOG(ERR, WK_CMD_RUNNER, "Cannot iterate core " "information. " "(core = %d, type = %d)\n", - lcore_id, comp_info->type); + lcore_id, comp_info->wk_type); return SPP_RET_NG; } } @@ -753,7 +753,7 @@ exec_cmd(const struct spp_command *cmd) cmd->spec.comp.wk_action, cmd->spec.comp.name, cmd->spec.comp.core, - cmd->spec.comp.type); + cmd->spec.comp.wk_type); if (ret == 0) { RTE_LOG(INFO, WK_CMD_RUNNER, "Exec flush.\n"); ret = spp_flush(); diff --git a/src/shared/secondary/spp_worker_th/spp_proc.c b/src/shared/secondary/spp_worker_th/spp_proc.c index 386144f..b51486f 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.c +++ b/src/shared/secondary/spp_worker_th/spp_proc.c @@ -315,12 +315,12 @@ dump_component_info(const struct spp_component_info *comp_info) int cnt = 0; for (cnt = 0; cnt < RTE_MAX_LCORE; cnt++) { tmp_ci = &comp_info[cnt]; - if (tmp_ci->type == SPP_COMPONENT_UNUSE) + if (tmp_ci->wk_type == SPPWK_TYPE_NONE) continue; RTE_LOG(DEBUG, APP, "component[%d] name=%s, type=%d, " "core=%u, index=%d\n", - cnt, tmp_ci->name, tmp_ci->type, + cnt, tmp_ci->name, tmp_ci->wk_type, tmp_ci->lcore_id, tmp_ci->component_id); sprintf(str, "component[%d] rx=%d", cnt, @@ -616,12 +616,12 @@ del_vhost_sockfile(struct sppwk_port_info *vhost) } /* Get component type of target component_info */ -enum spp_component_type +enum sppwk_worker_type spp_get_component_type(int id) { struct spp_component_info *component_info = (g_mng_data.p_component_info + id); - return component_info->type; + return component_info->wk_type; } /* Get core ID of target component */ @@ -671,7 +671,7 @@ spp_check_used_port( for (cnt = 0; cnt < RTE_MAX_LCORE; cnt++) { component = (component_info + cnt); - if (component->type == SPP_COMPONENT_UNUSE) + if (component->wk_type == SPPWK_TYPE_NONE) continue; if (rxtx == SPP_PORT_RXTX_RX) { @@ -718,7 +718,7 @@ get_free_lcore_id(void) int cnt = 0; for (cnt = 0; cnt < RTE_MAX_LCORE; cnt++) { - if ((comp_info + cnt)->type == SPP_COMPONENT_UNUSE) + if ((comp_info + cnt)->wk_type == SPPWK_TYPE_NONE) return cnt; } return SPP_RET_NG; @@ -749,7 +749,7 @@ sppwk_get_lcore_id(const char *comp_name) int del_comp_info(int lcore_id, int nof_comps, int *comp_ary) { - int idx; /* The index of comp_ary to be deleted. */ + int idx = 0; /* The index of comp_ary to be deleted. */ int cnt; /* Find the index. */ @@ -896,7 +896,7 @@ flush_component(void) spp_port_ability_update(component_info); #ifdef SPP_VF_MODULE - if (component_info->type == SPP_COMPONENT_CLASSIFIER_MAC) + if (component_info->wk_type == SPPWK_TYPE_CLS) ret = spp_classifier_mac_update(component_info); else ret = spp_forward_update(component_info); @@ -908,7 +908,7 @@ flush_component(void) RTE_LOG(ERR, APP, "Flush error. " "( component = %s, type = %d)\n", component_info->name, - component_info->type); + component_info->wk_type); return SPP_RET_NG; } } diff --git a/src/shared/secondary/spp_worker_th/spp_proc.h b/src/shared/secondary/spp_worker_th/spp_proc.h index 61f3597..491274a 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.h +++ b/src/shared/secondary/spp_worker_th/spp_proc.h @@ -87,13 +87,13 @@ enum spp_core_status { SPP_CORE_IDLE_REQUEST /**< Request idling */ }; -/* Process type for each component */ -enum spp_component_type { - SPP_COMPONENT_UNUSE, /**< Not used */ - SPP_COMPONENT_CLASSIFIER_MAC, /**< Classifier_mac */ - SPP_COMPONENT_MERGE, /**< Merger */ - SPP_COMPONENT_FORWARD, /**< Forwarder */ - SPP_COMPONENT_MIRROR, /**< Mirror */ +/* Type of SPP worker thread. */ +enum sppwk_worker_type { + SPPWK_TYPE_NONE, /**< Not used */ + SPPWK_TYPE_CLS, /**< Classifier_mac */ + SPPWK_TYPE_MRG, /**< Merger */ + SPPWK_TYPE_FWD, /**< Forwarder */ + SPPWK_TYPE_MIR, /**< Mirror */ }; /* Classifier Type */ @@ -207,7 +207,7 @@ struct sppwk_port_info { /* Component info */ struct spp_component_info { char name[SPP_NAME_STR_LEN]; /**< Component name */ - enum spp_component_type type; /**< Component type */ + enum sppwk_worker_type wk_type; /**< Component type */ unsigned int lcore_id; /**< Logical core ID for component */ int component_id; /**< Component ID */ int num_rx_port; /**< The number of rx ports */ @@ -388,7 +388,7 @@ enum spp_core_status spp_get_core_status(unsigned int lcore_id); * @return * Type of component executed */ -enum spp_component_type spp_get_component_type(int id); +enum sppwk_worker_type spp_get_component_type(int id); /** * Run check_core_status() for SPP_CORE_STATUS_CHECK_MAX times with diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index 9fd8da1..0eb8234 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -824,7 +824,7 @@ spp_classifier_get_component_status( RTE_LOG(ERR, SPP_CLASSIFIER_MAC, "Component[%d] Not used. " "(status)(core = %d, type = %d)\n", - id, lcore_id, SPP_COMPONENT_CLASSIFIER_MAC); + id, lcore_id, SPPWK_TYPE_CLS); return SPP_RET_NG; } diff --git a/src/vf/spp_forward.c b/src/vf/spp_forward.c index 67fcd19..cededb2 100644 --- a/src/vf/spp_forward.c +++ b/src/vf/spp_forward.c @@ -20,8 +20,7 @@ struct forward_rxtx { /* Information on the path used for forward. */ struct forward_path { char name[SPP_NAME_STR_LEN]; /* component name */ - volatile enum spp_component_type type; - /* component type */ + volatile enum sppwk_worker_type wk_type; int num_rx; /* number of receive ports */ int num_tx; /* number of trans ports */ struct forward_rxtx ports[RTE_MAX_ETHPORTS]; @@ -62,11 +61,11 @@ spp_forward_update(struct spp_component_info *component) struct forward_path *path = &info->path[info->upd_index]; /* Forward component allows only one receiving port. */ - if ((component->type == SPP_COMPONENT_FORWARD) && + if ((component->wk_type == SPPWK_TYPE_FWD) && unlikely(num_rx > 1)) { RTE_LOG(ERR, FORWARD, "Component[%d] Setting error. (type = %d, rx = %d)\n", - component->component_id, component->type, num_rx); + component->component_id, component->wk_type, num_rx); return SPP_RET_NG; } @@ -74,7 +73,7 @@ spp_forward_update(struct spp_component_info *component) if (unlikely(num_tx != 0) && unlikely(num_tx != 1)) { RTE_LOG(ERR, FORWARD, "Component[%d] Setting error. (type = %d, tx = %d)\n", - component->component_id, component->type, num_tx); + component->component_id, component->wk_type, num_tx); return SPP_RET_NG; } @@ -85,10 +84,10 @@ spp_forward_update(struct spp_component_info *component) "(name = %s, type = %d)\n", component->component_id, component->name, - component->type); + component->wk_type); memcpy(&path->name, component->name, SPP_NAME_STR_LEN); - path->type = component->type; + path->wk_type = component->wk_type; path->num_rx = component->num_rx_port; path->num_tx = component->num_tx_port; for (cnt = 0; cnt < num_rx; cnt++) @@ -109,7 +108,7 @@ spp_forward_update(struct spp_component_info *component) "(name = %s, type = %d)\n", component->component_id, component->name, - component->type); + component->wk_type); return SPP_RET_OK; } @@ -149,7 +148,7 @@ spp_forward(int id) path = &info->path[info->ref_index]; /* Practice condition check */ - if (path->type == SPP_COMPONENT_MERGE) { + if (path->wk_type == SPPWK_TYPE_MRG) { /* merger */ if (!(path->num_tx == 1 && path->num_rx >= 1)) return SPP_RET_OK; @@ -197,15 +196,15 @@ spp_forward_get_component_status( struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS]; struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS]; - if (unlikely(path->type == SPP_COMPONENT_UNUSE)) { + if (unlikely(path->wk_type == SPPWK_TYPE_NONE)) { RTE_LOG(ERR, FORWARD, "Component[%d] Not used. " "(status)(core = %d, type = %d)\n", - id, lcore_id, path->type); + id, lcore_id, path->wk_type); return SPP_RET_NG; } - if (path->type == SPP_COMPONENT_MERGE) + if (path->wk_type == SPPWK_TYPE_MRG) component_type = SPP_TYPE_MERGE_STR; else component_type = SPP_TYPE_FORWARD_STR; diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c index 4134647..5075c95 100644 --- a/src/vf/spp_vf.c +++ b/src/vf/spp_vf.c @@ -213,7 +213,7 @@ slave_main(void *arg __attribute__ ((unused))) for (cnt = 0; cnt < core->num; cnt++) { /* Component classification to call a function. */ if (spp_get_component_type(core->id[cnt]) == - SPP_COMPONENT_CLASSIFIER_MAC) { + SPPWK_TYPE_CLS) { /* Component type for classifier. */ ret = spp_classifier_mac_do(core->id[cnt]); if (unlikely(ret != 0)) -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> This update is to rename functions of flushing temporarily stored command. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- .../secondary/spp_worker_th/cmd_runner.c | 23 +++++------ src/shared/secondary/spp_worker_th/spp_proc.c | 40 ++++++++++--------- src/shared/secondary/spp_worker_th/spp_proc.h | 22 +++++----- 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c index 5df7b92..f8ce5ac 100644 --- a/src/shared/secondary/spp_worker_th/cmd_runner.c +++ b/src/shared/secondary/spp_worker_th/cmd_runner.c @@ -475,26 +475,25 @@ update_port(enum sppwk_action wk_action, return ret; } -/* Flush command to execute it */ +/* Activate temporarily stored command. */ static int -spp_flush(void) +flush_cmd(void) { - int ret = SPP_RET_NG; + int ret; struct cancel_backup_info *backup_info = NULL; sppwk_get_mng_data(NULL, NULL, NULL, NULL, NULL, NULL, &backup_info); - /* Initial setting of each interface. */ - ret = flush_port(); + ret = update_port_info(); if (ret < SPP_RET_OK) return ret; - /* Flush of core index. */ - flush_core(); + /* TODO(yasufum) confirm why no returned value. */ + update_lcore_info(); - /* Flush of component */ - ret = flush_component(); + /* TODO(yasufum) confirm why no checking for returned value. */ + ret = update_comp_info(); backup_mng_info(backup_info); return ret; @@ -744,7 +743,7 @@ exec_cmd(const struct spp_command *cmd) &cmd->spec.cls_table.port); if (ret == 0) { RTE_LOG(INFO, WK_CMD_RUNNER, "Exec flush.\n"); - ret = spp_flush(); + ret = flush_cmd(); } break; @@ -756,7 +755,7 @@ exec_cmd(const struct spp_command *cmd) cmd->spec.comp.wk_type); if (ret == 0) { RTE_LOG(INFO, WK_CMD_RUNNER, "Exec flush.\n"); - ret = spp_flush(); + ret = flush_cmd(); } break; @@ -768,7 +767,7 @@ exec_cmd(const struct spp_command *cmd) cmd->spec.port.name, &cmd->spec.port.ability); if (ret == 0) { RTE_LOG(INFO, WK_CMD_RUNNER, "Exec flush.\n"); - ret = spp_flush(); + ret = flush_cmd(); } break; diff --git a/src/shared/secondary/spp_worker_th/spp_proc.c b/src/shared/secondary/spp_worker_th/spp_proc.c index b51486f..3cdc108 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.c +++ b/src/shared/secondary/spp_worker_th/spp_proc.c @@ -19,6 +19,7 @@ #include "shared/secondary/add_port.h" #include "shared/secondary/utils.h" +/* TODO(yasufum) change log label after filename is revised. */ #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1 /* A set of pointers of management data */ @@ -812,9 +813,9 @@ delete_port_info(struct sppwk_port_info *p_info, int nof_ports, return SPP_RET_OK; } -/* Flush initial setting of each interface. */ +/* Activate temporarily stored port info while flushing. */ int -flush_port(void) +update_port_info(void) { int ret = 0; int cnt = 0; @@ -846,9 +847,9 @@ flush_port(void) return SPP_RET_OK; } -/* Flush changed core. */ +/* Activate temporarily stored lcore info while flushing. */ void -flush_core(void) +update_lcore_info(void) { int cnt = 0; struct core_mng_info *info = NULL; @@ -877,38 +878,39 @@ flush_core(void) } } -/* Flush change for forwarder or classifier_mac */ +/* Activate temporarily stored component info while flushing. */ int -flush_component(void) +update_comp_info(void) { int ret = 0; int cnt = 0; - struct spp_component_info *component_info = NULL; - int *p_change_component = g_mng_data.p_change_component; - struct spp_component_info *p_component_info = - g_mng_data.p_component_info; + struct spp_component_info *comp_info = NULL; + int *p_change_comp = g_mng_data.p_change_component; + struct spp_component_info *p_comp_info = g_mng_data.p_component_info; for (cnt = 0; cnt < RTE_MAX_LCORE; cnt++) { - if (*(p_change_component + cnt) == 0) + if (*(p_change_comp + cnt) == 0) continue; - component_info = (p_component_info + cnt); - spp_port_ability_update(component_info); + comp_info = (p_comp_info + cnt); + spp_port_ability_update(comp_info); #ifdef SPP_VF_MODULE - if (component_info->wk_type == SPPWK_TYPE_CLS) - ret = spp_classifier_mac_update(component_info); + if (comp_info->wk_type == SPPWK_TYPE_CLS) + ret = spp_classifier_mac_update(comp_info); else - ret = spp_forward_update(component_info); + ret = spp_forward_update(comp_info); #endif /* SPP_VF_MODULE */ + #ifdef SPP_MIRROR_MODULE - ret = spp_mirror_update(component_info); + ret = spp_mirror_update(comp_info); #endif /* SPP_MIRROR_MODULE */ + if (unlikely(ret < 0)) { RTE_LOG(ERR, APP, "Flush error. " "( component = %s, type = %d)\n", - component_info->name, - component_info->wk_type); + comp_info->name, + comp_info->wk_type); return SPP_RET_NG; } } diff --git a/src/shared/secondary/spp_worker_th/spp_proc.h b/src/shared/secondary/spp_worker_th/spp_proc.h index 491274a..c066f0c 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.h +++ b/src/shared/secondary/spp_worker_th/spp_proc.h @@ -595,25 +595,23 @@ int delete_port_info(struct sppwk_port_info *p_info, int nof_ports, struct sppwk_port_info *p_info_ary[]); /** - * Flush initial setting of each interface. + * Activate temporarily stored port info while flushing. * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG failed. + * @retval SPP_RET_OK if succeeded. + * @retval SPP_RET_NG if failed. */ -int flush_port(void); +int update_port_info(void); -/** - * Flush changed core. - */ -void flush_core(void); +/* Activate temporarily stored lcore info while flushing. */ +void update_lcore_info(void); /** - * Flush change for forwarder or classifier_mac. + * Activate temporarily stored component info while flushing. * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG failed. + * @retval SPP_RET_OK if succeeded. + * @retval SPP_RET_NG if failed. */ -int flush_component(void); +int update_comp_info(void); /** * Port type to string -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> spp_proc.c and its header file define a set of utility functions for parsing or running commands of SPP worker threads. The term `spp proc` is not appropriate for the meaning, rename to simply `cmd_utils`. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/mirror/Makefile | 2 +- src/mirror/spp_mirror.c | 2 +- src/pcap/Makefile | 2 +- src/pcap/{spp_proc.c => cmd_utils.c} | 2 +- src/pcap/{spp_proc.h => cmd_utils.h} | 6 +++--- src/pcap/command_dec.h | 2 +- src/pcap/command_proc.h | 2 +- src/pcap/spp_pcap.c | 2 +- src/pcap/spp_pcap.h | 2 +- src/shared/secondary/spp_worker_th/cmd_parser.h | 2 +- src/shared/secondary/spp_worker_th/cmd_runner.h | 6 +++--- .../spp_worker_th/{spp_proc.c => cmd_utils.c} | 2 +- .../spp_worker_th/{spp_proc.h => cmd_utils.h} | 11 +++++------ src/shared/secondary/spp_worker_th/command_conn.h | 2 +- src/shared/secondary/spp_worker_th/mirror_deps.h | 2 +- src/shared/secondary/spp_worker_th/ringlatencystats.c | 2 +- src/shared/secondary/spp_worker_th/spp_port.h | 8 ++++---- src/shared/secondary/spp_worker_th/vf_deps.h | 8 ++++---- src/vf/Makefile | 2 +- src/vf/spp_vf.c | 2 +- 20 files changed, 34 insertions(+), 35 deletions(-) rename src/pcap/{spp_proc.c => cmd_utils.c} (99%) rename src/pcap/{spp_proc.h => cmd_utils.h} (99%) rename src/shared/secondary/spp_worker_th/{spp_proc.c => cmd_utils.c} (99%) rename src/shared/secondary/spp_worker_th/{spp_proc.h => cmd_utils.h} (99%) diff --git a/src/mirror/Makefile b/src/mirror/Makefile index 07bf7ca..d1ae9ce 100644 --- a/src/mirror/Makefile +++ b/src/mirror/Makefile @@ -17,7 +17,7 @@ SPP_WKT_DIR = ../shared/secondary/spp_worker_th SRCS-y := spp_mirror.c SRCS-y += ../shared/common.c SRCS-y += ../shared/secondary/utils.c ../shared/secondary/add_port.c -SRCS-y += $(SPP_WKT_DIR)/spp_proc.c +SRCS-y += $(SPP_WKT_DIR)/cmd_utils.c SRCS-y += $(SPP_WKT_DIR)/spp_port.c SRCS-y += $(SPP_WKT_DIR)/command_conn.c SRCS-y += $(SPP_WKT_DIR)/cmd_parser.c diff --git a/src/mirror/spp_mirror.c b/src/mirror/spp_mirror.c index 26c250b..574e31f 100644 --- a/src/mirror/spp_mirror.c +++ b/src/mirror/spp_mirror.c @@ -14,7 +14,7 @@ #include "shared/secondary/utils.h" #include "shared/secondary/spp_worker_th/cmd_runner.h" #include "shared/secondary/spp_worker_th/cmd_parser.h" -#include "shared/secondary/spp_worker_th/spp_proc.h" +#include "shared/secondary/spp_worker_th/cmd_utils.h" #include "shared/secondary/spp_worker_th/spp_port.h" /* Declare global variables */ diff --git a/src/pcap/Makefile b/src/pcap/Makefile index a58b79a..e5e0b00 100644 --- a/src/pcap/Makefile +++ b/src/pcap/Makefile @@ -15,7 +15,7 @@ SPP_WKT_DIR = ../shared/secondary/spp_worker_th # all source are stored in SRCS-y SRCS-y := spp_pcap.c -SRCS-y += spp_proc.c +SRCS-y += cmd_utils.c SRCS-y += command_proc.c command_dec.c SRCS-y += ../shared/common.c SRCS-y += $(SPP_WKT_DIR)/command_conn.c diff --git a/src/pcap/spp_proc.c b/src/pcap/cmd_utils.c similarity index 99% rename from src/pcap/spp_proc.c rename to src/pcap/cmd_utils.c index 4e3b2c9..be12058 100644 --- a/src/pcap/spp_proc.c +++ b/src/pcap/cmd_utils.c @@ -8,7 +8,7 @@ #include <rte_eth_ring.h> #include <rte_log.h> -#include "spp_proc.h" +#include "cmd_utils.h" #define RTE_LOGTYPE_SPP_PROC RTE_LOGTYPE_USER2 diff --git a/src/pcap/spp_proc.h b/src/pcap/cmd_utils.h similarity index 99% rename from src/pcap/spp_proc.h rename to src/pcap/cmd_utils.h index 2265b21..61b6da5 100644 --- a/src/pcap/spp_proc.h +++ b/src/pcap/cmd_utils.h @@ -2,8 +2,8 @@ * Copyright(c) 2018 Nippon Telegraph and Telephone Corporation */ -#ifndef _SPP_PROC_H_ -#define _SPP_PROC_H_ +#ifndef _SPPWK_CMD_UTILS_H_ +#define _SPPWK_CMD_UTILS_H_ /** * @file @@ -386,4 +386,4 @@ void spp_get_mng_data_addr(struct startup_param **startup_param_addr, int **capture_request_addr, int **capture_status_addr); -#endif /* _SPP_PROC_H_ */ +#endif /* _SPPWK_CMD_UTILS_H_ */ diff --git a/src/pcap/command_dec.h b/src/pcap/command_dec.h index 0835382..84f7ae6 100644 --- a/src/pcap/command_dec.h +++ b/src/pcap/command_dec.h @@ -12,7 +12,7 @@ * Decode and validate the command message string. */ -#include "spp_proc.h" +#include "cmd_utils.h" /** max number of command per request */ #define SPP_CMD_MAX_COMMANDS 32 diff --git a/src/pcap/command_proc.h b/src/pcap/command_proc.h index 8094649..cbaf6a2 100644 --- a/src/pcap/command_proc.h +++ b/src/pcap/command_proc.h @@ -13,7 +13,7 @@ * result JSON formatted data. */ -#include "spp_proc.h" +#include "cmd_utils.h" /** * initialize command processor. diff --git a/src/pcap/spp_pcap.c b/src/pcap/spp_pcap.c index f8f3f79..b048237 100644 --- a/src/pcap/spp_pcap.c +++ b/src/pcap/spp_pcap.c @@ -13,7 +13,7 @@ #include <lz4frame.h> #include "shared/common.h" -#include "spp_proc.h" +#include "cmd_utils.h" #include "spp_pcap.h" #include "command_proc.h" #include "command_dec.h" diff --git a/src/pcap/spp_pcap.h b/src/pcap/spp_pcap.h index d282226..6a4ded7 100644 --- a/src/pcap/spp_pcap.h +++ b/src/pcap/spp_pcap.h @@ -5,7 +5,7 @@ #ifndef __SPP_PCAP_H__ #define __SPP_PCAP_H__ -#include "spp_proc.h" +#include "cmd_utils.h" /** * @file diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index c8839f1..de4dcba 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -10,7 +10,7 @@ * @brief Define a set of vars and functions for parsing SPP worker commands. */ -#include "spp_proc.h" +#include "cmd_utils.h" /* Maximum number of commands per request. */ #define SPPWK_MAX_CMDS 32 diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.h b/src/shared/secondary/spp_worker_th/cmd_runner.h index 4b768b7..5c79247 100644 --- a/src/shared/secondary/spp_worker_th/cmd_runner.h +++ b/src/shared/secondary/spp_worker_th/cmd_runner.h @@ -6,14 +6,14 @@ #define _SPPWK_CMD_RUNNER_H_ /** - * @file - * Run command for SPP worker thread. + * @file cmd_runner.h * + * Run command for SPP worker thread. * Receive command message from SPP controller and run. The result is returned * to SPP controller as a JSON formatted message. */ -#include "spp_proc.h" +#include "cmd_utils.h" /** * Setup connection for accepting commands from spp-ctl. diff --git a/src/shared/secondary/spp_worker_th/spp_proc.c b/src/shared/secondary/spp_worker_th/cmd_utils.c similarity index 99% rename from src/shared/secondary/spp_worker_th/spp_proc.c rename to src/shared/secondary/spp_worker_th/cmd_utils.c index 3cdc108..46aa118 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.c +++ b/src/shared/secondary/spp_worker_th/cmd_utils.c @@ -13,7 +13,7 @@ #include "vf_deps.h" #include "mirror_deps.h" -#include "spp_proc.h" +#include "cmd_utils.h" #include "spp_port.h" #include "shared/secondary/add_port.h" diff --git a/src/shared/secondary/spp_worker_th/spp_proc.h b/src/shared/secondary/spp_worker_th/cmd_utils.h similarity index 99% rename from src/shared/secondary/spp_worker_th/spp_proc.h rename to src/shared/secondary/spp_worker_th/cmd_utils.h index c066f0c..7f15ea6 100644 --- a/src/shared/secondary/spp_worker_th/spp_proc.h +++ b/src/shared/secondary/spp_worker_th/cmd_utils.h @@ -2,14 +2,13 @@ * Copyright(c) 2018-2019 Nippon Telegraph and Telephone Corporation */ -#ifndef _SPP_PROC_H_ -#define _SPP_PROC_H_ +#ifndef _SPPWK_CMD_UTILS_H_ +#define _SPPWK_CMD_UTILS_H_ /** - * @file - * SPP process + * @file cmd_utils.h * - * SPP component common function. + * Command utility functions for SPP worker thread. */ #include <netinet/in.h> @@ -698,4 +697,4 @@ void sppwk_get_mng_data(struct startup_param **startup_param_p, int **change_component_p, struct cancel_backup_info **backup_info_p); -#endif /* _SPP_PROC_H_ */ +#endif /* _SPPWK_CMD_UTILS_H_ */ diff --git a/src/shared/secondary/spp_worker_th/command_conn.h b/src/shared/secondary/spp_worker_th/command_conn.h index 517c0e9..9112847 100644 --- a/src/shared/secondary/spp_worker_th/command_conn.h +++ b/src/shared/secondary/spp_worker_th/command_conn.h @@ -12,7 +12,7 @@ * Command connection management. */ -#include "spp_proc.h" +#include "cmd_utils.h" /** result code - temporary error. please retry */ #define SPP_CONNERR_TEMPORARY -1 diff --git a/src/shared/secondary/spp_worker_th/mirror_deps.h b/src/shared/secondary/spp_worker_th/mirror_deps.h index 31d64b7..02e64d9 100644 --- a/src/shared/secondary/spp_worker_th/mirror_deps.h +++ b/src/shared/secondary/spp_worker_th/mirror_deps.h @@ -5,7 +5,7 @@ #ifndef __SPP_WORKER_TH_MIRROR_DEPS_H__ #define __SPP_WORKER_TH_MIRROR_DEPS_H__ -#include "spp_proc.h" +#include "cmd_utils.h" /** * Update Mirror info diff --git a/src/shared/secondary/spp_worker_th/ringlatencystats.c b/src/shared/secondary/spp_worker_th/ringlatencystats.c index 6ea5a7e..e0cc1aa 100644 --- a/src/shared/secondary/spp_worker_th/ringlatencystats.c +++ b/src/shared/secondary/spp_worker_th/ringlatencystats.c @@ -15,7 +15,7 @@ #include <rte_memcpy.h> #include "ringlatencystats.h" -#include "spp_proc.h" +#include "cmd_utils.h" #define NS_PER_SEC 1E9 diff --git a/src/shared/secondary/spp_worker_th/spp_port.h b/src/shared/secondary/spp_worker_th/spp_port.h index 10409ab..1f8161a 100644 --- a/src/shared/secondary/spp_worker_th/spp_port.h +++ b/src/shared/secondary/spp_worker_th/spp_port.h @@ -2,8 +2,8 @@ * Copyright(c) 2017-2018 Nippon Telegraph and Telephone Corporation */ -#ifndef __SPP_PORT_H__ -#define __SPP_PORT_H__ +#ifndef _SPP_PORT_H_ +#define _SPP_PORT_H_ /** * @file @@ -12,7 +12,7 @@ * Provide about the ability per port. */ -#include "spp_proc.h" +#include "cmd_utils.h" /** Calculate TCI of VLAN tag. */ #define SPP_VLANTAG_CALC_TCI(id, pcp) (((pcp & 0x07) << 13) | (id & 0x0fff)) @@ -110,4 +110,4 @@ uint16_t spp_eth_rx_burst(uint16_t port_id, uint16_t queue_id, uint16_t spp_eth_tx_burst(uint16_t port_id, uint16_t queue_id, struct rte_mbuf **tx_pkts, uint16_t nb_pkts); -#endif /* __SPP_PORT_H__ */ +#endif /* _SPP_PORT_H_ */ diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index 136c49e..4b9cecf 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -2,12 +2,12 @@ * Copyright(c) 2019 Nippon Telegraph and Telephone Corporation */ -#ifndef __SPP_WORKER_TH_VF_DEPS_H__ -#define __SPP_WORKER_TH_VF_DEPS_H__ +#ifndef _SPPWK_TH_VF_DEPS_H_ +#define _SPPWK_TH_VF_DEPS_H_ #include <rte_malloc.h> #include <rte_hash.h> -#include "spp_proc.h" +#include "cmd_utils.h" /* number of classifier information (reference/update) */ #define NUM_CLASSIFIER_MAC_INFO 2 @@ -149,4 +149,4 @@ int spp_forward_get_component_status( unsigned int lcore_id, int id, struct spp_iterate_core_params *params); -#endif /* __SPP_WORKER_TH_VF_DEPS_H__ */ +#endif /* _SPPWK_TH_VF_DEPS_H_ */ diff --git a/src/vf/Makefile b/src/vf/Makefile index 399871f..bdeff98 100644 --- a/src/vf/Makefile +++ b/src/vf/Makefile @@ -21,7 +21,7 @@ SRCS-y += $(SPP_WKT_DIR)/spp_port.c SRCS-y += $(SPP_WKT_DIR)/command_conn.c SRCS-y += $(SPP_WKT_DIR)/cmd_parser.c SRCS-y += $(SPP_WKT_DIR)/cmd_runner.c -SRCS-y += $(SPP_WKT_DIR)/spp_proc.c +SRCS-y += $(SPP_WKT_DIR)/cmd_utils.c SRCS-y += ../shared/common.c SRCS-y += ../shared/secondary/utils.c ../shared/secondary/add_port.c diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c index 5075c95..fd8944f 100644 --- a/src/vf/spp_vf.c +++ b/src/vf/spp_vf.c @@ -6,7 +6,7 @@ #include <arpa/inet.h> #include <getopt.h> -#include "shared/secondary/spp_worker_th/spp_proc.h" +#include "shared/secondary/spp_worker_th/cmd_utils.h" #include "spp_vf.h" #include "classifier_mac.h" #include "spp_forward.h" -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> This update is to rename function for executing several commands at once `process_request()` to `exec_cmds()`, and each of commands `exec_cmd() to `exec_one_cmd()` to be clear the relationship. Some comments and log messages are also revised. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- src/mirror/spp_mirror.c | 2 +- .../secondary/spp_worker_th/cmd_runner.c | 81 +++++++++---------- .../secondary/spp_worker_th/cmd_runner.h | 4 +- src/vf/spp_vf.c | 2 +- 4 files changed, 41 insertions(+), 48 deletions(-) diff --git a/src/mirror/spp_mirror.c b/src/mirror/spp_mirror.c index 574e31f..501b214 100644 --- a/src/mirror/spp_mirror.c +++ b/src/mirror/spp_mirror.c @@ -672,7 +672,7 @@ main(int argc, char *argv[]) { #endif /* Receive command */ - ret_do = sppwk_cmd_run(); + ret_do = sppwk_run_cmd(); if (unlikely(ret_do != SPP_RET_OK)) break; /* diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c index f8ce5ac..3c80db9 100644 --- a/src/shared/secondary/spp_worker_th/cmd_runner.c +++ b/src/shared/secondary/spp_worker_th/cmd_runner.c @@ -58,7 +58,7 @@ struct cmd_response { /** * List of worker process type. The order of items should be same as the order - * of enum `secondary_type` in spp_proc.h. + * of enum `secondary_type` in cmd_utils.h. */ /* TODO(yasufum) rename `secondary_type` to `sppwk_proc_type`. */ const char *SPPWK_PROC_TYPE_LIST[] = { @@ -81,7 +81,7 @@ const char *PORT_ABILITY_STAT_LIST[] = { /** * List of classifier type. The order of items should be same as the order of - * enum `spp_classifier_type` defined in spp_proc.h. + * enum `spp_classifier_type` defined in cmd_utils.h. */ /* TODO(yasufum) fix similar var in cmd_parser.c */ const char *CLS_TYPE_A_LIST[] = { @@ -726,7 +726,7 @@ append_json_block_brackets(const char *name, char **output, const char *str) /* Execute one command. */ static int -exec_cmd(const struct spp_command *cmd) +exec_one_cmd(const struct spp_command *cmd) { int ret; @@ -1620,72 +1620,65 @@ send_command_result_response(int *sock, spp_strbuf_free(msg); } -/* process command request from no-null-terminated string */ +/* Execute series of commands. */ static int -process_request(int *sock, const char *request_str, size_t request_str_len) +exec_cmds(int *sock, const char *req_str, size_t req_str_len) { int ret = SPP_RET_NG; int i; - struct sppwk_cmd_req request; + struct sppwk_cmd_req cmd_req; struct sppwk_parse_err_msg wk_err_msg; - struct cmd_result command_results[SPPWK_MAX_CMDS]; + struct cmd_result cmd_results[SPPWK_MAX_CMDS]; - memset(&request, 0, sizeof(struct sppwk_cmd_req)); + memset(&cmd_req, 0, sizeof(struct sppwk_cmd_req)); memset(&wk_err_msg, 0, sizeof(struct sppwk_parse_err_msg)); - memset(command_results, 0, sizeof(command_results)); - - RTE_LOG(DEBUG, WK_CMD_RUNNER, "Start command request processing. " - "request_str=\n%.*s\n", - (int)request_str_len, request_str); + memset(cmd_results, 0, sizeof(cmd_results)); /* Parse request message. */ - ret = sppwk_parse_req( - &request, request_str, request_str_len, &wk_err_msg); + RTE_LOG(DEBUG, WK_CMD_RUNNER, "Parse cmds, %.*s\n", + (int)req_str_len, req_str); + ret = sppwk_parse_req(&cmd_req, req_str, req_str_len, &wk_err_msg); + if (unlikely(ret != SPP_RET_OK)) { /* Setup and send error response. */ - prepare_parse_err_msg(command_results, &request, - &wk_err_msg); - send_decode_error_response(sock, &request, command_results); - RTE_LOG(DEBUG, WK_CMD_RUNNER, - "End command request processing.\n"); + prepare_parse_err_msg(cmd_results, &cmd_req, &wk_err_msg); + send_decode_error_response(sock, &cmd_req, cmd_results); + RTE_LOG(DEBUG, WK_CMD_RUNNER, "Failed to parse cmds.\n"); return SPP_RET_OK; } - RTE_LOG(DEBUG, WK_CMD_RUNNER, "Command request is valid. " - "num_command=%d, num_valid_command=%d\n", - request.num_command, request.num_valid_command); + RTE_LOG(DEBUG, WK_CMD_RUNNER, + "Num of cmds is %d, and valid cmds is %d\n", + cmd_req.num_command, cmd_req.num_valid_command); /* execute commands */ - for (i = 0; i < request.num_command ; ++i) { - ret = exec_cmd(request.commands + i); + for (i = 0; i < cmd_req.num_command ; ++i) { + ret = exec_one_cmd(cmd_req.commands + i); if (unlikely(ret != SPP_RET_OK)) { - set_cmd_result(&command_results[i], CMD_FAILED, + set_cmd_result(&cmd_results[i], CMD_FAILED, "error occur"); - - /* not execute remaining commands */ - for (++i; i < request.num_command ; ++i) - set_cmd_result(&command_results[i], + /* Does not execute remaining commands */ + for (++i; i < cmd_req.num_command ; ++i) + set_cmd_result(&cmd_results[i], CMD_INVALID, ""); - break; } - set_cmd_result(&command_results[i], CMD_SUCCESS, ""); + set_cmd_result(&cmd_results[i], CMD_SUCCESS, ""); } - if (request.is_requested_exit) { - /* Terminated by process exit command. */ - /* Other route is normal end because it responds to command. */ - set_cmd_result(&command_results[0], CMD_SUCCESS, ""); - send_command_result_response(sock, &request, command_results); + /* Exec exit command. */ + if (cmd_req.is_requested_exit) { + set_cmd_result(&cmd_results[0], CMD_SUCCESS, ""); + send_command_result_response(sock, &cmd_req, cmd_results); RTE_LOG(INFO, WK_CMD_RUNNER, - "Terminate process for exit.\n"); + "Process is terminated with exit cmd.\n"); return SPP_RET_NG; } /* send response */ - send_command_result_response(sock, &request, command_results); + send_command_result_response(sock, &cmd_req, cmd_results); RTE_LOG(DEBUG, WK_CMD_RUNNER, "End command request processing.\n"); @@ -1699,12 +1692,12 @@ sppwk_cmd_runner_conn(const char *ctl_ipaddr, int ctl_port) return spp_command_conn_init(ctl_ipaddr, ctl_port); } -/* Run command from spp-ctl. */ +/* Run command sent from spp-ctl. */ int -sppwk_cmd_run(void) +sppwk_run_cmd(void) { - int ret = SPP_RET_NG; - int msg_ret = -1; + int ret; + int msg_ret; static int sock = -1; static char *msgbuf; @@ -1734,7 +1727,7 @@ sppwk_cmd_run(void) return SPP_RET_NG; } - ret = process_request(&sock, msgbuf, msg_ret); + ret = exec_cmds(&sock, msgbuf, msg_ret); spp_strbuf_remove_front(msgbuf, msg_ret); return ret; diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.h b/src/shared/secondary/spp_worker_th/cmd_runner.h index 5c79247..5d85733 100644 --- a/src/shared/secondary/spp_worker_th/cmd_runner.h +++ b/src/shared/secondary/spp_worker_th/cmd_runner.h @@ -30,13 +30,13 @@ int sppwk_cmd_runner_conn(const char *ctl_ipaddr, int ctl_port); /** - * Run command from spp-ctl. + * Run command sent from spp-ctl. * * @retval SPP_RET_OK if succeeded. * TODO(yasufum) change exclude case of exit cmd because it is not NG. * @retval SPP_RET_NG if connection failure or received exit command. */ int -sppwk_cmd_run(void); +sppwk_run_cmd(void); #endif /* _SPPWK_CMD_RUNNER_H_ */ diff --git a/src/vf/spp_vf.c b/src/vf/spp_vf.c index fd8944f..deb5c7e 100644 --- a/src/vf/spp_vf.c +++ b/src/vf/spp_vf.c @@ -342,7 +342,7 @@ main(int argc, char *argv[]) { #endif /* Receive command */ - ret_do = sppwk_cmd_run(); + ret_do = sppwk_run_cmd(); if (unlikely(ret_do != SPP_RET_OK)) break; -- 2.17.1
From: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> The name of struct `spp_command` is too wide in meaning. It is just a set of attributes of command for SPP worker thread actually. This update is to rename it to `sppwk_cmd_attrs`. Signed-off-by: Yasufumi Ogawa <ogawa.yasufumi@lab.ntt.co.jp> --- .../secondary/spp_worker_th/cmd_parser.c | 47 ++++++++++--------- .../secondary/spp_worker_th/cmd_parser.h | 8 ++-- .../secondary/spp_worker_th/cmd_runner.c | 20 ++++---- 3 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.c b/src/shared/secondary/spp_worker_th/cmd_parser.c index 0f0e64c..621bea4 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.c +++ b/src/shared/secondary/spp_worker_th/cmd_parser.c @@ -796,25 +796,25 @@ cmd_ops_list[][SPPWK_MAX_PARAMS] = { { /* classifier_table(mac) */ { .name = "action", - .offset = offsetof(struct spp_command, + .offset = offsetof(struct sppwk_cmd_attrs, spec.cls_table.wk_action), .func = parse_cls_action }, { .name = "type", - .offset = offsetof(struct spp_command, + .offset = offsetof(struct sppwk_cmd_attrs, spec.cls_table.type), .func = parse_cls_type }, { .name = "mac address", - .offset = offsetof(struct spp_command, + .offset = offsetof(struct sppwk_cmd_attrs, spec.cls_table.mac), .func = parse_mac_addr }, { .name = "port", - .offset = offsetof(struct spp_command, + .offset = offsetof(struct sppwk_cmd_attrs, spec.cls_table), .func = parse_cls_port }, @@ -823,31 +823,31 @@ cmd_ops_list[][SPPWK_MAX_PARAMS] = { { /* classifier_table(VLAN) */ { .name = "action", - .offset = offsetof(struct spp_command, + .offset = offsetof(struct sppwk_cmd_attrs, spec.cls_table.wk_action), .func = parse_cls_action }, { .name = "type", - .offset = offsetof(struct spp_command, + .offset = offsetof(struct sppwk_cmd_attrs, spec.cls_table.type), .func = parse_cls_type }, { .name = "vlan id", - .offset = offsetof(struct spp_command, + .offset = offsetof(struct sppwk_cmd_attrs, spec.cls_table.vid), .func = parse_cls_vid }, { .name = "mac address", - .offset = offsetof(struct spp_command, + .offset = offsetof(struct sppwk_cmd_attrs, spec.cls_table.mac), .func = parse_mac_addr }, { .name = "port", - .offset = offsetof(struct spp_command, + .offset = offsetof(struct sppwk_cmd_attrs, spec.cls_table), .func = parse_cls_port }, @@ -859,23 +859,23 @@ cmd_ops_list[][SPPWK_MAX_PARAMS] = { { /* component */ { .name = "action", - .offset = offsetof(struct spp_command, + .offset = offsetof(struct sppwk_cmd_attrs, spec.comp.wk_action), .func = parse_comp_action }, { .name = "component name", - .offset = offsetof(struct spp_command, spec.comp), + .offset = offsetof(struct sppwk_cmd_attrs, spec.comp), .func = parse_comp_name }, { .name = "core", - .offset = offsetof(struct spp_command, spec.comp), + .offset = offsetof(struct sppwk_cmd_attrs, spec.comp), .func = parse_comp_lcore_id }, { .name = "component type", - .offset = offsetof(struct spp_command, spec.comp), + .offset = offsetof(struct sppwk_cmd_attrs, spec.comp), .func = parse_comp_type }, SPPWK_CMD_NO_PARAMS, @@ -883,38 +883,39 @@ cmd_ops_list[][SPPWK_MAX_PARAMS] = { { /* port */ { .name = "action", - .offset = offsetof(struct spp_command, + .offset = offsetof(struct sppwk_cmd_attrs, spec.port.wk_action), .func = parse_port_action }, { .name = "port", - .offset = offsetof(struct spp_command, spec.port), + .offset = offsetof(struct sppwk_cmd_attrs, spec.port), .func = parse_port }, { .name = "port rxtx", - .offset = offsetof(struct spp_command, spec.port), + .offset = offsetof(struct sppwk_cmd_attrs, spec.port), .func = parse_port_rxtx }, { .name = "component name", - .offset = offsetof(struct spp_command, spec.port.name), + .offset = offsetof(struct sppwk_cmd_attrs, + spec.port.name), .func = parse_comp_name_portcmd }, { .name = "port vlan operation", - .offset = offsetof(struct spp_command, spec.port), + .offset = offsetof(struct sppwk_cmd_attrs, spec.port), .func = parse_port_vlan_ops }, { .name = "port vid", - .offset = offsetof(struct spp_command, spec.port), + .offset = offsetof(struct sppwk_cmd_attrs, spec.port), .func = parse_port_vid }, { .name = "port pcp", - .offset = offsetof(struct spp_command, spec.port), + .offset = offsetof(struct sppwk_cmd_attrs, spec.port), .func = parse_port_pcp }, SPPWK_CMD_NO_PARAMS, @@ -1130,7 +1131,7 @@ sppwk_parse_req( int i; /* decode request */ - request->num_command = 1; + request->nof_cmds = 1; ret = parse_wk_cmd(request, request_str, wk_err_msg); if (unlikely(ret != SPP_RET_OK)) { RTE_LOG(ERR, WK_CMD_PARSER, @@ -1139,10 +1140,10 @@ sppwk_parse_req( ret, (int)request_str_len, request_str); return ret; } - request->num_valid_command = 1; + request->nof_valid_cmds = 1; /* check getter command */ - for (i = 0; i < request->num_valid_command; ++i) { + for (i = 0; i < request->nof_valid_cmds; ++i) { switch (request->commands[i].type) { case SPPWK_CMDTYPE_CLIENT_ID: request->is_requested_client_id = 1; diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.h b/src/shared/secondary/spp_worker_th/cmd_parser.h index de4dcba..5a7df84 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.h +++ b/src/shared/secondary/spp_worker_th/cmd_parser.h @@ -108,7 +108,7 @@ struct sppwk_cmd_port { }; /* TODO(yasufum) Add usage and desc for members. What's command descriptors? */ -struct spp_command { +struct sppwk_cmd_attrs { enum sppwk_cmd_type type; /**< command type */ union { /**< command descriptors */ @@ -121,9 +121,9 @@ struct spp_command { /* Request parameters. */ struct sppwk_cmd_req { - int num_command; /**< Number of accepted commands */ - int num_valid_command; /**< Number of executed commands */ - struct spp_command commands[SPPWK_MAX_CMDS]; /**< list of cmds */ + int nof_cmds; /**< Number of accepted commands */ + int nof_valid_cmds; /**< Number of executed commands */ + struct sppwk_cmd_attrs commands[SPPWK_MAX_CMDS]; /**< list of cmds */ int is_requested_client_id; int is_requested_status; diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c index 3c80db9..c3e1c9c 100644 --- a/src/shared/secondary/spp_worker_th/cmd_runner.c +++ b/src/shared/secondary/spp_worker_th/cmd_runner.c @@ -726,7 +726,7 @@ append_json_block_brackets(const char *name, char **output, const char *str) /* Execute one command. */ static int -exec_one_cmd(const struct spp_command *cmd) +exec_one_cmd(const struct sppwk_cmd_attrs *cmd) { int ret; @@ -856,7 +856,7 @@ prepare_parse_err_msg(struct cmd_result *results, const char *tmp_buff; char error_messege[CMD_ERR_MSG_LEN]; - for (i = 0; i < request->num_command; i++) { + for (i = 0; i < request->nof_cmds; i++) { if (wk_err_msg->code == 0) set_cmd_result(&results[i], CMD_SUCCESS, ""); else @@ -865,7 +865,7 @@ prepare_parse_err_msg(struct cmd_result *results, if (wk_err_msg->code != 0) { tmp_buff = get_parse_err_msg(wk_err_msg, error_messege); - set_cmd_result(&results[request->num_valid_command], + set_cmd_result(&results[request->nof_valid_cmds], CMD_FAILED, tmp_buff); } } @@ -1482,7 +1482,7 @@ append_info_value(const char *name, char **output) static void send_decode_error_response(int *sock, const struct sppwk_cmd_req *request, - struct cmd_result *command_results) + struct cmd_result *cmd_results) { int ret = SPP_RET_NG; char *msg, *tmp_buff; @@ -1496,7 +1496,7 @@ send_decode_error_response(int *sock, /* create & append result array */ ret = append_command_results_value("results", &tmp_buff, - request->num_command, command_results); + request->nof_cmds, cmd_results); if (unlikely(ret < SPP_RET_OK)) { spp_strbuf_free(tmp_buff); RTE_LOG(ERR, WK_CMD_RUNNER, @@ -1541,7 +1541,7 @@ send_decode_error_response(int *sock, static void send_command_result_response(int *sock, const struct sppwk_cmd_req *request, - struct cmd_result *command_results) + struct cmd_result *cmd_results) { int ret = SPP_RET_NG; char *msg, *tmp_buff; @@ -1555,7 +1555,7 @@ send_command_result_response(int *sock, /* create & append result array */ ret = append_command_results_value("results", &tmp_buff, - request->num_command, command_results); + request->nof_cmds, cmd_results); if (unlikely(ret < SPP_RET_OK)) { spp_strbuf_free(tmp_buff); RTE_LOG(ERR, WK_CMD_RUNNER, @@ -1650,16 +1650,16 @@ exec_cmds(int *sock, const char *req_str, size_t req_str_len) RTE_LOG(DEBUG, WK_CMD_RUNNER, "Num of cmds is %d, and valid cmds is %d\n", - cmd_req.num_command, cmd_req.num_valid_command); + cmd_req.nof_cmds, cmd_req.nof_valid_cmds); /* execute commands */ - for (i = 0; i < cmd_req.num_command ; ++i) { + for (i = 0; i < cmd_req.nof_cmds; ++i) { ret = exec_one_cmd(cmd_req.commands + i); if (unlikely(ret != SPP_RET_OK)) { set_cmd_result(&cmd_results[i], CMD_FAILED, "error occur"); /* Does not execute remaining commands */ - for (++i; i < cmd_req.num_command ; ++i) + for (++i; i < cmd_req.nof_cmds; ++i) set_cmd_result(&cmd_results[i], CMD_INVALID, ""); break; -- 2.17.1