Unformatted text preview:

1Texas A&M UniversityECEN 449 – Microprocessor System DesignIntroduction to Linux2Texas A&M UniversityObjectives of this Lecture Unit• Learn basics of Linux O/S3Texas A&M UniversityObjectives• The Operating System environment and services• How are services accessed in Linux?4Texas A&M UniversityMotivation• Applications need an execution environment:– Portability, standard interfaces– File and device controlled access– Preemptive multitasking– Virtual memory (protected memory, paging)– Shared libraries– Shared copy-on-write executables– TCP/IP networking– SMP support• Hardware developers need to integrate new devices– Standard framework to write device drivers– Layered architecture dependent and independent code– Extensibility, dynamic kernel modules5Texas A&M UniversityLinux O/S ArchitectureFig. Source: IBM, Anatomy of Linux Kernel6Texas A&M UniversityGeneral view of O/SFig. Source: W. Knottenbelt, UK7Texas A&M UniversityLinux KernelFig. Source: IBM, Anatomy of Linux Kernel8Texas A&M UniversityThe Operating System Kernel• Resident in memory, privileged mode• System calls offer general purpose services• Controls and mediates access to hardware• Implements and supports fundamental abstractions:– Process, file (file system, devices, interprocess communication)• Schedules / allocates system resources:– CPU, memory, disk, devices, etc.• Enforces security and protection• Event driven:– Responds to user requests for service (system calls)– Attends interrupts and exceptions– Context switch at quantum time expiration9Texas A&M UniversityLinux Execution Environment• Program• Libraries• Kernel subsystems10Texas A&M UniversityLinux Execution Environment• Execution paths11Texas A&M UniversityLinux Source Layout12Texas A&M UniversityLinux Code Layout• Linux/arch– Architecture dependent code.– Highly-optimized common utility routines such as memcpy• Linux/drivers– Largest amount of code – Device, bus, platform and general directories– Character and block devices , network, video– Buses – pci, agp, usb, pcmcia, scsi, etc• Linux/fs– Virtual file system (VFS) framework.– Actual file systems: • Disk format: ext2, ext3, fat, RAID, journaling, etc• But also in-memory file systems: RAM, Flash, ROM13Texas A&M UniversityLinux Code Layout• Linux/include– Architecture-dependent include subdirectories.– Need to be included to compile your driver code:• gcc … -I/<kernel-source-tree>/include …– Kernel-only portions are guarded by #ifdefs#ifdef __KERNEL__/* kernel stuff */#endif– Specific directories: asm, math-emu, net, pcmcia, scsi, video.14Texas A&M UniversityVFS and File SystemsFig. Source: Anatomy of Linux Kernel, IBM15Texas A&M UniversityLinux commands• ls : list directory contents• ls –l : long or verbose option to lsdrwxr-xr-x 2 reddy faculty 4096 May 17 2005 bin/d for directory, r for read, w for write x for executable r-x : faculty can read and execute, but can’t writer-x: others can read and execute, but can’t writereddy is the owner, belongs to group “faculty”size is 4096 bytes, created on May 17 2005, name of the directory bin* -rw------- 1 reddy faculty 43231 Jun 20 2007 temp.txt16Texas A&M University• mkdir: create a directory• rm: remove a file• rm –r : remove recursively• rm –i: ask before removing or confirm• vi or emacs : editors to open and edit files• cp : copy one file to another cp file1 file2: copies file1 to file2• cat file1 : list the contents of file1 • more file1: list one screen of file1• grep string file1 : list all the lines in file1 that contain string• mv file1 file2 : move file1 to file2 i.e., rename file1 to file2, remove earlier file if file2 exists.17Texas A&M UniversityLinux commands• diff file1 file2 : find the differences between file1 and file2 • grep string file1 | wc– Look for string in file1 and do “word count” on those lines of the file• Command1 | command2– Run command1 and “pipe” the result into command2• grep string file1 > file2– Store the result of grep into file2 instead of displaying them on the terminal• grep string file1 &– Run the command in the background– Can run other commands in the foreground– Or use the terminal for other things18Texas A&M UniversityReentrant code• A function or code that can be reentered safely– It can be executed safely concurrently• Int i;Function f(){i = i+2;return(i);}• Returned value i can change if two threads enter f concurrently– --Not reentrant19Texas A&M UniversityReentrant code• function f(int i){int temp = i;return (temp+2);}• f() return value is only based on how it is called f(1), f(2) …– Not on the order in which it is called or how many threads are executing f()20Texas A&M UniversityProcess and System Calls• Process: program in execution. Unique “pid”. Hierarchy.• User address space vs. kernel address space• Application requests OS services through TRAP mechanism– x86: syscall number in eax register, exception (int $0x80)– result = read (file descriptor, user buffer, amount in bytes)– Read returns real amount of bytes transferred or error code (<0)• Kernel has access to kernel address space (code, data, and device ports and memory), and to user address space, but only to the process that is currently running• “Current” process descriptor. “currentàpid” points to current pid• Two stacks per process: user stack and kernel stack• Special instructions to copy parameters / results between user and kernel space21Texas A&M UniversityExceptions and Interrupts• Hardware switch to kernel mode. Uses “interrupt stack”.• Synchronous exceptions: page fault, illegal instruction, etc– Triggered in the context of the current process– Can access user space; have a default kernel recovery action– Can be managed by the process itself (signal handling)• Signal (signum, handler) [ signal(SIGSEGV,invalid_mem_handler) ]– Can also be initiated by the kernel or other (related) process• Kill (pid, signum) [ kill(1234, SIGSTOP) ]• Asynchronous interrupts: devices, clock, etc– Not in the context of the related process à no access to user memory, must buffer data in kernel space– Can signal a process (will be handled when scheduled to run)• Traps, exceptions, interrupts can trigger process scheduling22Texas A&M UniversityScheduling and Exception Delivering• Kernel is non preemptible


View Full Document

TAMU ECEN 449 - linux-intro

Download linux-intro
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view linux-intro and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view linux-intro 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?