Therac-25 Computer-controlled radiation therapy machine

Slides:



Advertisements
Similar presentations
I/O Systems & Mass-Storage Systems
Advertisements

I/O Management and Disk Scheduling
Chapter 4 Device Management and Disk Scheduling DEVICE MANAGEMENT Content I/O device overview I/O device overview I/O organization and architecture I/O.
Categories of I/O Devices
Device Drivers. Linux Device Drivers Linux supports three types of hardware device: character, block and network –character devices: R/W without buffering.
R4 Dynamically loading processes. Overview R4 is closely related to R3, much of what you have written for R3 applies to R4 In R3, we executed procedures.
FIU Chapter 7: Input/Output Jerome Crooks Panyawat Chiamprasert
Avishai Wool lecture Introduction to Systems Programming Lecture 8 Input-Output.
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Embedded Real-time Systems The Linux kernel. The Operating System Kernel Resident in memory, privileged mode System calls offer general purpose services.
CMPT 300: Final Review Chapters 8 – Memory Management: Ch. 8, 9 Address spaces Logical (virtual): generated by the CPU Physical: seen by the memory.
Device Management.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
1 Today I/O Systems Storage. 2 I/O Devices Many different kinds of I/O devices Software that controls them: device drivers.
I/O Systems CSCI 444/544 Operating Systems Fall 2008.
Group 7 Jhonathan Briceño Reginal Etienne Christian Kruger Felix Martinez Dane Minott Immer S Rivera Ander Sahonero.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Copyright ©: Nahrstedt, Angrave, Abdelzaher
I/O Tanenbaum, ch. 5 p. 329 – 427 Silberschatz, ch. 13 p
Device Management. Serial Port Serial Device Serial Device Memory CPU Printer Terminal Modem Mouse etc.
System Calls 1.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13+14: I/O Systems and Mass- Storage Structure I/O Hardware Application I/O.
1 I/O Management and Disk Scheduling Chapter Categories of I/O Devices Human readable Used to communicate with the user Printers Video display terminals.
Segmentation & O/S Input/Output Chapter 4 & 5 Tuesday, April 3, 2007.
COMP 3438 – Part I - Lecture 4 Introduction to Device Drivers Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Chapter 13: I/O Systems Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Jan 2, 2005 Chapter 13: I/O Systems I/O Hardware.
Hardware Definitions –Port: Point of connection –Bus: Interface Daisy Chain (A=>B=>…=>X) Shared Direct Device Access –Controller: Device Electronics –Registers:
I/O Systems I/O Hardware Application I/O Interface
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Principles of I/0 hardware.
1 Comp 104: Operating Systems Concepts Devices. 2 Today Devices –Introduction –Handling I/O Device handling Buffering and caching.
Recall: Three I/O Methods Synchronous: Wait for I/O operation to complete. Asynchronous: Post I/O request and switch to other work. DMA (Direct Memory.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Device Drivers CPU I/O Interface Device Driver DEVICECONTROL OPERATIONSDATA TRANSFER OPERATIONS Disk Seek to Sector, Track, Cyl. Seek Home Position.
UNIX Files File organization and a few primitives.
Chapter 13: I/O Systems. 13.2/34 Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem Transforming I/O Requests to Hardware.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 13: I/O Systems I/O Hardware Application I/O Interface Kernel I/O Subsystem.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
Chapter 13 – I/O Systems (Pgs ). Devices  Two conflicting properties A. Growing uniformity in interfaces (both h/w and s/w): e.g., USB, TWAIN.
Interfacing Device Drivers with the Kernel
Silberschatz, Galvin and Gagne  Operating System Concepts Six Step Process to Perform DMA Transfer.
1 Lecture 1: Computer System Structures We go over the aspects of computer architecture relevant to OS design  overview  input and output (I/O) organization.
COMP 3438 – Part I - Lecture 5 Character Device Drivers
Slides created by: Professor Ian G. Harris Operating Systems  Allow the processor to perform several tasks at virtually the same time Ex. Web Controlled.
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 12: I/O Systems I/O hardwared Application I/O Interface Kernel I/O.
I/O Software CS 537 – Introduction to Operating Systems.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
ECE 456 Computer Architecture Lecture #9 – Input/Output Instructor: Dr. Honggang Wang Fall 2013.
1 Chapter 2: Operating-System Structures Services Interface provided to users & programmers –System calls (programmer access) –User level access to system.
1 Chapter 11 I/O Management and Disk Scheduling Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and.
Introduction to Operating Systems Concepts
Chapter 13: I/O Systems.
Module 12: I/O Systems I/O hardware Application I/O Interface
Chapter 12: File System Implementation
Operating System I/O System Monday, August 11, 2008.
CS703 - Advanced Operating Systems
CSCI 315 Operating Systems Design
CPSC 457 Operating Systems
I/O Systems I/O Hardware Application I/O Interface
Operating System Concepts
13: I/O Systems I/O hardwared Application I/O Interface
CS703 - Advanced Operating Systems
Lecture Topics: 11/1 General Operating System Concepts Processes
Chapter 5: I/O Systems.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 13: I/O Systems.
Module 12: I/O Systems I/O hardwared Application I/O Interface
Chapter 13: I/O Systems “The two main jobs of a computer are I/O and [CPU] processing. In many cases, the main job is I/O, and the [CPU] processing is.
Presentation transcript:

Therac-25 Computer-controlled radiation therapy machine Massively overdosed 6 people, June 1985–January 1987 Medical linear accelerator Radiation beam bent and spread using magnets Controlled by a PDP-11 Dual-mode – electron setting (low energy) or X- ray photon (high energy) Slides created by: Professor Ian G. Harris

History of the Device Therac-6 Therac-20 Therac-25 Photon mode only Manual device, PDP-11 for convenience Hardware safety features Therac-20 Dual mode device Therac-25 Automatic device PDP-11 required Some hardware safety features replaced by software Slides created by: Professor Ian G. Harris

Turntable Turntable in the wrong position = Death Mirror Rotates equipment into the beam path 3 modes, 3 sets of equipment Electron mode – scan magnets to spread beam X-ray photon mode – flattener needed to focus and weaken beam Very high energy beam Field light position – mirror needed to pass light Turntable in the wrong position = Death Slides created by: Professor Ian G. Harris

Basic Operation Operator enters desired parameters Each parameter is verified by sensors After all parameters are verified, operator can type ‘p’ for ‘proceed’ Treatment Pause shutdown Small parameter variation Wait 5 secs, press ‘p’ Treatment Suspend shutdown Major problem Must reset system Slides created by: Professor Ian G. Harris

Therac-25 Software Borrowed code from Therac-20 Assumed that the code was good Ignored the fact that hardware safety had been removed Written in PDP 11 assembly code Real-time OS developed for this device Preemptive, priority scheduling algorithm 0.1 second time quantum Slides created by: Professor Ian G. Harris

Software Tasks Critical Tasks Non-Critical Tasks Treatment Monitor – manages all stages of the setup and treatment process Servo Task – controls gun emission, dose rate, beam steering, and machine motions Housekeeper Task – performs checks of system status, limits, displays messages to CRT Non-Critical Tasks Keyboard processor Screen processor Hand task – set turntable to proper position for selected mode/power Slides created by: Professor Ian G. Harris

Data Entry Process Treat task accepts data in the Datent state Keyboard handler writes data to the MEOS structure Hand task uses low byte of MEOS to rotate turntable Keyboard handler assumes that: data entry is complete when the cursor is at the bottom of the page Does not consider parameter corrections Slides created by: Professor Ian G. Harris

Data Entry Complete When data entry is complete, Datent does the following Calls MAGNET subroutine to adjust bending magnets Move to Set Up Test state (apply radiation) MAGNET subroutine takes time (8sec), calls Ptime for each magnet Ptime exits if MEOS is changed, but only on the first call to Ptime If MEOS changes during calls to Ptime (other than the first), the change is not registered by Hand Possible Error Operator sets field light mode by mistake Turntable rotates to mirror Operator quickly changes mode to photon mode X-ray photons are emitted with no attenuation Slides created by: Professor Ian G. Harris

Software Problems Bytes of MEOS can be non-correlated Offset parameters byte can be updated while mode/energy byte changes are ignored Access to MEOS should be mutually exclusive No read access while data entry is not complete Proper detection of Data Entry Complete Solution “the key for moving the back through the prescription sequence must not be used for editing or any other purpose.” Slides created by: Professor Ian G. Harris

Second Bug Occurred during the Set Up Test phase, after Datent Each pass through Set Up Test increments the turntable position check variable Class3 If Class3 is non-zero then the turntable position must be checked to match the parameters Set Up Test is executed hundreds of times Rescheduled waiting for other events Class3 is 1 byte long Every 256th pass through Set Up Test, checking is not performed If the operator presses “set” on pass 256, turntable position can be in field light position Slides created by: Professor Ian G. Harris

Hardware Abstraction A processor may use many types of I/O devices Each device has a different interface Look at the datasheets Applications cannot handle variations in hardware There are far too many Operating systems abstract hardware details from user processes Disk vs. USB flash – no difference Slides created by: Professor Ian G. Harris

Device Drivers A uniform interface (mostly) for the interaction between SW and HW devices User Application Library Function System Call Device Driver HW User Space Kernel “Hello, world.” printf vfprintf HDMI or UART driver HDMI or UART port Slides created by: Professor Ian G. Harris

Functions of Device Drivers Initialize the device Accept read/write requests from the layer above Check validity of input parameters Add device-specific detail to requests Disk write – track, sector, cylinder number Check if device is in use Control the device Conform to device input protocol (SATA, I2C, …) Respond to device i.e. accept incoming network message Slides created by: Professor Ian G. Harris

Device Driver Implementation System Call HW Device void vfprintf (…) { open(device); … write(device,data); VGA Controller IC I/O protocol Interrupts Interface to system calls is defined as a standard set of functions Driver code must convert system requests into I/O signaling in the protocol of the device Must respond to interrupts from the device Driver may include interrupt service routines Slides created by: Professor Ian G. Harris

Device Driver Protocol Structure for the behavior of a device driver Each interface function in the driver should write appropriate data into the device registers Most devices have registers to accept commands Typically write to them using standard bus protocol (I2C, etc.) After writing a command, verify that command is accepted Check error conditions (ACK or NACK, etc.) Synchronize with the device I/O Block or not, wait for interrupt or not Several options on this Slides created by: Professor Ian G. Harris

Virtual File System Switch File System Interface All devices look like files on a linux system Special files are created, usually in the /dev directory Device interaction is the same (mostly) as file interaction User programs Virtual File System Switch Hardware fd=open(“/dev/abc”) read(fd) write(fd,dat) close(fd) abc_open() abc_read() abc_write() abc_close() System calls Device driver routines Slides created by: Professor Ian G. Harris

Driver Routine Execution Execute as part of the operating system Need highest access to interact with HW Can be compiled into the kernel Common on embedded systems Drivers are fixed Can be loaded dynamically Loadable Kernel Modules (LKM) in linux Bugs in drivers can be damaging Same access as OS Security vulnerabilities are an issue Slides created by: Professor Ian G. Harris

Types of Devices Three types depending on how data is transferred Character Device Can read and write individual characters efficiently to this device Block Device More efficient to read/write blocks of data (i.e. disk drives) I/O buffering is commonly used Network Device Device needs to be services periodically Interrupts are needed Slides created by: Professor Ian G. Harris

Major and Minor Numbers Each device is assigned a major number which indicates the device type and its driver Minor number is the specific device within the major number Name Create/Owner Permissions Major Minor /dev/usbmon0 root, root crw------- 252 /dev/usbmon1 1 Slides created by: Professor Ian G. Harris

Device Driver Interface Each device must implement an interface according to its type Character drivers implement the file_operations interface struct file_operations { ssize_t (*read) (struct file *, char *, size_t, loff_t *); ssize_t (*write) (struct file *, const char *, size_t, loff_t *); int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); int (*open) (struct inode *, struct file *); int (*release) (struct inode *, struct file *); … }; open, release, read, write are the basics Slides created by: Professor Ian G. Harris

Driver Routine Example Need a driver for an SRAM chip connected via I2C We did this before Philips PCF8570, 256 locations, 8-bit Decide how to map device access to file access operations Device is random access but files are sequential access Solution: Make device sequential access Maintain readPtr and writePtr for next read/write access address Read operation reads from readPtr++ Write operation writes to writePtr++ Slides created by: Professor Ian G. Harris

open and release Note: This is a simplified version Driver-specific data structure in the inode, mem_dev int mem_open(struct inode *inode, struct file *file){ mem_dev->readPtr = 0; mem_dev->writePtr = 0; return 0; } int mem_release(struct inode *inode, struct file *fd){ Slides created by: Professor Ian G. Harris

write considerations Write takes 4 arguments struct file *fp: file pointer (not needed) char *buf: buffer to write to device size_t count: number of bytes to write to device loff_t *ppos: Position in device to write to Should be mem_dev->writePtr Copying data requires special functions User space and kernel space may have different memory mappings May not trust pointers provided by user app copy_to_user(), copy_from_user() Slides created by: Professor Ian G. Harris

write implementation WriteMTSR writes a char to an I2C slave at the given address MEM_I2C_ADDR is the I2C address of the memory Must update *ppos int mem_write(struct file *fp, char *buff, size_t cnt, loft_t *ppos){ char data; for (int i=0; i<cnt; i++) { copy_from_user(&data, buff+cnt, 1); WriteMTSR(MEM_I2C_ADDR, (*ppos)++, data); } return 0; Slides created by: Professor Ian G. Harris

init Function init is called when the driver is loaded Or during boot for a static driver Responsibilities: Associating a device major number with the driver Allocating memory for the per-device structure Connecting the entry points (open(), read(), etc.) with the driver Initializing hardware Check if it exists Slides created by: Professor Ian G. Harris

register_chrdev Function Registers the driver with the virtual file system switch (VFS) struct file_operations mem_fops = { NULL, /* lseek() */ mem_read, /* read() */ mem_write, /* write() */ … }; long mem_init(long kmem_start) { printk("Sample Device Driver Initialization\n"); if (register_chrdev(22, “mem", &mem_fops)) printk("error--cannot register!\n"); TurnOnI2C(); return 0; } Slides created by: Professor Ian G. Harris

Modified version of slide by Paul Krzyzanowski Buffered I/O Kernel copies the write data to a block of memory (buffer): Allow the process to write bytes to the buffer and continue processing Buffer does not need to be written to the disk … yet Read operation: When the device is ready, the kernel places the data in the buffer Why is buffering important? Deals with device burstiness Rate mismatch between host and device Caching (for block devices) Alignment (for block devices) Modified version of slide by Paul Krzyzanowski

Buffer Cache Pool of kernel memory to hold frequently used blocks from block devices Minimizes the number of I/O requests that require device I/O Allows applications to read/write from/to the device as a stream of bytes or arbitrary-sized blocks User I/O Requests Buffer Cache Device Block I/O Requests fast slow Modified version of slide by Paul Krzyzanowski