SlideShare a Scribd company logo
1 of 24
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
The Next Linux Superpower:
eBPF Primer
Sasha Goldshtein
CTO, Sela Group
@goldshtn
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Agenda
• Modern Linux tracing landscape
• BPF
• BCC – BPF Compiler Collection
• Using BCC tools
• Authoring BCC tools
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Linux Tracing Tools, Today
Ease of use
BPF/BCC
SysDig
ktap
SystemTap
LTTng
ftrace
perf
custom .ko
new stable dead
Level of detail, features
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Berkeley Packet Filters (BPF)
• Originally designed for, well, packet filtering:
dst port 80 and len >= 100
• Custom instruction set, interpreted/JIT compiled
• Verified to be safe: no unsafe memory accesses, no backward jumps
0: (bf) r6 = r1
1: (85) call 14
2: (67) r0 <<= 32
3: (77) r0 >>= 32
4: (15) if r0 == 0x49f goto pc+40
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Extended BPF (3.18 and ongoing)
• Attach BPF programs to kprobes/uprobes (4.1) and tracepoints (4.7)
• Data structures: array, hash (expandable), stack map (4.6)
• Output to trace buffer (4.3) and perf cyclic buffer (4.4)
• Helper functions: get time, get current comm, get current CPU, etc.
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
BCC: BPF Compiler Collection
• Library and Python/Lua module for compiling, loading, and executing
BPF programs
• Compile BPF program from C source
• Attach BPF program to kprobe/uprobe/tracepoint/USDT/socket
• Poll data from BPF program using Python/Lua
• Can do in-kernel aggregation and filtering
• Growing collection of tracing and performance tools
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
BCC
• The BCC repository contains a variety of existing scripts and tools to
get you started
• The BPF module (Python/Lua) can be used to build new tools or one-
off scripts
$ ls.py
argdist.py
bashreadline.py
biolatency.py
biosnoop.py
biotop.py
bitesize.py
btrfsdist.py
btrfsslower.py
cachestat.py
cpudist.py
dcsnoop.py
dcstat.py
execsnoop.py
ext4dist.py
ext4slower.py
filelife.py
fileslower.py
filetop.py
funccount.py
funclatency.py
gethostlatency.py
hardirqs.py
killsnoop.py
mdflush.py
memleak.py
offcputime.py
offwaketime.py
oomkill.py
opensnoop.py
pidpersec.py
runqlat.py
softirqs.py
solisten.py
stackcount.py
stacksnoop.py
statsnoop.py
syncsnoop.py
tcpaccept.py
tcpconnect.py
tcpconnlat.py
tcpretrans.py
tplist.py
trace.py
vfscount.py
vfsstat.py
wakeuptime.py
xfsdist.py
xfsslower.py
zfsdist.py
zfsslower.py
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Specialized Tools
# ./hardirqs.py
Tracing hard irq event time... Hit Ctrl-C to end.
^C
HARDIRQ TOTAL_usecs
virtio0-input.0 959
ahci[0000:00:1f.2] 1290
# ./biolatency.py
Tracing block device I/O... Hit Ctrl-C to end.
^C
usecs : count distribution
64 -> 127 : 7 |********* |
128 -> 255 : 14 |****************** |
256 -> 511 : 5 |****** |
512 -> 1023 : 30 |****************************************|
1024 -> 2047 : 1 |* |
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Specialized Tools
# ./filetop.py
01:35:51 loadavg: 0.01 0.04 0.03 2/139 3611
PID COMM READS WRITES R_Kb W_Kb T FILE
2496 sshd 3 1 48 0 O ptmx
2939 screen 4 1 16 0 O ptmx
2496 sshd 1 3 16 0 S TCP
3611 clear 2 0 8 0 R screen
2939 screen 1 3 4 0 O 0
3589 filetop.py 2 0 2 0 R loadavg
3611 clear 1 0 0 0 R libtinfo.so.5.9
3611 clear 1 0 0 0 R libc-2.21.so
3611 filetop.py 3 0 0 0 R clear
3611 filetop.py 2 0 0 0 R ld-2.21.so
3611 clear 0 1 0 0 O 2
3589 filetop.py 0 3 0 0 O 2
# ./cachestat.py
HITS MISSES DIRTIES READ_HIT% WRITE_HIT% BUFFERS_MB CACHED_MB
0 0 0 0.0% 0.0% 54 482
842 0 0 100.0% 0.0% 54 482
889 128 0 87.4% 12.6% 54 482
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Specialized Tools
# ./stackcount.py __kmalloc
Tracing 1 functions for "__kmalloc"... Hit Ctrl-C to end.
^C
__kmalloc
alloc_fdtable
dup_fd
copy_process.part.31
_do_fork
sys_clone
do_syscall_64
return_from_SYSCALL_64
4
__kmalloc
create_pipe_files
__do_pipe_flags
sys_pipe
entry_SYSCALL_64_fastpath
6
__kmalloc
htree_dirblock_to_tree
ext4_htree_fill_tree
ext4_readdir
iterate_dir
SyS_getdents
entry_SYSCALL_64_fastpath
14
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
BPF Tracing Targets
Target Support Overhead
kprobes Native Low
uprobes Native
Medium
handler runs in KM
Kernel tracepoints NativeNEW Low
USDT tracepoints
Temporary
through uprobes
Medium
handler runs in KM
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Multi-Tools: argdist
# ./argdist.py -C 'p:c:write(int fd, const void *buf,
size_t count):size_t:count:fd==1'
[01:49:00]
p:c:write(int fd, const void *buf, size_t count):size_t:count:fd==1
COUNT EVENT
1 count = 3134
1 count = 170
1 count = 181
2 count = 18
3 count = 30
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Multi-Tools: argdist
# ./argdist.py -i 5 -H 'r::__vfs_read(void *file, void *buf,
size_t count):size_t:$entry(count):$latency > 1000000'
[01:51:40]
count : count distribution
0 -> 1 : 20 |****************************************|
2 -> 3 : 0 | |
4 -> 7 : 0 | |
8 -> 15 : 0 | |
16 -> 31 : 0 | |
32 -> 63 : 0 | |
64 -> 127 : 0 | |
128 -> 255 : 6 |************ |
256 -> 511 : 0 | |
512 -> 1023 : 0 | |
1024 -> 2047 : 1 |** |
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Multi-Tools: trace
# ./trace.py 'r:/usr/bin/bash:readline "%s", retval'
TIME PID COMM FUNC -
02:02:26 3711 bash readline ls –la
02:02:36 3711 bash readline wc -l src.c
# ./tplist.py -v block:block_rq_complete
block:block_rq_complete
dev_t dev;
sector_t sector;
unsigned int nr_sector;
int errors;
char rwbs[8];
# ./trace.py 't:block:block_rq_complete "sectors=%d", tp.nr_sector'
TIME PID COMM FUNC -
02:03:56 0 swapper/0 block_rq_complete sectors=16
02:03:56 0 swapper/0 block_rq_complete sectors=8
02:03:58 0 swapper/0 block_rq_complete sectors=24
02:04:00 0 swapper/0 block_rq_complete sectors=0
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Multi-Tools: trace
# ./tplist.py -l pthread -v libpthread:pthread_create
/usr/lib64/libpthread-2.21.so libpthread:pthread_create
location 0x7c63
8 unsigned bytes @ register %rax
8 unsigned bytes @ -192(%rbp)
8 unsigned bytes @ -168(%rbp)
8 unsigned bytes @ -176(%rbp)
# ./trace.py 'u:pthread:pthread_create "%llx", arg3'
TIME PID COMM FUNC -
02:07:29 4051 contentions pthread_create 400e00
02:07:29 4051 contentions pthread_create 400e00
02:07:29 4051 contentions pthread_create 400e00
02:07:29 4051 contentions pthread_create 400e00
^C
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Multi-Tools: trace
# trace -p $(pidof node) 'u:node:http__server__request
"%s %s (from %s:%d)" arg5, arg6, arg3, arg4'
TIME PID COMM FUNC -
04:50:44 22185 node http__server__request GET /foofoo (from ::1:51056)
04:50:46 22185 node http__server__request GET / (from ::1:51056)
^C
# ./trace.py 'u:/tmp/libjvm.so:thread__start "%s [%d]", arg1, arg4' 
'u:/tmp/libjvm.so:thread__stop "%s [%d]", arg1, arg4'
TIME PID COMM FUNC -
06:55:24 32157 java thread__start Reference Handler [32157]
06:55:24 32158 java thread__start Finalizer [32158]
06:55:24 32159 java thread__start Signal Dispatcher [32159]
06:55:24 32160 java thread__start C2 CompilerThread0 [32160]
06:55:24 32161 java thread__start C2 CompilerThread1 [32161]
06:55:24 32162 java thread__start C1 CompilerThread2 [32162]
06:55:24 32163 java thread__start Service Thread [32163]
06:55:28 32159 java thread__stop Signal Dispatcher [32159]
^C
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Kernel
Custom Tool Design
BPF program
Tracepoint kprobe
Python/Lua driver
App process
uprobeUSDT
Probe handler
Probe handler
Hash or
histogram
Cyclic buffer
U
K
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
BPF Program: Counting Allocations
#include <linux/ptrace.h>
struct alloc_info_t {
u64 count;
u64 size;
};
BPF_HASH(allocs, u32, struct alloc_info_t);
int handler(struct pt_regs *ctx, size_t size) {
u32 pid = bpf_get_current_pid_tgid();
struct alloc_info_t init = { 0 }, *info;
info = allocs.lookup_or_init(&pid, &init);
info->count += 1;
info->size += size;
return 0;
}
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
BPF Driver
#!/usr/bin/env python
from bcc import BPF
from time import sleep
program = BPF(src_file="allocs.c")
program.attach_kprobe(event="__kmalloc", fn_name="handler")
allocs = program.get_table("allocs")
while True:
sleep(5)
print("n%-8s %-8s %-10s" % ("PID", "COUNT", "SIZE"))
for key, value in sorted(
allocs.items(), key=lambda (k, v): k.value):
print("%-8d %-8d %-8d" %
(key.value, value.count, value.size))
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
BPF Execution
# ./allocs.py
PID COUNT SIZE
28064 3 456
28157 10 76
28158 5 1116
PID COUNT SIZE
28001 113 1828
28064 8 1216
28110 38 683
28157 46 328
28158 5 1116
28159 41 12894
^C
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Deployment
• At development-time, BCC has a bunch of dependencies, which are
not required for deployment
• For Python tools, deploy Python + libbcc.so
• For Lua tools, deploy only bcc-lua
• Statically links libbcc.a but allows plugging libbcc.so
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Summary
• Tracing can identify bugs and performance issues that no debugger or
profiler can catch
• Tools make low-overhead, dynamic, production tracing possible
• BPF is the next-generation backend for Linux tracing tools
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
Thank You!
Sasha Goldshtein
@goldshtn

More Related Content

What's hot

Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Valeriy Kravchuk
 
BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabTaeung Song
 
Linux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF SuperpowersLinux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF SuperpowersBrendan Gregg
 
Kernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPFKernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPFBrendan Gregg
 
Kernel Recipes 2017: Using Linux perf at Netflix
Kernel Recipes 2017: Using Linux perf at NetflixKernel Recipes 2017: Using Linux perf at Netflix
Kernel Recipes 2017: Using Linux perf at NetflixBrendan Gregg
 
Linux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPFLinux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPFBrendan Gregg
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)Brendan Gregg
 
Container Performance Analysis
Container Performance AnalysisContainer Performance Analysis
Container Performance AnalysisBrendan Gregg
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudAndrea Righi
 
CETH for XDP [Linux Meetup Santa Clara | July 2016]
CETH for XDP [Linux Meetup Santa Clara | July 2016] CETH for XDP [Linux Meetup Santa Clara | July 2016]
CETH for XDP [Linux Meetup Santa Clara | July 2016] IO Visor Project
 
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsTIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsXiaozhe Wang
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!Affan Syed
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareBrendan Gregg
 
The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecturehugo lu
 
Overview of FreeBSD PMC Tools
Overview of FreeBSD PMC ToolsOverview of FreeBSD PMC Tools
Overview of FreeBSD PMC ToolsACMBangalore
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Ray Jenkins
 

What's hot (20)

Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
 
BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLab
 
Linux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF SuperpowersLinux 4.x Tracing Tools: Using BPF Superpowers
Linux 4.x Tracing Tools: Using BPF Superpowers
 
Kernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPFKernel Recipes 2017: Performance Analysis with BPF
Kernel Recipes 2017: Performance Analysis with BPF
 
Kernel Recipes 2017: Using Linux perf at Netflix
Kernel Recipes 2017: Using Linux perf at NetflixKernel Recipes 2017: Using Linux perf at Netflix
Kernel Recipes 2017: Using Linux perf at Netflix
 
Linux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPFLinux 4.x Tracing: Performance Analysis with bcc/BPF
Linux 4.x Tracing: Performance Analysis with bcc/BPF
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
 
eBPF Basics
eBPF BasicseBPF Basics
eBPF Basics
 
Introduction to Perf
Introduction to PerfIntroduction to Perf
Introduction to Perf
 
Container Performance Analysis
Container Performance AnalysisContainer Performance Analysis
Container Performance Analysis
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloud
 
CETH for XDP [Linux Meetup Santa Clara | July 2016]
CETH for XDP [Linux Meetup Santa Clara | July 2016] CETH for XDP [Linux Meetup Santa Clara | July 2016]
CETH for XDP [Linux Meetup Santa Clara | July 2016]
 
eBPF Workshop
eBPF WorkshopeBPF Workshop
eBPF Workshop
 
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling ToolsTIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
TIP1 - Overview of C/C++ Debugging/Tracing/Profiling Tools
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!
 
UM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of SoftwareUM2019 Extended BPF: A New Type of Software
UM2019 Extended BPF: A New Type of Software
 
The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecture
 
Cache profiling on ARM Linux
Cache profiling on ARM LinuxCache profiling on ARM Linux
Cache profiling on ARM Linux
 
Overview of FreeBSD PMC Tools
Overview of FreeBSD PMC ToolsOverview of FreeBSD PMC Tools
Overview of FreeBSD PMC Tools
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 

Similar to The Next Linux Superpower: eBPF Primer

Performance Wins with BPF: Getting Started
Performance Wins with BPF: Getting StartedPerformance Wins with BPF: Getting Started
Performance Wins with BPF: Getting StartedBrendan Gregg
 
Piwik elasticsearch kibana at OSC Tokyo 2016 Spring
Piwik elasticsearch kibana at OSC Tokyo 2016 SpringPiwik elasticsearch kibana at OSC Tokyo 2016 Spring
Piwik elasticsearch kibana at OSC Tokyo 2016 SpringTakashi Yamamoto
 
Systems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting StartedSystems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting StartedBrendan Gregg
 
Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Brendan Gregg
 
FØCAL Boston AiR - Computer Vision Tracing and Hardware Simulation
FØCAL Boston AiR - Computer Vision Tracing and Hardware SimulationFØCAL Boston AiR - Computer Vision Tracing and Hardware Simulation
FØCAL Boston AiR - Computer Vision Tracing and Hardware SimulationFØCAL
 
Systemtap
SystemtapSystemtap
SystemtapFeng Yu
 
Cfgmgmtcamp 2023 — eBPF Superpowers
Cfgmgmtcamp 2023 — eBPF SuperpowersCfgmgmtcamp 2023 — eBPF Superpowers
Cfgmgmtcamp 2023 — eBPF SuperpowersRaphaël PINSON
 
Package Management via Spack on SJTU π Supercomputer
Package Management via Spack on SJTU π SupercomputerPackage Management via Spack on SJTU π Supercomputer
Package Management via Spack on SJTU π SupercomputerJianwen Wei
 
Python and Machine Learning
Python and Machine LearningPython and Machine Learning
Python and Machine Learningtrygub
 
IPv6 for Pentesters
IPv6 for PentestersIPv6 for Pentesters
IPv6 for Pentesterscamsec
 
IETF 104 Hackathon VPP Prototyping Stateless SRv6/GTP-U Translation
IETF 104 Hackathon VPP Prototyping Stateless SRv6/GTP-U TranslationIETF 104 Hackathon VPP Prototyping Stateless SRv6/GTP-U Translation
IETF 104 Hackathon VPP Prototyping Stateless SRv6/GTP-U TranslationKentaro Ebisawa
 
Efficient System Monitoring in Cloud Native Environments
Efficient System Monitoring in Cloud Native EnvironmentsEfficient System Monitoring in Cloud Native Environments
Efficient System Monitoring in Cloud Native EnvironmentsGergely Szabó
 
The true story_of_hello_world
The true story_of_hello_worldThe true story_of_hello_world
The true story_of_hello_worldfantasy zheng
 
Prometheus as exposition format for eBPF programs running on Kubernetes
Prometheus as exposition format for eBPF programs running on KubernetesPrometheus as exposition format for eBPF programs running on Kubernetes
Prometheus as exposition format for eBPF programs running on KubernetesLeonardo Di Donato
 
Building Modern Data Streaming Apps with Python
Building Modern Data Streaming Apps with PythonBuilding Modern Data Streaming Apps with Python
Building Modern Data Streaming Apps with PythonTimothy Spann
 
IAA Life in Lockdown series: Securing Internet Routing
IAA Life in Lockdown series: Securing Internet RoutingIAA Life in Lockdown series: Securing Internet Routing
IAA Life in Lockdown series: Securing Internet RoutingAPNIC
 
FunctionalJS - May 2014 - Streams
FunctionalJS - May 2014 - StreamsFunctionalJS - May 2014 - Streams
FunctionalJS - May 2014 - Streamsdarach
 
Metasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCUMetasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCUKiwamu Okabe
 

Similar to The Next Linux Superpower: eBPF Primer (20)

Performance Wins with BPF: Getting Started
Performance Wins with BPF: Getting StartedPerformance Wins with BPF: Getting Started
Performance Wins with BPF: Getting Started
 
Piwik elasticsearch kibana at OSC Tokyo 2016 Spring
Piwik elasticsearch kibana at OSC Tokyo 2016 SpringPiwik elasticsearch kibana at OSC Tokyo 2016 Spring
Piwik elasticsearch kibana at OSC Tokyo 2016 Spring
 
Systems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting StartedSystems@Scale 2021 BPF Performance Getting Started
Systems@Scale 2021 BPF Performance Getting Started
 
Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)Performance Wins with eBPF: Getting Started (2021)
Performance Wins with eBPF: Getting Started (2021)
 
Origins of Serverless
Origins of ServerlessOrigins of Serverless
Origins of Serverless
 
FØCAL Boston AiR - Computer Vision Tracing and Hardware Simulation
FØCAL Boston AiR - Computer Vision Tracing and Hardware SimulationFØCAL Boston AiR - Computer Vision Tracing and Hardware Simulation
FØCAL Boston AiR - Computer Vision Tracing and Hardware Simulation
 
Systemtap
SystemtapSystemtap
Systemtap
 
Cfgmgmtcamp 2023 — eBPF Superpowers
Cfgmgmtcamp 2023 — eBPF SuperpowersCfgmgmtcamp 2023 — eBPF Superpowers
Cfgmgmtcamp 2023 — eBPF Superpowers
 
Package Management via Spack on SJTU π Supercomputer
Package Management via Spack on SJTU π SupercomputerPackage Management via Spack on SJTU π Supercomputer
Package Management via Spack on SJTU π Supercomputer
 
Python and Machine Learning
Python and Machine LearningPython and Machine Learning
Python and Machine Learning
 
IPv6 for Pentesters
IPv6 for PentestersIPv6 for Pentesters
IPv6 for Pentesters
 
IPv6 for Pentesters
IPv6 for PentestersIPv6 for Pentesters
IPv6 for Pentesters
 
IETF 104 Hackathon VPP Prototyping Stateless SRv6/GTP-U Translation
IETF 104 Hackathon VPP Prototyping Stateless SRv6/GTP-U TranslationIETF 104 Hackathon VPP Prototyping Stateless SRv6/GTP-U Translation
IETF 104 Hackathon VPP Prototyping Stateless SRv6/GTP-U Translation
 
Efficient System Monitoring in Cloud Native Environments
Efficient System Monitoring in Cloud Native EnvironmentsEfficient System Monitoring in Cloud Native Environments
Efficient System Monitoring in Cloud Native Environments
 
The true story_of_hello_world
The true story_of_hello_worldThe true story_of_hello_world
The true story_of_hello_world
 
Prometheus as exposition format for eBPF programs running on Kubernetes
Prometheus as exposition format for eBPF programs running on KubernetesPrometheus as exposition format for eBPF programs running on Kubernetes
Prometheus as exposition format for eBPF programs running on Kubernetes
 
Building Modern Data Streaming Apps with Python
Building Modern Data Streaming Apps with PythonBuilding Modern Data Streaming Apps with Python
Building Modern Data Streaming Apps with Python
 
IAA Life in Lockdown series: Securing Internet Routing
IAA Life in Lockdown series: Securing Internet RoutingIAA Life in Lockdown series: Securing Internet Routing
IAA Life in Lockdown series: Securing Internet Routing
 
FunctionalJS - May 2014 - Streams
FunctionalJS - May 2014 - StreamsFunctionalJS - May 2014 - Streams
FunctionalJS - May 2014 - Streams
 
Metasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCUMetasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCU
 

More from Sasha Goldshtein

Visual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET FrameworkVisual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET FrameworkSasha Goldshtein
 
Swift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS XSwift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS XSasha Goldshtein
 
C# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with XamarinC# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with XamarinSasha Goldshtein
 
Modern Backends for Mobile Apps
Modern Backends for Mobile AppsModern Backends for Mobile Apps
Modern Backends for Mobile AppsSasha Goldshtein
 
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013Sasha Goldshtein
 
Mastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and ProductionMastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and ProductionSasha Goldshtein
 
Delivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in MinutesDelivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in MinutesSasha Goldshtein
 
Building Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET BackendBuilding Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET BackendSasha Goldshtein
 
Building iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile ServicesBuilding iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile ServicesSasha Goldshtein
 
Attacking Web Applications
Attacking Web ApplicationsAttacking Web Applications
Attacking Web ApplicationsSasha Goldshtein
 
Windows Azure Mobile Services
Windows Azure Mobile ServicesWindows Azure Mobile Services
Windows Azure Mobile ServicesSasha Goldshtein
 
First Steps in Android Development
First Steps in Android DevelopmentFirst Steps in Android Development
First Steps in Android DevelopmentSasha Goldshtein
 
First Steps in iOS Development
First Steps in iOS DevelopmentFirst Steps in iOS Development
First Steps in iOS DevelopmentSasha Goldshtein
 
JavaScript, Meet Cloud: Node.js on Windows Azure
JavaScript, Meet Cloud: Node.js on Windows AzureJavaScript, Meet Cloud: Node.js on Windows Azure
JavaScript, Meet Cloud: Node.js on Windows AzureSasha Goldshtein
 
First Steps in Android Development with Eclipse and Xamarin
First Steps in Android Development with Eclipse and XamarinFirst Steps in Android Development with Eclipse and Xamarin
First Steps in Android Development with Eclipse and XamarinSasha Goldshtein
 

More from Sasha Goldshtein (20)

Visual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET FrameworkVisual Studio 2015 and the Next .NET Framework
Visual Studio 2015 and the Next .NET Framework
 
Swift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS XSwift: Apple's New Programming Language for iOS and OS X
Swift: Apple's New Programming Language for iOS and OS X
 
C# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with XamarinC# Everywhere: Cross-Platform Mobile Apps with Xamarin
C# Everywhere: Cross-Platform Mobile Apps with Xamarin
 
Modern Backends for Mobile Apps
Modern Backends for Mobile AppsModern Backends for Mobile Apps
Modern Backends for Mobile Apps
 
.NET Debugging Workshop
.NET Debugging Workshop.NET Debugging Workshop
.NET Debugging Workshop
 
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
Performance and Debugging with the Diagnostics Hub in Visual Studio 2013
 
Mastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and ProductionMastering IntelliTrace in Development and Production
Mastering IntelliTrace in Development and Production
 
Introduction to RavenDB
Introduction to RavenDBIntroduction to RavenDB
Introduction to RavenDB
 
State of the Platforms
State of the PlatformsState of the Platforms
State of the Platforms
 
Delivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in MinutesDelivering Millions of Push Notifications in Minutes
Delivering Millions of Push Notifications in Minutes
 
Building Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET BackendBuilding Mobile Apps with a Mobile Services .NET Backend
Building Mobile Apps with a Mobile Services .NET Backend
 
Building iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile ServicesBuilding iOS and Android Apps with Mobile Services
Building iOS and Android Apps with Mobile Services
 
Task and Data Parallelism
Task and Data ParallelismTask and Data Parallelism
Task and Data Parallelism
 
What's New in C++ 11?
What's New in C++ 11?What's New in C++ 11?
What's New in C++ 11?
 
Attacking Web Applications
Attacking Web ApplicationsAttacking Web Applications
Attacking Web Applications
 
Windows Azure Mobile Services
Windows Azure Mobile ServicesWindows Azure Mobile Services
Windows Azure Mobile Services
 
First Steps in Android Development
First Steps in Android DevelopmentFirst Steps in Android Development
First Steps in Android Development
 
First Steps in iOS Development
First Steps in iOS DevelopmentFirst Steps in iOS Development
First Steps in iOS Development
 
JavaScript, Meet Cloud: Node.js on Windows Azure
JavaScript, Meet Cloud: Node.js on Windows AzureJavaScript, Meet Cloud: Node.js on Windows Azure
JavaScript, Meet Cloud: Node.js on Windows Azure
 
First Steps in Android Development with Eclipse and Xamarin
First Steps in Android Development with Eclipse and XamarinFirst Steps in Android Development with Eclipse and Xamarin
First Steps in Android Development with Eclipse and Xamarin
 

Recently uploaded

Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Anthony Dahanne
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics
 

Recently uploaded (20)

Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024VictoriaMetrics Anomaly Detection Updates: Q1 2024
VictoriaMetrics Anomaly Detection Updates: Q1 2024
 

The Next Linux Superpower: eBPF Primer

  • 1. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 The Next Linux Superpower: eBPF Primer Sasha Goldshtein CTO, Sela Group @goldshtn
  • 2. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Agenda • Modern Linux tracing landscape • BPF • BCC – BPF Compiler Collection • Using BCC tools • Authoring BCC tools
  • 3. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Linux Tracing Tools, Today Ease of use BPF/BCC SysDig ktap SystemTap LTTng ftrace perf custom .ko new stable dead Level of detail, features
  • 4. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Berkeley Packet Filters (BPF) • Originally designed for, well, packet filtering: dst port 80 and len >= 100 • Custom instruction set, interpreted/JIT compiled • Verified to be safe: no unsafe memory accesses, no backward jumps 0: (bf) r6 = r1 1: (85) call 14 2: (67) r0 <<= 32 3: (77) r0 >>= 32 4: (15) if r0 == 0x49f goto pc+40
  • 5. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Extended BPF (3.18 and ongoing) • Attach BPF programs to kprobes/uprobes (4.1) and tracepoints (4.7) • Data structures: array, hash (expandable), stack map (4.6) • Output to trace buffer (4.3) and perf cyclic buffer (4.4) • Helper functions: get time, get current comm, get current CPU, etc.
  • 6. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 BCC: BPF Compiler Collection • Library and Python/Lua module for compiling, loading, and executing BPF programs • Compile BPF program from C source • Attach BPF program to kprobe/uprobe/tracepoint/USDT/socket • Poll data from BPF program using Python/Lua • Can do in-kernel aggregation and filtering • Growing collection of tracing and performance tools
  • 7. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 BCC • The BCC repository contains a variety of existing scripts and tools to get you started • The BPF module (Python/Lua) can be used to build new tools or one- off scripts $ ls.py argdist.py bashreadline.py biolatency.py biosnoop.py biotop.py bitesize.py btrfsdist.py btrfsslower.py cachestat.py cpudist.py dcsnoop.py dcstat.py execsnoop.py ext4dist.py ext4slower.py filelife.py fileslower.py filetop.py funccount.py funclatency.py gethostlatency.py hardirqs.py killsnoop.py mdflush.py memleak.py offcputime.py offwaketime.py oomkill.py opensnoop.py pidpersec.py runqlat.py softirqs.py solisten.py stackcount.py stacksnoop.py statsnoop.py syncsnoop.py tcpaccept.py tcpconnect.py tcpconnlat.py tcpretrans.py tplist.py trace.py vfscount.py vfsstat.py wakeuptime.py xfsdist.py xfsslower.py zfsdist.py zfsslower.py
  • 8. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07
  • 9. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Specialized Tools # ./hardirqs.py Tracing hard irq event time... Hit Ctrl-C to end. ^C HARDIRQ TOTAL_usecs virtio0-input.0 959 ahci[0000:00:1f.2] 1290 # ./biolatency.py Tracing block device I/O... Hit Ctrl-C to end. ^C usecs : count distribution 64 -> 127 : 7 |********* | 128 -> 255 : 14 |****************** | 256 -> 511 : 5 |****** | 512 -> 1023 : 30 |****************************************| 1024 -> 2047 : 1 |* |
  • 10. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Specialized Tools # ./filetop.py 01:35:51 loadavg: 0.01 0.04 0.03 2/139 3611 PID COMM READS WRITES R_Kb W_Kb T FILE 2496 sshd 3 1 48 0 O ptmx 2939 screen 4 1 16 0 O ptmx 2496 sshd 1 3 16 0 S TCP 3611 clear 2 0 8 0 R screen 2939 screen 1 3 4 0 O 0 3589 filetop.py 2 0 2 0 R loadavg 3611 clear 1 0 0 0 R libtinfo.so.5.9 3611 clear 1 0 0 0 R libc-2.21.so 3611 filetop.py 3 0 0 0 R clear 3611 filetop.py 2 0 0 0 R ld-2.21.so 3611 clear 0 1 0 0 O 2 3589 filetop.py 0 3 0 0 O 2 # ./cachestat.py HITS MISSES DIRTIES READ_HIT% WRITE_HIT% BUFFERS_MB CACHED_MB 0 0 0 0.0% 0.0% 54 482 842 0 0 100.0% 0.0% 54 482 889 128 0 87.4% 12.6% 54 482
  • 11. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Specialized Tools # ./stackcount.py __kmalloc Tracing 1 functions for "__kmalloc"... Hit Ctrl-C to end. ^C __kmalloc alloc_fdtable dup_fd copy_process.part.31 _do_fork sys_clone do_syscall_64 return_from_SYSCALL_64 4 __kmalloc create_pipe_files __do_pipe_flags sys_pipe entry_SYSCALL_64_fastpath 6 __kmalloc htree_dirblock_to_tree ext4_htree_fill_tree ext4_readdir iterate_dir SyS_getdents entry_SYSCALL_64_fastpath 14
  • 12. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 BPF Tracing Targets Target Support Overhead kprobes Native Low uprobes Native Medium handler runs in KM Kernel tracepoints NativeNEW Low USDT tracepoints Temporary through uprobes Medium handler runs in KM
  • 13. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Multi-Tools: argdist # ./argdist.py -C 'p:c:write(int fd, const void *buf, size_t count):size_t:count:fd==1' [01:49:00] p:c:write(int fd, const void *buf, size_t count):size_t:count:fd==1 COUNT EVENT 1 count = 3134 1 count = 170 1 count = 181 2 count = 18 3 count = 30
  • 14. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Multi-Tools: argdist # ./argdist.py -i 5 -H 'r::__vfs_read(void *file, void *buf, size_t count):size_t:$entry(count):$latency > 1000000' [01:51:40] count : count distribution 0 -> 1 : 20 |****************************************| 2 -> 3 : 0 | | 4 -> 7 : 0 | | 8 -> 15 : 0 | | 16 -> 31 : 0 | | 32 -> 63 : 0 | | 64 -> 127 : 0 | | 128 -> 255 : 6 |************ | 256 -> 511 : 0 | | 512 -> 1023 : 0 | | 1024 -> 2047 : 1 |** |
  • 15. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Multi-Tools: trace # ./trace.py 'r:/usr/bin/bash:readline "%s", retval' TIME PID COMM FUNC - 02:02:26 3711 bash readline ls –la 02:02:36 3711 bash readline wc -l src.c # ./tplist.py -v block:block_rq_complete block:block_rq_complete dev_t dev; sector_t sector; unsigned int nr_sector; int errors; char rwbs[8]; # ./trace.py 't:block:block_rq_complete "sectors=%d", tp.nr_sector' TIME PID COMM FUNC - 02:03:56 0 swapper/0 block_rq_complete sectors=16 02:03:56 0 swapper/0 block_rq_complete sectors=8 02:03:58 0 swapper/0 block_rq_complete sectors=24 02:04:00 0 swapper/0 block_rq_complete sectors=0
  • 16. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Multi-Tools: trace # ./tplist.py -l pthread -v libpthread:pthread_create /usr/lib64/libpthread-2.21.so libpthread:pthread_create location 0x7c63 8 unsigned bytes @ register %rax 8 unsigned bytes @ -192(%rbp) 8 unsigned bytes @ -168(%rbp) 8 unsigned bytes @ -176(%rbp) # ./trace.py 'u:pthread:pthread_create "%llx", arg3' TIME PID COMM FUNC - 02:07:29 4051 contentions pthread_create 400e00 02:07:29 4051 contentions pthread_create 400e00 02:07:29 4051 contentions pthread_create 400e00 02:07:29 4051 contentions pthread_create 400e00 ^C
  • 17. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Multi-Tools: trace # trace -p $(pidof node) 'u:node:http__server__request "%s %s (from %s:%d)" arg5, arg6, arg3, arg4' TIME PID COMM FUNC - 04:50:44 22185 node http__server__request GET /foofoo (from ::1:51056) 04:50:46 22185 node http__server__request GET / (from ::1:51056) ^C # ./trace.py 'u:/tmp/libjvm.so:thread__start "%s [%d]", arg1, arg4' 'u:/tmp/libjvm.so:thread__stop "%s [%d]", arg1, arg4' TIME PID COMM FUNC - 06:55:24 32157 java thread__start Reference Handler [32157] 06:55:24 32158 java thread__start Finalizer [32158] 06:55:24 32159 java thread__start Signal Dispatcher [32159] 06:55:24 32160 java thread__start C2 CompilerThread0 [32160] 06:55:24 32161 java thread__start C2 CompilerThread1 [32161] 06:55:24 32162 java thread__start C1 CompilerThread2 [32162] 06:55:24 32163 java thread__start Service Thread [32163] 06:55:28 32159 java thread__stop Signal Dispatcher [32159] ^C
  • 18. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Kernel Custom Tool Design BPF program Tracepoint kprobe Python/Lua driver App process uprobeUSDT Probe handler Probe handler Hash or histogram Cyclic buffer U K
  • 19. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 BPF Program: Counting Allocations #include <linux/ptrace.h> struct alloc_info_t { u64 count; u64 size; }; BPF_HASH(allocs, u32, struct alloc_info_t); int handler(struct pt_regs *ctx, size_t size) { u32 pid = bpf_get_current_pid_tgid(); struct alloc_info_t init = { 0 }, *info; info = allocs.lookup_or_init(&pid, &init); info->count += 1; info->size += size; return 0; }
  • 20. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 BPF Driver #!/usr/bin/env python from bcc import BPF from time import sleep program = BPF(src_file="allocs.c") program.attach_kprobe(event="__kmalloc", fn_name="handler") allocs = program.get_table("allocs") while True: sleep(5) print("n%-8s %-8s %-10s" % ("PID", "COUNT", "SIZE")) for key, value in sorted( allocs.items(), key=lambda (k, v): k.value): print("%-8d %-8d %-8d" % (key.value, value.count, value.size))
  • 21. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 BPF Execution # ./allocs.py PID COUNT SIZE 28064 3 456 28157 10 76 28158 5 1116 PID COUNT SIZE 28001 113 1828 28064 8 1216 28110 38 683 28157 46 328 28158 5 1116 28159 41 12894 ^C
  • 22. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Deployment • At development-time, BCC has a bunch of dependencies, which are not required for deployment • For Python tools, deploy Python + libbcc.so • For Lua tools, deploy only bcc-lua • Statically links libbcc.a but allows plugging libbcc.so
  • 23. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Summary • Tracing can identify bugs and performance issues that no debugger or profiler can catch • Tools make low-overhead, dynamic, production tracing possible • BPF is the next-generation backend for Linux tracing tools
  • 24. SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 SRECon Europe 2016 @goldshtn https://s.sashag.net/bpf07 Thank You! Sasha Goldshtein @goldshtn

Editor's Notes

  1. Missing: cpudist