DPDK helloworld 源码阅读
在 DPDK Programmer's Guides 中的 EAL 一篇中有一個(gè)圖可以很清晰地看到一個(gè)DPDK的應(yīng)用程序的大致執(zhí)行思路:
初始化檢查CPU支持、微架構(gòu)配置等完成后,執(zhí)行main()函數(shù)。
下面對照此思路閱讀 /dpdk/examples/helloworld/main.c 這個(gè)代碼:
/* SPDX-License-Identifier: BSD-3-Clause* Copyright(c) 2010-2014 Intel Corporation*/#include <stdio.h> #include <string.h> #include <stdint.h> #include <errno.h> #include <sys/queue.h>#include <rte_memory.h> #include <rte_launch.h> #include <rte_eal.h> #include <rte_per_lcore.h> #include <rte_lcore.h> #include <rte_debug.h>static int lcore_hello(__attribute__((unused)) void *arg) {unsigned lcore_id;lcore_id = rte_lcore_id(); // ⑤ 返回當(dāng)前執(zhí)行單元的線程IDprintf("hello from core %u\n", lcore_id);return 0; }int main(int argc, char **argv) {int ret;unsigned lcore_id;ret = rte_eal_init(argc, argv); // ① 初始化EALif (ret < 0)rte_panic("Cannot init EAL\n");RTE_LCORE_FOREACH_SLAVE(lcore_id) { // ② 瀏覽除主lcore之外的所有l(wèi)corerte_eal_remote_launch(lcore_hello, NULL, lcore_id); // ③ 在lcore上執(zhí)行函數(shù)}lcore_hello(NULL);rte_eal_mp_wait_lcore(); // ④ 等待lcore完成工作return 0; }① rte_eal_init()初始化環(huán)境抽象層(EAL)。此函數(shù)僅在應(yīng)用程序的main()函數(shù)中盡快在MASTER lcore上執(zhí)行。
② 宏:RTE_LCORE_FOREACH_SLAVE(i) :瀏覽除主lcore之外的所有正在運(yùn)行的lcores。
③ rte_eal_remote_launch(lcore_hello, NULL, lcore_id);在另一個(gè)lcore上啟動(dòng)一個(gè)函數(shù)。應(yīng)僅在MASTER lcore上執(zhí)行。第一個(gè)參數(shù)是函數(shù)名,第二個(gè)參數(shù)是以什么參數(shù)執(zhí)行該函數(shù),第三個(gè)參數(shù)是邏輯核的ID。
④ rte_eal_mp_wait_lcore();應(yīng)僅在MASTER lcore上執(zhí)行,等到lcore完成它的工作。一個(gè)lcore有三種狀態(tài):WAIT、RUNNING、FINISHED,對應(yīng)空閑、正在執(zhí)行一個(gè)函數(shù)、執(zhí)行完成。依據(jù)三個(gè)狀態(tài)來協(xié)調(diào)線程的launch和wait。
⑤ rte_lcore_id() 返回執(zhí)行單元的線程ID
API 文檔:
- DPDK Programmer's Guides - initialization-and-core-launching
- EAL環(huán)境抽象層 包括上文的 ①
- CPU-multicore:lcore ②、⑤
- CPU-multicore:launch ③、④
轉(zhuǎn)載于:https://www.cnblogs.com/ZCplayground/p/9317194.html
總結(jié)
以上是生活随笔為你收集整理的DPDK helloworld 源码阅读的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iPhone 14 Pro外观提前看:感
- 下一篇: 深信服笔试,抓兔子