7/26/2019 Trace Kernel Source 2009
1/32
Trace Kernel Source
Advanced Operating Systems
2009
RTLab
7/26/2019 Trace Kernel Source 2009
2/32
Outline
Linux Kernel
Android Linux Kernel
2RTLab
7/26/2019 Trace Kernel Source 2009
3/32
Outline
Linux Kernel
Android Linux Kernel
3RTLab
7/26/2019 Trace Kernel Source 2009
4/32
Linux Features
Free
Open system
Open source
GNU GPL (General Public License)
POSIX (Portable Operating System Interface) standard High portability
High performance
Robust
Large development toolset
Large number of device drivers Large number of application programs
4RTLab
7/26/2019 Trace Kernel Source 2009
5/32
Features (Cont.)
Multi-user
allows several users to work on the same machine at the sametime
Multi-process/Multi-processors
more than one program can be executed at a time, whether usingone or several processors
Virtual memory
Loadable kernel modules
Networking
Shared libraries Support different file systems
Support different executable file formats
Support different networking protocols
Support different architectures
5RTLab
7/26/2019 Trace Kernel Source 2009
6/32
Kernel
System call interface kernel
Process control
Memory management
File system management I/O,
Device drivers
6RTLab
7/26/2019 Trace Kernel Source 2009
7/32
Linux Kernel Architecture
User View of Linux Operating System
Linux Kernel Architecture
Kernel Source Code Organization
7RTLab
7/26/2019 Trace Kernel Source 2009
8/32
User View of Linux Operating System
Hardware
Kernel
Shell
Applications
8RTLab
7/26/2019 Trace Kernel Source 2009
9/32
System Structure
System calls interface
File systems
ext2fs xiafs proc
minix nfs msdos
iso9660
Task management
Scheduler
Signals
Loadable modules
Memory management
Central kernel
Machine interface
ipv4
ethernet
...
Network ManagerPeripheral managers
b lock characte r
sound card cdrom isdn
scsi pci network
Buffer Cache
Processes
Machine 9RTLab
7/26/2019 Trace Kernel Source 2009
10/32
Original UNIX System Structure
(the users)
shells and commands
compilers and interpreterssystem libraries
system-call interface to the kernel
kernel interface to the hardware
terminal controllers device controllers memory controllers
terminals devices and tapes physical memory
signals file system CPU scheduling
terminal swapping page replacementHandling
char I/O syst. block I/O syst. demand paging
terminal disk and tape virtualdrivers drivers memory
kernel
hardware
system
programs
(1)
(2)
10RTLab
7/26/2019 Trace Kernel Source 2009
11/32
Linux Kernel Architecture
11RTLab
7/26/2019 Trace Kernel Source 2009
12/32
Analysis of Linux Kernel Architecture
Stability
Safety
Speed
Brevity Compatability
Portability
Reusability and modifiability Monolithic kernel vs. microkernel
Linux takes the advantages of monolithic kerneland microkernel
12RTLab
7/26/2019 Trace Kernel Source 2009
13/32
Kernel Source
Source code web site:
http://www.kernel.org
latest stable version
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2
Source code version:
X.Y.Z
2.6.31
Distributions:
ftp://linux.cis.nctu.edu.tw/distributions/
RED HAT, Ubuntu, Fedora, Debian, Mandriva
13RTLab
http://www.kernel.org/http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2ftp://linux.cis.nctu.edu.tw/distributions/ftp://linux.cis.nctu.edu.tw/distributions/http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2http://www.kernel.org/7/26/2019 Trace Kernel Source 2009
14/32
Source Code Organization
init
ipc
lib
mm
kernel net
fs
include
arch drivers
14RTLab
7/26/2019 Trace Kernel Source 2009
15/32
Outline
Linux Kernel
Andro id Linux Kernel
15RTLab
7/26/2019 Trace Kernel Source 2009
16/32
RTLab 16
7/26/2019 Trace Kernel Source 2009
17/32
AndroidKernel - 1
Gold-Fish
Goldfish: a virtual CPU that Android emulator runs
Goldfish executes ARM926T instructions and has
hooks for input and output
Yaffs2 FLASH file system
Yet Another Flash File System, 2nd edition
New Android Functionality
RTLab 17
7/26/2019 Trace Kernel Source 2009
18/32
AndroidKernel - 2
Bluetooth
Scheduler
Slight changes to the CPU process scheduler and
time-keeping algorithms
Binder (IPC)
Low Memory Killer
Ashmem Anonymous SHared MEMory system
Interfaces so processes can share named blocks
of memory RTLab 18
7/26/2019 Trace Kernel Source 2009
19/32
AndroidKernel - 3
Debugging
RAM Console and Log Device
Android Debug Bridge
New Real-Time Clock
Switch support
Timed GPIO support
Power Management
RTLab 19
7/26/2019 Trace Kernel Source 2009
20/32
Resource
Android Open Source Project
http://source.android.com/download
WebGit
http://android.git.kernel.org/
RTLab 20
7/26/2019 Trace Kernel Source 2009
21/32
RTLab 21
Project Description
bionic C runtime: libc, libm, libdl, dynamic linker
bootloader/legacy Bootloader reference code
build Build system
dalvik Dalvik virtual machine
development High-level development and debugging tools
frameworks/base Core Android app framework libraries
frameworks/policies/base Framework configuration policies
hardware/libhardware Hardware abstraction libraryhardware/ril Radio interface layer
kernel Linux kernel
prebuilt Binaries to support Linux and Mac OS builds
recovery System recovery environment
system/bluetooth Bluetooth tools
system/core Minimal bootable environment
system/extras Low-level debugging/inspection tools
system/wlan/ti TI 1251 WLAN driver and tools
http://source.android.com/projects
7/26/2019 Trace Kernel Source 2009
22/32
Resources for Tracing Linux
GNU Global source code tag system
http://www.gnu.org/software/global/
support C, C++, Yacc, Java and PHP4
find the locations of a specified object quickly.
locate not only object definitions but also objectreferences.
allows duplicate objects.
locate also path which includes specified pattern.
22RTLab
http://www.gnu.org/software/global/http://www.gnu.org/software/global/7/26/2019 Trace Kernel Source 2009
23/32
Resources for Tracing Linux
LXR
Source code navigator
http://lxr.linux.no/source/
function, struct, macro E-Books
KernelAnalysis-HOWTO:
http://www.linux.org/docs/ldp/howto/KernelAnalysis-
HOWTO.html
The Linux Kernel:
http://www.tldp.org/LDP/tlk/tlk.html
23RTLab
http://lxr.linux.no/source/http://www.linux.org/docs/ldp/howto/KernelAnalysis-HOWTO.htmlhttp://www.linux.org/docs/ldp/howto/KernelAnalysis-HOWTO.htmlhttp://www.tldp.org/LDP/tlk/tlk.htmlhttp://www.tldp.org/LDP/tlk/tlk.htmlhttp://www.linux.org/docs/ldp/howto/KernelAnalysis-HOWTO.htmlhttp://www.linux.org/docs/ldp/howto/KernelAnalysis-HOWTO.htmlhttp://www.linux.org/docs/ldp/howto/KernelAnalysis-HOWTO.htmlhttp://lxr.linux.no/source/7/26/2019 Trace Kernel Source 2009
24/32
Resources for Tracing Linux
Linux Kernel 2.4 Internals:
http://www.moses.uklinux.net/patches/lki.html
LinuxHQ:
http://www.linuxhq.com Books
Understanding the Linux Kernel, 3/e Daniel P. Bovet, Marco Cesati
O'Reilly & Associates.
Linux Core Kernel Commentary In-Depth Code Annotation, S. Maxwell, Coriolis Open Press, 1999.
24RTLab
http://www.moses.uklinux.net/patches/lki.htmlhttp://www.linuxhq.com/http://www.linuxhq.com/http://www.moses.uklinux.net/patches/lki.html7/26/2019 Trace Kernel Source 2009
25/32
Resources for Tracing Linux
The Linux Kernel, Version 0.8-3, D. A Rusling, 1998.
Linux Kernel Internals, 2nd edition, M. Beck et al., Addison-Wesley, 1998.
Linux Kernel, R. Card et al., John Wiley & Sons, 1998.
Linux Device Drivers, 2nd Edition: OReilly/()
Linux:
Windows
UltraEdit
25RTLab
7/26/2019 Trace Kernel Source 2009
26/32
Resources for Tracing Linux
VisualStudio
Source Browser, find in files
Unix grep: grep [option] pattern [file]
ex : grepri return rtlcore.c
ctags: find -name *.[ch] | xargs ctags
tags
cflow: cflow r fun_name *.c
call graph
c2html: c2html < file.c > file.html
26RTLab
7/26/2019 Trace Kernel Source 2009
27/32
Resources for Tracing
Source code browser Cscope
http://cscope.sourceforge.net/
KScope http://kscope.sourceforge.net/sshots.shtml
Source Insight http://www.sourceinsight.com/
27RTLab
http://cscope.sourceforge.net/http://kscope.sourceforge.net/sshots.shtmlhttp://www.sourceinsight.com/http://www.sourceinsight.com/http://kscope.sourceforge.net/sshots.shtmlhttp://cscope.sourceforge.net/http://cscope.sourceforge.net/http://cscope.sourceforge.net/7/26/2019 Trace Kernel Source 2009
28/32
KScope - Screenshots 1
28RTLab
7/26/2019 Trace Kernel Source 2009
29/32
KScope - Screenshots 2
29RTLab
7/26/2019 Trace Kernel Source 2009
30/32
KScope - Screenshots 3
30RTLab
7/26/2019 Trace Kernel Source 2009
31/32
Source Insight - Screenshots
31RTLab
7/26/2019 Trace Kernel Source 2009
32/32
Thank You!
32RTLab