精品国产人成在线_亚洲高清无码在线观看_国产在线视频国产永久2021_国产AV综合第一页一个的一区免费影院黑人_最近中文字幕MV高清在线视频

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

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

3天內不再提示

eBPF技術實踐之virtio-net網卡隊列可觀測

Linux閱碼場 ? 來源:Linux閱碼場 ? 2024-11-14 11:18 ? 次閱讀

在系統領域中,最具挑戰性的問題通常是組件之間的邊界定位。其中,virtio-net前后端的定界尤為困難。當網絡報文從內核發送到virtio-net后端,或者從virtio-net后端發送到內核時,這一路徑難以進行觀測。一些復雜的網絡抖動問題很可能是由于網卡隊列不正常工作引起的。為了解決這類問題,我們基于eBPF技術擴展了網卡隊列的可觀測能力,使得virtio網卡前后端的定界問題不再困擾。

virtio-net 前后端驅動簡介

virtio-net (后面稱為 virtio 網卡)通常由兩個組件組成:virtio driver(也稱為virtio前端)和virtio device(也稱為virtio后端)。virtio前端運行在客戶機的內核中,而virtio后端可以由宿主機的內核承擔。virtio網卡通常支持多隊列,包括發送隊列和接收隊列。每個隊列通過三個 ring 來實現,即avail ring、used ring和desc ring。現在我們將重點介紹 virtio 網卡前端的報文發送和接收流程,以更好地理解整個工作流程。

virtio 網卡前端發送報文

virto網卡前端發送報文主要流程包括:

a.start_xmit:virtio網卡驅動的報文發送入口函數會首先清理已發送的報文,即通過調用free_old_xmit_skbs函數來釋放描述符中的報文,直到avail->idx等于used->idx為止;

b.xmit_skb:主要是為報文添加vnet_hdr頭部信息,并將skb以scatter-gather形式顯示,以記錄報文數據的地址和長度信息;

c.virtqueue_add_outbuf:進行DMA映射,將scatter-gather記錄的報文數據地址和長度信息添加到desc環中,并增加avail->idx的值;

d.virtqueue_notify:當發送隊列存在數據,則通知后端。

7aaa4c30-9069-11ef-a511-92fbcf53809c.png

virtio 網卡前端接收報文

virito網阿卡前端接收報文主要流程包括:

a.網卡硬中斷:硬中斷會將napi加入到CPU的處理隊列,并啟用中斷抑制,以及觸發軟中斷;

b.net_rx_action:網絡軟中斷入口函數;

c.virtnet_poll:這個函數是virtio網卡的NAPI poll的回調函數。如果當前隊列是發送隊列,它將清理發送隊列,也就是執行virtnet_poll_cleantx函數。如果當前隊列是接收隊列,它將進行報文的接收;

d.virtnet_receive:根據used->idx的值,從描述符環中讀取報文數據,并更新last_used_idx。內核會為報文數據分配skb,并進入GRO流程,進行報文的合并;e.try_fill_recv:要給desc環添加空的內存區域,并增加avail->idx的值,以確保接收隊列始終有可用的內存;

f.virtqueue_napi_complete:當接收的報文數量少于預定的budget(一般為64)時,表示沒有更多的數據可以接收。這時,調用virtqueue_napi_complete來表示單次napi處理完畢。同時,通過virtqueue_enable_cb_prepare來關閉中斷抑制。

7adc430c-9069-11ef-a511-92fbcf53809c.png

網卡隊列可觀測

經過前面的分析,我們了解到virtio網卡隊列中的幾個重要參數,即avail->idx、used->idx和last_used_idx。使用這些參數,我們可以清晰地了解網卡隊列當前包含的報文數量,并進一步得到以下可觀測指標:

a.發送隊列報文數:表示尚未被virtio網卡后端發送的報文數量。計算方法是avail->idx - used->idx;

b.接收隊列報文數:表示尚未被virtio網卡前端接收的報文數量。計算方法是used->idx - last_used_idx;

c.網卡隊列的last_used_idx:表示virtio網卡后端處理報文的進度;

d.隊列飽和度:表示當前網卡隊列使用量,計算方法是隊列報文數/隊列長度。

工作原理

我們將可觀測的代碼集成在了rtrace的工具里,rtrace是龍蜥社區推出的系統工具集SysAK的一個網絡診斷分析工具,關于rtrace的具體原理,我們將在下回分析,eBPF 具體代碼請參考代碼:

https://gitee.com/anolis/sysak/blob/opensource_branch_sync/source/tools/detect/net/rtrace/src/bpf/virtio.bpf.c

virtio 網卡隊列指標采集的主要流程如下:

a.rtrace掛載eBPF采集程序到內核dev_id_show和dev_port_show函數;

b.rtrace周期性讀取/sys/class/net/[interface]/dev_id和/sys/class/net/[interface]/dev_port兩個文件,其中dev_id文件用來表示采集發送隊列信息,dev_port文件用來表示采集接收隊列信息;

c.當讀取文件時,會觸發內核執行dev_id_show和dev_port_show兩個函數。由于已經掛載了eBPF采集程序,內核會先執行eBPF采集程序;

d.eBPF采集程序通過解析dev_id_show和dev_port_show入參struct net_device獲取網卡隊列vring,然后從vring中解析出avail idx、used idx、隊列長度和last_used_idx;

e.將數據發送給rtrace做進一步處理。

7af93be2-9069-11ef-a511-92fbcf53809c.png

故障檢測

下面是rtrace采集的網卡隊列信息輸出。

我們可以看到0926的1號發送隊列的飽和度和last_used_idx分別是0.05%/3593,0928的1號發送隊列的飽和度和last_used_idx分別是0.07%/3593,可以看到發送隊列的飽和度在增加,但是last_used_idx在多個采集周期內保持不變。因此,可以確定1號發送隊列出現了故障。

隨后我們修復了1號發送隊列故障,可以看見在0906的1號發送隊列飽和度和last_used_idx分別是0.00%/3599,隊列里面不再有駐留的報文,恢復了正常。

0924
SendQueue0.05%/35930.00%/8520.00%/45060.00%/16000.00%/4570.00%/5090.00%/31400.00%/13520.00%/3860.00%/4100.00%/17140.00%/17580.00%/16190.00%/4460.00%/35770.00%/24430.00%/460.00%/940.00%/2120.00%/2310.00%/1460.00%/1480.00%/2260.00%/640.00%/1090.00%/840.00%/780.00%/560.00%/870.00%/880.00%/850.00%/52
RecvQueue0.00%/28050.00%/132970.00%/4750.00%/3670.00%/123780.00%/1300.00%/2220.00%/111200.00%/3550.00%/30160.00%/1330.00%/1800.00%/129800.00%/103630.00%/28250.00%/6500.00%/1510.00%/5050.00%/51800.00%/2000.00%/266700.00%/1690.00%/10420.00%/98200.00%/95860.00%/33740.00%/2290.00%/14020.00%/87960.00%/1170.00%/3010.00%/275
0925
SendQueue0.05%/35930.00%/8520.00%/45060.00%/16000.00%/4570.00%/5090.00%/31400.00%/13520.00%/3860.00%/4100.00%/17140.00%/17580.00%/16190.00%/4460.00%/35770.00%/24440.00%/460.00%/940.00%/2120.00%/2310.00%/1460.00%/1480.00%/2260.00%/640.00%/1090.00%/840.00%/780.00%/560.00%/870.00%/890.00%/850.00%/52
RecvQueue0.00%/28050.00%/132970.00%/4750.00%/3670.00%/123780.00%/1300.00%/2220.00%/111200.00%/3550.00%/30160.00%/1330.00%/1800.00%/129800.00%/103630.00%/28250.00%/6500.00%/1510.00%/5050.00%/51800.00%/2000.00%/266700.00%/1690.00%/10420.00%/98200.00%/95860.00%/33740.00%/2290.00%/14020.00%/87960.00%/1170.00%/3030.00%/275
0926
SendQueue0.05%/35930.00%/8520.00%/45060.00%/16000.00%/4570.00%/5090.00%/31400.00%/13520.00%/3860.00%/4100.00%/17140.00%/17580.00%/16190.00%/4460.00%/35770.00%/24440.00%/460.00%/940.00%/2120.00%/2310.00%/1460.00%/1480.00%/2260.00%/640.00%/1090.00%/840.00%/780.00%/560.00%/870.00%/910.00%/850.00%/52
RecvQueue0.00%/28050.00%/132970.00%/4750.00%/3670.00%/123780.00%/1300.00%/2220.00%/111200.00%/3550.00%/30160.00%/1330.00%/1800.00%/129800.00%/103630.00%/28250.00%/6500.00%/1510.00%/5050.00%/51800.00%/2000.00%/266700.00%/1690.00%/10420.00%/98200.00%/95860.00%/33740.00%/2290.00%/14020.00%/87960.00%/1170.00%/3050.00%/275
0927
SendQueue0.07%/35930.00%/8520.00%/45060.00%/16000.00%/4570.00%/5090.00%/31400.00%/13520.00%/3860.00%/4100.00%/17140.00%/17580.00%/16190.00%/4460.00%/35770.00%/24440.00%/460.00%/940.00%/2120.00%/2310.00%/1460.00%/1480.00%/2260.00%/640.00%/1090.00%/840.00%/780.00%/560.00%/870.00%/930.00%/850.00%/52
RecvQueue0.00%/28050.00%/132980.00%/4750.00%/3670.00%/123780.00%/1300.00%/2220.00%/111200.00%/3550.00%/30160.00%/1330.00%/1800.00%/129800.00%/103630.00%/28250.00%/6500.00%/1510.00%/5050.00%/51800.00%/2000.00%/266700.00%/1690.00%/10420.00%/98200.00%/95860.00%/33740.00%/2290.00%/14020.00%/87960.00%/1170.00%/3070.00%/275
0928
SendQueue0.07%/35930.00%/8520.00%/45060.00%/16000.00%/4570.00%/5090.00%/31400.00%/13520.00%/3860.00%/4140.00%/17140.00%/17580.00%/16190.00%/4460.00%/35770.00%/24450.00%/460.00%/940.00%/2120.00%/2310.00%/1460.00%/1490.00%/2260.00%/640.00%/1090.00%/840.00%/780.00%/560.00%/870.00%/960.00%/870.00%/52
RecvQueue0.00%/28050.00%/132980.00%/4750.00%/3670.00%/123780.00%/1300.00%/2220.00%/111200.00%/3550.00%/30160.00%/1330.00%/1800.00%/129800.00%/103630.00%/28250.00%/6500.00%/1510.00%/5050.00%/51800.00%/2050.00%/266700.00%/1690.00%/10420.00%/98200.00%/95860.00%/33740.00%/2290.00%/14020.00%/87970.00%/1180.00%/3090.00%/275
0929
SendQueue0.07%/35930.00%/8520.00%/45060.00%/16000.00%/4570.00%/5090.00%/31400.00%/13520.00%/3860.00%/4140.00%/17140.00%/17580.00%/16190.00%/4460.00%/35770.00%/24450.00%/460.00%/940.00%/2120.00%/2310.00%/1460.00%/1490.00%/2260.00%/640.00%/1090.00%/840.00%/780.00%/560.00%/870.00%/980.00%/870.00%/52
RecvQueue0.00%/28050.00%/132980.00%/4750.00%/3670.00%/123780.00%/1300.00%/2220.00%/111200.00%/3550.00%/30160.00%/1330.00%/1800.00%/129800.00%/103630.00%/28250.00%/6500.00%/1510.00%/5050.00%/51800.00%/2050.00%/266700.00%/1690.00%/10420.00%/98200.00%/95860.00%/33740.00%/2290.00%/14020.00%/87970.00%/1180.00%/3110.00%/275
0930
SendQueue0.07%/35930.00%/8520.00%/45060.00%/16000.00%/4570.00%/5090.00%/31400.00%/13520.00%/3860.00%/4140.00%/17140.00%/17580.00%/16190.00%/4460.00%/35770.00%/24450.00%/460.00%/940.00%/2120.00%/2310.00%/1460.00%/1490.00%/2260.00%/640.00%/1090.00%/840.00%/780.00%/560.00%/870.00%/1000.00%/870.00%/52
RecvQueue0.00%/28050.00%/132980.00%/4750.00%/3670.00%/123780.00%/1300.00%/2220.00%/111200.00%/3550.00%/30160.00%/1330.00%/1800.00%/129800.00%/103630.00%/28250.00%/6500.00%/1510.00%/5050.00%/51800.00%/2050.00%/266700.00%/1690.00%/10420.00%/98200.00%/95860.00%/33740.00%/2290.00%/14020.00%/87970.00%/1180.00%/3130.00%/275
//...省略
0906
SendQueue0.00%/35990.00%/8560.00%/45110.00%/16020.00%/4650.00%/5100.00%/31400.00%/13520.00%/3860.00%/4200.00%/17160.00%/17660.00%/16190.00%/4480.00%/35780.00%/24510.00%/460.00%/940.00%/2120.00%/2310.00%/1480.00%/1490.00%/2260.00%/640.00%/1090.00%/850.00%/870.00%/560.00%/870.00%/1010.00%/1030.00%/52
RecvQueue0.00%/28070.00%/132990.00%/4770.00%/3690.00%/123780.00%/1400.00%/2230.00%/111200.00%/3550.00%/30320.00%/1420.00%/1800.00%/129800.00%/103630.00%/28250.00%/6520.00%/1510.00%/5050.00%/51800.00%/2050.00%/266700.00%/1700.00%/10570.00%/98200.00%/95860.00%/33740.00%/2300.00%/14140.00%/88000.00%/1180.00%/3270.00%/275

總結

在virtio網卡中,前端和后端之間通過共享的網卡隊列進行通信。為了更好地理解和觀測網卡隊列的狀態和性能指標,通過觀測avail idx、used idx、last_used_idx等指標,我們可以對virtio網卡的性能進行評估和優化。同時,這些指標也為我們提供了對網卡隊列狀態的深入理解,有助于進行故障排查和性能調優。

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 數據
    +關注

    關注

    8

    文章

    6888

    瀏覽量

    88826
  • 網卡
    +關注

    關注

    3

    文章

    303

    瀏覽量

    27336
  • 程序
    +關注

    關注

    116

    文章

    3775

    瀏覽量

    80845

原文標題:eBPF 技術實踐之 virtio-net 網卡隊列可觀測

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

收藏 人收藏

    評論

    相關推薦

    4G模組UDP應用的最佳實踐

    今天說的是4G模組UDP應用,展示最佳實踐,送你參考。
    的頭像 發表于 11-08 09:24 ?183次閱讀
    4G模組<b class='flag-5'>之</b>UDP應用的最佳<b class='flag-5'>實踐</b>!

    破局新生丨基調聽云可觀測性與應用安全技術研討會在平潭圓滿舉辦

    、制造、科技、能源、政企、互聯網等多個行業的決策層領導,共同探討可觀測性與應用安全技術在企業數字化轉型中的熱點應用和實踐。大會由基調聽云銷售VP李甜甜主持,她在介
    的頭像 發表于 10-29 16:01 ?343次閱讀
    破局新生丨基調聽云<b class='flag-5'>可觀測</b>性與應用安全<b class='flag-5'>技術</b>研討會在平潭圓滿舉辦

    【質量視角】可觀測性背景下的質量保障思路

    目前質量團隊正在積極建設和完善應用監控能力,旨在能及時發現并解決問題,為線上服務穩定性保駕護航。隨著可觀測性概念的逐漸普及,監控的建設也有了新的挑戰和使命。本文將探討在可觀測性背景下,作為一個測試
    的頭像 發表于 10-25 17:21 ?201次閱讀
    【質量視角】<b class='flag-5'>可觀測</b>性背景下的質量保障思路

    網卡的演進和應用

    隨著云計算和虛擬化技術的發展,網卡在功能和硬件結構方面也經歷了四個階段,即網卡、智能網卡、基于FPGA的DPU和DPU SoC網卡。本文將重
    的頭像 發表于 10-24 16:45 ?224次閱讀
    <b class='flag-5'>網卡</b>的演進和應用

    華為云發布全棧可觀測平臺 AOM,以 AI 賦能應用運維可觀測

    應用可用性與穩定性。 該平臺發布標志著華為云在推動數字化轉型和智能化運維領域的又一重大突破,全棧可觀測平臺的推出不僅為企業提供了更加全面和深入的系統監控和數據分析能力,還通過集成先進的人工智能技術,實現了對復雜應用環境的實時優化和問題預警。 應用
    的頭像 發表于 10-15 09:54 ?469次閱讀
    華為云發布全棧<b class='flag-5'>可觀測</b>平臺 AOM,以 AI 賦能應用運維<b class='flag-5'>可觀測</b>

    嵌入式環形隊列與消息隊列的實現原理

    嵌入式環形隊列,也稱為環形緩沖區或循環隊列,是一種先進先出(FIFO)的數據結構,用于在固定大小的存儲區域中高效地存儲和訪問數據。其主要特點包括固定大小的數組和兩個指針(頭指針和尾指針),分別指向隊列的起始位置和結束位置。
    的頭像 發表于 09-02 15:29 ?337次閱讀

    玩轉RT-Thread消息隊列的應用

    在嵌入式系統開發中,實時處理串口和ADC數據是一項重要的任務。本文將介紹如何在RT-Thread實時操作系統中,利用消息隊列來同時處理來自串口和ADC的數據。通過這種方法,我們能夠高效地管理和處理
    的頭像 發表于 07-23 08:11 ?546次閱讀
    玩轉RT-Thread<b class='flag-5'>之</b>消息<b class='flag-5'>隊列</b>的應用

    Net5.5G,全球運營商的AI

    在AI時代飛翔,運營商的Net5.5G共識與實踐
    的頭像 發表于 07-05 16:12 ?582次閱讀
    <b class='flag-5'>Net</b>5.5G,全球運營商的AI<b class='flag-5'>之</b>翼

    DataDog和Dynatrace缺席,觀測云成為中國峰會的明星

    在亞馬遜云科技中國峰會的圓滿落幕之際,國內監控觀測服務的佼佼者——觀測云,以其在中國可觀測性領域的杰出表現,榮獲了中國峰會獨家榮譽。盡管全球知名的監控觀測品牌DataDog和Dynat
    的頭像 發表于 06-04 17:13 ?388次閱讀

    網卡揭秘:如何選擇適合您需求的網卡

    基于以太網技術,隨著網絡技術的發展,光纖通信逐漸成為主流,光纖網卡因此誕生。光纖網卡通過光纖傳輸數據,相比傳統銅線,具有更遠的傳輸距離和更高的帶寬。
    的頭像 發表于 04-10 10:04 ?631次閱讀
    光<b class='flag-5'>網卡</b>揭秘:如何選擇適合您需求的<b class='flag-5'>網卡</b>

    MCU專屬隊列功能模塊QueueForMcu應用

    當需要從隊列頭部獲取多個數據,但又不希望數據從隊列中刪除時,可以使用 Queue_Peek_Array 函數來實現,該函數的參數與返回值與 Queue_Pop_Array 完全相同。
    發表于 03-20 11:44 ?417次閱讀
    MCU專屬<b class='flag-5'>隊列</b>功能模塊<b class='flag-5'>之</b>QueueForMcu應用

    eBPF動手實踐系列三:基于原生libbpf庫的eBPF編程改進方案簡析

    在上一篇文章《eBPF動手實踐系列二:構建基于純C語言的eBPF項目》中,我們初步實現了脫離內核源碼進行純C語言eBPF項目的構建。libbpf庫在早期和內核源碼結合的比較緊密,如今的
    的頭像 發表于 03-19 14:19 ?764次閱讀
    <b class='flag-5'>eBPF</b>動手<b class='flag-5'>實踐</b>系列三:基于原生libbpf庫的<b class='flag-5'>eBPF</b>編程改進方案簡析

    基于原生libbpf庫的eBPF編程改進方案

    為了簡化 eBPF程序的開發流程,降低開發者在使用 libbpf 庫時的入門難度,libbpf-bootstrap 框架應運而生。基于libbpf-bootstrap框架的編程方案是目前網絡上看到的最主流編程方案。
    發表于 03-19 14:19 ?579次閱讀
    基于原生libbpf庫的<b class='flag-5'>eBPF</b>編程改進方案

    如何構建APISIX基于DeepFlow的統一可觀測性能力呢?

    隨著應用組件的可觀測性逐漸受到重視,Apache APISIX 引入插件機制豐富了可觀測數據源。
    的頭像 發表于 01-18 10:11 ?914次閱讀
    如何構建APISIX基于DeepFlow的統一<b class='flag-5'>可觀測</b>性能力呢?

    聊一聊消息隊列技術選型的7種消息場景

    我們在做消息隊列技術選型時,往往會結合業務場景進行考慮。今天來聊一聊消息隊列可能會用到的 7 種消息場景。
    的頭像 發表于 12-09 17:50 ?1319次閱讀
    聊一聊消息<b class='flag-5'>隊列</b><b class='flag-5'>技術</b>選型的7種消息場景