• ubuntu 18.04 中 eBPF samples/bpf 编译


    1. history 信息

    一次成功编译 bpf 后执行 history 得到的信息:

    1. yingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$ history
    2. 1 ls
    3. 2 mkdir ex
    4. 3 cd ex
    5. 4 mkdir ex_kernel
    6. 5 ls /boot/
    7. 6 sudo apt install linux-source
    8. 7 ls /usr/src/
    9. 8 uname -r
    10. 9 cd ex_kernel/
    11. 10 wget http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/v5.x/linux-5.4.tar.gz
    12. 11 ls
    13. 12 tar zxf linux-5.4.tar.gz
    14. 13 ls
    15. 14 cd linux-5.4/
    16. 15 cp /boot/config-5.4.0-152-generic .config
    17. 16 make oldconfig
    18. 17 python --version
    19. 18 sudo apt install python3
    20. 19 python3 --version
    21. 20 python
    22. 21 sudo apt install -y bison build-essential cmake flex git libedit-dev pkg-config libmnl-dev python zlib1g-dev libssl-dev libelf-dev libcap-dev libfl-dev llvm clang pkg-config gcc-multilib luajit libluajit-5.1-dev libncurses5-dev libclang-dev clang-tools
    23. 22 make oldconfig
    24. 23 make prepare
    25. 24 make modules_prepare
    26. 25 make headers_install
    27. 26 make M=samples/bpf
    28. 27 cd samples/bpf
    29. 28 ls
    30. 29 ./sockex1
    31. 30 ./trace5
    32. 31 ./tracex5
    33. 32 ./sampleip
    34. 33 cd ..
    35. 34 l
    36. 35 wget
    37. 36 wget http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/v5.x/linux-5.4.1.tar.gz
    38. 37 ls
    39. 38 tar zxf linux-5.4.1.tar.gz
    40. 39 uname -r
    41. 40 cd linux-5.4.1/
    42. 41 cp /boot/config-5.4.0-152-generic .config
    43. 42 cd ..
    44. 43 cd linux-5.4
    45. 44 ls
    46. 45 cd samples/bpf/
    47. 46 ls
    48. 47 sudo ./tracex6
    49. 48 ls
    50. 49 sudo ./sockex1
    51. 50 cd ../../../linux-5.4.1/
    52. 51 ls
    53. 52 make oldconfig
    54. 53 make prepare
    55. 54 make modules_prepare
    56. 55 make headers_install
    57. 56 make M=samples/bpf
    58. 57 ls
    59. 58 cd samples/bpf/
    60. 59 ls
    61. 60 sudo ./sockex1
    62. 61 cd ../..
    63. 62 ls
    64. 63 cd ..
    65. 64 ls
    66. 65 git --version
    67. 66 sudo apt install nasm
    68. 67 ls
    69. 68 cd ..
    70. 69 mkdir asm_ex
    71. 70 cd ex
    72. 71 cd ex_kernel/
    73. 72 ls
    74. 73 cd linux-5.4
    75. 74 ls
    76. 75 make -j4
    77. 76 llc -version
    78. 77 ls
    79. 78 history
    80. yingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$

    2. 使用 ubuntu 18.04

        ubuntu 18.04 编译 BPF比较简单, ubuntu 22.04 适合系统熟手;

    找一台 旧机器,安装一个 ubuntu 18.0;

    使用国内源

    1. yingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$ cat /etc/apt/sources.list
    2. deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
    3. deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
    4. deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    5. deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    6. deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    7. deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    8. deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    9. deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    10. deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    11. deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    12. yingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$

             

    1. sudo apt update
    2. sudo apt upgrade

    3. 选择linux kernel 源代码版本

    1. $ name -r
    2. yingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$ uname -r
    3. 5.4.0-84-generic
    4. yingzhi@yingzhi-Host:~/ex/ex_kernel/linux-5.4$

    http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/v5.x/linux-5.4.1.tar.gz

    1. $ wget http://ftp.sjtu.edu.cn/sites/ftp.kernel.org/pub/linux/kernel/v5.x/linux-5.4.1.tar.gz
    2. $ tar dxf linux-5.4.1.tar.gz
    3. $ cd linux-5.4.1/
    4. # or 版本不一定合适
    5. $ sudo apt install linux-source
    6. $ ls /usr/src/

    4. 编译 bpf

    4.1 准备环境

    sudo apt install -y bison build-essential cmake flex git libedit-dev pkg-config libmnl-dev    python zlib1g-dev libssl-dev libelf-dev libcap-dev libfl-dev llvm clang pkg-config    gcc-multilib luajit libluajit-5.1-dev libncurses5-dev libclang-dev clang-tools

    4.2 拷贝当前系统的kernel 配置文件 .config

    $ cp /boot/config-5.4.0-152-generic /home/yingzhi/ex/ex_kernel/linux-5.4.1/.config

    4.3 编译ebpf samples

    1. $ cd /home/yingzhi/ex/ex_kernel/linux-5.4.1/
    2. $ make oldconfig
    3. $ make prepare
    4. $ make modules_prepare
    5. $ make headers_install
    6. $ make M=samples/bpf

    4.4 运行 示例

    ls ./samples/bpf/

    $ sudo ./sockex1

    5. bpf 原理

    5.1 架构

    5.2 编写并分析一个示例

    5.3 bpf map

    5.4 bpf trace

    5.5 bpf tool

    5.6 bpf && network

    5.7 xdp

    6. eBPF JIT

    7. 参考:

    1. 

    eBPF - Introduction, Tutorials & Community Resources

  • 相关阅读:
    阅读分享--重读Youtube深度学习推荐系统论文,字字珠玑,惊为神文
    「项目管理」甘特图制定项目计划的方法
    怎样做一个好的汇报
    室内渲染的艺术:创造理想空间的视觉魔法!
    这样封装echarts简单好用
    计算机网络-第2章物理层
    小学数学学习:神奇的走马灯数 142857
    微服务篇-B 深入理解SOA框架(Dubbo)_III SpringBoot整合Dubbo(学习总结)
    Springboot毕设项目婚车租赁系统的设计与实现hsh20(java+VUE+Mybatis+Maven+Mysql)
    pdf误删恢复如何恢复?分享4种恢复方法!
  • 原文地址:https://blog.csdn.net/eloudy/article/details/132952341