From: Yasufumi Ogawa <yasufum.o@gmail.com> Functions for classifier table are hard to maintain because for long names of functions and variables, complex dependencies of shared libs and dedicated functions, or so. This update is to fix these issues. Some of dependencies are still remained, but reduced by separating many dedicated functions from shared libs or adding comments for explaining. Yasufumi Ogawa (11): shared/sec: refactor defines of VLAN in spp_vf shared/sec: rename struct mac_classification shared/sec: refactor comments in vf_deps.h shared/sec: rename struct classified_data shared/sec: revise usage of term component_info shared/sec: revise members of struct cls_port_info shared/sec: rename func free_mac_classification shared/sec: refactor updating classifier info shared/sec: refactor updating forwarder shared/sec: refactor getting classifier status shared/sec: refactor setup cls table stat in JSON .../secondary/spp_worker_th/cmd_parser.c | 2 +- .../secondary/spp_worker_th/cmd_runner.c | 37 +- .../secondary/spp_worker_th/cmd_utils.c | 4 +- .../secondary/spp_worker_th/cmd_utils.h | 5 +- src/shared/secondary/spp_worker_th/vf_deps.h | 158 +++----- src/vf/classifier_mac.c | 382 +++++++++--------- src/vf/classifier_mac.h | 2 +- src/vf/spp_forward.c | 105 +++-- 8 files changed, 330 insertions(+), 365 deletions(-) -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> * Rename `SPP_NUM_VLAN_VID` to `NOF_VLAN` and move it to `vf_deps.h`. * Rename `NUM_CLASSIFIER_MAC_INFO` to `NOF_CLS_INFO` and move it to `classifier_mac.c`. * Rename `NUM_CLASSIFIER_MAC_TABLE_ENTRY` to `NOF_CLS_TABLE_ENTRIES`. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- src/shared/secondary/spp_worker_th/cmd_utils.h | 3 --- src/shared/secondary/spp_worker_th/vf_deps.h | 6 +++--- src/vf/classifier_mac.c | 17 ++++++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.h b/src/shared/secondary/spp_worker_th/cmd_utils.h index ee44cee..1d6c332 100644 --- a/src/shared/secondary/spp_worker_th/cmd_utils.h +++ b/src/shared/secondary/spp_worker_th/cmd_utils.h @@ -40,9 +40,6 @@ #define SPP_PORT_ABILITY_MAX 4 /* Max num of port abilities. */ -/** Number of VLAN ID */ -#define SPP_NUM_VLAN_VID 4096 - /** Maximum VLAN PCP */ #define SPP_VLAN_PCP_MAX 7 diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index fe03490..fd0dc5d 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -9,8 +9,8 @@ #include <rte_hash.h> #include "cmd_utils.h" -/* number of classifier information (reference/update) */ -#define NUM_CLASSIFIER_MAC_INFO 2 +/** Number of VLAN ID */ +#define NOF_VLAN 4096 /* mac address classification */ struct mac_classification { @@ -54,7 +54,7 @@ struct component_info { int mac_addr_entry; /* mac address entry flag */ /* mac address classification per vlan-id */ - struct mac_classification *mac_classifications[SPP_NUM_VLAN_VID]; + struct mac_classification *mac_classifications[NOF_VLAN]; int n_classified_data_tx; /* number of transmission ports */ struct classified_data classified_data_rx; /* RX handled by cls */ diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index b3a6cba..76dd9e7 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -35,8 +35,11 @@ #define DEFAULT_HASH_FUNC rte_jhash #endif +/* number of classifier information (reference/update) */ +#define NOF_CLS_INFO 2 + /* number of classifier mac table entry */ -#define NUM_CLASSIFIER_MAC_TABLE_ENTRY 128 +#define NOF_CLS_TABLE_ENTRIES 128 /* interval that wait until change update index (micro second) */ #define CHANGE_UPDATE_INDEX_WAIT_INTERVAL SPP_CHANGE_UPDATE_INTERVAL @@ -53,7 +56,7 @@ /* classifier management information */ struct management_info { /* classifier information */ - struct component_info cmp_infos[NUM_CLASSIFIER_MAC_INFO]; + struct component_info cmp_infos[NOF_CLS_INFO]; /* Reference index number for classifier information */ volatile int ref_index; @@ -75,7 +78,7 @@ uninit_classifier(struct management_info *mng_info) mng_info->is_used = 0; - for (i = 0; i < NUM_CLASSIFIER_MAC_INFO; ++i) + for (i = 0; i < NOF_CLS_INFO; ++i) uninit_component_info(mng_info->cmp_infos + (long)i); memset(mng_info, 0, sizeof(struct management_info)); @@ -298,7 +301,7 @@ create_mac_classification(void) /* set hash creating parameters */ struct rte_hash_parameters hash_params = { .name = hash_tab_name, - .entries = NUM_CLASSIFIER_MAC_TABLE_ENTRY, + .entries = NOF_CLS_TABLE_ENTRIES, .key_len = sizeof(struct ether_addr), .hash_func = DEFAULT_HASH_FUNC, .hash_func_init_val = 0, @@ -440,7 +443,7 @@ uninit_component_info(struct component_info *cmp_info) { int i; - for (i = 0; i < SPP_NUM_VLAN_VID; ++i) + for (i = 0; i < NOF_VLAN; ++i) free_mac_classification(cmp_info->mac_classifications[i]); memset(cmp_info, 0, sizeof(struct component_info)); @@ -686,7 +689,7 @@ change_classifier_index(struct management_info *mng_info, int id) "Core[%u] Change update index.\n", id); mng_info->ref_index = (mng_info->upd_index + 1) % - NUM_CLASSIFIER_MAC_INFO; + NOF_CLS_INFO; } } @@ -943,7 +946,7 @@ spp_classifier_mac_iterate_table( RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC, "Core[%u] Start iterate classifier table.\n", i); - for (n = 0; n < SPP_NUM_VLAN_VID; ++n) { + for (n = 0; n < NOF_VLAN; ++n) { if (cmp_info->mac_classifications[n] == NULL) continue; -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> Struct `mac_classification` defines a set of attirbutes for classification. This update is to rename the struct to `mac_classifier` and also its members. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- src/shared/secondary/spp_worker_th/vf_deps.h | 27 ++++----- src/vf/classifier_mac.c | 61 ++++++++++---------- 2 files changed, 39 insertions(+), 49 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index fd0dc5d..c6016b8 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -12,19 +12,12 @@ /** Number of VLAN ID */ #define NOF_VLAN 4096 -/* mac address classification */ -struct mac_classification { - /* hash table keeps classification */ - struct rte_hash *classification_tab; - - /* number of valid classification */ - int num_active_classified; - - /* index of valid classification */ - int active_classifieds[RTE_MAX_ETHPORTS]; - - /* index of default classification */ - int default_classified; +/* Classifier for MAC addresses. */ +struct mac_classifier { + struct rte_hash *cls_tbl; /* Hash table for MAC classification. */ + int nof_cls_ports; /* Num of ports classified validly. */ + int cls_ports[RTE_MAX_ETHPORTS]; /* Ports for classification. */ + int default_cls_idx; /* Default index for classification. */ }; /* classified data (destination port, target packets, etc) */ @@ -54,7 +47,7 @@ struct component_info { int mac_addr_entry; /* mac address entry flag */ /* mac address classification per vlan-id */ - struct mac_classification *mac_classifications[NOF_VLAN]; + struct mac_classifier *mac_classifications[NOF_VLAN]; int n_classified_data_tx; /* number of transmission ports */ struct classified_data classified_data_rx; /* RX handled by cls */ @@ -64,13 +57,13 @@ struct component_info { /* free mac classification instance. */ static inline void -free_mac_classification(struct mac_classification *mac_cls) +free_mac_classification(struct mac_classifier *mac_cls) { if (mac_cls == NULL) return; - if (mac_cls->classification_tab != NULL) - rte_hash_free(mac_cls->classification_tab); + if (mac_cls->cls_tbl != NULL) + rte_hash_free(mac_cls->cls_tbl); rte_free(mac_cls); } diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index 76dd9e7..5398d25 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -272,23 +272,23 @@ is_used_mng_info(const struct management_info *mng_info) } /* create mac classification instance. */ -static struct mac_classification * +static struct mac_classifier * create_mac_classification(void) { - struct mac_classification *mac_cls; + struct mac_classifier *mac_cls; char hash_tab_name[HASH_TABLE_NAME_BUF_SZ]; struct rte_hash **mac_cls_tab; - mac_cls = (struct mac_classification *)rte_zmalloc( - NULL, sizeof(struct mac_classification), 0); + mac_cls = (struct mac_classifier *)rte_zmalloc( + NULL, sizeof(struct mac_classifier), 0); if (unlikely(mac_cls == NULL)) return NULL; - mac_cls->num_active_classified = 0; - mac_cls->default_classified = -1; + mac_cls->nof_cls_ports = 0; + mac_cls->default_cls_idx = -1; - mac_cls_tab = &mac_cls->classification_tab; + mac_cls_tab = &mac_cls->cls_tbl; /* make hash table name(require uniqueness between processes) */ sprintf(hash_tab_name, "cmtab_%07x%02hx", @@ -328,7 +328,7 @@ init_component_info(struct component_info *cmp_info, { int ret = SPP_RET_NG; int i; - struct mac_classification *mac_cls; + struct mac_classifier *mac_cls; struct ether_addr eth_addr; char mac_addr_str[ETHER_ADDR_STR_BUF_SZ]; struct classified_data *clsd_data_rx = &cmp_info->classified_data_rx; @@ -385,8 +385,7 @@ init_component_info(struct component_info *cmp_info, mac_cls = cmp_info->mac_classifications[vid]; /* store active tx_port that associate with mac address */ - mac_cls->active_classifieds[ - mac_cls->num_active_classified++] = i; + mac_cls->cls_ports[mac_cls->nof_cls_ports++] = i; /* mac address entry flag set */ cmp_info->mac_addr_entry = 1; @@ -394,7 +393,7 @@ init_component_info(struct component_info *cmp_info, /* store default classified */ if (unlikely(tx_port->cls_attrs.mac_addr == SPP_DEFAULT_CLASSIFIED_DMY_ADDR)) { - mac_cls->default_classified = i; + mac_cls->default_cls_idx = i; RTE_LOG(INFO, SPP_CLASSIFIER_MAC, "default classified. vid=%hu, " "iface_type=%d, iface_no=%d, " @@ -412,7 +411,7 @@ init_component_info(struct component_info *cmp_info, ether_format_addr(mac_addr_str, sizeof(mac_addr_str), ð_addr); - ret = rte_hash_add_key_data(mac_cls->classification_tab, + ret = rte_hash_add_key_data(mac_cls->cls_tbl, (void *)ð_addr, (void *)(long)i); if (unlikely(ret < 0)) { RTE_LOG(ERR, SPP_CLASSIFIER_MAC, @@ -518,7 +517,7 @@ push_packet(struct rte_mbuf *pkt, struct classified_data *clsd_data) static inline int get_general_default_classified_index(struct component_info *cmp_info) { - struct mac_classification *mac_cls; + struct mac_classifier *mac_cls; mac_cls = cmp_info->mac_classifications[VLAN_UNTAGGED_VID]; if (unlikely(mac_cls == NULL)) { @@ -527,7 +526,7 @@ get_general_default_classified_index(struct component_info *cmp_info) return SPP_RET_NG; } - return mac_cls->default_classified; + return mac_cls->default_cls_idx; } /* handle L2 multicast(include broadcast) packet */ @@ -537,7 +536,7 @@ handle_l2multicast_packet(struct rte_mbuf *pkt, struct classified_data *clsd_data) { int i; - struct mac_classification *mac_cls; + struct mac_classifier *mac_cls; uint16_t vid = get_vid(pkt); int gen_def_clsd_idx = get_general_default_classified_index(cmp_info); int n_act_clsd; @@ -545,7 +544,7 @@ handle_l2multicast_packet(struct rte_mbuf *pkt, /* select mac address classification by vid */ mac_cls = cmp_info->mac_classifications[vid]; if (unlikely(mac_cls == NULL || - mac_cls->num_active_classified == 0)) { + mac_cls->nof_cls_ports == 0)) { /* specific vlan is not registered * use untagged's default(as general default) */ @@ -564,18 +563,16 @@ handle_l2multicast_packet(struct rte_mbuf *pkt, } /* add to mbuf's refcnt */ - n_act_clsd = mac_cls->num_active_classified; + n_act_clsd = mac_cls->nof_cls_ports; if (gen_def_clsd_idx >= 0 && vid != VLAN_UNTAGGED_VID) ++n_act_clsd; rte_mbuf_refcnt_update(pkt, (int16_t)(n_act_clsd - 1)); /* transmit to specific segment & general default */ - for (i = 0; i < mac_cls->num_active_classified; i++) { - LOG_CLS((long)mac_cls->active_classifieds[i], - pkt, cmp_info, clsd_data); - push_packet(pkt, clsd_data + - (long)mac_cls->active_classifieds[i]); + for (i = 0; i < mac_cls->nof_cls_ports; i++) { + LOG_CLS((long)mac_cls->cls_ports[i], pkt, cmp_info, clsd_data); + push_packet(pkt, clsd_data + (long)mac_cls->cls_ports[i]); } if (gen_def_clsd_idx >= 0 && vid != VLAN_UNTAGGED_VID) { @@ -592,7 +589,7 @@ select_classified_index(const struct rte_mbuf *pkt, int ret; struct ether_hdr *eth; void *lookup_data; - struct mac_classification *mac_cls; + struct mac_classifier *mac_cls; uint16_t vid; eth = rte_pktmbuf_mtod(pkt, struct ether_hdr *); @@ -607,7 +604,7 @@ select_classified_index(const struct rte_mbuf *pkt, } /* find in table (by destination mac address) */ - ret = rte_hash_lookup_data(mac_cls->classification_tab, + ret = rte_hash_lookup_data(mac_cls->cls_tbl, (const void *)ð->d_addr, &lookup_data); if (ret >= 0) { LOG_DBG(cmp_info->name, "Mac address is registered. " @@ -624,7 +621,7 @@ select_classified_index(const struct rte_mbuf *pkt, return -2; /* if default is not set, use untagged's default */ - if (unlikely(mac_cls->default_classified < 0 && + if (unlikely(mac_cls->default_cls_idx < 0 && vid != VLAN_UNTAGGED_VID)) { LOG_DBG(cmp_info->name, "Vid's default is not set. " "use general default. vid=%hu\n", vid); @@ -633,7 +630,7 @@ select_classified_index(const struct rte_mbuf *pkt, /* use default */ LOG_DBG(cmp_info->name, "Use vid's default. vid=%hu\n", vid); - return mac_cls->default_classified; + return mac_cls->default_cls_idx; } /* @@ -865,7 +862,7 @@ static void mac_classification_iterate_table( struct spp_iterate_classifier_table_params *params, uint16_t vid, - struct mac_classification *mac_cls, + struct mac_classifier *mac_cls, __rte_unused struct component_info *cmp_info, struct classified_data *clsd_data) { @@ -881,13 +878,13 @@ mac_classification_iterate_table( if (unlikely(vid == VLAN_UNTAGGED_VID)) type = SPP_CLASSIFIER_TYPE_MAC; - if (mac_cls->default_classified >= 0) { + if (mac_cls->default_cls_idx >= 0) { port.iface_type = (clsd_data + - mac_cls->default_classified)->iface_type; + mac_cls->default_cls_idx)->iface_type; port.iface_no = (clsd_data + - mac_cls->default_classified)->iface_no_global; + mac_cls->default_cls_idx)->iface_no_global; - LOG_ENT((long)mac_cls->default_classified, + LOG_ENT((long)mac_cls->default_cls_idx, vid, SPP_DEFAULT_CLASSIFIED_SPEC_STR, cmp_info, clsd_data); @@ -902,7 +899,7 @@ mac_classification_iterate_table( next = 0; while (1) { - ret = rte_hash_iterate(mac_cls->classification_tab, + ret = rte_hash_iterate(mac_cls->cls_tbl, &key, &data, &next); if (unlikely(ret < 0)) -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> This update is to revise comments and format in `vf_deps.h` for refactoring. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- src/shared/secondary/spp_worker_th/vf_deps.h | 81 +++++++------------- src/vf/classifier_mac.c | 67 +++++++--------- 2 files changed, 53 insertions(+), 95 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index c6016b8..3e8fc01 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -21,24 +21,15 @@ struct mac_classifier { }; /* classified data (destination port, target packets, etc) */ +/* TODO(yasufum) rename `classified_data`. */ +/* TODO(yasufum) confirm what `iface_no_global` does mean? */ struct classified_data { - /* interface type (see "enum port_type") */ - enum port_type iface_type; - - /* index of ports handled by classifier */ - int iface_no; - - /* id for interface generated by spp_vf */ - int iface_no_global; - - /* port id generated by DPDK */ - uint16_t port; - - /* the number of packets in pkts[] */ - uint16_t num_pkt; - - /* packet array to be classified */ - struct rte_mbuf *pkts[MAX_PKT_BURST]; + enum port_type iface_type; + int iface_no; /* Index of ports handled by classifier. */ + int iface_no_global; /* ID for interface generated by spp_vf */ + uint16_t port; /* Ethdev port ID. */ + uint16_t nof_pkts; /* Number of packets in pkts[]. */ + struct rte_mbuf *pkts[MAX_PKT_BURST]; /* packets to be classified. */ }; /* classifier component information */ @@ -71,24 +62,18 @@ free_mac_classification(struct mac_classifier *mac_cls) /** * classifier(mac address) update component info. * - * @param component_info - * The pointer to struct sppwk_comp_info.@n - * The data for updating the internal data of classifier. - * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG failed. + * @param comp_info Pointer to internal data of classifier. + * @retval SPP_RET_OK If succeeded. + * @retval SPP_RET_NG If failed. */ -int spp_classifier_mac_update(struct sppwk_comp_info *component_info); +int spp_classifier_mac_update(struct sppwk_comp_info *comp_info); /** - * Update forward info - * - * @param component - * The pointer to struct sppwk_comp_info.@n - * The data for updating the internal data of forwarder and merger. + * Update forwarder info. * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG failed. + * @param component Pointer to data of forwarder and merger. + * @retval SPP_RET_OK If succeeded. + * @retval SPP_RET_NG If failed. */ int spp_forward_update(struct sppwk_comp_info *component); @@ -102,17 +87,11 @@ int spp_classifier_mac_iterate_table( /** * classifier get component status. * - * - * @param lcore_id - * The logical core ID for classifier. - * @param id - * The unique component ID. - * @param params - * The pointer to struct spp_iterate_core_params.@n - * Detailed data of classifier status. - * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG failed. + * @param[in] lcore_id Lcore ID for classifier. + * @param[in] id Unique component ID. + * @param[in,out] params Pointer to detailed data of classifier status. + * @retval SPP_RET_OK If succeeded. + * @retval SPP_RET_NG If failed. */ int spp_classifier_get_component_status(unsigned int lcore_id, int id, struct spp_iterate_core_params *params); @@ -120,19 +99,13 @@ int spp_classifier_get_component_status(unsigned int lcore_id, int id, /** * Merge/Forward get component status * - * @param lcore_id - * The logical core ID for forwarder and merger. - * @param id - * The unique component ID. - * @param params - * The pointer to struct spp_iterate_core_params.@n - * Detailed data of forwarder/merger status. - * - * @retval SPP_RET_OK succeeded. - * @retval SPP_RET_NG failed. + * @param lcore_id Lcore ID for forwarder and merger. + * @param id Unique component ID. + * @param params Pointer detailed data of forwarder and merger status. + * @retval SPP_RET_OK If succeeded. + * @retval SPP_RET_NG If failed. */ -int spp_forward_get_component_status( - unsigned int lcore_id, int id, +int spp_forward_get_component_status(unsigned int lcore_id, int id, struct spp_iterate_core_params *params); #endif /* _SPPWK_TH_VF_DEPS_H_ */ diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index 5398d25..cd0c546 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -342,7 +342,7 @@ init_component_info(struct component_info *cmp_info, clsd_data_rx->iface_no = 0; clsd_data_rx->iface_no_global = 0; clsd_data_rx->port = 0; - clsd_data_rx->num_pkt = 0; + clsd_data_rx->nof_pkts = 0; } else { clsd_data_rx->iface_type = component_info->rx_ports[0]->iface_type; @@ -351,7 +351,7 @@ init_component_info(struct component_info *cmp_info, component_info->rx_ports[0]->iface_no; clsd_data_rx->port = component_info->rx_ports[0]->ethdev_port_id; - clsd_data_rx->num_pkt = 0; + clsd_data_rx->nof_pkts = 0; } /* set tx */ @@ -366,7 +366,7 @@ init_component_info(struct component_info *cmp_info, clsd_data_tx[i].iface_no = i; clsd_data_tx[i].iface_no_global = tx_port->iface_no; clsd_data_tx[i].port = tx_port->ethdev_port_id; - clsd_data_tx[i].num_pkt = 0; + clsd_data_tx[i].nof_pkts = 0; if (tx_port->cls_attrs.mac_addr == 0) continue; @@ -457,19 +457,19 @@ transmit_packet(struct classified_data *clsd_data) /* transmit packets */ n_tx = spp_eth_tx_burst(clsd_data->port, 0, - clsd_data->pkts, clsd_data->num_pkt); + clsd_data->pkts, clsd_data->nof_pkts); /* free cannot transmit packets */ - if (unlikely(n_tx != clsd_data->num_pkt)) { - for (i = n_tx; i < clsd_data->num_pkt; i++) + if (unlikely(n_tx != clsd_data->nof_pkts)) { + for (i = n_tx; i < clsd_data->nof_pkts; i++) rte_pktmbuf_free(clsd_data->pkts[i]); RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC, "drop packets(tx). num=%hu, ethdev_port_id=%hu\n", - (uint16_t)(clsd_data->num_pkt - n_tx), + (uint16_t)(clsd_data->nof_pkts - n_tx), clsd_data->port); } - clsd_data->num_pkt = 0; + clsd_data->nof_pkts = 0; } /* transmit packet to one destination. */ @@ -480,13 +480,13 @@ transmit_all_packet(struct component_info *cmp_info) struct classified_data *clsd_data_tx = cmp_info->classified_data_tx; for (i = 0; i < cmp_info->n_classified_data_tx; i++) { - if (unlikely(clsd_data_tx[i].num_pkt != 0)) { + if (unlikely(clsd_data_tx[i].nof_pkts != 0)) { RTE_LOG(INFO, SPP_CLASSIFIER_MAC, "transmit all packets (drain). " "index=%d, " - "num_pkt=%hu\n", + "nof_pkts=%hu\n", i, - clsd_data_tx[i].num_pkt); + clsd_data_tx[i].nof_pkts); transmit_packet(&clsd_data_tx[i]); } } @@ -496,19 +496,19 @@ transmit_all_packet(struct component_info *cmp_info) static inline void push_packet(struct rte_mbuf *pkt, struct classified_data *clsd_data) { - clsd_data->pkts[clsd_data->num_pkt++] = pkt; + clsd_data->pkts[clsd_data->nof_pkts++] = pkt; /* transmit packet, if buffer is filled */ - if (unlikely(clsd_data->num_pkt == MAX_PKT_BURST)) { + if (unlikely(clsd_data->nof_pkts == MAX_PKT_BURST)) { RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC, "transmit packets (buffer is filled). " "iface_type=%d, iface_no={%d,%d}, " - "tx_port=%hu, num_pkt=%hu\n", + "tx_port=%hu, nof_pkts=%hu\n", clsd_data->iface_type, clsd_data->iface_no_global, clsd_data->iface_no, clsd_data->port, - clsd_data->num_pkt); + clsd_data->nof_pkts); transmit_packet(clsd_data); } } @@ -679,14 +679,12 @@ change_classifier_index(struct management_info *mng_info, int id) 0, 0); /* Transmit all packets for switching the using data. */ - transmit_all_packet(mng_info->cmp_infos + - mng_info->ref_index); + transmit_all_packet(mng_info->cmp_infos + mng_info->ref_index); RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC, "Core[%u] Change update index.\n", id); mng_info->ref_index = - (mng_info->upd_index + 1) % - NOF_CLS_INFO; + (mng_info->upd_index + 1) % NOF_CLS_INFO; } } @@ -695,7 +693,6 @@ int spp_classifier_mac_init(void) { memset(g_mng_infos, 0, sizeof(g_mng_infos)); - return 0; } @@ -778,13 +775,13 @@ spp_classifier_mac_do(int id) cur_tsc = rte_rdtsc(); if (unlikely(cur_tsc - prev_tsc > drain_tsc)) { for (i = 0; i < cmp_info->n_classified_data_tx; i++) { - if (likely(clsd_data_tx[i].num_pkt == 0)) + if (likely(clsd_data_tx[i].nof_pkts == 0)) continue; RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC, "transmit packets (drain). index=%d, " - "num_pkt=%hu, interval=%lu\n", - i, clsd_data_tx[i].num_pkt, + "nof_pkts=%hu, interval=%lu\n", + i, clsd_data_tx[i].nof_pkts, cur_tsc - prev_tsc); transmit_packet(&clsd_data_tx[i]); } @@ -889,18 +886,13 @@ mac_classification_iterate_table( SPP_DEFAULT_CLASSIFIED_SPEC_STR, cmp_info, clsd_data); - (*params->element_proc)( - params, - type, - vid, - SPP_DEFAULT_CLASSIFIED_SPEC_STR, - &port); + (*params->element_proc)(params, type, vid, + SPP_DEFAULT_CLASSIFIED_SPEC_STR, &port); } next = 0; while (1) { - ret = rte_hash_iterate(mac_cls->cls_tbl, - &key, &data, &next); + ret = rte_hash_iterate(mac_cls->cls_tbl, &key, &data, &next); if (unlikely(ret < 0)) break; @@ -913,11 +905,7 @@ mac_classification_iterate_table( LOG_ENT((long)data, vid, mac_addr_str, cmp_info, clsd_data); - (*params->element_proc)( - params, - type, - vid, - mac_addr_str, + (*params->element_proc)(params, type, vid, mac_addr_str, &port); } } @@ -947,12 +935,9 @@ spp_classifier_mac_iterate_table( if (cmp_info->mac_classifications[n] == NULL) continue; - mac_classification_iterate_table( - params, - (uint16_t)n, + mac_classification_iterate_table(params, (uint16_t) n, cmp_info->mac_classifications[n], - cmp_info, - clsd_data); + cmp_info, clsd_data); } } -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> This update is to rename struct `classified_data` to `cls_port_info` because it is a set of attributes of a port and not classified data actually. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- src/shared/secondary/spp_worker_th/vf_deps.h | 13 +++-- src/vf/classifier_mac.c | 50 ++++++++++---------- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index 3e8fc01..8085357 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -20,14 +20,13 @@ struct mac_classifier { int default_cls_idx; /* Default index for classification. */ }; -/* classified data (destination port, target packets, etc) */ -/* TODO(yasufum) rename `classified_data`. */ -/* TODO(yasufum) confirm what `iface_no_global` does mean? */ -struct classified_data { +/* Set of attirbutes of port for classification. */ +/* TODO(yasufum) confirm what is `iface_no_global`. */ +struct cls_port_info { enum port_type iface_type; int iface_no; /* Index of ports handled by classifier. */ int iface_no_global; /* ID for interface generated by spp_vf */ - uint16_t port; /* Ethdev port ID. */ + uint16_t ethdev_port_id; /* Ethdev port ID. */ uint16_t nof_pkts; /* Number of packets in pkts[]. */ struct rte_mbuf *pkts[MAX_PKT_BURST]; /* packets to be classified. */ }; @@ -41,9 +40,9 @@ struct component_info { struct mac_classifier *mac_classifications[NOF_VLAN]; int n_classified_data_tx; /* number of transmission ports */ - struct classified_data classified_data_rx; /* RX handled by cls */ + struct cls_port_info classified_data_rx; /* RX handled by cls */ /* transmission ports handled by classifier */ - struct classified_data classified_data_tx[RTE_MAX_ETHPORTS]; + struct cls_port_info classified_data_tx[RTE_MAX_ETHPORTS]; }; /* free mac classification instance. */ diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index cd0c546..b2388af 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -183,7 +183,7 @@ log_classification( long clsd_idx, struct rte_mbuf *pkt, struct component_info *cmp_info, - struct classified_data *clsd_data, + struct cls_port_info *clsd_data, const char *func_name, int line_num) { @@ -203,8 +203,7 @@ log_classification( if (clsd_idx < 0) snprintf(iface_str, sizeof(iface_str), "%ld", clsd_idx); else - spp_format_port_string( - iface_str, + spp_format_port_string(iface_str, clsd_data[clsd_idx].iface_type, clsd_data[clsd_idx].iface_no_global); @@ -231,7 +230,7 @@ log_entry( uint16_t vid, const char *mac_addr_str, struct component_info *cmp_info, - struct classified_data *clsd_data, + struct cls_port_info *clsd_data, const char *func_name, int line_num) { @@ -331,8 +330,8 @@ init_component_info(struct component_info *cmp_info, struct mac_classifier *mac_cls; struct ether_addr eth_addr; char mac_addr_str[ETHER_ADDR_STR_BUF_SZ]; - struct classified_data *clsd_data_rx = &cmp_info->classified_data_rx; - struct classified_data *clsd_data_tx = cmp_info->classified_data_tx; + struct cls_port_info *clsd_data_rx = &cmp_info->classified_data_rx; + struct cls_port_info *clsd_data_tx = cmp_info->classified_data_tx; struct sppwk_port_info *tx_port = NULL; uint16_t vid; @@ -341,7 +340,7 @@ init_component_info(struct component_info *cmp_info, clsd_data_rx->iface_type = UNDEF; clsd_data_rx->iface_no = 0; clsd_data_rx->iface_no_global = 0; - clsd_data_rx->port = 0; + clsd_data_rx->ethdev_port_id = 0; clsd_data_rx->nof_pkts = 0; } else { clsd_data_rx->iface_type = @@ -349,7 +348,7 @@ init_component_info(struct component_info *cmp_info, clsd_data_rx->iface_no = 0; clsd_data_rx->iface_no_global = component_info->rx_ports[0]->iface_no; - clsd_data_rx->port = + clsd_data_rx->ethdev_port_id = component_info->rx_ports[0]->ethdev_port_id; clsd_data_rx->nof_pkts = 0; } @@ -362,10 +361,10 @@ init_component_info(struct component_info *cmp_info, vid = tx_port->cls_attrs.vlantag.vid; /* store ports information */ - clsd_data_tx[i].iface_type = tx_port->iface_type; - clsd_data_tx[i].iface_no = i; + clsd_data_tx[i].iface_type = tx_port->iface_type; + clsd_data_tx[i].iface_no = i; clsd_data_tx[i].iface_no_global = tx_port->iface_no; - clsd_data_tx[i].port = tx_port->ethdev_port_id; + clsd_data_tx[i].ethdev_port_id = tx_port->ethdev_port_id; clsd_data_tx[i].nof_pkts = 0; if (tx_port->cls_attrs.mac_addr == 0) @@ -450,13 +449,13 @@ uninit_component_info(struct component_info *cmp_info) /* transmit packet to one destination. */ static inline void -transmit_packet(struct classified_data *clsd_data) +transmit_packet(struct cls_port_info *clsd_data) { int i; uint16_t n_tx; /* transmit packets */ - n_tx = spp_eth_tx_burst(clsd_data->port, 0, + n_tx = spp_eth_tx_burst(clsd_data->ethdev_port_id, 0, clsd_data->pkts, clsd_data->nof_pkts); /* free cannot transmit packets */ @@ -466,7 +465,7 @@ transmit_packet(struct classified_data *clsd_data) RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC, "drop packets(tx). num=%hu, ethdev_port_id=%hu\n", (uint16_t)(clsd_data->nof_pkts - n_tx), - clsd_data->port); + clsd_data->ethdev_port_id); } clsd_data->nof_pkts = 0; @@ -477,7 +476,7 @@ static inline void transmit_all_packet(struct component_info *cmp_info) { int i; - struct classified_data *clsd_data_tx = cmp_info->classified_data_tx; + struct cls_port_info *clsd_data_tx = cmp_info->classified_data_tx; for (i = 0; i < cmp_info->n_classified_data_tx; i++) { if (unlikely(clsd_data_tx[i].nof_pkts != 0)) { @@ -494,7 +493,7 @@ transmit_all_packet(struct component_info *cmp_info) /* set mbuf pointer to tx buffer and transmit packet, if buffer is filled */ static inline void -push_packet(struct rte_mbuf *pkt, struct classified_data *clsd_data) +push_packet(struct rte_mbuf *pkt, struct cls_port_info *clsd_data) { clsd_data->pkts[clsd_data->nof_pkts++] = pkt; @@ -507,7 +506,7 @@ push_packet(struct rte_mbuf *pkt, struct classified_data *clsd_data) clsd_data->iface_type, clsd_data->iface_no_global, clsd_data->iface_no, - clsd_data->port, + clsd_data->ethdev_port_id, clsd_data->nof_pkts); transmit_packet(clsd_data); } @@ -533,7 +532,7 @@ get_general_default_classified_index(struct component_info *cmp_info) static inline void handle_l2multicast_packet(struct rte_mbuf *pkt, struct component_info *cmp_info, - struct classified_data *clsd_data) + struct cls_port_info *clsd_data) { int i; struct mac_classifier *mac_cls; @@ -640,7 +639,7 @@ select_classified_index(const struct rte_mbuf *pkt, static inline void classify_packet(struct rte_mbuf **rx_pkts, uint16_t n_rx, struct component_info *cmp_info, - struct classified_data *clsd_data) + struct cls_port_info *clsd_data) { int i; long clsd_idx; @@ -747,8 +746,8 @@ spp_classifier_mac_do(int id) struct component_info *cmp_info = NULL; struct rte_mbuf *rx_pkts[MAX_PKT_BURST]; - struct classified_data *clsd_data_rx = NULL; - struct classified_data *clsd_data_tx = NULL; + struct cls_port_info *clsd_data_rx = NULL; + struct cls_port_info *clsd_data_tx = NULL; uint64_t cur_tsc, prev_tsc = 0; const uint64_t drain_tsc = (rte_get_tsc_hz() + US_PER_S - 1) / @@ -792,7 +791,8 @@ spp_classifier_mac_do(int id) return SPP_RET_OK; /* retrieve packets */ - n_rx = spp_eth_rx_burst(clsd_data_rx->port, 0, rx_pkts, MAX_PKT_BURST); + n_rx = spp_eth_rx_burst(clsd_data_rx->ethdev_port_id, 0, rx_pkts, + MAX_PKT_BURST); if (unlikely(n_rx == 0)) return SPP_RET_OK; @@ -812,7 +812,7 @@ spp_classifier_get_component_status( int i, nof_tx, nof_rx = 0; /* Num of RX and TX ports. */ struct management_info *mng_info; struct component_info *cmp_info; - struct classified_data *clsd_data; + struct cls_port_info *clsd_data; struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS]; struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS]; @@ -861,7 +861,7 @@ mac_classification_iterate_table( uint16_t vid, struct mac_classifier *mac_cls, __rte_unused struct component_info *cmp_info, - struct classified_data *clsd_data) + struct cls_port_info *clsd_data) { int ret; const void *key; @@ -918,7 +918,7 @@ spp_classifier_mac_iterate_table( int i, n; struct management_info *mng_info; struct component_info *cmp_info; - struct classified_data *clsd_data; + struct cls_port_info *clsd_data; for (i = 0; i < RTE_MAX_LCORE; i++) { mng_info = g_mng_infos + i; -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> Several types of `component`s and its attributes are defined as structs. Some of instances of attributes of components are roughly named as `component_info`, but it is confusing because it has no info which type of component. This update is to fix the issue by revising the names. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- src/shared/secondary/spp_worker_th/vf_deps.h | 9 +-- src/vf/classifier_mac.c | 79 ++++++++++---------- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index 8085357..8364a13 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -32,13 +32,10 @@ struct cls_port_info { }; /* classifier component information */ -struct component_info { +struct cls_comp_info { char name[STR_LEN_NAME]; /* component name */ int mac_addr_entry; /* mac address entry flag */ - - /* mac address classification per vlan-id */ - struct mac_classifier *mac_classifications[NOF_VLAN]; - + struct mac_classifier *mac_clfs[NOF_VLAN]; /* classifiers per VLAN. */ int n_classified_data_tx; /* number of transmission ports */ struct cls_port_info classified_data_rx; /* RX handled by cls */ /* transmission ports handled by classifier */ @@ -78,7 +75,7 @@ int spp_forward_update(struct sppwk_comp_info *component); void init_classifier_info(int component_id); -void uninit_component_info(struct component_info *cmp_info); +void uninit_component_info(struct cls_comp_info *cmp_info); int spp_classifier_mac_iterate_table( struct spp_iterate_classifier_table_params *params); diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index b2388af..8edad6d 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -56,7 +56,7 @@ /* classifier management information */ struct management_info { /* classifier information */ - struct component_info cmp_infos[NOF_CLS_INFO]; + struct cls_comp_info cmp_infos[NOF_CLS_INFO]; /* Reference index number for classifier information */ volatile int ref_index; @@ -182,7 +182,7 @@ static void log_classification( long clsd_idx, struct rte_mbuf *pkt, - struct component_info *cmp_info, + struct cls_comp_info *cmp_info, struct cls_port_info *clsd_data, const char *func_name, int line_num) @@ -229,7 +229,7 @@ log_entry( long clsd_idx, uint16_t vid, const char *mac_addr_str, - struct component_info *cmp_info, + struct cls_comp_info *cmp_info, struct cls_port_info *clsd_data, const char *func_name, int line_num) @@ -322,8 +322,8 @@ create_mac_classification(void) /* initialize classifier information. */ static int -init_component_info(struct component_info *cmp_info, - const struct sppwk_comp_info *component_info) +init_component_info(struct cls_comp_info *cmp_info, + const struct sppwk_comp_info *wk_comp_info) { int ret = SPP_RET_NG; int i; @@ -336,7 +336,7 @@ init_component_info(struct component_info *cmp_info, uint16_t vid; /* set rx */ - if (component_info->nof_rx == 0) { + if (wk_comp_info->nof_rx == 0) { clsd_data_rx->iface_type = UNDEF; clsd_data_rx->iface_no = 0; clsd_data_rx->iface_no_global = 0; @@ -344,20 +344,20 @@ init_component_info(struct component_info *cmp_info, clsd_data_rx->nof_pkts = 0; } else { clsd_data_rx->iface_type = - component_info->rx_ports[0]->iface_type; + wk_comp_info->rx_ports[0]->iface_type; clsd_data_rx->iface_no = 0; clsd_data_rx->iface_no_global = - component_info->rx_ports[0]->iface_no; + wk_comp_info->rx_ports[0]->iface_no; clsd_data_rx->ethdev_port_id = - component_info->rx_ports[0]->ethdev_port_id; + wk_comp_info->rx_ports[0]->ethdev_port_id; clsd_data_rx->nof_pkts = 0; } /* set tx */ - cmp_info->n_classified_data_tx = component_info->nof_tx; + cmp_info->n_classified_data_tx = wk_comp_info->nof_tx; cmp_info->mac_addr_entry = 0; - for (i = 0; i < component_info->nof_tx; i++) { - tx_port = component_info->tx_ports[i]; + for (i = 0; i < wk_comp_info->nof_tx; i++) { + tx_port = wk_comp_info->tx_ports[i]; vid = tx_port->cls_attrs.vlantag.vid; /* store ports information */ @@ -371,17 +371,16 @@ init_component_info(struct component_info *cmp_info, continue; /* if mac classification is NULL, make instance */ - if (unlikely(cmp_info->mac_classifications[vid] == NULL)) { + if (unlikely(cmp_info->mac_clfs[vid] == NULL)) { RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC, "Mac classification is not registered." " create. vid=%hu\n", vid); - cmp_info->mac_classifications[vid] = + cmp_info->mac_clfs[vid] = create_mac_classification(); - if (unlikely(cmp_info->mac_classifications[vid] == - NULL)) + if (unlikely(cmp_info->mac_clfs[vid] == NULL)) return SPP_RET_NG; } - mac_cls = cmp_info->mac_classifications[vid]; + mac_cls = cmp_info->mac_clfs[vid]; /* store active tx_port that associate with mac address */ mac_cls->cls_ports[mac_cls->nof_cls_ports++] = i; @@ -437,14 +436,14 @@ init_component_info(struct component_info *cmp_info, /* uninitialize classifier information. */ void -uninit_component_info(struct component_info *cmp_info) +uninit_component_info(struct cls_comp_info *cmp_info) { int i; for (i = 0; i < NOF_VLAN; ++i) - free_mac_classification(cmp_info->mac_classifications[i]); + free_mac_classification(cmp_info->mac_clfs[i]); - memset(cmp_info, 0, sizeof(struct component_info)); + memset(cmp_info, 0, sizeof(struct cls_comp_info)); } /* transmit packet to one destination. */ @@ -473,7 +472,7 @@ transmit_packet(struct cls_port_info *clsd_data) /* transmit packet to one destination. */ static inline void -transmit_all_packet(struct component_info *cmp_info) +transmit_all_packet(struct cls_comp_info *cmp_info) { int i; struct cls_port_info *clsd_data_tx = cmp_info->classified_data_tx; @@ -514,11 +513,11 @@ push_packet(struct rte_mbuf *pkt, struct cls_port_info *clsd_data) /* get index of general default classified */ static inline int -get_general_default_classified_index(struct component_info *cmp_info) +get_general_default_classified_index(struct cls_comp_info *cmp_info) { struct mac_classifier *mac_cls; - mac_cls = cmp_info->mac_classifications[VLAN_UNTAGGED_VID]; + mac_cls = cmp_info->mac_clfs[VLAN_UNTAGGED_VID]; if (unlikely(mac_cls == NULL)) { LOG_DBG(cmp_info->name, "Untagged's default is not set. " "vid=%d\n", (int)VLAN_UNTAGGED_VID); @@ -531,7 +530,7 @@ get_general_default_classified_index(struct component_info *cmp_info) /* handle L2 multicast(include broadcast) packet */ static inline void handle_l2multicast_packet(struct rte_mbuf *pkt, - struct component_info *cmp_info, + struct cls_comp_info *cmp_info, struct cls_port_info *clsd_data) { int i; @@ -541,7 +540,7 @@ handle_l2multicast_packet(struct rte_mbuf *pkt, int n_act_clsd; /* select mac address classification by vid */ - mac_cls = cmp_info->mac_classifications[vid]; + mac_cls = cmp_info->mac_clfs[vid]; if (unlikely(mac_cls == NULL || mac_cls->nof_cls_ports == 0)) { /* specific vlan is not registered @@ -583,7 +582,7 @@ handle_l2multicast_packet(struct rte_mbuf *pkt, /* select index of classified */ static inline int select_classified_index(const struct rte_mbuf *pkt, - struct component_info *cmp_info) + struct cls_comp_info *cmp_info) { int ret; struct ether_hdr *eth; @@ -595,7 +594,7 @@ select_classified_index(const struct rte_mbuf *pkt, vid = get_vid(pkt); /* select mac address classification by vid */ - mac_cls = cmp_info->mac_classifications[vid]; + mac_cls = cmp_info->mac_clfs[vid]; if (unlikely(mac_cls == NULL)) { LOG_DBG(cmp_info->name, "Mac classification is not " "registered. vid=%hu\n", vid); @@ -638,7 +637,7 @@ select_classified_index(const struct rte_mbuf *pkt, */ static inline void classify_packet(struct rte_mbuf **rx_pkts, uint16_t n_rx, - struct component_info *cmp_info, + struct cls_comp_info *cmp_info, struct cls_port_info *clsd_data) { int i; @@ -697,12 +696,12 @@ spp_classifier_mac_init(void) /* classifier(mac address) update component info. */ int -spp_classifier_mac_update(struct sppwk_comp_info *component_info) +spp_classifier_mac_update(struct sppwk_comp_info *wk_comp_info) { int ret = SPP_RET_NG; - int id = component_info->comp_id; + int id = wk_comp_info->comp_id; struct management_info *mng_info = g_mng_infos + id; - struct component_info *cmp_info = NULL; + struct cls_comp_info *cmp_info = NULL; RTE_LOG(INFO, SPP_CLASSIFIER_MAC, "Component[%u] Start update component.\n", id); @@ -710,13 +709,13 @@ spp_classifier_mac_update(struct sppwk_comp_info *component_info) cmp_info = mng_info->cmp_infos + mng_info->upd_index; /* initialize update side classifier information */ - ret = init_component_info(cmp_info, component_info); + ret = init_component_info(cmp_info, wk_comp_info); if (unlikely(ret != SPP_RET_OK)) { RTE_LOG(ERR, SPP_CLASSIFIER_MAC, "Cannot update classifier mac. ret=%d\n", ret); return ret; } - memcpy(cmp_info->name, component_info->name, STR_LEN_NAME); + memcpy(cmp_info->name, wk_comp_info->name, STR_LEN_NAME); /* change index of reference side */ mng_info->upd_index = mng_info->ref_index; @@ -743,7 +742,7 @@ spp_classifier_mac_do(int id) int i; int n_rx; struct management_info *mng_info = g_mng_infos + id; - struct component_info *cmp_info = NULL; + struct cls_comp_info *cmp_info = NULL; struct rte_mbuf *rx_pkts[MAX_PKT_BURST]; struct cls_port_info *clsd_data_rx = NULL; @@ -811,7 +810,7 @@ spp_classifier_get_component_status( int ret = SPP_RET_NG; int i, nof_tx, nof_rx = 0; /* Num of RX and TX ports. */ struct management_info *mng_info; - struct component_info *cmp_info; + struct cls_comp_info *cmp_info; struct cls_port_info *clsd_data; struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS]; struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS]; @@ -860,7 +859,7 @@ mac_classification_iterate_table( struct spp_iterate_classifier_table_params *params, uint16_t vid, struct mac_classifier *mac_cls, - __rte_unused struct component_info *cmp_info, + __rte_unused struct cls_comp_info *cmp_info, struct cls_port_info *clsd_data) { int ret; @@ -917,7 +916,7 @@ spp_classifier_mac_iterate_table( { int i, n; struct management_info *mng_info; - struct component_info *cmp_info; + struct cls_comp_info *cmp_info; struct cls_port_info *clsd_data; for (i = 0; i < RTE_MAX_LCORE; i++) { @@ -932,12 +931,12 @@ spp_classifier_mac_iterate_table( "Core[%u] Start iterate classifier table.\n", i); for (n = 0; n < NOF_VLAN; ++n) { - if (cmp_info->mac_classifications[n] == NULL) + if (cmp_info->mac_clfs[n] == NULL) continue; mac_classification_iterate_table(params, (uint16_t) n, - cmp_info->mac_classifications[n], - cmp_info, clsd_data); + cmp_info->mac_clfs[n], cmp_info, + clsd_data); } } -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> To refactor, revise members of struct `cls_port_info` in which struct of information of port is name as "classified data" and it is not describing the feature. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- src/shared/secondary/spp_worker_th/vf_deps.h | 10 +-- src/vf/classifier_mac.c | 65 ++++++++++---------- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index 8364a13..79e2abb 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -20,7 +20,7 @@ struct mac_classifier { int default_cls_idx; /* Default index for classification. */ }; -/* Set of attirbutes of port for classification. */ +/* Attirbutes of port for classification. */ /* TODO(yasufum) confirm what is `iface_no_global`. */ struct cls_port_info { enum port_type iface_type; @@ -36,10 +36,10 @@ struct cls_comp_info { char name[STR_LEN_NAME]; /* component name */ int mac_addr_entry; /* mac address entry flag */ struct mac_classifier *mac_clfs[NOF_VLAN]; /* classifiers per VLAN. */ - int n_classified_data_tx; /* number of transmission ports */ - struct cls_port_info classified_data_rx; /* RX handled by cls */ - /* transmission ports handled by classifier */ - struct cls_port_info classified_data_tx[RTE_MAX_ETHPORTS]; + int nof_tx_ports; /* Number of TX ports info entries. */ + /* Classifier has one RX port and several TX ports. */ + struct cls_port_info rx_port_i; /* RX port info classified. */ + struct cls_port_info tx_ports_i[RTE_MAX_ETHPORTS]; /* TX info. */ }; /* free mac classification instance. */ diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index 8edad6d..4213372 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -330,42 +330,43 @@ init_component_info(struct cls_comp_info *cmp_info, struct mac_classifier *mac_cls; struct ether_addr eth_addr; char mac_addr_str[ETHER_ADDR_STR_BUF_SZ]; - struct cls_port_info *clsd_data_rx = &cmp_info->classified_data_rx; - struct cls_port_info *clsd_data_tx = cmp_info->classified_data_tx; + /* Classifier has one RX port and several TX ports. */ + struct cls_port_info *cls_rx_port_info = &cmp_info->rx_port_i; + struct cls_port_info *cls_tx_ports_info = cmp_info->tx_ports_i; struct sppwk_port_info *tx_port = NULL; uint16_t vid; /* set rx */ if (wk_comp_info->nof_rx == 0) { - clsd_data_rx->iface_type = UNDEF; - clsd_data_rx->iface_no = 0; - clsd_data_rx->iface_no_global = 0; - clsd_data_rx->ethdev_port_id = 0; - clsd_data_rx->nof_pkts = 0; + cls_rx_port_info->iface_type = UNDEF; + cls_rx_port_info->iface_no = 0; + cls_rx_port_info->iface_no_global = 0; + cls_rx_port_info->ethdev_port_id = 0; + cls_rx_port_info->nof_pkts = 0; } else { - clsd_data_rx->iface_type = + cls_rx_port_info->iface_type = wk_comp_info->rx_ports[0]->iface_type; - clsd_data_rx->iface_no = 0; - clsd_data_rx->iface_no_global = + cls_rx_port_info->iface_no = 0; + cls_rx_port_info->iface_no_global = wk_comp_info->rx_ports[0]->iface_no; - clsd_data_rx->ethdev_port_id = + cls_rx_port_info->ethdev_port_id = wk_comp_info->rx_ports[0]->ethdev_port_id; - clsd_data_rx->nof_pkts = 0; + cls_rx_port_info->nof_pkts = 0; } /* set tx */ - cmp_info->n_classified_data_tx = wk_comp_info->nof_tx; + cmp_info->nof_tx_ports = wk_comp_info->nof_tx; cmp_info->mac_addr_entry = 0; for (i = 0; i < wk_comp_info->nof_tx; i++) { tx_port = wk_comp_info->tx_ports[i]; vid = tx_port->cls_attrs.vlantag.vid; /* store ports information */ - clsd_data_tx[i].iface_type = tx_port->iface_type; - clsd_data_tx[i].iface_no = i; - clsd_data_tx[i].iface_no_global = tx_port->iface_no; - clsd_data_tx[i].ethdev_port_id = tx_port->ethdev_port_id; - clsd_data_tx[i].nof_pkts = 0; + cls_tx_ports_info[i].iface_type = tx_port->iface_type; + cls_tx_ports_info[i].iface_no = i; + cls_tx_ports_info[i].iface_no_global = tx_port->iface_no; + cls_tx_ports_info[i].ethdev_port_id = tx_port->ethdev_port_id; + cls_tx_ports_info[i].nof_pkts = 0; if (tx_port->cls_attrs.mac_addr == 0) continue; @@ -475,9 +476,9 @@ static inline void transmit_all_packet(struct cls_comp_info *cmp_info) { int i; - struct cls_port_info *clsd_data_tx = cmp_info->classified_data_tx; + struct cls_port_info *clsd_data_tx = cmp_info->tx_ports_i; - for (i = 0; i < cmp_info->n_classified_data_tx; i++) { + for (i = 0; i < cmp_info->nof_tx_ports; i++) { if (unlikely(clsd_data_tx[i].nof_pkts != 0)) { RTE_LOG(INFO, SPP_CLASSIFIER_MAC, "transmit all packets (drain). " @@ -756,8 +757,8 @@ spp_classifier_mac_do(int id) change_classifier_index(mng_info, id); cmp_info = mng_info->cmp_infos + mng_info->ref_index; - clsd_data_rx = &cmp_info->classified_data_rx; - clsd_data_tx = cmp_info->classified_data_tx; + clsd_data_rx = &cmp_info->rx_port_i; + clsd_data_tx = cmp_info->tx_ports_i; /** * decide classifier information of the current cycle If at least, @@ -765,14 +766,14 @@ spp_classifier_mac_do(int id) * classifying. If not, stop classifying. */ if (!(clsd_data_rx->iface_type != UNDEF && - cmp_info->n_classified_data_tx >= 1 && - cmp_info->mac_addr_entry == 1)) + cmp_info->nof_tx_ports >= 1 && + cmp_info->mac_addr_entry == 1)) return SPP_RET_OK; /* drain tx packets, if buffer is not filled for interval */ cur_tsc = rte_rdtsc(); if (unlikely(cur_tsc - prev_tsc > drain_tsc)) { - for (i = 0; i < cmp_info->n_classified_data_tx; i++) { + for (i = 0; i < cmp_info->nof_tx_ports; i++) { if (likely(clsd_data_tx[i].nof_pkts == 0)) continue; @@ -825,19 +826,17 @@ spp_classifier_get_component_status( } cmp_info = mng_info->cmp_infos + mng_info->ref_index; - clsd_data = cmp_info->classified_data_tx; + clsd_data = cmp_info->tx_ports_i; memset(rx_ports, 0x00, sizeof(rx_ports)); - if (cmp_info->classified_data_rx.iface_type != UNDEF) { + if (cmp_info->rx_port_i.iface_type != UNDEF) { nof_rx = 1; - rx_ports[0].iface_type = cmp_info-> - classified_data_rx.iface_type; - rx_ports[0].iface_no = cmp_info-> - classified_data_rx.iface_no_global; + rx_ports[0].iface_type = cmp_info->rx_port_i.iface_type; + rx_ports[0].iface_no = cmp_info->rx_port_i.iface_no_global; } memset(tx_ports, 0x00, sizeof(tx_ports)); - nof_tx = cmp_info->n_classified_data_tx; + nof_tx = cmp_info->nof_tx_ports; for (i = 0; i < nof_tx; i++) { tx_ports[i].iface_type = clsd_data[i].iface_type; tx_ports[i].iface_no = clsd_data[i].iface_no_global; @@ -925,7 +924,7 @@ spp_classifier_mac_iterate_table( continue; cmp_info = mng_info->cmp_infos + mng_info->ref_index; - clsd_data = cmp_info->classified_data_tx; + clsd_data = cmp_info->tx_ports_i; RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC, "Core[%u] Start iterate classifier table.\n", i); -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> Rename free_mac_classification() to free_mac_classifier() for releasing resources of classifier. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- src/shared/secondary/spp_worker_th/vf_deps.h | 14 ++++++-------- src/vf/classifier_mac.c | 8 +++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index 79e2abb..9b59b3d 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -42,17 +42,15 @@ struct cls_comp_info { struct cls_port_info tx_ports_i[RTE_MAX_ETHPORTS]; /* TX info. */ }; -/* free mac classification instance. */ +/* Release instance of mac classifier. */ static inline void -free_mac_classification(struct mac_classifier *mac_cls) +free_mac_classifier(struct mac_classifier *mac_clf) { - if (mac_cls == NULL) + if (mac_clf == NULL) return; - - if (mac_cls->cls_tbl != NULL) - rte_hash_free(mac_cls->cls_tbl); - - rte_free(mac_cls); + if (mac_clf->cls_tbl != NULL) + rte_hash_free(mac_clf->cls_tbl); + rte_free(mac_clf); } /** diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index 4213372..232ed19 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -437,14 +437,12 @@ init_component_info(struct cls_comp_info *cmp_info, /* uninitialize classifier information. */ void -uninit_component_info(struct cls_comp_info *cmp_info) +uninit_component_info(struct cls_comp_info *comp_info) { int i; - for (i = 0; i < NOF_VLAN; ++i) - free_mac_classification(cmp_info->mac_clfs[i]); - - memset(cmp_info, 0, sizeof(struct cls_comp_info)); + free_mac_classifier(comp_info->mac_clfs[i]); + memset(comp_info, 0, sizeof(struct cls_comp_info)); } /* transmit packet to one destination. */ -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> Rename spp_classifier_mac_update() to update_classifier(), and revise names of vars and log messages in the function for refactoring. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- .../secondary/spp_worker_th/cmd_utils.c | 2 +- src/shared/secondary/spp_worker_th/vf_deps.h | 2 +- src/vf/classifier_mac.c | 23 ++++++++++--------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.c b/src/shared/secondary/spp_worker_th/cmd_utils.c index ae6be1a..d5faa35 100644 --- a/src/shared/secondary/spp_worker_th/cmd_utils.c +++ b/src/shared/secondary/spp_worker_th/cmd_utils.c @@ -891,7 +891,7 @@ update_comp_info(void) #ifdef SPP_VF_MODULE if (comp_info->wk_type == SPPWK_TYPE_CLS) - ret = spp_classifier_mac_update(comp_info); + ret = update_classifier(comp_info); else ret = spp_forward_update(comp_info); #endif /* SPP_VF_MODULE */ diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index 9b59b3d..8d3cd81 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -60,7 +60,7 @@ free_mac_classifier(struct mac_classifier *mac_clf) * @retval SPP_RET_OK If succeeded. * @retval SPP_RET_NG If failed. */ -int spp_classifier_mac_update(struct sppwk_comp_info *comp_info); +int update_classifier(struct sppwk_comp_info *comp_info); /** * Update forwarder info. diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index 232ed19..f6074e4 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -695,26 +695,27 @@ spp_classifier_mac_init(void) /* classifier(mac address) update component info. */ int -spp_classifier_mac_update(struct sppwk_comp_info *wk_comp_info) +update_classifier(struct sppwk_comp_info *wk_comp_info) { - int ret = SPP_RET_NG; - int id = wk_comp_info->comp_id; - struct management_info *mng_info = g_mng_infos + id; - struct cls_comp_info *cmp_info = NULL; + int ret; + int wk_id = wk_comp_info->comp_id; + struct management_info *mng_info = g_mng_infos + wk_id; + struct cls_comp_info *cls_info = NULL; RTE_LOG(INFO, SPP_CLASSIFIER_MAC, - "Component[%u] Start update component.\n", id); + "Start updating classifier, id=%u.\n", wk_id); - cmp_info = mng_info->cmp_infos + mng_info->upd_index; + /* TODO(yasufum) rename `infos`. */ + cls_info = mng_info->cmp_infos + mng_info->upd_index; /* initialize update side classifier information */ - ret = init_component_info(cmp_info, wk_comp_info); + ret = init_component_info(cls_info, wk_comp_info); if (unlikely(ret != SPP_RET_OK)) { RTE_LOG(ERR, SPP_CLASSIFIER_MAC, - "Cannot update classifier mac. ret=%d\n", ret); + "Cannot update classifier, ret=%d.\n", ret); return ret; } - memcpy(cmp_info->name, wk_comp_info->name, STR_LEN_NAME); + memcpy(cls_info->name, wk_comp_info->name, STR_LEN_NAME); /* change index of reference side */ mng_info->upd_index = mng_info->ref_index; @@ -729,7 +730,7 @@ spp_classifier_mac_update(struct sppwk_comp_info *wk_comp_info) uninit_component_info(mng_info->cmp_infos + mng_info->upd_index); RTE_LOG(INFO, SPP_CLASSIFIER_MAC, - "Component[%u] Complete update component.\n", id); + "Done update classifier, id=%u.\n", wk_id); return SPP_RET_OK; } -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> Rename spp_forward_update() to update_forwarder(), and revise vars and log messages for refactoring. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- .../secondary/spp_worker_th/cmd_utils.c | 2 +- src/shared/secondary/spp_worker_th/vf_deps.h | 6 +- src/vf/spp_forward.c | 70 +++++++++---------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.c b/src/shared/secondary/spp_worker_th/cmd_utils.c index d5faa35..709c3da 100644 --- a/src/shared/secondary/spp_worker_th/cmd_utils.c +++ b/src/shared/secondary/spp_worker_th/cmd_utils.c @@ -893,7 +893,7 @@ update_comp_info(void) if (comp_info->wk_type == SPPWK_TYPE_CLS) ret = update_classifier(comp_info); else - ret = spp_forward_update(comp_info); + ret = update_forwarder(comp_info); #endif /* SPP_VF_MODULE */ #ifdef SPP_MIRROR_MODULE diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index 8d3cd81..3ae4fc9 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -54,13 +54,13 @@ free_mac_classifier(struct mac_classifier *mac_clf) } /** - * classifier(mac address) update component info. + * Update classifier info. * * @param comp_info Pointer to internal data of classifier. * @retval SPP_RET_OK If succeeded. * @retval SPP_RET_NG If failed. */ -int update_classifier(struct sppwk_comp_info *comp_info); +int update_classifier(struct sppwk_comp_info *wk_comp_info); /** * Update forwarder info. @@ -69,7 +69,7 @@ int update_classifier(struct sppwk_comp_info *comp_info); * @retval SPP_RET_OK If succeeded. * @retval SPP_RET_NG If failed. */ -int spp_forward_update(struct sppwk_comp_info *component); +int update_forwarder(struct sppwk_comp_info *wk_comp_info); void init_classifier_info(int component_id); diff --git a/src/vf/spp_forward.c b/src/vf/spp_forward.c index 909f084..7746d40 100644 --- a/src/vf/spp_forward.c +++ b/src/vf/spp_forward.c @@ -51,64 +51,64 @@ spp_forward_init(void) /* Update forward info */ int -spp_forward_update(struct sppwk_comp_info *component) +update_forwarder(struct sppwk_comp_info *comp_info) { int cnt = 0; - int nof_rx = component->nof_rx; - int nof_tx = component->nof_tx; + int nof_rx = comp_info->nof_rx; + int nof_tx = comp_info->nof_tx; int max = (nof_rx > nof_tx)?nof_rx*nof_tx:nof_tx; - struct forward_info *info = &g_forward_info[component->comp_id]; - struct forward_path *path = &info->path[info->upd_index]; - - /* Forward component allows only one receiving port. */ - if ((component->wk_type == SPPWK_TYPE_FWD) && + struct forward_info *fwd_info = &g_forward_info[comp_info->comp_id]; + /* TODO(yasufum) rename `path` of struct forward_path. */ + struct forward_path *fwd_path = &fwd_info->path[fwd_info->upd_index]; + + /** + * Check num of RX and TX ports because forwarder has just a set of + * RX and TX. + */ + if ((comp_info->wk_type == SPPWK_TYPE_FWD) && unlikely(nof_rx > 1)) { RTE_LOG(ERR, FORWARD, - "Component[%d] Setting error. (type = %d, rx = %d)\n", - component->comp_id, component->wk_type, nof_rx); + "Invalid forwarder type or num of RX ports " + "(id=%d, type=%d, nof_rx=%d).\n", + comp_info->comp_id, comp_info->wk_type, nof_rx); return SPP_RET_NG; } - - /* Component allows only one transmit port. */ if (unlikely(nof_tx != 0) && unlikely(nof_tx != 1)) { RTE_LOG(ERR, FORWARD, - "Component[%d] Setting error. (type = %d, tx = %d)\n", - component->comp_id, component->wk_type, nof_tx); + "Invalid forwarder type or num of TX ports " + "(id=%d, type=%d, nof_tx=%d).\n", + comp_info->comp_id, comp_info->wk_type, nof_tx); return SPP_RET_NG; } - memset(path, 0x00, sizeof(struct forward_path)); + memset(fwd_path, 0x00, sizeof(struct forward_path)); RTE_LOG(INFO, FORWARD, - "Component[%d] Start update component. " - "(name = %s, type = %d)\n", - component->comp_id, - component->name, - component->wk_type); - - memcpy(&path->name, component->name, STR_LEN_NAME); - path->wk_type = component->wk_type; - path->num_rx = component->nof_rx; - path->num_tx = component->nof_tx; + "Start updating forwarder (id=%d, name=%s, type=%d)\n", + comp_info->comp_id, comp_info->name, + comp_info->wk_type); + + memcpy(&fwd_path->name, comp_info->name, STR_LEN_NAME); + fwd_path->wk_type = comp_info->wk_type; + fwd_path->num_rx = comp_info->nof_rx; + fwd_path->num_tx = comp_info->nof_tx; for (cnt = 0; cnt < nof_rx; cnt++) - memcpy(&path->ports[cnt].rx, component->rx_ports[cnt], + memcpy(&fwd_path->ports[cnt].rx, comp_info->rx_ports[cnt], sizeof(struct sppwk_port_info)); - /* Transmit port is set according with larger nof_rx / nof_tx. */ + /* TX port is set according with larger nof_rx / nof_tx. */ for (cnt = 0; cnt < max; cnt++) - memcpy(&path->ports[cnt].tx, component->tx_ports[0], + memcpy(&fwd_path->ports[cnt].tx, comp_info->tx_ports[0], sizeof(struct sppwk_port_info)); - info->upd_index = info->ref_index; - while (likely(info->ref_index == info->upd_index)) + fwd_info->upd_index = fwd_info->ref_index; + while (likely(fwd_info->ref_index == fwd_info->upd_index)) rte_delay_us_block(SPP_CHANGE_UPDATE_INTERVAL); RTE_LOG(INFO, FORWARD, - "Component[%d] Complete update component. " - "(name = %s, type = %d)\n", - component->comp_id, - component->name, - component->wk_type); + "Done update forwarder. (id=%d, name=%s, type=%d)\n", + comp_info->comp_id, comp_info->name, + comp_info->wk_type); return SPP_RET_OK; } -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> This update is to rename spp_classifier_get_component_status() to get_classifier_status() to simplify, and revise vars and log messages for refactoring. Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- .../secondary/spp_worker_th/cmd_runner.c | 12 +++---- src/shared/secondary/spp_worker_th/vf_deps.h | 8 ++--- src/vf/classifier_mac.c | 22 ++++++------ src/vf/spp_forward.c | 35 +++++++++---------- 4 files changed, 36 insertions(+), 41 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c index a768575..856e79e 100644 --- a/src/shared/secondary/spp_worker_th/cmd_runner.c +++ b/src/shared/secondary/spp_worker_th/cmd_runner.c @@ -532,15 +532,11 @@ spp_iterate_core_info(struct spp_iterate_core_params *params) comp_info = (comp_info_base + core->id[cnt]); #ifdef SPP_VF_MODULE if (comp_info->wk_type == SPPWK_TYPE_CLS) { - ret = spp_classifier_get_component_status( - lcore_id, - core->id[cnt], - params); + ret = get_classifier_status(lcore_id, + core->id[cnt], params); } else { - ret = spp_forward_get_component_status( - lcore_id, - core->id[cnt], - params); + ret = get_forwarder_status(lcore_id, + core->id[cnt], params); } #endif /* SPP_VF_MODULE */ #ifdef SPP_MIRROR_MODULE diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index 3ae4fc9..fb34215 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -79,7 +79,7 @@ int spp_classifier_mac_iterate_table( struct spp_iterate_classifier_table_params *params); /** - * classifier get component status. + * Get classifier status. * * @param[in] lcore_id Lcore ID for classifier. * @param[in] id Unique component ID. @@ -87,11 +87,11 @@ int spp_classifier_mac_iterate_table( * @retval SPP_RET_OK If succeeded. * @retval SPP_RET_NG If failed. */ -int spp_classifier_get_component_status(unsigned int lcore_id, int id, +int get_classifier_status(unsigned int lcore_id, int id, struct spp_iterate_core_params *params); /** - * Merge/Forward get component status + * Get forwarder status. * * @param lcore_id Lcore ID for forwarder and merger. * @param id Unique component ID. @@ -99,7 +99,7 @@ int spp_classifier_get_component_status(unsigned int lcore_id, int id, * @retval SPP_RET_OK If succeeded. * @retval SPP_RET_NG If failed. */ -int spp_forward_get_component_status(unsigned int lcore_id, int id, +int get_forwarder_status(unsigned int lcore_id, int id, struct spp_iterate_core_params *params); #endif /* _SPPWK_TH_VF_DEPS_H_ */ diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index f6074e4..9023a69 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -803,29 +803,29 @@ spp_classifier_mac_do(int id) /* classifier iterate component information */ int -spp_classifier_get_component_status( - unsigned int lcore_id, int id, +get_classifier_status(unsigned int lcore_id, int id, struct spp_iterate_core_params *params) { int ret = SPP_RET_NG; - int i, nof_tx, nof_rx = 0; /* Num of RX and TX ports. */ + int i; + int nof_tx, nof_rx = 0; /* Num of RX and TX ports. */ struct management_info *mng_info; struct cls_comp_info *cmp_info; - struct cls_port_info *clsd_data; + struct cls_port_info *port_info; struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS]; struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS]; mng_info = g_mng_infos + id; if (!is_used_mng_info(mng_info)) { RTE_LOG(ERR, SPP_CLASSIFIER_MAC, - "Component[%d] Not used. " - "(status)(core = %d, type = %d)\n", + "Classifier is not used " + "(comp_id=%d, lcore_id=%d, type=%d).\n", id, lcore_id, SPPWK_TYPE_CLS); return SPP_RET_NG; } cmp_info = mng_info->cmp_infos + mng_info->ref_index; - clsd_data = cmp_info->tx_ports_i; + port_info = cmp_info->tx_ports_i; memset(rx_ports, 0x00, sizeof(rx_ports)); if (cmp_info->rx_port_i.iface_type != UNDEF) { @@ -837,14 +837,14 @@ spp_classifier_get_component_status( memset(tx_ports, 0x00, sizeof(tx_ports)); nof_tx = cmp_info->nof_tx_ports; for (i = 0; i < nof_tx; i++) { - tx_ports[i].iface_type = clsd_data[i].iface_type; - tx_ports[i].iface_no = clsd_data[i].iface_no_global; + tx_ports[i].iface_type = port_info[i].iface_type; + tx_ports[i].iface_no = port_info[i].iface_no_global; } /* Set the information with the function specified by the command. */ + /* TODO(yasufum) rename `element_proc` */ ret = (*params->element_proc)( - params, lcore_id, - cmp_info->name, SPPWK_TYPE_CLS_STR, + params, lcore_id, cmp_info->name, SPPWK_TYPE_CLS_STR, nof_rx, rx_ports, nof_tx, tx_ports); if (unlikely(ret != SPP_RET_OK)) return SPP_RET_NG; diff --git a/src/vf/spp_forward.c b/src/vf/spp_forward.c index 7746d40..3d40951 100644 --- a/src/vf/spp_forward.c +++ b/src/vf/spp_forward.c @@ -182,50 +182,49 @@ spp_forward(int id) return SPP_RET_OK; } -/* Merge/Forward get component status */ +/* Get forwarder status */ int -spp_forward_get_component_status( - unsigned int lcore_id, int id, +get_forwarder_status(unsigned int lcore_id, int id, struct spp_iterate_core_params *params) { int ret = SPP_RET_NG; int cnt; const char *component_type = NULL; - struct forward_info *info = &g_forward_info[id]; - struct forward_path *path = &info->path[info->ref_index]; + struct forward_info *fwd_info = &g_forward_info[id]; + struct forward_path *fwd_path = &fwd_info->path[fwd_info->ref_index]; struct sppwk_port_idx rx_ports[RTE_MAX_ETHPORTS]; struct sppwk_port_idx tx_ports[RTE_MAX_ETHPORTS]; - if (unlikely(path->wk_type == SPPWK_TYPE_NONE)) { + if (unlikely(fwd_path->wk_type == SPPWK_TYPE_NONE)) { RTE_LOG(ERR, FORWARD, - "Component[%d] Not used. " - "(status)(core = %d, type = %d)\n", - id, lcore_id, path->wk_type); + "Forwarder is not used. " + "(id=%d, lcore=%d, type=%d).\n", + id, lcore_id, fwd_path->wk_type); return SPP_RET_NG; } - if (path->wk_type == SPPWK_TYPE_MRG) + if (fwd_path->wk_type == SPPWK_TYPE_MRG) component_type = SPPWK_TYPE_MRG_STR; else component_type = SPPWK_TYPE_FWD_STR; memset(rx_ports, 0x00, sizeof(rx_ports)); - for (cnt = 0; cnt < path->num_rx; cnt++) { - rx_ports[cnt].iface_type = path->ports[cnt].rx.iface_type; - rx_ports[cnt].iface_no = path->ports[cnt].rx.iface_no; + for (cnt = 0; cnt < fwd_path->num_rx; cnt++) { + rx_ports[cnt].iface_type = fwd_path->ports[cnt].rx.iface_type; + rx_ports[cnt].iface_no = fwd_path->ports[cnt].rx.iface_no; } memset(tx_ports, 0x00, sizeof(tx_ports)); - for (cnt = 0; cnt < path->num_tx; cnt++) { - tx_ports[cnt].iface_type = path->ports[cnt].tx.iface_type; - tx_ports[cnt].iface_no = path->ports[cnt].tx.iface_no; + for (cnt = 0; cnt < fwd_path->num_tx; cnt++) { + tx_ports[cnt].iface_type = fwd_path->ports[cnt].tx.iface_type; + tx_ports[cnt].iface_no = fwd_path->ports[cnt].tx.iface_no; } /* Set the information with the function specified by the command. */ ret = (*params->element_proc)( params, lcore_id, - path->name, component_type, - path->num_rx, rx_ports, path->num_tx, tx_ports); + fwd_path->name, component_type, + fwd_path->num_rx, rx_ports, fwd_path->num_tx, tx_ports); if (unlikely(ret != SPP_RET_OK)) return SPP_RET_NG; -- 2.17.1
From: Yasufumi Ogawa <yasufum.o@gmail.com> This update is to refactor setting up a list of entries in classifier table for `status` command. Names of function for setting up JSON are revised, but still hard to understand the features. append_classifier_table() for setting up the entries calls several nested functions as in the following order. append_classifier_table() // This function. -> add_classifier_table() // Wrapper and doesn't almost nothing. -> add_classifier_table_val() // Setup data and call iterator. -> iterate_adding_mac_entry() Signed-off-by: Yasufumi Ogawa <yasufum.o@gmail.com> --- .../secondary/spp_worker_th/cmd_parser.c | 2 +- .../secondary/spp_worker_th/cmd_runner.c | 25 ++++++-- .../secondary/spp_worker_th/cmd_utils.h | 2 +- src/shared/secondary/spp_worker_th/vf_deps.h | 8 ++- src/vf/classifier_mac.c | 64 +++++++++++-------- src/vf/classifier_mac.h | 2 +- 6 files changed, 67 insertions(+), 36 deletions(-) diff --git a/src/shared/secondary/spp_worker_th/cmd_parser.c b/src/shared/secondary/spp_worker_th/cmd_parser.c index 55fc1d2..13e7013 100644 --- a/src/shared/secondary/spp_worker_th/cmd_parser.c +++ b/src/shared/secondary/spp_worker_th/cmd_parser.c @@ -651,7 +651,7 @@ parse_mac_addr(void *output, const char *arg_val, const char *str_val = arg_val; /* If given value is the default, use dummy address instead. */ - if (unlikely(strcmp(str_val, SPP_DEFAULT_CLASSIFIED_SPEC_STR) == 0)) + if (unlikely(strcmp(str_val, SPPWK_TERM_DEFAULT) == 0)) str_val = SPP_DEFAULT_CLASSIFIED_DMY_ADDR_STR; /* Check if the given value is valid. */ diff --git a/src/shared/secondary/spp_worker_th/cmd_runner.c b/src/shared/secondary/spp_worker_th/cmd_runner.c index 856e79e..bc3ae06 100644 --- a/src/shared/secondary/spp_worker_th/cmd_runner.c +++ b/src/shared/secondary/spp_worker_th/cmd_runner.c @@ -561,12 +561,12 @@ spp_iterate_core_info(struct spp_iterate_core_params *params) /* Iterate classifier_table to create response to status command */ #ifdef SPP_VF_MODULE static int -spp_iterate_classifier_table( +add_classifier_table( struct spp_iterate_classifier_table_params *params) { int ret; - ret = spp_classifier_mac_iterate_table(params); + ret = add_classifier_table_val(params); if (unlikely(ret != 0)) { RTE_LOG(ERR, WK_CMD_RUNNER, "Cannot iterate classifier_mac_table.\n"); return SPP_RET_NG; @@ -1219,7 +1219,10 @@ append_core_value(const char *name, char **output, return ret; } -/* append one element of classifier table for JSON format */ +/** + * Operator function called in iterator for getting each of entries of + * classifier table named as iterate_adding_mac_entry(). + */ #ifdef SPP_VF_MODULE static int append_classifier_element_value( @@ -1276,10 +1279,18 @@ append_classifier_element_value( } #endif /* SPP_VF_MODULE */ -/* append a list of classifier table for JSON format */ +/** + * Append entries of classifier table in JSON. Before iterating the entries, + * this function calls several nested functions. + * append_classifier_table() // This function. + * -> add_classifier_table() // Wrapper and doesn't almost nothing. + * -> add_classifier_table_val() // Setup data and call iterator. + * -> iterate_adding_mac_entry() + * + */ #ifdef SPP_VF_MODULE static int -append_classifier_table_value(const char *name, char **output, +append_classifier_table(const char *name, char **output, void *tmp __attribute__ ((unused))) { int ret = SPP_RET_NG; @@ -1296,7 +1307,7 @@ append_classifier_table_value(const char *name, char **output, itr_params.output = tmp_buff; itr_params.element_proc = append_classifier_element_value; - ret = spp_iterate_classifier_table(&itr_params); + ret = add_classifier_table(&itr_params); if (unlikely(ret != SPP_RET_OK)) { spp_strbuf_free(itr_params.output); return SPP_RET_NG; @@ -1388,7 +1399,7 @@ struct cmd_response response_info_list[] = { { "master-lcore", append_master_lcore_value }, { "core", append_core_value }, #ifdef SPP_VF_MODULE - { "classifier_table", append_classifier_table_value }, + { "classifier_table", append_classifier_table}, #endif /* SPP_VF_MODULE */ { "", NULL } }; diff --git a/src/shared/secondary/spp_worker_th/cmd_utils.h b/src/shared/secondary/spp_worker_th/cmd_utils.h index 1d6c332..b8ab10c 100644 --- a/src/shared/secondary/spp_worker_th/cmd_utils.h +++ b/src/shared/secondary/spp_worker_th/cmd_utils.h @@ -47,7 +47,7 @@ #define SPP_CORE_STATUS_CHECK_MAX 5 /** Character sting for default port of classifier */ -#define SPP_DEFAULT_CLASSIFIED_SPEC_STR "default" +#define SPPWK_TERM_DEFAULT "default" /** Value for default MAC address of classifier */ #define SPP_DEFAULT_CLASSIFIED_DMY_ADDR 0x010000000000 diff --git a/src/shared/secondary/spp_worker_th/vf_deps.h b/src/shared/secondary/spp_worker_th/vf_deps.h index fb34215..beafc64 100644 --- a/src/shared/secondary/spp_worker_th/vf_deps.h +++ b/src/shared/secondary/spp_worker_th/vf_deps.h @@ -75,7 +75,13 @@ void init_classifier_info(int component_id); void uninit_component_info(struct cls_comp_info *cmp_info); -int spp_classifier_mac_iterate_table( +/** + * Setup data of classifier table and call iterator function for getting + * each of entries. + * + * @params[in] params Object which has pointer of operator func and attrs. + */ +int add_classifier_table_val( struct spp_iterate_classifier_table_params *params); /** diff --git a/src/vf/classifier_mac.c b/src/vf/classifier_mac.c index 9023a69..8d677a9 100644 --- a/src/vf/classifier_mac.c +++ b/src/vf/classifier_mac.c @@ -224,6 +224,7 @@ log_classification( log_classification(clsd_idx, pkt, cmp_info, clsd_data, \ __func__, __LINE__) +/* Log DEBUG message for classified MAC and VLAN info. */ static void log_entry( long clsd_idx, @@ -852,13 +853,17 @@ get_classifier_status(unsigned int lcore_id, int id, return SPP_RET_OK; } +/** + * For setting up a response for `status` command, iterate adding each of + * entries in MAC address table to the result message. + */ static void -mac_classification_iterate_table( +iterate_adding_mac_entry( struct spp_iterate_classifier_table_params *params, uint16_t vid, struct mac_classifier *mac_cls, __rte_unused struct cls_comp_info *cmp_info, - struct cls_port_info *clsd_data) + struct cls_port_info *port_info) { int ret; const void *key; @@ -873,18 +878,20 @@ mac_classification_iterate_table( type = SPP_CLASSIFIER_TYPE_MAC; if (mac_cls->default_cls_idx >= 0) { - port.iface_type = (clsd_data + + port.iface_type = (port_info + mac_cls->default_cls_idx)->iface_type; - port.iface_no = (clsd_data + + port.iface_no = (port_info + mac_cls->default_cls_idx)->iface_no_global; - LOG_ENT((long)mac_cls->default_cls_idx, - vid, - SPP_DEFAULT_CLASSIFIED_SPEC_STR, - cmp_info, clsd_data); - - (*params->element_proc)(params, type, vid, - SPP_DEFAULT_CLASSIFIED_SPEC_STR, &port); + /* Logging DEBUG message. */ + LOG_ENT((long)mac_cls->default_cls_idx, vid, + SPPWK_TERM_DEFAULT, cmp_info, port_info); + /** + * Append "default" entry. `element_proc` is a funciton + * pointer to append_classifier_element_value(). + */ + (*params->element_proc)(params, type, vid, SPPWK_TERM_DEFAULT, + &port); } next = 0; @@ -897,25 +904,32 @@ mac_classification_iterate_table( ether_format_addr(mac_addr_str, sizeof(mac_addr_str), (const struct ether_addr *)key); - port.iface_type = (clsd_data + (long)data)->iface_type; - port.iface_no = (clsd_data + (long)data)->iface_no_global; + port.iface_type = (port_info + (long)data)->iface_type; + port.iface_no = (port_info + (long)data)->iface_no_global; - LOG_ENT((long)data, vid, mac_addr_str, cmp_info, clsd_data); + LOG_ENT((long)data, vid, mac_addr_str, cmp_info, port_info); + /** + * Append each entry of MAC address. `element_proc` is a + * funciton pointer to append_classifier_element_value(). + */ (*params->element_proc)(params, type, vid, mac_addr_str, &port); } } -/* classifier(mac address) iterate classifier table. */ +/** + * Setup data of classifier table and call iterator function for getting + * each of entries. + */ int -spp_classifier_mac_iterate_table( +add_classifier_table_val( struct spp_iterate_classifier_table_params *params) { - int i, n; + int i, vlan_id; struct management_info *mng_info; struct cls_comp_info *cmp_info; - struct cls_port_info *clsd_data; + struct cls_port_info *port_info; for (i = 0; i < RTE_MAX_LCORE; i++) { mng_info = g_mng_infos + i; @@ -923,18 +937,18 @@ spp_classifier_mac_iterate_table( continue; cmp_info = mng_info->cmp_infos + mng_info->ref_index; - clsd_data = cmp_info->tx_ports_i; + port_info = cmp_info->tx_ports_i; RTE_LOG(DEBUG, SPP_CLASSIFIER_MAC, - "Core[%u] Start iterate classifier table.\n", i); + "Start iterate classifier table on lcore %u.\n", i); - for (n = 0; n < NOF_VLAN; ++n) { - if (cmp_info->mac_clfs[n] == NULL) + for (vlan_id = 0; vlan_id < NOF_VLAN; ++vlan_id) { + if (cmp_info->mac_clfs[vlan_id] == NULL) continue; - mac_classification_iterate_table(params, (uint16_t) n, - cmp_info->mac_clfs[n], cmp_info, - clsd_data); + iterate_adding_mac_entry(params, (uint16_t) vlan_id, + cmp_info->mac_clfs[vlan_id], cmp_info, + port_info); } } diff --git a/src/vf/classifier_mac.h b/src/vf/classifier_mac.h index d3c5ab6..21433e6 100644 --- a/src/vf/classifier_mac.h +++ b/src/vf/classifier_mac.h @@ -56,7 +56,7 @@ int spp_classifier_mac_do(int id); * @retval SPP_RET_OK succeeded. * @retval SPP_RET_NG failed. */ -int spp_classifier_mac_iterate_table( +int add_classifier_table_val( struct spp_iterate_classifier_table_params *params); #endif /* _CLASSIFIER_MAC_H_ */ -- 2.17.1