diff options
| author | songyanchao <[email protected]> | 2022-10-19 09:11:29 +0000 |
|---|---|---|
| committer | songyanchao <[email protected]> | 2022-10-19 09:11:29 +0000 |
| commit | ea6fe2955f4008742fcab6a15d38cd677014182e (patch) | |
| tree | ba9ef38e453ab2f912a78ec631933c0b728b78c4 | |
| parent | 7cf1716558bc6c36eeb5190c79bc63cd99c943ba (diff) | |
🐞 fix(TSG-12257): 修复Bug:"mrglobal.conf没有配置任何PCI类型的网卡时,mrzcpd会接管所有CX6网卡"v4.6.5-20221019
修复Bug:"mrglobal.conf没有配置任何PCI类型的网卡时,mrzcpd会接管所有CX6网卡"
| -rw-r--r-- | service/include/sc_phydev.h | 34 | ||||
| -rw-r--r-- | service/src/core.c | 44 | ||||
| -rw-r--r-- | service/src/phydev.c | 12 |
3 files changed, 52 insertions, 38 deletions
diff --git a/service/include/sc_phydev.h b/service/include/sc_phydev.h index 2ed6f0f..a99c2d2 100644 --- a/service/include/sc_phydev.h +++ b/service/include/sc_phydev.h @@ -1,7 +1,8 @@ #pragma once #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif #include <common.h> @@ -12,7 +13,7 @@ extern "C" { #include <rte_pci.h> #ifndef MR_PHYDEV_PCI_MAX -#define MR_PHYDEV_PCI_MAX 64 +#define MR_PHYDEV_PCI_MAX 64 #endif // RSS模式 @@ -95,8 +96,7 @@ struct phydev_info unsigned int vlan_filter_deny_ids[4096]; /* PCI地址/虚设备地址 */ - union - { + union { /* For PCI Device */ struct rte_pci_addr pci_addr; /* For vdev device */ @@ -162,8 +162,7 @@ struct phydev_qinfo queue_id_t queue_id; }; - -#define __QGROUP_MAX_QUEUE RTE_MAX_QUEUES_PER_PORT +#define __QGROUP_MAX_QUEUE RTE_MAX_QUEUES_PER_PORT /* 队列分组 */ struct phydev_qgroup @@ -241,8 +240,8 @@ struct phydev char str_indirect_pool[MR_SYMBOL_MAX]; /* 报文缓冲区 */ - struct rte_mempool *direct_pool; - struct rte_mempool *indirect_pool; + struct rte_mempool * direct_pool; + struct rte_mempool * indirect_pool; /* 选项 */ unsigned int promisc; @@ -263,7 +262,7 @@ struct phydev /* Handles for default rules */ #define __DEV_MAX_DEFAULT_FLOWS 256 - struct rte_flow *default_flow_handles[__DEV_MAX_DEFAULT_FLOWS]; + struct rte_flow * default_flow_handles[__DEV_MAX_DEFAULT_FLOWS]; unsigned int nr_default_flow_handles; }; @@ -279,26 +278,27 @@ struct phydev_main; int phydev_list(struct phydev_main * ctx, struct phydev * devs[], int nr_max_devs); -int phydev_iterate(struct phydev_main *ctx, struct phydev **phydev); +int phydev_iterate(struct phydev_main * ctx, struct phydev ** phydev); int whitelist_phydev_iterate(struct phydev_main * ctx, struct phydev_whitelist ** phydev_wh); +uint16_t whitelist_phydev_get_num(struct phydev_main * ctx); + struct phydev * phydev_lookup(struct phydev_main * ctx, const char * devsym); struct phydev * phydev_lookup_id(struct phydev_main * ctx, port_id_t port_id); -struct phydev *phydev_open(struct phydev_main *ctx, struct phydev_param *param); - -int phydev_use_queue(struct phydev *dev, enum phydev_qgroup_type q_type, queue_id_t *queue_out); +struct phydev * phydev_open(struct phydev_main * ctx, struct phydev_param * param); -void phydev_unuse_queue(struct phydev *dev, enum phydev_qgroup_type q_type, queue_id_t queue); +int phydev_use_queue(struct phydev * dev, enum phydev_qgroup_type q_type, queue_id_t * queue_out); -void phydev_stat_get(struct phydev *phydev, struct phydev_stat *phydev_stat); +void phydev_unuse_queue(struct phydev * dev, enum phydev_qgroup_type q_type, queue_id_t queue); -void phydev_stat_last_save(struct phydev *phydev, struct phydev_stat *phydev_stat_last); +void phydev_stat_get(struct phydev * phydev, struct phydev_stat * phydev_stat); -void phydev_stat_last_get(struct phydev *phydev, struct phydev_stat *phydev_stat_last); +void phydev_stat_last_save(struct phydev * phydev, struct phydev_stat * phydev_stat_last); +void phydev_stat_last_get(struct phydev * phydev, struct phydev_stat * phydev_stat_last); #ifdef __cplusplus } diff --git a/service/src/core.c b/service/src/core.c index 94467b5..f96a238 100644 --- a/service/src/core.c +++ b/service/src/core.c @@ -15,14 +15,14 @@ #include <unistd.h> #include <MESA_prof_load.h> +#include <cJSON.h> #include <ctrlmsg.h> -#include <rpc.h> #include <ldbc.h> +#include <rpc.h> #include <sc_common.h> #include <sc_mrb.h> #include <sc_vdev.h> #include <systemd/sd-daemon.h> -#include <cJSON.h> const char * mr_logo = " __ ___ _ _____ ______\n" " / |/ /___ ___________(_)__/__ / ___ _________ / ____/___ ____ __ __\n" @@ -62,11 +62,11 @@ const char service_git_version[] = ""; #endif #ifndef MR_PMD_BASIC_LIB_PATH -#define MR_PMD_BASIC_LIB_PATH "/opt/tsg/mrzcpd/lib/pmds" +#define MR_PMD_BASIC_LIB_PATH "/opt/tsg/mrzcpd/lib/pmds" #endif #ifndef MR_PMD_FOR_MLX5_DRIVER_PATH -#define MR_PMD_FOR_MLX5_DRIVER_PATH "/opt/tsg/mrzcpd/lib/pmds/mlx5" +#define MR_PMD_FOR_MLX5_DRIVER_PATH "/opt/tsg/mrzcpd/lib/pmds/mlx5" #endif #ifndef MR_SERVICE_DEFAULT_RX_BURST @@ -373,10 +373,9 @@ static void sc_eal_init(struct sc_main * sc, const char * cmd) unsigned int main_core = 0; MESA_load_profile_uint_def(sc->local_cfgfile, "service", "main_core", &main_core, 0); - nr_io_cores = MESA_load_profile_uint_range(sc->local_cfgfile, - "service", "iocore", RTE_DIM(io_cores), io_cores); - nr_smartoffload_cores = MESA_load_profile_uint_range(sc->local_cfgfile, - "service", "offload_core", RTE_DIM(smartoffload_cores), smartoffload_cores); + nr_io_cores = MESA_load_profile_uint_range(sc->local_cfgfile, "service", "iocore", RTE_DIM(io_cores), io_cores); + nr_smartoffload_cores = MESA_load_profile_uint_range(sc->local_cfgfile, "service", "offload_core", + RTE_DIM(smartoffload_cores), smartoffload_cores); if (nr_io_cores < 0) { @@ -460,7 +459,8 @@ static void sc_eal_init(struct sc_main * sc, const char * cmd) } char str_socket_mem[MR_STRING_MAX]; - ret = MESA_load_profile_string_nodef(sc->local_cfgfile, "eal", "socket-mem", str_socket_mem, sizeof(str_socket_mem)); + ret = + MESA_load_profile_string_nodef(sc->local_cfgfile, "eal", "socket-mem", str_socket_mem, sizeof(str_socket_mem)); if (ret > 0) { @@ -484,7 +484,7 @@ static void sc_eal_init(struct sc_main * sc, const char * cmd) char str_devargs[MR_STRING_MAX]; snprintf(str_devargs, sizeof(str_devargs) - 1, "%s", phydev_wh_iter->pci_addr); - if(phydev_wh_iter->mlx5_allow_duplicate_pattern == 0) + if (phydev_wh_iter->mlx5_allow_duplicate_pattern == 0) { strcat(str_devargs, ",allow_duplicate_pattern=0"); } @@ -493,6 +493,9 @@ static void sc_eal_init(struct sc_main * sc, const char * cmd) WRITE_ARG(str_devargs); } + if (whitelist_phydev_get_num(sc->phydev_main) == 0) + WRITE_ARG("--no-pci"); + unsigned int en_single_file_segments = 0; MESA_load_profile_uint_def(sc->local_cfgfile, "eal", "single-file-segments", &en_single_file_segments, 0); @@ -602,8 +605,7 @@ static int sc_rpc_server_init(struct sc_main * sc) char rpc_addr[MR_STRING_MAX] = {0}; unsigned int rpc_port = 0; struct sockaddr_in srv_sockaddr; - MESA_load_profile_string_def(sc->local_cfgfile, "rpc", "addr", rpc_addr, - sizeof(rpc_addr), RPC_DEFAULT_ADDR); + MESA_load_profile_string_def(sc->local_cfgfile, "rpc", "addr", rpc_addr, sizeof(rpc_addr), RPC_DEFAULT_ADDR); MESA_load_profile_uint_def(sc->local_cfgfile, "rpc", "port", &rpc_port, RPC_DEFAULT_PORT); if (inet_pton(AF_INET, rpc_addr, &srv_sockaddr.sin_addr) <= 0) { @@ -617,12 +619,11 @@ static int sc_rpc_server_init(struct sc_main * sc) { return RT_ERR; } - if(rpc_server_listen_accept(sc->rpc_srv_handler, srv_sockaddr) != 0) + if (rpc_server_listen_accept(sc->rpc_srv_handler, srv_sockaddr) != 0) { return RT_ERR; } return RT_SUCCESS; - } static int sc_distributer_init(struct sc_main * sc) { @@ -876,7 +877,7 @@ cJSON * service_monit_loop(struct sc_main * sc) } static int __rte_service_register_helper(const struct rte_service_spec * spec, const cpu_set_t * cpu_set, - unsigned int * out_service_id) + unsigned int * out_service_id) { int ret = 0; uint32_t service_id = 0; @@ -1071,7 +1072,7 @@ int main(int argc, char * argv[]) ret = EXIT_FAILURE; goto quit; } - if(sc_rpc_server_init(sc) != RT_SUCCESS) + if (sc_rpc_server_init(sc) != RT_SUCCESS) { MR_ERROR("rpc server module initialization failed. "); ret = EXIT_FAILURE; @@ -1093,8 +1094,9 @@ int main(int argc, char * argv[]) if (flow_main_init(sc) != RT_SUCCESS) { - MR_ERROR("offload management module initialization failed. "); - ret = EXIT_FAILURE; goto quit; + MR_ERROR("offload management module initialization failed. "); + ret = EXIT_FAILURE; + goto quit; } if (hwinfo_init(sc) != RT_SUCCESS) @@ -1223,7 +1225,7 @@ int main(int argc, char * argv[]) ret = EXIT_FAILURE; goto quit; } - if(rpc_server_dispatch_thread(sc->rpc_srv_handler) != RT_SUCCESS) + if (rpc_server_dispatch_thread(sc->rpc_srv_handler) != RT_SUCCESS) { MR_ERROR("Launch rpc dispatch thread failed"); ret = EXIT_FAILURE; @@ -1353,14 +1355,14 @@ int main(int argc, char * argv[]) continue; ret = rte_service_lcore_start(lcore_id); - if (ret && ret !=-EALREADY) + if (ret && ret != -EALREADY) { MR_ERROR("Failed at start service core %u: ret = %d", lcore_id, ret); goto quit; } } - while(true) + while (true) { sleep(1); } diff --git a/service/src/phydev.c b/service/src/phydev.c index a113cfd..7d7c98a 100644 --- a/service/src/phydev.c +++ b/service/src/phydev.c @@ -734,6 +734,18 @@ int whitelist_phydev_iterate(struct phydev_main * ctx, struct phydev_whitelist * return 0; } +uint16_t whitelist_phydev_get_num(struct phydev_main * ctx) +{ + uint16_t phydev_num = 0; + struct phydev_whitelist * phydev_wh_iter = NULL; + + while (whitelist_phydev_iterate(ctx, &phydev_wh_iter) >= 0) + { + phydev_num++; + } + return phydev_num; +} + struct phydev * phydev_lookup(struct phydev_main * ctx, const char * devsym) { struct phydev * dev_iter = NULL; |
