Linux Kernel: Michael Opdenacker Thomas Petazzoni
Linux Kernel: Michael Opdenacker Thomas Petazzoni
Linux kernel
introduction
Michael Opdenacker
Thomas Petazzoni
Free Electrons
© Copyright 20042009, Free Electrons.
Creative Commons BYSA 3.0 license
Latest update: Jan 19, 2011,
Document sources, updates and translations:
http://freeelectrons.com/docs/kernelintro
Corrections, suggestions, contributions and translations are welcome!
1
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Embedded Linux driver development
Kernel overview
Linux features
2
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Linux kernel in the system
User app B
C library
Call to services Event notification,
information exposition
Linux Kernel
Manage
hardware Event notification
Hardware
3
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
History
The Linux kernel is one component of a system, which also
requires libraries and applications to provide features to end
users.
The Linux kernel was created as a hobby in 1991
by a Finnish student, Linus Torvalds.
Linux quickly started to be used as the kernel for free software
operating systems
Linus Torvalds has been able to create a large and dynamic
developer and user community around Linux.
Nowadays, hundreds of people contribute to each kernel release,
individuals or companies big and small.
4
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Linux license
The whole Linux sources are Free Software released
under the GNU General Public License version 2 (GPL v2).
For the Linux kernel, this basically implies that:
When you receive or buy a device with Linux on it,
you should receive the Linux sources, with the right to
study, modify and redistribute them.
When you produce Linux based devices, you must
release the sources to the recipient, with the same rights,
with no restriction..
5
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Linux kernel key features
Portability and hardware Security
support It can't hide its flaws. Its code
Runs on most architectures. is reviewed by many experts.
Scalability Stability and reliability.
Can run on super computers
Modularity
as well as on tiny devices
Can include only what a
(4 MB of RAM is enough).
system needs even at run
Compliance to standards and time.
interoperability.
Easy to program
Exhaustive networking You can learn from existing
support. code. Many useful resources
on the net.
6
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Supported hardware architectures
2.6.31 status
See the arch/ directory in the kernel sources
Minimum: 32 bit processors, with or without MMU, and gcc support
32 bit architectures (arch/ subdirectories)
arm, avr32, blackfin, cris, frv, h8300, m32r, m68k,
m68knommu, microblaze, mips, mn10300, parisc, s390,
sparc, um, xtensa
64 bit architectures:
alpha, ia64, sparc64
32/64 bit architectures
powerpc, x86, sh
Find details in kernel sources: arch/<arch>/Kconfig,
arch/<arch>/README, or Documentation/<arch>/
7
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
System calls
The main interface between the kernel and userspace is the set
of system calls
About ~300 system calls that provides the main kernel services
File and device operations, networking operations, interprocess
communication, process management, memory mapping, timers,
threads, synchronization primitives, etc.
This interface is stable over time: only new system calls can be
added by the kernel developers
This system call interface is wrapped by the C library, and
userspace applications usually never make a system call directly
but rather use the corresponding C library function
8
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Virtual filesystems
Linux makes system and kernel information available in
userspace through virtual filesystems (virtual files not
existing on any real storage). No need to know kernel
programming to access such information!
Mounting /proc:
sudo mount t proc none /proc
Mounting /sys:
sudo mount t sysfs none /sys
9
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
/proc details
A few examples:
/proc/cpuinfo: processor information
/proc/meminfo: memory status
/proc/version: kernel version and build information
/proc/cmdline: kernel command line
/proc/<pid>/environ: calling environment
/proc/<pid>/cmdline: process command line
... and many more! See by yourself!
Lots of details about the /proc interface are available in
Documentation/filesystems/proc.txt
(almost 2000 lines) in the kernel sources.
10
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Embedded Linux usage
Kernel overview
Linux versioning scheme and development process
11
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Until 2.6 (1)
One stable major branch every 2 or 3 years
Identified by an even middle number
Examples: 1.0, 2.0, 2.2, 2.4
One development branch to integrate new functionalities and
major changes
Identified by an odd middle number
Examples: 2.1, 2.3, 2.5
After some time, a development version becomes the new
base version for the stable branch
Minor releases once in while: 2.2.23, 2.5.12, etc.
12
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Until 2.6 (2)
Stable version
Development Stable
Note: in reality, many more minor
versions exist inside the stable and
development branches
13
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Changes since Linux 2.6 (1)
Since 2.6.0, kernel developers have been able to
introduce lots of new features one by one on a steady pace,
without having to make major changes in existing
subsystems.
Opening a new Linux 2.7 (or 2.9) development branch will
be required only when Linux 2.6 is no longer able to
accommodate key features without undergoing traumatic
changes.
Thanks to this, more features are released to users at a
faster pace.
14
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Changes since Linux 2.6 (2)
Since 2.6.14, the kernel developers agreed
on the following development model:
After the release of a 2.6.x version, a twoweeks merge window
opens, during which major additions are merged.
The merge window is closed
by the release of test version 2.6.(x+1)rc1
The bug fixing period opens, for 6 to 10 weeks.
At regular intervals during the bug fixing period,
2.6.(x+1)rcY test versions are released.
When considered sufficiently stable,
kernel 2.6.(x+1) is released, and the process starts again.
15
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Merge and bug fixing windows
2 weeks 6 to 10 weeks
Merge window Bug fixing period
2.6.22.1
Bug fix updates
16
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
More stability for the 2.6 kernel tree
Issue: bug and security fixes only released for
most recent stable kernel versions.
Some people need to have a recent kernel, but
with long term support for security updates.
You could get long term support from a
commercial embedded Linux provider.
You could reuse sources for the kernel used in
Ubuntu Long Term Support releases (5 years of
free security updates).
You could choose one of the versions advertised
as “long term” in the kernel.org front page. They
will be maintained longer (2 or 3 years), unlike
other versions.
17
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
What's new in each Linux release?
??!
commit 3c92c2ba33cd7d666c5f83cc32aa590e794e91b0
Author: Andi Kleen <[email protected]>
Date: Tue Oct 11 01:28:33 2005 +0200
[PATCH] i386: Don't discard upper 32bits of HWCR on K8
Need to use long long, not long when RMWing a MSR. I think
it's harmless right now, but still should be better fixed
if AMD adds any bits in the upper 32bit of HWCR.
Bug was introduced with the TLB flush filter fix for i386
Signedoffby: Andi Kleen <[email protected]>
Signedoffby: Linus Torvalds <[email protected]>
...
The official list of changes for each Linux release is just a
huge list of individual patches!
Very difficult to find out the key changes and to get the
global picture out of individual changes.
Fortunately, a summary of key changes
with enough details is available on
http://wiki.kernelnewbies.org/LinuxChanges
18
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Related documents
All our technical presentations
on http://freeelectrons.com/docs
Linux kernel
Device drivers
Architecture specifics
Embedded Linux system development
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
How to help
You can help us to improve and maintain this document...
By sending corrections, suggestions, contributions and
translations
By asking your organization to order development, consulting
and training services performed by the authors of these
documents (see http://freeelectrons.com/).
By sharing this document with your friends, colleagues
and with the local Free Software community.
By adding links on your website to our online materials,
to increase their visibility in search engine results.
Free Electrons. Kernel, drivers and embedded Linux development, consulting, training and support. http//freeelectrons.com
Linux kernel
Linux device drivers
Free Electrons
Board support code Our services
Mainstreaming kernel code
Kernel debugging
Custom Development
System integration
Embedded Linux Training
Embedded Linux demos and prototypes
All materials released with a free license! System optimization
Unix and GNU/Linux basics Application and interface development
Linux kernel and drivers development
Realtime Linux, uClinux Consulting and technical support
Development and profiling tools Help in decision making
Lightweight tools for embedded systems System architecture
Root filesystem creation System design and performance review
Audio and multimedia Development tool and application support
System optimization Investigating issues and fixing tool bugs