chinese直男口爆体育生外卖, 99久久er热在这里只有精品99, 又色又爽又黄18禁美女裸身无遮挡, gogogo高清免费观看日本电视,私密按摩师高清版在线,人妻视频毛茸茸,91论坛 兴趣闲谈,欧美 亚洲 精品 8区,国产精品久久久久精品免费

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

如何用eBPF寫TCP擁塞控制算法?

Linux閱碼場 ? 來源:csdn ? 作者:dog250 ? 2020-12-26 09:44 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

其實不想用這個題目的,只因為TCP相關(guān)的東西比較吸引人的眼球,這篇文章的主題還是eBPF,而不是TCP。

用eBPF寫TCP擁塞控制算法只是本文所講內(nèi)容的一個再平凡不過的例子。

先看兩個問題,或者說是兩個痛點:

內(nèi)核越來越策略化。

內(nèi)核接口不穩(wěn)定。

分別簡單說一下。

所謂內(nèi)核策略化就是說越來越多的靈巧的算法,小tricks等靈活多變的代碼進入內(nèi)核,舉例來講,包括但不限于以下這些:

TCP擁塞控制算法。

TC排隊規(guī)則,數(shù)據(jù)包調(diào)度算法。

各種查找的哈希算法。

這部分策略化的代碼幾乎都是用“回調(diào)函數(shù)”實現(xiàn)的,這在另一方面烘托了Linux內(nèi)核也是模塊化設(shè)計的,且機制和策略分離,當需要一種新的算法時,只需要register一組新的回調(diào)函數(shù)即可。

然而,…

然而不夠完美,因為上述第2點,“內(nèi)核接口不穩(wěn)定”!即每一個內(nèi)核版本的數(shù)據(jù)結(jié)構(gòu)以及API都是不兼容的。

這意味著什么?

這意味著,即便是高度封裝好的算法模塊代碼,也需要為不同版本的Linux內(nèi)核維護一套代碼,當涉及內(nèi)核模塊由于版本問題不得不升級時,數(shù)據(jù)結(jié)構(gòu)和api的適配工作往往是耗時且出力不討好的。

但其實,很多算法根本就是與內(nèi)核數(shù)據(jù)結(jié)構(gòu),內(nèi)核api這些無關(guān)的。

兩個內(nèi)核版本,數(shù)據(jù)結(jié)構(gòu)只是字段變化了位置,新增了字段,更新了字段名字,即便如此,不得不對算法模塊進行重新編譯…

如果能在模塊載入內(nèi)核的時候,對函數(shù)和數(shù)據(jù)結(jié)構(gòu)字段進行重定位就好了!

我們的目標是,一次編寫,多次運行。

又是Facebook走在了前面,來自Facebook的BPF CO-RE(Compile Once – Run Everywhere):
http://vger.kernel.org/bpfconf2019_talks/bpf-core.pdf
沒錯,eBPF,就是它!

我們看下其描述:

BPF CO-RE talk discussed issues that developers currently run into when developing, testing, deploying, and running BPF applications at scale, taking Facebook’s experience as an example. Today, most types of BPF programs access internal kernel structures, which necessitates the need to compile BPF program’s C code “on the fly” on every single production machine due to changing struct/union layouts and definitions inside kernel. This causes many problems and inconveniences, starting from the need to have kernel sources available everywhere and in sync with running kernel, which is a hassle to set up and maintain. Reliance on embedded LLVM/Clang for compilation means big application binary size, increased memory usage, and some rare, but impactful production issues due to increased resource usage due to compilation. With current approach testing BPF programs against multitude of production kernels is a stressful, time-consuming, and error-prone process. The goal of BPF CO-RE is to solve all of those issues and move BPF app development flow closer to typical experience, one would expect when developing applications: compile BPF code once and distribute it as a binary. Having a good way to validate that BPF application will run without issues on all active kernels is also a must.

The complexity hides in the need to adjust compiled BPF assembly code to every specific kernel in production, as memory layout of kernel data structures changes between kernel versions and even different kernel build configurations. BPF CO-RE solution relies on self-describing kernel providing BTF type information and layout (ability to produce it was recently committed upstream). With the help from Clang compiler emitting special relocations during BPF compilation and with libbpf as a dynamic loader, it’s possible to reconciliate correct field offsets just before loading BPF program into kernel. As BPF programs are often required to work without modification (i.e., re-compilation) on multiple kernel versions/configurations with incompatible internal changes, there is a way to specify conditional BPF logic based on actual kernel version and configuration, also using relocations emitted from Clang. Not having to rely on kernel headers significantly improves the testing story and makes it possible to have a good tooling support to do pre-validation before deploying to production.

There are still issues which will have to be worked around for now. There is currently no good way to extract #define macro from kernel, so this has to be dealt with by copy/pasting the necessary definitions manually. Code directly relying on size of structs/unions has to be avoided as well, as it isn’t relocatable in general case. While there are some raw ideas how to solve issues like that in the future, BPF CO-RE developers prioritize providing basic mechanisms to allow “Compile Once - Run Everywhere” approach and significantly improve testing and pre-validation experience through better tooling, enabled by BPF CO-RE. As existing applications are adapted to BPF CO-RE, there will be new learning and better understanding of additional facilities that need to be provided to provide best developer experience possible.

該機制可以:

用eBPF的一組字節(jié)碼實現(xiàn)內(nèi)核模塊的一組回調(diào)函數(shù)。

對使用到的內(nèi)核數(shù)據(jù)結(jié)構(gòu)字段進行重定位,適配當前內(nèi)核的對應偏移。

后果就是:

很多內(nèi)核算法模塊可以用eBPF來編寫了。

Linux 5.6用TCP擁塞控制算法舉了一例,我們看一下:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=09903869f69f

可以看到,這個eBPF程序是與內(nèi)核版本無關(guān)的,你可以看到它的tcp_sock結(jié)構(gòu)體的定義:

struct tcp_sock { struct inet_connection_sock inet_conn; __u32 rcv_nxt; __u32 snd_nxt; __u32 snd_una; __u8 ecn_flags; __u32 delivered; __u32 delivered_ce; __u32 snd_cwnd; __u32 snd_cwnd_cnt; __u32 snd_cwnd_clamp; __u32 snd_ssthresh; __u8 syn_data:1, /* SYN includes data */ syn_fastopen:1, /* SYN includes Fast Open option */ syn_fastopen_exp:1,/* SYN includes Fast Open exp. option */ syn_fastopen_ch:1, /* Active TFO re-enabling probe */ syn_data_acked:1,/* data in SYN is acked by SYN-ACK */ save_syn:1, /* Save headers of SYN packet */ is_cwnd_limited:1,/* forward progress limited by snd_cwnd? */ syn_smc:1; /* SYN includes SMC */ __u32 max_packets_out; __u32 lsndtime; __u32 prior_cwnd;} __attribute__((preserve_access_index));

這里注意到兩點:

該結(jié)構(gòu)體并非內(nèi)核頭文件里的對應結(jié)構(gòu)體,它只包含了內(nèi)核對應結(jié)構(gòu)體里TCP CC算法用到的字段,它是內(nèi)核對應同名結(jié)構(gòu)體的子集。

preserve_access_index屬性表示eBPF字節(jié)碼在載入的時候,會對這個結(jié)構(gòu)體里的字段進行重定向,滿足當前內(nèi)核版本的同名結(jié)構(gòu)體字段的偏移。

我們在看下eBPF實現(xiàn)的TCP CC回調(diào)函數(shù)是個什么樣子:

BPF_TCP_OPS_3(tcp_reno_cong_avoid, void, struct sock *, sk, __u32, ack, __u32, acked){ struct tcp_sock *tp = tcp_sk(sk); if (!tcp_is_cwnd_limited(sk)) return; /* In "safe" area, increase. */ if (tcp_in_slow_start(tp)) { acked = tcp_slow_start(tp, acked); if (!acked) return; } /* In dangerous area, increase slowly. */ tcp_cong_avoid_ai(tp, tp->snd_cwnd, acked);}... SEC(".struct_ops")struct tcp_congestion_ops dctcp = { .init = (void *)dctcp_init, .in_ack_event = (void *)dctcp_update_alpha, .cwnd_event = (void *)dctcp_cwnd_event, .ssthresh = (void *)dctcp_ssthresh, .cong_avoid = (void *)tcp_reno_cong_avoid, .undo_cwnd = (void *)dctcp_cwnd_undo, .set_state = (void *)dctcp_state, .flags = TCP_CONG_NEEDS_ECN, .name = "bpf_dctcp",};

沒啥特殊的,幾乎和內(nèi)核模塊的寫法一樣,唯一不同的是:

它和內(nèi)核版本無關(guān)了。你用llvm/clang編譯出來.o字節(jié)碼將可以被載入到所有的內(nèi)核。

它讓人感覺這是在用戶態(tài)編程

是的,這就是在用戶態(tài)寫的TCP CC算法,eBPF字節(jié)碼的對應verifier會對你的代碼進行校驗,它不允許可以crash內(nèi)核的eBPF代碼載入,你的危險代碼幾乎無法通過verify。

如果你想搞明白這一切背后是怎么做到的,看兩個文件就夠了:

net/ipv4/bpf_tcp_ca.c

kernel/bpf/bpf_struct_ops.c

當然,經(jīng)理不會知道這意味著什么。

浙江溫州皮鞋濕,下雨進水不會胖。

原文標題:用eBPF寫TCP擁塞控制算法

文章出處:【微信公眾號:Linuxer】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

責任編輯:haq

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學習之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 內(nèi)核
    +關(guān)注

    關(guān)注

    4

    文章

    1468

    瀏覽量

    42881
  • TCP
    TCP
    +關(guān)注

    關(guān)注

    8

    文章

    1425

    瀏覽量

    83522

原文標題:用eBPF寫TCP擁塞控制算法

文章出處:【微信號:LinuxDev,微信公眾號:Linux閱碼場】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點推薦

    TCP/IP(Socket)協(xié)議深度剖析

    TCP/IP協(xié)議作為互聯(lián)網(wǎng)通信的基礎(chǔ)架構(gòu),其核心機制Socket編程承載著全球數(shù)據(jù)交換的使命。本文將深入剖析這一協(xié)議的七層架構(gòu)、三次握手與四次揮手的精妙設(shè)計、流量控制擁塞控制的動態(tài)平
    的頭像 發(fā)表于 03-03 17:06 ?497次閱讀

    PID控制算法

    PID及其衍生算法是應用最廣泛的算法之一,是當之無愧的萬能算法,如果能夠熟練掌握PID算法的設(shè)計與實現(xiàn)過程,對于一般的研發(fā)人員來講,應該是足夠應對一般研發(fā)問題了,而難能可貴的是,在我所
    發(fā)表于 01-23 08:18

    看透微突發(fā):利用 INT 技術(shù)實現(xiàn)交換機隊列級的實時擁塞告警

    星融元開發(fā)的 EasyRoCE-CMA 是基于 INT 技術(shù)的擁塞監(jiān)控工具 。它利用納秒級精度的 HDC 與 BDC 捕獲信息 ,實現(xiàn)交換機端口級擁塞與丟包的一站式可視化 。該工具能精準定位故障根因,輔助 AI 智算網(wǎng)絡(luò)快速調(diào)優(yōu) 。
    的頭像 發(fā)表于 01-16 15:29 ?1226次閱讀
    看透微突發(fā):利用 INT 技術(shù)實現(xiàn)交換機隊列級的實時<b class='flag-5'>擁塞</b>告警

    何用FPGA控制ADV7513實現(xiàn)HDMI畫面顯示和音頻播放

    HDMI接口顯示使用DMT時序+TMDS編碼來實現(xiàn)。當用FPGA控制HDMI的數(shù)據(jù)傳輸時,通??梢圆捎眉僐TL實現(xiàn)TMDS算法或者使用專門的HDMI芯片(如ADV7513)這兩種方案來完成。本文主要是介紹如何用FPGA
    的頭像 發(fā)表于 12-02 11:05 ?6814次閱讀
    如<b class='flag-5'>何用</b>FPGA<b class='flag-5'>控制</b>ADV7513實現(xiàn)HDMI畫面顯示和音頻播放

    ECN如何在HPC和數(shù)據(jù)中心中應對網(wǎng)絡(luò)擁塞

    ECN(Explicit Congestion Notification)是一種改進后的擁塞控制方法,它不依賴于丟包來指示擁塞,而是在數(shù)據(jù)包的頭部標記擁塞發(fā)生的信號。ECN通過向數(shù)據(jù)包
    的頭像 發(fā)表于 09-26 14:53 ?2672次閱讀
    ECN如何在HPC和數(shù)據(jù)中心中應對網(wǎng)絡(luò)<b class='flag-5'>擁塞</b>

    解析DCQCN:RDMA在數(shù)據(jù)中心網(wǎng)絡(luò)的關(guān)鍵擁塞控制協(xié)議

    DCQCN ( Data Center Quantized Congestion Notification),數(shù)據(jù)中心量化擁塞通知。它是一種專門為數(shù)據(jù)中心網(wǎng)絡(luò)設(shè)計的端到端擁塞控制協(xié)議。其核心目的是在使用RDMA(RoCEv2)
    的頭像 發(fā)表于 09-15 11:45 ?1868次閱讀
    解析DCQCN:RDMA在數(shù)據(jù)中心網(wǎng)絡(luò)的關(guān)鍵<b class='flag-5'>擁塞</b><b class='flag-5'>控制</b>協(xié)議

    PID控制算法學習筆記資料

    用于新手學習PID控制算法
    發(fā)表于 08-12 16:22 ?7次下載

    Modbus TCP 轉(zhuǎn) Modbus RTU電腦端 TCP 與西門子 V20 變頻器的通信案例

    在工業(yè)自動化控制系統(tǒng)中,經(jīng)常需要實現(xiàn)不同設(shè)備之間的通信與數(shù)據(jù)交互。本案例旨在展示如何通過 Modbus 協(xié)議,將電腦作為主站(Modbus TCP)與多臺西門子變頻器 V20(Modbus RTU
    的頭像 發(fā)表于 07-27 17:19 ?916次閱讀
    Modbus <b class='flag-5'>TCP</b> 轉(zhuǎn) Modbus RTU電腦端 <b class='flag-5'>TCP</b> 與西門子 V20 變頻器的通信案例

    基于eBPF的Kubernetes網(wǎng)絡(luò)異常檢測系統(tǒng)

    作為一名在云原生領(lǐng)域深耕多年的運維工程師,我見過太多因為網(wǎng)絡(luò)問題導致的生產(chǎn)事故。傳統(tǒng)的監(jiān)控手段往往是事后諸葛亮,當你發(fā)現(xiàn)問題時,用戶已經(jīng)在抱怨了。今天,我將分享如何利用 eBPF 這一革命性技術(shù),構(gòu)建一套能夠?qū)崟r檢測 Kubernetes 網(wǎng)絡(luò)異常的系統(tǒng)。
    的頭像 發(fā)表于 07-24 14:09 ?741次閱讀

    什么是Modbus TCP協(xié)議

    Modbus TCP是一種基于TCP/IP協(xié)議的Modbus通信協(xié)議,用于在客戶機和服務器之間進行數(shù)據(jù)通信。它常用于工業(yè)自動化控制、電力監(jiān)控與管理、溫濕度監(jiān)測等領(lǐng)域。Modbus TCP
    的頭像 發(fā)表于 07-23 17:18 ?4301次閱讀
    什么是Modbus <b class='flag-5'>TCP</b>協(xié)議

    何用AI負載為SONiC交換機調(diào)整ECN水線

    顯式擁塞通知(ECN)是計算機網(wǎng)絡(luò)中的一種機制,它允許發(fā)送設(shè)備明確地通知接收設(shè)備網(wǎng)絡(luò)擁塞,而不是依賴于傳統(tǒng)的“丟包”方法。在傳統(tǒng)的TCP/IP網(wǎng)絡(luò)中,當路由器或交換機出現(xiàn)擁塞時,它會丟
    的頭像 發(fā)表于 07-11 14:12 ?2599次閱讀
    如<b class='flag-5'>何用</b>AI負載為SONiC交換機調(diào)整ECN水線

    當CCLinkIE撞上Modbus TCP:照明控制系統(tǒng)的“方言戰(zhàn)爭”終結(jié)術(shù)

    在樓宇自動化系統(tǒng)中,新舊協(xié)議的兼容性問題常成為工程師的“隱形絆腳石”。CCLinkIE網(wǎng)絡(luò)的高速實時性與Modbus TCP照明控制器的通用性看似“天生對立”,但通過協(xié)議轉(zhuǎn)換方案,兩者可以實現(xiàn)“精準
    發(fā)表于 07-10 15:49

    CAN轉(zhuǎn)Modbus TCP網(wǎng)關(guān)賦能食品攪拌機智能協(xié)同控制

    在食品攪拌機的自動化控制系統(tǒng)中,設(shè)備通信協(xié)議的多樣性給系統(tǒng)集成帶來挑戰(zhàn)。JH-CAN-TCP疆鴻智能CAN主站轉(zhuǎn)Modbus TCP從站的網(wǎng)關(guān),成為連接西門子PLC與伺服系統(tǒng)的關(guān)鍵橋梁。 西門子
    的頭像 發(fā)表于 07-02 20:09 ?389次閱讀

    RDMA簡介7之可靠傳輸

    網(wǎng)絡(luò)無損,需要進行嚴格的流量控制擁塞管理。流量控制指通過調(diào)整發(fā)送端的發(fā)送速率,確保接收端能夠處理并接收所有數(shù)據(jù)包。RoCE v2使用了IEEE 802.11Qbb中提出的基于優(yōu)先級的流量控制
    發(fā)表于 06-13 10:01

    使用NXP 88W8801芯片組進行iPerf3測試期間TCP中的周期性丟包現(xiàn)象,怎么解決?

    OS: Linux Buildroot 內(nèi)核版本: 4.9.0-1 Interface : USB 問題描述: 我在 TCP iPerf3 測試期間遇到周期性丟包。使用以下命令執(zhí)行測試: bash
    發(fā)表于 04-02 06:53