1

Click here to load reader

Computer Systems

Embed Size (px)

DESCRIPTION

basic introduction to computer systems

Citation preview

Page 1: Computer Systems

Initial ComputersHardware circuits operated on data stored in memory. Initial circuits were hardwired. One has to rewire the circuit to change the program. Then programmable systems allowed users to easily. This device can be used to perform any computation , depending on which switches are closed.

Von Neumann Computers.

if the instruction sequence is move,add,mul the programmer would write [1000,0100,0001] . However it was realized that 00,01,10,11 would be sufficient to encode. Thus it becomes necessary to decode the instruction before executing.

Thus the job of CPU is to fetch instructions from main memory, decode them, and execute them.Tominimize logic gates used the number of instructions the CPU can recognize is kept small. Frequently accessed data and instructions are kept in cache. If the program is too big to be kept in the main memory then only the required sections of the program are loaded from disk to the main memory

Computer SystemsCSA Showcase Illumination

von Neumann realized that not only data, but also the instructions could be stored in memory. The CPU operates on data and instructions to produce output

The Linker combines executables of multiple programs and combines them into a single one. The loaders loadsthem into memory

Process of Translation

The user gives the program in terms of high level language like C++. This has to be translated to instructions understandable by the CPU. The compiler does this job. The compiler allocates memory locations for variables in the program, converts high level language statements into machine code.

How the Memory looks at runtimeThe memory is divided into various segments. The stack like behavior of functions leads to an elegant mechanism for handling local variables (which are destroyed when a function returns) Space allocated by malloc / new remains in heap unless freed

Supporting Multiple ProcessOften users want to execute multiple programs (process) on the CPU. When a Running process issues a IO call (for example), that program is suspended ( put into Waiting state ). Meanwhile other process can utilize the CPU.

This means process can be swapped in and out of memory to disk. Thus addressing within a process should not be tied to a specific physical address. So logical address is used in the process and the hardware (MMU) converts the logical address into physical address.

The virtual address space is larger than the physical address space, allowing programs to use a larger address space, so the programmer/compiler can produce code without worrying about the actual memory size of the system.

Instead of loading the entire program into the memory at once, we can load the required chunks of memory as and when necessary. This is called demand paging. Since transfer of pages from disk to memory is costly, demand paging reduces this cost.

The Linker combines the executable from various programs into memory.

The Loader loads the final executable into memory. When you type a.out the loader is invoked.

Supporting Multiple Processsome of the issues are

Synchronization: When multiple processes are run, there may be need to synchronize . For eg.CPU can produce data faster than a terminal can accept (consume). This is modeled as producer consumer problem with buffer as the critical resource to avoid buffer overflow/underflow. A process requests permission to use the resource and releases it after using it .If the request cannot be satisfied, the process is put onto a queue of waiting process. This is an example of simple semaphore mechanism.

Deadlock: This occurs when processes wait for each other to release resources.

All these issues must be handled by OS

Mutual Exclusion: Shared memory and devices are critical regions whose access must be regulated. The figure shows what happens if access to terminal is not regulated

Handling Mutual Exclusion: Each process executes a primitive called Reserve, which allocates the resource if available or waits until it becomes available.

process Pi{

while( true ){

Reserve Use Critical ResourceReleaseNon Critical code

}}

This Reserve and Release can be handled using Semaphore mechanism, which acts like lock variable, but instead of busy waiting includes a scheduling mechanism that puts the waiting process on the queue.The OS is

responsible for maintaining the page table and also for protecting processes from accessing memory of another

Activation Record of a function

The state of main() when control passes to f() is stored in activation record.

An activation record holds information relevant to the activation of a procedure.