1 / 22

CS 6560 Operating System Design

CS 6560 Operating System Design. Lecture 5: System Calls Interrupts. System Calls. LKD: Chapter 4: System Calls. References. Our textbook: Robert Love, Linux Kernel Development, 2nd edition, Novell Press, 2005. Understanding the LINUX Kernel, 3rd. edition, O’Reilly, 2005. (covers 2.6)

anoush
Download Presentation

CS 6560 Operating System Design

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 6560 Operating System Design Lecture 5: System Calls Interrupts

  2. System Calls • LKD: Chapter 4: System Calls

  3. References • Our textbook: Robert Love, Linux Kernel Development, 2nd edition, Novell Press, 2005. • Understanding the LINUX Kernel, 3rd. edition, O’Reilly, 2005. (covers 2.6) • Class notes at Georga Tech: • http://www-static.cc.gatech.edu/classes/AY2001/cs3210_spring/ • Intel Documentation: • http://developer.intel.com/design/index.htm

  4. Why System Calls? • Need a model and a mechanism for users to access system resources, which is • User portable: abstracts kernel to users • Device portable: abstracts kernel to devices • Safe: protects users and devices • Efficient: simple and fast

  5. Standardization • POSIX: IEEE 1003 • Describes Kernel Application Interface (API) (more at the level of a C library)

  6. How? • User program calls a C function which jumps into the kernel • Architecture dependent, for x86, two ways: • Software interrupt • Sysenter instruction: see Intel Docs

  7. Design Principles • System calls should • Have a single purpose • Implement method, not policy

  8. Steps for System Call • 1) Push registers on stack • 2) call library function • 3) place function # in register (register eax on x86) (or stack) • 4) execute INT instruction (INT 80h on x86 machines) or special sys call instruction • 5) dispatch to sys call interrupt handler, change to privileged mode • 6) runs sys_xx function in the kernel • 7) return to library function in user mode • 8) return back to program • 9) clean up the stack

  9. Function Call Numbers • See man 2 intro - This is the man chapter on system calls (may be out of date) • Locate unistd.h files in various places • In the system for app development • /usr/include/asm/ • /usr/include/kernel/ • In the kernel development files • include/asm- • Locate entry point - depends upon arch. For example, for i386: ./arch/i386/kernel/syscall_table.S: .long sys_fork

  10. Entry Points • ENTRY(sys_call_table) • .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */ • .long sys_exit • .long sys_fork • .long sys_read • .long sys_write • .long sys_open /* 5 */ • .long sys_close • .long sys_waitpid • .long sys_creat • .long sys_link • .long sys_unlink /* 10 */ • .long sys_execve • .long sys_chdir • .long sys_time

  11. Numbers correspond • #ifndef _ASM_I386_UNISTD_H_ • #define _ASM_I386_UNISTD_H_ • /* • * This file contains the system call numbers. • */ • #define __NR_restart_syscall 0 • #define __NR_exit 1 • #define __NR_fork 2 • #define __NR_read 3 • #define __NR_write 4 • #define __NR_open 5 • #define __NR_close 6 • #define __NR_waitpid 7 • #define __NR_creat 8 • #define __NR_link 9 • #define __NR_unlink 10

  12. include/asm-i386/unistd.hsame as /usr/include/ • #ifndef _ASM_I386_UNISTD_H_ • #define _ASM_I386_UNISTD_H_ • /* • * This file contains the system call numbers. • */ • #define __NR_restart_syscall 0 • #define __NR_exit 1 • #define __NR_fork 2 • #define __NR_read 3 • #define __NR_write 4 • #define __NR_open 5 • #define __NR_close 6 • #define __NR_waitpid 7 • #define __NR_creat 8 • #define __NR_link 9 • #define __NR_unlink 10 • #define __NR_execve 11

  13. Details • Read in the book: • How it works • How to make one • Look at Georgia Tech class notes • Diagrams • More details • Strace function • HW assignment next week to make and install a system call

  14. Final point • Don’t just add more system calls - keep the kernel interface simple

  15. Interrupts • LKD Ch6

  16. Why Interupts? • Allow CPU to exchange data with slow devices • Handle exceptions - error conditions • Provide protected access to resources such as the kernel

  17. How do Interrupts Work? • Use Interrupt handlers: Interrupt service routines (ISR) • Just C functions that can be called at any time • Must return quickly • Run in special context • Must be registered (Use: request_itq)

  18. Example ISR • See the text for an example

  19. Interrupt Context • Context (while in kernel): • Process Context • Executing a system call on behalf of a process • current points to task_struct of current process • Interrupt Context • Reponding to an interrupt • current points to task_struct of whatever process was interrupted

  20. Top and Bottom Halves • Conflicting needs: • Return quickly • Get lots of work done • Solution: Break up the interrupt processing into two parts • Top half: returns quickly, after setting up work to be done • Bottom half: scheduled by the kernel to get work done at a later time (see next chapter)

  21. /proc entry • Look at /proc/interrupts

  22. Details • Read the book for more details • Disabling and enabling interrupts • Knowing status of an interrupt • More needed: must know a lot more before writing any code, see /usr/src/linux/Documentation • Next time: look at example and study deferred work: top and bottom halves

More Related