Docsity

Project Specification - Phase 1 for Operating Systems | CS 3243, Study Guides, Projects, Research of Operating Systems

Toggle sidebar
bg1
Project Specification – Phase 1
CS 3243/5243 – Operating Systems
The semester course project is on the design and implementation of an OS simulator. The simulator will
run on a virtual CPU. The CPU’s architecture and instruction repertoire are posted at the course
website. The specification of the basic OS simulator is also posted at the course website. The project
would involve making changes to the already presented code and thus enhancing the OS simulator.
The project is divided into two phases. Phase 1 has two parts. The requirements for Phase 1 are
discussed at the end of the document.
To facilitate better understanding of the project, the original specification used to develop the basic OS
simulator is presented below. In addition, the source code for most of Phase 1 is also provided.
Original Specification:
The memory hierarchy comprises a set of simulated registers, a program/data simulated RAM, called
memory and a simulated hard drive called disk. The contents of the disk and RAM are hex characters;
and of sizes 2048 and 1024 words, respectively. (Each word is 4 bytes or 8 hex characters long.)
Ancillary programs to dispatch processes/programs from disk to RAM, to compute effective addresses,
to access memory, to fetch instructions and decode instructions will also be needed. Additional support
programs for conversions between hex, decimal, and binary numbers will be necessary.
The following sections describe the components of the simulator and its virtual machine environments.
The Driver:
The OS driver constitutes the core, or the main thread, of the simulator. Its function is to simply call the
loader to load user programs, which are already assembled (given as a stream of hex character) and
call the CPU to execute the programs in RAM. When a program completes, or an interrupt is received,
the Driver dispatches the next program, or responds to interrupts accordingly. This cycle continues
forever or until your simulator is shut down when no more user programs are pending.
The following program sketch should help you design and implement the Driver module for a single
batched system:
Driver {
loader();
loop
scheduler();
dispatcher();
CPU();
waitforinterrupt();
endloop;
}
The Loader
The loader module opens (once at the start) the program-file and does the loading of the user
programs/jobs into the disk. Programs are loaded into disk according to the format of the batched user
programs in the program-file. Ancillary programs would be needed to process (strip off) the special
control “cards” – which start with, e.g., ‘// Job1 17 2’ before storing the (binary) hex-code. The data
sections start with, e.g., ‘// Data B C C’.
pf3
pf4
pf5

Partial preview of the text

Download Project Specification - Phase 1 for Operating Systems | CS 3243 and more Study Guides, Projects, Research Operating Systems in PDF only on Docsity!

Project Specification – Phase 1 CS 3243/5243 – Operating Systems The semester course project is on the design and implementation of an OS simulator. The simulator will run on a virtual CPU. The CPU’s architecture and instruction repertoire are posted at the course website. The specification of the basic OS simulator is also posted at the course website. The project would involve making changes to the already presented code and thus enhancing the OS simulator. The project is divided into two phases. Phase 1 has two parts. The requirements for Phase 1 are discussed at the end of the document. To facilitate better understanding of the project, the original specification used to develop the basic OS simulator is presented below. In addition, the source code for most of Phase 1 is also provided. Original Specification: The memory hierarchy comprises a set of simulated registers , a program/data simulated RAM, called memory and a simulated hard drive called disk. The contents of the disk and RAM are hex characters; and of sizes 2048 and 1024 words, respectively. (Each word is 4 bytes or 8 hex characters long.) Ancillary programs to dispatch processes/programs from disk to RAM, to compute effective addresses, to access memory, to fetch instructions and decode instructions will also be needed. Additional support programs for conversions between hex, decimal, and binary numbers will be necessary. The following sections describe the components of the simulator and its virtual machine environments. The Driver: The OS driver constitutes the core, or the main thread, of the simulator. Its function is to simply call the loader to load user programs, which are already assembled (given as a stream of hex character) and call the CPU to execute the programs in RAM. When a program completes, or an interrupt is received, the Driver dispatches the next program, or responds to interrupts accordingly. This cycle continues forever or until your simulator is shut down when no more user programs are pending. The following program sketch should help you design and implement the Driver module for a single batched system: Driver { loader(); loop scheduler(); dispatcher(); CPU(); waitforinterrupt(); endloop; } The Loader The loader module opens (once at the start) the program-file and does the loading of the user programs/jobs into the disk. Programs are loaded into disk according to the format of the batched user programs in the program-file. Ancillary programs would be needed to process (strip off) the special control “cards” – which start with, e.g., ‘// Job1 17 2’ before storing the (binary) hex-code. The data sections start with, e.g., ‘// Data B C C’.

The // Job1 17 2 means user program/job 1 is of size 17(hex) or (23 in decimal) words with the priority set to 2. Data segment of the program starts with // Data B C C which means the number of words in the input buffer is B (11 in hex), the size of the output buffer is 12 (C in hex) words and the size of the temporary buffer is 12 (in hex) words. The control cards in the program-file contain directives – attribute data about each program, which must be extracted and stored in the program’s profile/history in the Process Control Block (PCB) (see below). The basic steps of the loader are: while not end-of-programdata-file do { Read-File(); Insert hex-code into disk[disk-base-reg + j-th index]; } The Scheduler The Scheduler loads programs from the disk into RAM. The scheduler must note in the PCB, which physical addresses in RAM each program/job begins. This ‘start’ address must be stored in the base- register of the process. It must also use the Input/Output buffer size information (in the control cards) for allocating space in RAM. The Scheduler method either loads one program at a time (in a simple batching system) or multiple programs (in a multiprogramming system) depending on passed parameter(s). Thus, the Scheduler works closely with the Memory manager and the Effective-Address method. The basic steps of the scheduler are: b := 0; for (j=0; j < N; j++) { // N is the number of programs to load to fit memory k := 0; // k controls the number of lines of hex-chars of program while not end-of-program do // each line has 4 instructions (or words) or 32 hex characters (16 bytes) if (size[j] – 32k >= 32) { // you may change this logic to suit your purpose for(i=0; i<32; i++) { memory[b+memory-base-reg + i + 32k] := disk[b+disk-base-reg + i + 32k]; //base-reg points to 1st^ byte b := i + 32k; } } // end of if==true else { for (t=0; t < size[j] - 32k; t++) { memory[b+memory-base-reg + t + 32k] := disk[disk-base-reg + t+ 32k]; b := t + 32k; } } // end of else k++; end do; } Memory This method is the only means/unit by which RAM can be accessed. A known absolute/physical address must always be passed to this method. The Memory simply fetches an instruction or datum or writes datum into RAM. Effective-Address This method takes a logical address and returns the corresponding absolute/physical address for the calling unit (e.g., the CPU). The Effective-Address method also supports the Fetch and Decode

The heart of the DMA-channel module/thread will look like the following: loop switch(type) { case 0: Read(ch, next(p_rec), buf[next_io]); case 1: Write(ch, next(p_rec), buf[next_io]); } signal(ComputeOnly) // signal the main CPU to use the channel/bus next_io := next_io + 4; // assuming 1 word of 4 bytes at a time end; //loop ComputeOnly This method implements a simple instruction cycle algorithm with dynamic relocation of the program (via the base-register technique). loop w : = Fetch(memory[map(PC)]);// fetch instruction at RAM address – mapped PC Decode(w, oc, addrptr); // part of decoding of the instruction in w PC := PC + 1; // getting ready for next instruction Execute(oc) { case 0: // corresponding code using addrptr of operands case 1: // corresponding code or send interrupt … } end; // loop The CPU is supported by a PCB, which may have the following (suggested) structure: typedef struct PCB { cpuid: // information the assigned CPU (for multiprocessor system) struct state: // record of environment that is saved on interrupt // including the pc, registers, permissions, buffers, caches, active // pages/blocks code-size; struct registers: // accumulators, index, general struct sched: // burst-time, priority, queue-type, time-slice, remain-time struct accounts: // cpu-time, time-limit, time-delays, start/end times, io-times struct memories: // page-table-base, pages, page-size // base-registers – logical/physical map, limit-reg struct progeny: // child-procid, child-code-pointers parent: ptr; // pointer to parent (if this process is spawned, else ‘null’) struct resources: // file-pointers, io-devices – unitclass, unit#, open-file-tables status; // {running, ready, blocked, new} status_info: // pointer to ‘ready-list of active processes’ or // ‘resource-list on blocked processes’ priority: integer; // of the process }

II. Queues and other code

Need – queues (new, ready, block-on-io, suspend) Need – conversion routines or use built-in calls (C,C++,Java) between hex, decimal, binary types.

III. Multiprocessor Architecture:

The virtual CPU for Phase 1 is distributed system architecture. The core simulation system maintains the memory and the various queues as well as the PCB. A detailed explanation of the working of the system is given below: The loader loads all the programs into disk and the scheduler is called to load the programs into the RAM as specified in the loader section above. The multiprocessor dispatcher (m-dispatcher), which extends the single-CPU dispatcher described above, accesses the ready queue and assigns the processes to available CPU’s in order. Any process can be assigned to any available CPU. The m-dispatcher makes a note of which segment of RAM or memory space is assigned to each CPU and the CPU can only access that part of the RAM. The CPU can access instructions & data specified in only its part of the RAM. Similarly output can be written to only the assigned part of the RAM for a given process. Care must be taken to ensure that the CPU does not modify or access memory outside its assigned space. If a process tries to access memory outside its assigned range, a trap is generated and the program is aborted. The CPU fetches each instruction from its assigned cache, decodes the instruction and executes it. On end of the program (or trap), the CPU signals the scheduler about the end of the program (or trap), and it is assigned the next process from the ready queue. To facilitate the design and minimize the overhead/delay due to bus contention, caches are to be used in each CPU. Each cache must be of equivalent in size to the largest job size. A short-term loader module must be written to support the swapping of instructions/data between the RAM and the caches on context-switches or temporary blocking on interrupts. (This feature will be useful in Phase 2 for page frame replacements.)

Multiprocessor Memory Management:

As mentioned above, the memory is maintained by the system. Therefore, appropriate semaphores and locks must be used to access memory. When a program needs to access the memory, it must first acquire a lock and while it has the lock, no other process should be able to access the memory.

Multiprocessor program cache:

As indicated, each CPU maintains a program cache. As the m-dispatcher assigns a process to a CPU, the whole process is loaded into the program cache of the CPU by the short-term loader. The CPU fetches each instruction from its assigned cache, decodes the instruction and executes it. On the execution of instructions, a note is made of which addresses in the caches, and corresponding addresses in memory, that are being modified. For example, if an instruction specifies to write the output to the memory, the appropriate output buffer-cache is changed. Also the address of the output buffer to be changed in the RAM is noted, and eventually modified in RAM on context switching or blocking due to interrupt. At the end of the program execution, only modified words are written back to the memory. The scheduler is signaled about the end of the program (or trap) and the CPU is assigned the next process from the ready queue. A CPU can be assigned any job such that when a job is blocked or context-switched, it may not be reassigned to the same CPU. Therefore, on context switch it is imperative to write back the modified words of the program cache. At all times, the PCB must be updated to reflect the state of the process on the CPU. This process continues until all the programs are executed or until the ready queue becomes empty.