add exercises for kernel training

Signed-off-by: default avatarGabriel Krisman Bertazi <krisman@collabora.com>
parents
File added
% Created 2019-11-20 Wed 20:28
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\author{Gabriel Krisman Bertazi <krisman@collabora.com>}
\date{\today}
\title{Bootstrap the kernel}
\hypersetup{
pdfauthor={Gabriel Krisman Bertazi <krisman@collabora.com>},
pdftitle={Bootstrap the kernel},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 26.1 (Org mode 9.0.5)},
pdflang={English}}
\begin{document}
\maketitle
\section{Exercise}
\label{sec:org4c5992d}
\subsection{Part 1}
\label{sec:org82e0e73}
Git clone the mainline kernel and boot it using a qemu environment.
\subsection{Tips:}
\label{sec:orgd36952a}
Generate a kvmconfig using:
make x86\_64\_defconfig
make kvmconfig
\subsection{Enable ftrace}
\label{sec:orgd3a7c59}
Rebuild your kernel with ftrace enabled.
\end{document}
#+TITLE: Kernel Hello World
#+AUTHOR: Gabriel Krisman Bertazi <krisman@collabora.com>
#+OPTIONS: toc:nil
* Exercise
** Part 1: printk
Build a kernel adding a log line into the dmesg in any part of the
kernel, printing the "Hello World" string using KERN_DEBUG log level.
Boot and make sure it appeared.
** Part 2: dynamic debug
Redo the exercise, but using dynamic debug. Enable your dyndbg during
boot and as a module load.
** Part 3: Oops log
Force a null pointer exception on the kernel, show, only using the Oops
log the exact asm instruction where the issue triggered.
** Part 4: BUG()
Add a BUG() to capture the null pointer exception you just added,
instead of just letting it crash.
** Part 5: sysrq
Dump all sleeping tasks from your kernel.
** Part 6: Git
Commit each of the previous parts of this exercise in your git
repository. Write an adequate commit message following the kernel
standards. Generate a patch series and send it to yourself. check the
result with your email client.
File added
% Created 2019-11-20 Wed 20:26
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\author{Gabriel Krisman Bertazi <krisman@collabora.com>}
\date{\today}
\title{Kernel Hello World}
\hypersetup{
pdfauthor={Gabriel Krisman Bertazi <krisman@collabora.com>},
pdftitle={Kernel Hello World},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 26.1 (Org mode 9.0.5)},
pdflang={English}}
\begin{document}
\maketitle
\section{Exercise}
\label{sec:org6fb2757}
\subsection{Part 1: printk}
\label{sec:orgd148981}
Build a kernel adding a log line into the dmesg in any part of the
kernel, printing the "Hello World" string using KERN\(_{\text{DEBUG}}\) log level.
Boot and make sure it appeared.
\subsection{Part 2: dynamic debug}
\label{sec:orgad0ebdc}
Redo the exercise, but using dynamic debug. Enable your dyndbg during
boot and as a module load.
\subsection{Part 3: Oops log}
\label{sec:org6fd6fdb}
Force a null pointer exception on the kernel, show, only using the Oops
log the exact asm instruction where the issue triggered.
\subsection{Part 4: BUG()}
\label{sec:orgc84d985}
Add a BUG() to capture the null pointer exception you just added,
instead of just letting it crash.
\subsection{Part 5: sysrq}
\label{sec:orgcf1971b}
Dump all sleeping tasks from your kernel.
\subsection{Part 6: Git}
\label{sec:org79e1803}
Commit each of the previous parts of this exercise in your git
repository. Write an adequate commit message following the kernel
standards. Generate a patch series and send it to yourself. check the
result with your email client.
\end{document}
#+TITLE: Introduction to ftrace
#+AUTHOR: Gabriel Krisman Bertazi <krisman@collabora.com>
#+OPTIONS: toc:nil ^:nil
* Exercise
Use ftrace to dump the stack every time a USB device
is inserted or removed.
** Tip
Check the function usb_bus_notify() in linux/drivers/usb/core/usb.c
File added
% Created 2019-11-20 Wed 20:38
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\author{Gabriel Krisman Bertazi <krisman@collabora.com>}
\date{\today}
\title{Introduction to ftrace}
\hypersetup{
pdfauthor={Gabriel Krisman Bertazi <krisman@collabora.com>},
pdftitle={Introduction to ftrace},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 26.1 (Org mode 9.0.5)},
pdflang={English}}
\begin{document}
\maketitle
\section{Exercise}
\label{sec:org0d11f7a}
Use ftrace to dump the stack every time a USB device
is inserted or removed.
\subsection{Tip}
\label{sec:org8d2dbda}
Check the function usb\_bus\_notify() in linux/drivers/usb/core/usb.c
\end{document}
#+TITLE: trace-cmd
#+AUTHOR: Gabriel Krisman Bertazi <krisman@collabora.com>
#+OPTIONS: toc:nil ^:nil
* Exercise
Install trace-cmd. Use it to observe the execution of
tick_do_update_jiffies64 in your system with kernelshark
File added
% Created 2019-11-20 Wed 20:43
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\author{Gabriel Krisman Bertazi <krisman@collabora.com>}
\date{\today}
\title{trace-cmd}
\hypersetup{
pdfauthor={Gabriel Krisman Bertazi <krisman@collabora.com>},
pdftitle={trace-cmd},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 26.1 (Org mode 9.0.5)},
pdflang={English}}
\begin{document}
\maketitle
\section{Exercise}
\label{sec:orga34c176}
Install trace-cmd. Use it to observe the execution of
tick\_do\_update\_jiffies64 in your system with kernelshark
\end{document}
#+TITLE: funccount jiffies
#+AUTHOR: Gabriel Krisman Bertazi <krisman@collabora.com>
#+OPTIONS: toc:nil ^:nil
* Introduction
funccount is a very important tool from the perf-tools testsuite. It
allows a developer to identify functions that executed many times, and
eventually identifying hot code paths. Given a specific function and a
timespan, funccount prints how many times a function executed.
* Exercise
Leverage ftrace to deduce how many times the function
tick_do_update_jiffies64 executed in 60 seconds.
File added
% Created 2019-11-20 Wed 20:43
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\author{Gabriel Krisman Bertazi <krisman@collabora.com>}
\date{\today}
\title{funccount jiffies}
\hypersetup{
pdfauthor={Gabriel Krisman Bertazi <krisman@collabora.com>},
pdftitle={funccount jiffies},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 26.1 (Org mode 9.0.5)},
pdflang={English}}
\begin{document}
\maketitle
\section{Introduction}
\label{sec:org59312e1}
funccount is a very important tool from the perf-tools testsuite. It
allows a developer to identify functions that executed many times, and
eventually identifying hot code paths. Given a specific function and a
timespan, funccount prints how many times a function executed.
\section{Exercise}
\label{sec:org42b9d37}
Leverage ftrace to deduce how many times the function
tick\_do\_update\_jiffies64 executed in 60 seconds.
\end{document}
#+TITLE: Poor-man's strace using ftrace
#+AUTHOR: Gabriel Krisman Bertazi <krisman@collabora.com>
#+OPTIONS: toc:nil
* Introduction
strace is a tool to snoop on the system call layer, allowing you to
trace all the system calls executed by a program:
For instance:
#+BEGIN_SRC
root@dilma:/sys/kernel/debug/tracing# strace /bin/true
execve("/bin/true", ["/bin/true"], 0x7ffc22fb4090 /* 20 vars */) = 0
brk(NULL) = 0x557fa1308000
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=216602, ...}) = 0
mmap(NULL, 216602, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f32c8466000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1820104, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, -1, 0) = 0x7f32c8464000
mmap(NULL, 1832568, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f32c82a4000
mprotect(0x7f32c82c9000, 1642496, PROT_NONE) = 0
close(3) = 0
arch_prctl(ARCH_SET_FS, 0x7f32c8465580) = 0
mprotect(0x7f32c845a000, 12288, PROT_READ) = 0
mprotect(0x557fa0eac000, 4096, PROT_READ) = 0
mprotect(0x7f32c84c2000, 4096, PROT_READ) = 0
munmap(0x7f32c8466000, 216602) = 0
exit_group(0) = ?
+++ exited with 0 +++
#+END_SRC
* Exercise
Write a script that leverages ftrace to reproduce the behavior of strace
by printing the system calls executed by a program that is running on
the system.
Your program must support the following parameters:
- '-p <pid>' : Trace the following PID only
- '-x <program>' : program to be executed
- '-t <threshold> : Only trace systemcalls that took longer than <threshold>n
- '-i <syscall>: syscalls to be ignored
Your program should support '-p' or 'x' one at a time, and never both
together.
Test your program against command line applications in your shell
Your program do not need to print the syscall parameters or return code.
File added
% Created 2019-11-20 Wed 20:43
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\author{Gabriel Krisman Bertazi <krisman@collabora.com>}
\date{\today}
\title{Poor-man's strace using ftrace}
\hypersetup{
pdfauthor={Gabriel Krisman Bertazi <krisman@collabora.com>},
pdftitle={Poor-man's strace using ftrace},
pdfkeywords={},
pdfsubject={},
pdfcreator={Emacs 26.1 (Org mode 9.0.5)},
pdflang={English}}
\begin{document}
\maketitle
\section{Introduction}
\label{sec:orga09619a}
strace is a tool to snoop on the system call layer, allowing you to
trace all the system calls executed by a program:
For instance:
\begin{verbatim}
root@dilma:/sys/kernel/debug/tracing# strace /bin/true
execve("/bin/true", ["/bin/true"], 0x7ffc22fb4090 /* 20 vars */) = 0
brk(NULL) = 0x557fa1308000
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=216602, ...}) = 0
mmap(NULL, 216602, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f32c8466000
close(3) = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1820104, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, -1, 0) = 0x7f32c8464000
mmap(NULL, 1832568, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f32c82a4000
mprotect(0x7f32c82c9000, 1642496, PROT_NONE) = 0
close(3) = 0
arch_prctl(ARCH_SET_FS, 0x7f32c8465580) = 0
mprotect(0x7f32c845a000, 12288, PROT_READ) = 0
mprotect(0x557fa0eac000, 4096, PROT_READ) = 0
mprotect(0x7f32c84c2000, 4096, PROT_READ) = 0
munmap(0x7f32c8466000, 216602) = 0
exit_group(0) = ?
+++ exited with 0 +++
\end{verbatim}
\section{Exercise}
\label{sec:org99653a0}
Write a script that leverages ftrace to reproduce the behavior of strace
by printing the system calls executed by a program that is running on
the system.
Your program must support the following parameters:
\begin{itemize}
\item '-p <pid>' : Trace the following PID only
\item '-x <program>' : program to be executed
\item '-t <threshold> : Only trace systemcalls that took longer than <threshold>n
\item '-i <syscall>: syscalls to be ignored
\end{itemize}
Your program should support '-p' or 'x' one at a time, and never both
together.
Test your program against command line applications in your shell
Your program do not need to print the syscall parameters or return code.
\end{document}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment