DPDK KNI 接口2
Posted mysky007
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DPDK KNI 接口2相关的知识,希望对你有一定的参考价值。
kni 源码讲解
1 /* Initialise EAL */ 2 ret = rte_eal_init(argc, argv); 3 if (ret < 0) 4 rte_exit(EXIT_FAILURE, "Could not initialise EAL (%d)\n", ret); 5 argc -= ret; 6 argv += ret; 7 8 /* Parse application arguments (after the EAL ones) */ 9 ret = parse_args(argc, argv); 10 if (ret < 0) 11 rte_exit(EXIT_FAILURE, "Could not parse input parameters\n"); 12 13 /* Create the mbuf pool */ 14 pktmbuf_pool = rte_pktmbuf_pool_create("mbuf_pool", NB_MBUF, 15 MEMPOOL_CACHE_SZ, 0, MBUF_DATA_SZ, rte_socket_id()); 16 if (pktmbuf_pool == NULL) 17 rte_exit(EXIT_FAILURE, "Could not initialise mbuf pool\n"); 18 return -1; 19 20 21 /* Get number of ports found in scan */ 22 nb_sys_ports = rte_eth_dev_count_avail(); 23 if (nb_sys_ports == 0) 24 rte_exit(EXIT_FAILURE, "No supported Ethernet device found\n"); 25 26 /* Check if the configured port ID is valid */ 27 for (i = 0; i < RTE_MAX_ETHPORTS; i++) 28 if (kni_port_params_array[i] && !rte_eth_dev_is_valid_port(i)) 29 rte_exit(EXIT_FAILURE, "Configured invalid " 30 "port ID %u\n", i); 31 32 /* Initialize KNI subsystem */ 33 init_kni(); 34 35 /* Initialise each port */ 36 RTE_ETH_FOREACH_DEV(port) 37 /* Skip ports that are not enabled */ 38 if (!(ports_mask & (1 << port))) 39 continue; 40 init_port(port); 41 42 if (port >= RTE_MAX_ETHPORTS) 43 rte_exit(EXIT_FAILURE, "Can not use more than " 44 "%d ports for kni\n", RTE_MAX_ETHPORTS); 45 46 kni_alloc(port); 47 48 check_all_ports_link_status(ports_mask); 49 50 pid = getpid(); 51 RTE_LOG(INFO, APP, "========================\n"); 52 RTE_LOG(INFO, APP, "KNI Running\n"); 53 RTE_LOG(INFO, APP, "kill -SIGUSR1 %d\n", pid); 54 RTE_LOG(INFO, APP, " Show KNI Statistics.\n"); 55 RTE_LOG(INFO, APP, "kill -SIGUSR2 %d\n", pid); 56 RTE_LOG(INFO, APP, " Zero KNI Statistics.\n"); 57 RTE_LOG(INFO, APP, "========================\n"); 58 fflush(stdout); 59 60 ret = rte_ctrl_thread_create(&kni_link_tid, 61 "KNI link status check", NULL, 62 monitor_all_ports_link_status, NULL); 63 if (ret < 0) 64 rte_exit(EXIT_FAILURE, 65 "Could not create link status thread!\n"); 66 67 /* Launch per-lcore function on every lcore */ 68 rte_eal_mp_remote_launch(main_loop, NULL, CALL_MASTER); 69 RTE_LCORE_FOREACH_SLAVE(i) 70 if (rte_eal_wait_lcore(i) < 0) 71 return -1; 72 73 monitor_links = 0; 74 pthread_join(kni_link_tid, &retval); 75 76 /* Release resources */ 77 RTE_ETH_FOREACH_DEV(port) 78 if (!(ports_mask & (1 << port))) 79 continue; 80 kni_free_kni(port); 81 82 for (i = 0; i < RTE_MAX_ETHPORTS; i++) 83 if (kni_port_params_array[i]) 84 rte_free(kni_port_params_array[i]); 85 kni_port_params_array[i] = NULL; 86 87 88 return 0;
main 主要完成步骤:
1.进行EAL层的初始化
2.解析DPDK和应用层的参数
3.分配报文的mempool,为接收报文做准备
4.初始化以及启动接口
5.启动各个核上的线程
以上是关于DPDK KNI 接口2的主要内容,如果未能解决你的问题,请参考以下文章
(dpdk f-stack)-通过kni与kernel上服务通信
(dpdk f-stack)-通过kni与kernel上服务通信