linux internals & linux device driver
Post on 13-Apr-2017
252 Views
Preview:
TRANSCRIPT
Linux Internals Linux Internals & &
Device DriversDevice Drivers
BySateesh Kumar G
© Sateesh KG
Topics Topics Introduction to Kernel Introduction to Kernel Features of Linux KernelFeatures of Linux Kernel Understanding Linux KernelUnderstanding Linux Kernel Introduction to Device DriversIntroduction to Device Drivers Building and Running ModuleBuilding and Running Module Character DriversCharacter Drivers Concurrency and Race ConditionsConcurrency and Race Conditions Advance Char Driver OperationAdvance Char Driver Operation Blocking IOBlocking IO Async NotificationsAsync Notifications InterruptsInterrupts
© Sateesh KG
Topics cont..Topics cont.. Bottom halves and SoftirqsBottom halves and Softirqs Tasklets and Work QueuesTasklets and Work Queues Memory ManagementMemory Management Page Allocator Page Allocator Address Translation and Page TablesAddress Translation and Page Tables Portmap and memory map IOsPortmap and memory map IOs Block Device DriverBlock Device Driver PCI DriversPCI Drivers Network DriversNetwork Drivers
© Sateesh KG
1. Monolithic kernel. ( NOT DERIVED FROM UNIX, REWRITTEN FROM SCRATCH )
2. Statically compiled + support for dynamic extension through LKMs
3. Limited support for kernel threading. Kernel threads do not support user processes.
4. Multithreaded application support. Linux defines its own version of LWPs ( Light weight processes ) using a nonstandard system call clone, while all other unix versions use
kernel threads to implement LWPs.
5. 2.4.x version of the kernel is non-preemptive while running in privileged mode. The 2.6 +version allows pre-emption as an optional feature.
6. Multiprocessor support.
7. Support for several filesystems.
8. Unix STREAMS I/O is not part of the kernel. Separately maintained.
9. FREE / FAST / POWERFUL / COMPACT / RELIABLE / SUPPORTED
10. Version numbering X.Y.Z ( X => version. Y=even => stable else development. Z = stable / dev release ).
Eg: Linux 3.8.2
Kernel website : www.kernel.org
Linux features in a nutshell
© Sateesh KG
Monolithic kernel Micro KernelMonolithic kernel Micro Kernel
Characteristics that differ between the Linux kernel and other Unix variants:Characteristics that differ between the Linux kernel and other Unix variants:
Dynamic loading of kernel moduleDynamic loading of kernel module
PreemptivePreemptive
Symmetric multiprocessor (SMP) support.Symmetric multiprocessor (SMP) support.
Linux does not differentiate between threads and normal processes.Linux does not differentiate between threads and normal processes.
Linux provides an object-oriented device model with device classes,hotpluggable events and Linux provides an object-oriented device model with device classes,hotpluggable events and
user-space device file system(sysfs).user-space device file system(sysfs).
© Sateesh KG
Components:1. Process Management
2. Memory Management
3. File Systems
4. Device Management
5. Networking
Understanding The Linux Kernel
© Sateesh KG
Fundamental ConceptsDifference between a "Program" and a "Process"
A Program is a complete set of executable instructions on the hard disk.
A Process is created when the program is loaded into memory. A process space has DATA, STACK and INSTRUCTIONS. It has an ID ( Identification ) and exists as long as it is required to run.
The same program can be run (loaded) twice. There will be two processes (but only one program).
The kernel is responsible for :
a. creating and destroying processes.b. Inter Process Communications.
c. processes to communicate with the outside world (Input/Output ).
© Sateesh KG
A Process's View Of the Kernel
Kernel = Black Box"Provider Of Services"
My CPUMy Memory
My CPUMy Memory
My CPUMy Memory
CPU, Memory, Devices, NICs,...
Process-2Process-1 Process-3
© Sateesh KG
The Internal View Of the KernelProcess-2Process-1 Process-3
The Task Queue
Task-1 Task-2 Task-3 Task-1 Task-3 Task-1 Task-2 Task-3 Task-1
Process-2 over
Process-1 overProcess-3 over
Task - 1 Task - 2 Task - 3
Seen fromoutside
Seen from inside
© Sateesh KG
The Various Process States....
Waiting
Running
Ready
The task is active and running in the non-privileged User Mode.This state can only be exited via an interrupt or a system call.( System calls are a special case of interrupts ). In either case, the processor is switched to the privileged mode and the appropriate interrupt routine is activated.
The process is waiting for an external event. Only after this has occurred, will it continue its execution.
Two kinds of "Waiting Processes" Interruptible - processes can be interrupted by signals uninterruptible - waiting ONLY for hardware conditions
The process is competing for the processor, which is however occupied with another process at the present time. Its ready to execute and will be executed at the first available moment."runnable"
"blocked"
© Sateesh KG
The Various Process States
Running Interrupt
Interrupt Service Routine
Waiting
Running System Call
Return from System Call
Ready
Scheduler
© Sateesh KG
Difference between User Space & Kernel Space
Multi-user Operating Systems.
One user -> can execute several programs simultaneously.
Programs require access to hardware / resources.
Need for protection of these “resources”. O.S needs to provide this protection.
This can ONLY be achieved if the CPU cooperates with the O.S to enforce access.
CPU’s provide support by running at different “levels”.
Unix / Linux use two levels ( though CPUs map provide more…)
Under Linux, the kernel code executes at the highest level, whereas user code executes at the lowest level.
We usually refer to Kernel Space and User Space since in addition to processor privilege levels, each mode has its own memory mapping as well.
Linux transfers execution from user space to kernel space whenever an application issues a system call or whenever an application is suspended by a hardware interrupt. Triggering a 0x80 interrupt switches processor to higher level.
Kernel code executing a system call is working in the context of a process. It will be able to access data in the process's address space. Interrupt handling code however is asynchronous with respect to processes.
© Sateesh KG
Useful web sites:
1. www.kernel.org
2. www.lwn.net
3. www.tldp.org
4. www.freshmeat.net
5. www.kernelnewbies.org
6. www.linuxdevices.com
Also you can refer
Linux-Journal
Linux-Gazette
Embedded Linux Journal.© Sateesh KG
top related