liuhangbin / liuhangbin.github.io Goto Github PK
View Code? Open in Web Editor NEWHangbin Liu's blog
Hangbin Liu's blog
https://liuhangbin.netlify.com/post/linux-perf-usage/
Brendan D. Gregg perf examples
Install 1 # yum install -y perf TODO: How to build, Kernel build options
Usage one line cmd statistics/count: increment an integer counter on events
sample: collect details (eg, instruction pointer or stack) from a subset of events (once every …)
trace: collect details from every event
list event List events: perf list
List specific tracepoint event:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 # perf list "net:" List of pre-defined events (to be used in -e): net:napi_gro_frags_entry [Tracepoint event] net:napi_gro_receive_entry [Tracepoint event] net:net_dev_queue [Tracepoint event] net:net_dev_xmit [Tracepoint event] net:netif_receive_skb [Tracepoint event] net:netif_receive_skb_entry [Tracepoint event] net:netif_rx [Tracepoint event] net:netif_rx_entry [Tracepoint event] net:netif_rx_ni_entry [Tracepoint event] # perf list "skb:" List of pre-defined events (to be used in -e): skb:consume_skb [Tracepoint event] skb:kfree_skb [Tracepoint event] skb:skb_copy_datagram_iovec [Tracepoint event] count event Count net events for the entire system, for 10 seconds:
https://liuhangbin.netlify.com/post/lkp/
How to install lkp on RHEL/CentOS/Fedora
git clone https://github.com/01org/lkp-tests.git cd lkp-tests && make install && cd ~ 1 2 3 4 5 6 7 8 on RHEL: # mv /etc/redhat-release /etc/centos-release # rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm # yum makecache fast # yum install kernel-debuginfo on Fedora: # dnf install kernel-debug mkdir -p /lkp/benchmarks ## BENCHMARK_ROOT=/lkp/benchmarks, but lkp didn’t init it, bug? run hackbench mkdir -p /lkp/benchmarks/turbostat lkp install lkp-tests/jobs/hackbench.
https://liuhangbin.netlify.com/post/how-to-create-github-pr/?code=74c1b18a693719669e87
As more and more open source codes start to use github to maintain their code and use pull requests to accept new patches. In this artical I will introduce how to create a github PR(Pull Requests).
For the detils of github PR, please see this page.
You need to have a github account :) Open the project you want to contribute. I will use CKI-project as my example Click “Fork” on the right top of the page.
https://liuhangbin.netlify.com/post/common-problems/
Python in RHEL8 Use alternatives --set python /usr/bin/python3 to set a specific version
Reference Python in RHEL8 and the reason
Liu, I am very grateful for your article. I have learned a lot from it😀👍.
But there seems to be no Chinese version, can I repost them and create a Chinese version for education purpose?
I will meticulously note the source.
https://liuhangbin.netlify.com/post/virtual-ifaces/
Introduction In this post I will give a brief introduction for all commonly used virtual interfaces. There is no code analysis. Only brief introduction and the usage on Linux. So anyone with a network background could have a look at this blog post. The interface list can be obtained with the command ip link help.
The first part is some frequently used interfaces and some interfaces that can be easily confused with one another.
https://liuhangbin.netlify.com/post/linux-tc-usage/
TC, means traffic control, can be achieved by using queuing disciplines(qdisc). Here is an example picture Classes There are two kinds of qdiscs, classless and classfull. Classless qciscs can only have a single scheduler assigned, can’t contain more classes Pfifo: limits the size of a queue by packtets Bfifo: limits the size of a queue by bytes Pfifo_fast: contains 3 fifo queues, from 0 to 2. 0 get the packets
https://liuhangbin.netlify.com/post/xdp-tc-ebpf-programing/
=== XDP Programing
Reference: another example code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 // SPDX-License-Identifier: GPL-2.
https://liuhangbin.netlify.com/post/virtual-iface-tunnels/
Introduction “An IP tunnel is an Internet Protocol (IP) network communications channel between two networks. It is used to transport another network protocol by encapsulation of its packets.” quote from Wikipedia.
Linux has supported many kinds of tunnels, but new users often get confused by their differences and about which one is best suited for a given use case. In this post, I will give a brief introduction for commonly used tunnel interfaces in the Linux kernel.
https://liuhangbin.netlify.com/post/mpls-on-linux/
MPLS Multiprotocol Label Switching is a routing protocol, which works in layer 2.5. It insert a lable between IP layer and protocol layer. This looks like VLAN, which works in layer 1.5 and in subnet. But MPLS works in global internet.
Enable MPLS Routing Some distribution may build mpls route as a module, so before start, please check if you have /proc/sys/net/mpls/, if not, then load the module first:
https://liuhangbin.netlify.com/post/netlink/
Create a socket struct sockaddr_nl { sa_family_t nl_family; /* AF_NETLINK / unsigned short nl_pad; / Zero. / pid_t nl_pid; / Port ID. / __u32 nl_groups; / Multicast groups mask. */ };
nl_pid = 0 // if the destination is in the kernel nl_pid = getpid() // For a user-space process
socket(AF_NETLINK, socket_type, netlink_family)
socket type: SOCK_RAW / SOCK_DGRAM
netlink family: NETLINK_ROUTE Routing tables, IP addresses, link parameters, neighbor setups, traffic classes, etc.
https://liuhangbin.netlify.com/post/syzkaller/
syzkaller source code
Some tips about how to use syzkaller how to unpack corpus
1 bin/syz-db unpack corpus.db corpus_dir How to setup build env before submit a patch Note: in this part you need to download and install a lot devel packages, syzkaller, kernel source code. Please leave at least 5G space for it.
When you want to write testcase for syzkaller, taking one of my patch as example, you may feel confused about how to wirte the .
https://liuhangbin.netlify.com/post/docker/
Install docker Reference https://yeasy.gitbooks.io/docker_practice/install/centos.html
Create docker group 1 2 3 4 5 6 $ sudo groupadd docker $ sudo usermod -aG docker $USER or $ sudo gpasswd -a $USER docker Start docker Pull image 1 2 3 $ docker run hello-world $ docker pull ubuntu:latest $ docker pull fedora:29 Start container 1 2 3 4 5 6 7 8 9 $ docker run unbutu:latest /bin/echo 'Hello World' $ docker run -t -i ubuntu:latest /bin/bash $ docker run -dit bash $ docker container ls $ docker attach $id <- container will stop after exit stdin $ docker exec -it $id bash $ docker container stop $id Show netns with ip 1 2 3 $ docker inspect -f '{{.
https://liuhangbin.netlify.com/post/ebpf-and-xdp/
What is eBPF Reference: bpf
The extended Berkeley Packet Filter (eBPF) has first appeared in Kernel 3.18. The original version is being referred to “classic” BPF (cBPF) . cBPF is known to many as being the packet filter language used by tcpdump.
Nowadays, the Linux kernel runs eBPF only and loaded cBPF bytecode is transparently translated into an eBPF representation in the kernel before program execution.
The eBPF networking specific use including loading BPF programs with tc (traffic control) and XDP (eXpress Data Path).
https://liuhangbin.netlify.com/post/grub/
Apart from edit /boot/grub2/grub.cfg or /etc/grub2.cfg. We’d better use grubby to config grub.
Here is the example of how to select default grub.
1 2 3 4 5 6 7 8 9 10 11 12 13 # grubby --default-kernel /boot/vmlinuz-4.20.0 # grubby --default-index 1 # grubby --set-default-index 0 # grubby --default-index 0 # grubby --default-kernel /boot/vmlinuz-4.20.0+ Grub missing If grub missing due to anyreason, and you are fall back to grub menu, you can try
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.