190 likes | 360 Views
제 33 강 : Copy Semantics(Adding IO Devices). Copy Semantics. Q: Why not DMA directly into user space? A: Because of copy semantics After write() system call returns, Powerpoint file is updated again. What does user expect? “ … previous I/O is already done at disk.
E N D
제33강 : Copy Semantics(Adding IO Devices) Copy Semantics
Q: Why not DMA directly into user space? • A: Because of copy semantics • After write() system call returns, Powerpoint file is updated again. • What does user expect? “ … previous I/O is already done at disk. now I have two versions: version of data written to disk newer version in Powerpoint …..” • How do you guarantee that? • Copy application data into kernel buffer before returning to user from sys call • Despite overhead, clean semantics is guaranteed. • What overhead? • (device <-> kernel buf <-> user buf) – Do you always need this overhead? • Read: Silberschatz et. Al., OS Concepts, Wiley, 6th-ed, p 474. kernel buffer
disk_tab t1 d_actf d_actl
disk_tab t1 d_actf d_actl update t2 “I have two versions one in disk, another in core”
disk_tab d_actf d_actl t1 update t2 “I have only one version before now
unix/conf.c file is created, along with the file “low.s”, by the program “mkconf.c”, to reflect the actual configuration of peripheral devices on a system. 4656: int (*bdevsw[])( ) 4657: { 4658: &nulldev, &nulldev, &rkstrategy, &rktab, /* rk */ 4659: &nodev, &nodev, &nodev, 0, /* rp */ 4660: &nodev, &nodev, &nodev, 0, /* rf */ 4661: &nodev, &nodev, &nodev, 0, /* tm */ 4662: &nodev, &nodev, &nodev, 0, /* tc */ 4663: &nodev, &nodev, &nodev, 0, /* hs */ 4664: &nodev, &nodev, &nodev, 0, /* hp */ 4665: &nodev, &nodev, &nodev, 0, /* ht */ 4666: 0 4667: }; 4668: 4669: int (*cdevsw[])( ) 4670: { 4671: &klopen, &klclose, &klread, &klwrite, &klsgtty, /* console */ 4672: 4673: &pcopen, &pcclose, &pcread, &pcwrite, &nodev, /* pc */ 4674: 4675: &lpopen, &lpclose, &lpread, &lpwrite, &nodev, /* lp */
d_open d_close d_read d_write new device address of device drivers 4635: struct cdevsw { /* array of structs pointing to functions */ 4636: int (*d_open)(); 4637: int (*d_close)(); 4638: int (*d_read)(); 4639: int (*d_write)(); 4640: int (*d_sgtty)(); 4641: } cdevsw[]; 4669: int (*cdevsw[] )() /* array of pointer to functions */ 4670: { 4671: &klopen, &klclose, &klread, &klwrite, &klsgtty, /* console */ 4672: 4673: &pcopen, &pcclose, &pcread, &pcwrite, &nodev, /* pc */ 4674: 4675: &lpopen, &lpclose, &lpread, &lpwrite, &nodev, /* lp */ 4676: 4682: &nulldev, &nulldev, &mmread, &mmwrite, &nodev, /* mem */ 4683: 4684: &nulldev, &nulldev, &rkread, &rkwrite, &nodev, /* rk */ 4692: 4693: }; unix/conf.h -------------------------- unix/conf.c --------------------------
d_open d_close d_read d_write new device address of device drivers switch tabledevswtab[] 4617 4635 15-1 • Run mkconf.c (In Linux, sysctl?) at each installation which checks presence/absence of I/O devices generate files for devsw[] (conf.c *.s ..) compile these files (conf.c *.s ..) *.o • Compile new device drivers, interrupt handler • Link kernel a.out • Reboot kernel new array cdevsw[] bdevsw[] low.s open) close() read() write()
Bus & I/O interface CPU 0000000 7777XXX 7777XXX 7777777 bus MMU memory bus I/O bus I/O Interface Memory address data read/write diagnose power off power busy/idle error … control status
vendor device name pointer to SW … plus new bus protocol (USB, PCI …) Bus & I/O interface CPU 0000000 7777XXX 7777XXX 7777777 bus MMU memory bus I/O bus I/O Interface Memory address data read/write diagnose power off control status vendor id device id interrupt line
Vendor Id Device Id Command Status Base Address Registers Interrupt Line ….. PCI (Peripheral Component Interconnect) Bus 32Bit bus for intel PC 1992 – by Intel supports PnP every device connected to PCI slot has configuration data structure PCI device header example: USB (Universal Serial Bus) serial interface specification for PC (1999 – Intel & 7 companies) Max 480 Mbps, can connect up to 127 devices (with USB Hub) supports PnP
PnP (Plug & Play) • In the past – OS build/reboot required – for every device add/remove • Hot-plug • one can add/remove device while system is running • introduced by Windows 95 1. User plugs in the device to I/O bus (USB-bus, PCI-bus, …) 2. New HW standard – recognize device and Interrupts the system 3. Device provides info. (new interface) eg {Vendor-name/ Device-name} 4. OS allocates “resources” eg interrupt address, memory address 5. OS looks for device drivers eg {IBM/HD-A} Miss? – Ask user for media 6. OS register addresses of the drivers Bus slot ID D1 D2 D3 D4 … open close read write ioctl Read_lp devswtab[]
Linux kernel module (1/3) Remember DLL? Some functions could be loaded/linked on demand during the run. Several functions can be grouped and packaged into “modules”. Linux kernel • Kernel module • Lumps of code that can be • dynamically linked into kernel • after system boot • Can be unlinked from kernel and removed dynamically • Benefit: • small (400KB) memory. flexible kernel • (no rebuild, no reboot needed to try new feature) • Typical Content: • device driver, file system, new kernel features, ... ... module 1 module 2 module 3 Each has symbol table
Linux kernel module (2/3) • To link new module (to in-core kernel) • 2 Methods: (1) use commands -- insmod(1), rmmod(1) commands (2) on-demand by running program -- kerneld daemon a. kernel realizes module missing (eg Mac file system) b. kernel notifies (IPC) kerneld c. kerneld finds & loads the module d. add new module’s symbols on top of current (memory resident) kernel’s symbol table this is called ("module stacking") e. unlink , unmount this module
Linux kernel module (3/3) • To unlink a module • notify the module • the module releases all system resources (semaphore, heap storage, ...) • delete module's symbol from kernel symbol table • delete module’s code