SlideShare a Scribd company logo
1 of 31
Download to read offline
Understanding Linux Kernel
Behaviour with Off-CPU Analysis
Han Qiao
Samsung Research UK
Why is my thread blocked? (red dotted line)
#ARM DS-5 system profiler
1. Acquiring a lock
2. Waiting for I/O
3. Sleeping voluntarily
What happens
Off-CPU?
ie. blocked
Limitation of a sampling based profiler
Off-CPU tracing method
http://brendangregg.com/offcpuanalysis
Off-CPU wakeup path analysis
● Requirements
○ Function argument (target, who I'm waking up)
○ Stack trace (cause, who's the caller)
○ Context information (process id, cpu id, timing, etc)
● Benefit
○ Identify performance bottlenecks
○ Account for all running applications system wide
○ Real time
http://www.brendangregg.com/blog/2016-02-01/linux-wakeup-offwake-profiling.html
Program Specification
int try_to_wake_up(struct task_struct *p,
unsigned int state, int wake_flags)
1. Function argument
(target, who I'm waking up)
2. Context information
(source process id, cpu id, timing, etc)
3. Stack trace
(cause, why am I called)
Naive jprobe
● Based on kprobe, but more accessible
● Attachable at any kernel function
● Keeps original function argument
● Calls Linux functions:
○ save_stack_trace
○ trace_printk
http://www.cs.dartmouth.edu/~reeves/kprobes-2016.pdf
24x
Overhead of profiling using naive jprobe
Optimizations
1. Jmp optimized kprobe
(https://lwn.net/Articles/370995/)
2. Custom stack walker
(pointer chasing)
3. Less printing
(in-kernel aggregation)
Jmp optimized kprobe
int kprobe_handler(struct kprobe *p, struct pt_regs *regs)
https://lwn.net/Articles/132196/
@ https://lwn.net/Articles/132196/
struct pt_regs {
long rbx;
long rdi;
long rbp;
long rax;
long rflags;
…
Inspect
registers*
*architecture dependent
Custom stack walker
ret = (void *)(*bp+8)
*Omits handler code from backtrace
http://eli.thegreenplace.net/2011/09/06/stack-frame-layout-on-x86-64/
Less printing
● Resolve kernel debug symbols
trace_printk("%pfn", (void *) stack_entries[i]);
● In-kernel aggregation (future work)
4x
Overhead of profiling using kprobe kernel module
Alternatives
● ftrace
(sched_waking static tracepoint > 3.18)
● eBPF
(in-kernel virtual machine JIT interpreter > 4.4)
● perf
● SystemTap
● LTTng
● HTrace
● systrace
ftrace
sudo ls /sys/kernel/debug/tracing/
available_tracers kprobe_profile set_ftrace_notrace trace_options
buffer_total_size_kb options set_graph_function trace_stat
current_tracer per_cpu set_graph_notrace tracing_cpumask
dyn_ftrace_total_info printk_formats snapshot tracing_max_latency
enabled_functions README stack_max_size tracing_on
function_profile_enabled set_event trace
…
ftrace
available_tracers kprobe_profile set_ftrace_notrace trace_options
buffer_total_size_kb options set_graph_function trace_stat
current_tracer per_cpu set_graph_notrace tracing_cpumask
dyn_ftrace_total_info printk_formats snapshot tracing_max_latency
enabled_functions README stack_max_size tracing_on
function_profile_enabled set_event trace
…
sudo ls /sys/kernel/debug/tracing/
Available
Tracers
cat available_tracers
blk
mmiotrace
function_graph
wakeup_dl
wakeup_rt
wakeup
function
nop
function tracer
sudo ls /sys/kernel/debug/tracing/
available_events instances set_event_pid trace_clock
available_filter_functions kprobe_events set_ftrace_filter trace_marker
available_tracers kprobe_profile set_ftrace_notrace trace_options
buffer_size_kb max_graph_depth set_ftrace_pid trace_pipe
buffer_total_size_kb options set_graph_function trace_stat
function_profile_enabled set_event trace
function tracer
echo try_to_wake_up >
set_ftrace_filter
kworker/2:1-74
[002]
d...
1025.046785:
try_to_wake_up
(target?)
function tracer
echo 1 >
options/func_stack_trace
kworker/2:1-74 [002] d...
1025.046787: <stack trace>
=> pollwake
=> __wake_up_common
=> __wake_up
=> n_tty_receive_buf_common
=> n_tty_receive_buf2
…
nop tracer
writebench.o-29118
[000]
2694376.974316:
sched_waking:
comm=run.sh
pid=29115
prio=120
target_cpu=001
echo sched:sched_waking >
set_event
eBPF
● Extended berkeley packet filter
● Subset of C that compiles to virtual machine bytecode via llvm
● Verifiably safe, no loops
● Extended from two registers to fourteen
● Originally used in network filters
● Easy loading and compilation with bcc
(https://github.com/iovisor/bcc)
No more tree walker
McCanne, S., & Jacobson, V. (1993, January). The BSD Packet Filter: A New Architecture for User-level Packet Capture. In USENIX winter (Vol. 46).
bpf source code
● Attaching to kprobe
SEC("kprobe/try_to_wake_up")
int bpf_prog1(struct pt_regs *ctx)
● Reading pointer value
bpf_probe_read(&ret, sizeof(ret), (void *)(*bp+8));
Micro benchmark
● 10 million syscall to write 512 bytes of 0 to /dev/null
○ Consistent measure of syscall overhead
○ Baseline ~92 nsec
● Try it yourself
○ dd if=/dev/zero of=/dev/null bs=512 count=1000k
Results
Conclusion
● Optimized kprobe outperforms other implementations by 3-6x
○ with a combined overhead of slightly under 400ns per syscall
● In-kernel aggregation could further reduce overhead to 200ns
○ by deferring printing cost to analysis time
● With overhead in the microsecond range, tracing can be enabled on
production systems without sampling to capture hard-to-reproduce bugs
○ lock contention
○ I/O latency
Future work
● Implement in-kernel aggregation with persistent tracing
● Integrate with ARM devices by applying kprobe patchset
(https://lwn.net/Articles/676434/)
● Investigate perf integration with eBPF
(https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=1f4
5b1d49073541947193bd7dac9e904142576aa)
Thank you!

More Related Content

What's hot

BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabTaeung Song
 
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
 
Performance Analysis Tools for Linux Kernel
Performance Analysis Tools for Linux KernelPerformance Analysis Tools for Linux Kernel
Performance Analysis Tools for Linux Kernellcplcp1
 
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 performance tools chapter 4 bcc
Bpf performance tools chapter 4   bccBpf performance tools chapter 4   bcc
Bpf performance tools chapter 4 bccViller Hsiao
 
bcc/BPF tools - Strategy, current tools, future challenges
bcc/BPF tools - Strategy, current tools, future challengesbcc/BPF tools - Strategy, current tools, future challenges
bcc/BPF tools - Strategy, current tools, future challengesIO Visor Project
 
LPC2019 BPF Tracing Tools
LPC2019 BPF Tracing ToolsLPC2019 BPF Tracing Tools
LPC2019 BPF Tracing ToolsBrendan 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
 
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
 
Spying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitSpying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitAndrea Righi
 
Profiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf ToolsProfiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf ToolsemBO_Conference
 
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
 
Kernel development
Kernel developmentKernel development
Kernel developmentNuno Martins
 
Linux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - WonokaerunLinux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - Wonokaerunidsecconf
 
re:Invent 2019 BPF Performance Analysis at Netflix
re:Invent 2019 BPF Performance Analysis at Netflixre:Invent 2019 BPF Performance Analysis at Netflix
re:Invent 2019 BPF Performance Analysis at NetflixBrendan Gregg
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Jarod Wang
 
Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005dflexer
 
Linux System Monitoring with eBPF
Linux System Monitoring with eBPFLinux System Monitoring with eBPF
Linux System Monitoring with eBPFHeinrich Hartmann
 

What's hot (20)

BPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLabBPF / XDP 8월 세미나 KossLab
BPF / XDP 8월 세미나 KossLab
 
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
 
Performance Analysis Tools for Linux Kernel
Performance Analysis Tools for Linux KernelPerformance Analysis Tools for Linux Kernel
Performance Analysis Tools for Linux Kernel
 
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 performance tools chapter 4 bcc
Bpf performance tools chapter 4   bccBpf performance tools chapter 4   bcc
Bpf performance tools chapter 4 bcc
 
bcc/BPF tools - Strategy, current tools, future challenges
bcc/BPF tools - Strategy, current tools, future challengesbcc/BPF tools - Strategy, current tools, future challenges
bcc/BPF tools - Strategy, current tools, future challenges
 
Cache profiling on ARM Linux
Cache profiling on ARM LinuxCache profiling on ARM Linux
Cache profiling on ARM Linux
 
LPC2019 BPF Tracing Tools
LPC2019 BPF Tracing ToolsLPC2019 BPF Tracing Tools
LPC2019 BPF Tracing Tools
 
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
 
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
 
Spying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profitSpying on the Linux kernel for fun and profit
Spying on the Linux kernel for fun and profit
 
Ixgbe internals
Ixgbe internalsIxgbe internals
Ixgbe internals
 
Profiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf ToolsProfiling your Applications using the Linux Perf Tools
Profiling your Applications using the Linux Perf Tools
 
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)
 
Kernel development
Kernel developmentKernel development
Kernel development
 
Linux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - WonokaerunLinux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - Wonokaerun
 
re:Invent 2019 BPF Performance Analysis at Netflix
re:Invent 2019 BPF Performance Analysis at Netflixre:Invent 2019 BPF Performance Analysis at Netflix
re:Invent 2019 BPF Performance Analysis at Netflix
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0
 
Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005Tuning parallelcodeonsolaris005
Tuning parallelcodeonsolaris005
 
Linux System Monitoring with eBPF
Linux System Monitoring with eBPFLinux System Monitoring with eBPF
Linux System Monitoring with eBPF
 

Similar to Tracer Evaluation

HKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightHKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightLinaro
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time OptimizationKan-Ru Chen
 
Interruption Timer Périodique
Interruption Timer PériodiqueInterruption Timer Périodique
Interruption Timer PériodiqueAnne Nicolas
 
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법GangSeok Lee
 
Open Source Systems Performance
Open Source Systems PerformanceOpen Source Systems Performance
Open Source Systems PerformanceBrendan Gregg
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Adrian Huang
 
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...confluent
 
Alexander Reelsen - Seccomp for Developers
Alexander Reelsen - Seccomp for DevelopersAlexander Reelsen - Seccomp for Developers
Alexander Reelsen - Seccomp for DevelopersDevDay Dresden
 
Swift profiling middleware and tools
Swift profiling middleware and toolsSwift profiling middleware and tools
Swift profiling middleware and toolszhang hua
 
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtKernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtAnne Nicolas
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak PROIDEA
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelVitaly Nikolenko
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLCommand Prompt., Inc
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLMark Wong
 
2015.07.16 Способы диагностики PostgreSQL
2015.07.16 Способы диагностики PostgreSQL2015.07.16 Способы диагностики PostgreSQL
2015.07.16 Способы диагностики PostgreSQLdev1ant
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?Roman Elizarov
 
Systemtap
SystemtapSystemtap
SystemtapFeng Yu
 

Similar to Tracer Evaluation (20)

HKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with CoresightHKG18-TR14 - Postmortem Debugging with Coresight
HKG18-TR14 - Postmortem Debugging with Coresight
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
Interruption Timer Périodique
Interruption Timer PériodiqueInterruption Timer Périodique
Interruption Timer Périodique
 
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
[2009 CodeEngn Conference 03] koheung - 윈도우 커널 악성코드에 대한 분석 및 방법
 
Open Source Systems Performance
Open Source Systems PerformanceOpen Source Systems Performance
Open Source Systems Performance
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...
 
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
Kafka Summit SF 2017 - One Day, One Data Hub, 100 Billion Messages: Kafka at ...
 
Alexander Reelsen - Seccomp for Developers
Alexander Reelsen - Seccomp for DevelopersAlexander Reelsen - Seccomp for Developers
Alexander Reelsen - Seccomp for Developers
 
Swift profiling middleware and tools
Swift profiling middleware and toolsSwift profiling middleware and tools
Swift profiling middleware and tools
 
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtKernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
 
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak   CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
CONFidence 2015: DTrace + OSX = Fun - Andrzej Dyjak
 
Debug generic process
Debug generic processDebug generic process
Debug generic process
 
Exploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernelExploitation of counter overflows in the Linux kernel
Exploitation of counter overflows in the Linux kernel
 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUs
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
pg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQLpg_proctab: Accessing System Stats in PostgreSQL
pg_proctab: Accessing System Stats in PostgreSQL
 
2015.07.16 Способы диагностики PostgreSQL
2015.07.16 Способы диагностики PostgreSQL2015.07.16 Способы диагностики PostgreSQL
2015.07.16 Способы диагностики PostgreSQL
 
Why GC is eating all my CPU?
Why GC is eating all my CPU?Why GC is eating all my CPU?
Why GC is eating all my CPU?
 
SOFA Tutorial
SOFA TutorialSOFA Tutorial
SOFA Tutorial
 
Systemtap
SystemtapSystemtap
Systemtap
 

Recently uploaded

DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 

Recently uploaded (20)

DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 

Tracer Evaluation

  • 1. Understanding Linux Kernel Behaviour with Off-CPU Analysis Han Qiao Samsung Research UK
  • 2. Why is my thread blocked? (red dotted line) #ARM DS-5 system profiler
  • 3. 1. Acquiring a lock 2. Waiting for I/O 3. Sleeping voluntarily What happens Off-CPU? ie. blocked
  • 4. Limitation of a sampling based profiler
  • 6. Off-CPU wakeup path analysis ● Requirements ○ Function argument (target, who I'm waking up) ○ Stack trace (cause, who's the caller) ○ Context information (process id, cpu id, timing, etc) ● Benefit ○ Identify performance bottlenecks ○ Account for all running applications system wide ○ Real time http://www.brendangregg.com/blog/2016-02-01/linux-wakeup-offwake-profiling.html
  • 7. Program Specification int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags) 1. Function argument (target, who I'm waking up) 2. Context information (source process id, cpu id, timing, etc) 3. Stack trace (cause, why am I called)
  • 8. Naive jprobe ● Based on kprobe, but more accessible ● Attachable at any kernel function ● Keeps original function argument ● Calls Linux functions: ○ save_stack_trace ○ trace_printk http://www.cs.dartmouth.edu/~reeves/kprobes-2016.pdf
  • 9. 24x Overhead of profiling using naive jprobe
  • 10. Optimizations 1. Jmp optimized kprobe (https://lwn.net/Articles/370995/) 2. Custom stack walker (pointer chasing) 3. Less printing (in-kernel aggregation)
  • 11. Jmp optimized kprobe int kprobe_handler(struct kprobe *p, struct pt_regs *regs) https://lwn.net/Articles/132196/ @ https://lwn.net/Articles/132196/
  • 12. struct pt_regs { long rbx; long rdi; long rbp; long rax; long rflags; … Inspect registers* *architecture dependent
  • 13. Custom stack walker ret = (void *)(*bp+8) *Omits handler code from backtrace http://eli.thegreenplace.net/2011/09/06/stack-frame-layout-on-x86-64/
  • 14. Less printing ● Resolve kernel debug symbols trace_printk("%pfn", (void *) stack_entries[i]); ● In-kernel aggregation (future work)
  • 15. 4x Overhead of profiling using kprobe kernel module
  • 16. Alternatives ● ftrace (sched_waking static tracepoint > 3.18) ● eBPF (in-kernel virtual machine JIT interpreter > 4.4) ● perf ● SystemTap ● LTTng ● HTrace ● systrace
  • 17. ftrace sudo ls /sys/kernel/debug/tracing/ available_tracers kprobe_profile set_ftrace_notrace trace_options buffer_total_size_kb options set_graph_function trace_stat current_tracer per_cpu set_graph_notrace tracing_cpumask dyn_ftrace_total_info printk_formats snapshot tracing_max_latency enabled_functions README stack_max_size tracing_on function_profile_enabled set_event trace …
  • 18. ftrace available_tracers kprobe_profile set_ftrace_notrace trace_options buffer_total_size_kb options set_graph_function trace_stat current_tracer per_cpu set_graph_notrace tracing_cpumask dyn_ftrace_total_info printk_formats snapshot tracing_max_latency enabled_functions README stack_max_size tracing_on function_profile_enabled set_event trace … sudo ls /sys/kernel/debug/tracing/
  • 20. function tracer sudo ls /sys/kernel/debug/tracing/ available_events instances set_event_pid trace_clock available_filter_functions kprobe_events set_ftrace_filter trace_marker available_tracers kprobe_profile set_ftrace_notrace trace_options buffer_size_kb max_graph_depth set_ftrace_pid trace_pipe buffer_total_size_kb options set_graph_function trace_stat function_profile_enabled set_event trace
  • 21. function tracer echo try_to_wake_up > set_ftrace_filter kworker/2:1-74 [002] d... 1025.046785: try_to_wake_up (target?)
  • 22. function tracer echo 1 > options/func_stack_trace kworker/2:1-74 [002] d... 1025.046787: <stack trace> => pollwake => __wake_up_common => __wake_up => n_tty_receive_buf_common => n_tty_receive_buf2 …
  • 24. eBPF ● Extended berkeley packet filter ● Subset of C that compiles to virtual machine bytecode via llvm ● Verifiably safe, no loops ● Extended from two registers to fourteen ● Originally used in network filters ● Easy loading and compilation with bcc (https://github.com/iovisor/bcc)
  • 25. No more tree walker McCanne, S., & Jacobson, V. (1993, January). The BSD Packet Filter: A New Architecture for User-level Packet Capture. In USENIX winter (Vol. 46).
  • 26. bpf source code ● Attaching to kprobe SEC("kprobe/try_to_wake_up") int bpf_prog1(struct pt_regs *ctx) ● Reading pointer value bpf_probe_read(&ret, sizeof(ret), (void *)(*bp+8));
  • 27. Micro benchmark ● 10 million syscall to write 512 bytes of 0 to /dev/null ○ Consistent measure of syscall overhead ○ Baseline ~92 nsec ● Try it yourself ○ dd if=/dev/zero of=/dev/null bs=512 count=1000k
  • 29. Conclusion ● Optimized kprobe outperforms other implementations by 3-6x ○ with a combined overhead of slightly under 400ns per syscall ● In-kernel aggregation could further reduce overhead to 200ns ○ by deferring printing cost to analysis time ● With overhead in the microsecond range, tracing can be enabled on production systems without sampling to capture hard-to-reproduce bugs ○ lock contention ○ I/O latency
  • 30. Future work ● Implement in-kernel aggregation with persistent tracing ● Integrate with ARM devices by applying kprobe patchset (https://lwn.net/Articles/676434/) ● Investigate perf integration with eBPF (https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=1f4 5b1d49073541947193bd7dac9e904142576aa)