HackMD
  • Prime
    Prime  Full-text search on all paid plans
    Search anywhere and reach everything in a Workspace with Prime plan.
    Got it
    • Prime  Full-text search on all paid plans
      Prime  Full-text search on all paid plans
      Search anywhere and reach everything in a Workspace with Prime plan.
      Got it
      • Sharing Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • More (Comment, Invitee)
      • Publishing
        Everyone on the web can find and read all notes of this public team.
        After the note is published, everyone on the web can find and read this note.
        See all published notes on profile page.
      • Commenting Enable
        Disabled Forbidden Owners Signed-in users Everyone
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Invitee
      • No invitee
      • Options
      • Versions and GitHub Sync
      • Transfer ownership
      • Delete this note
      • Template
      • Insert from template
      • Export
      • Dropbox
      • Google Drive
      • Gist
      • Import
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
      • Download
      • Markdown
      • HTML
      • Raw HTML
    Menu Sharing Help
    Menu
    Options
    Versions and GitHub Sync Transfer ownership Delete this note
    Export
    Dropbox Google Drive Gist
    Import
    Dropbox Google Drive Gist Clipboard
    Download
    Markdown HTML Raw HTML
    Back
    Sharing
    Sharing Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Note Permission
    Read
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    Write
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    More (Comment, Invitee)
    Publishing
    Everyone on the web can find and read all notes of this public team.
    After the note is published, everyone on the web can find and read this note.
    See all published notes on profile page.
    More (Comment, Invitee)
    Commenting Enable
    Disabled Forbidden Owners Signed-in users Everyone
    Permission
    Owners
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Invitee
    No invitee
       owned this note    owned this note      
    Published Linked with GitHub
    Like BookmarkBookmarked
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    Introduction to BPF Performance Tools - Mars Cheng === ###### tags: `COSCUP2020` `入門` `TR214` {%hackmd 7CD4pdKQTa2p6Y3VqH3VrQ %} > 請從這裡開始 slides: https://docs.google.com/presentation/d/1vjtrc5u33x4Oir06sJLIKuNfRDZIfjNOd7Xr04IhJ7k/ ## Who am I * TLKH Study club * interesting in BPF performance ## What is BPF ## extend BPF - 2011 classic BPF JIT - 2012 seccomp systemcall 對 file descriptor 限制的範圍 - 2013 eBPF merge 對設計簡單的 VM Instructions 做改善 - 2014 開 systemcall to user space - 2015-2017 perf_event added - can replace TCP 阻塞算法換 kernel module > 專注在 performance 應用 > BPF 通常比其他有效率 - trace-cmd trace-cmd -> kernel -> trace.dat post-processing -> result - bpf bpf progs-> kernel -> reult1(caculated by step 2) :::info perffomance is the currency of computing MIT 6.172 ::: > 較輕小 bpf 可以跑在 online 上 - bpf is programmable - 一般讀希望在 produce 放 kernel 的程式 - vpf 提供 sub kernel 驗證程式 - Tools for BPF performance ![](https://i.imgur.com/ygpXiMj.png) > 寫起來跟 awk 類似 ```bash bpftrace -e "kretprobe:vfs_read{@bytes=hits(retval);}" ``` type:identifier1 讀多少 bytes 的次數 - 對 CPU Bound 程式分析:分析最常被呼叫的 Function bpftrace -e 'profile:hz:49 /comm == "wc_nvive" / {@[ustack] = count();}' ### 舉例 1 - producer - Consumer Problem - produce list of words from files - update word frequency - find the max frequency of some word - Dessign Decisions - size of buffer - 太小會塞爆 - lock free 不容易設計 - 各開多少 thread ? - Naive Producer-Consumer Solution - 分析 - cpu 用了多少時間 - 或是 cpu 被 block 多少時間 - ![](https://i.imgur.com/ixEtTVJ.png) - 找 off cpu - Off-CPU analysis - 常見情形 - 主動 call system call - 被中斷等等 - 偵測方法 - 傳統方法全部列出來 - bpf 直接看 kernel status - tgid the thread ID of process - 看他 block 的時間和被喚回的時間差 - Producer 的 wait 不真正影響時間 - consumer - 何時 wait - queue 空的時候? - Use HeatMap to know - ## 舉例2 - gzip 壓縮一個檔案 - 哪部分用了最多的 memory - 找什麼時候觸發 page fault - 累積越多次就是觸發越多的路徑 - 可以知道哪部分佔最多 - 有時候 malloc 最多的地方可能不是 pagefault 最多的地方 - memory leak - 要了沒用 - malloc 被使用時去讀他的 stack trace - 把要多少 bytes 累加起來 - ## How to use bpf - really know your problem is - USE CPU and OFF CPU analysis to have a bird's eye view - 觀察 system call : clone 何時被執行 - Have basic knowledge of kernel and target SW - USE uprobe/probe/USDT to realize behaviors of a function - hist heatmap - Browse the tools ## - why bpf 做成 VM 跟有安全檢查的 kernel module 有啥不一樣 - 有 VM 的基本好處 sandbox 也可以直接對應到 machine code - VM 通常是不能 load 不太會 crash - Off cpu queue empty 改進方法 -

    Import from clipboard

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lost their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template is not available.


    Upgrade

    All
    • All
    • Team
    No template found.

    Create custom template


    Upgrade

    Delete template

    Do you really want to delete this template?

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Tutorials

    Book Mode Tutorial

    Slide Mode Tutorial

    YAML Metadata

    Contacts

    Facebook

    Twitter

    Feedback

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions

    Versions and GitHub Sync

    Sign in to link this note to GitHub Learn more
    This note is not linked with GitHub Learn more
     
    Add badge Pull Push GitHub Link Settings
    Upgrade now

    Version named by    

    More Less
    • Edit
    • Delete

    Note content is identical to the latest version.
    Compare with
      Choose a version
      No search result
      Version not found

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub

        Please sign in to GitHub and install the HackMD app on your GitHub repo. Learn more

         Sign in to GitHub

        HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Available push count

        Upgrade

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Upgrade

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully