1. 10 marks · processing environments: • single processor systems • multiprocessor systems •...

12
1. Discuss, with examples, how the problem of maintaining coherence of cached data manifests itself in the following processing environments: Single processor systems Multiprocessor systems Distributed systems   Let us look at the following example: Suppose an integer A which is to be incremented by 1 is located in file B, and file B resides in magnetic disk. The increment operation proceeds by first issuing an I/O operation to copy the disk block on which A resides to main memory. This operation is followed by copying A to the cache and to an internal register. Thus, the copy of A appears in several places; on the magnetic disk, in main memory, in the cache and in an internal register (Fig below). Once the increment takes place in the internal register, the value of A differs in the various storage systems. The value of A becomes the same only after the new value of A is written from the internal register back to the magnetic disk. Single processor systems In a computing environment where only one process executes at a time, this arrangement poses no difficulties, since access to integer A will always be to the copy at the highest level of hierarchy. However, in a multitasking environment, where the CPU is switched back and forth among various processes, extreme care must be taken to ensure that, if several processes wish to access A, then each process will obtain the most recently updated value of A. Multi-processor systems It is a bit more complicated since each of the CPUs might contain its own local cache. In such an environment, a copy of A may exist simultaneously in several caches. Since the various CPUs can all execute concurrently, we must make sure that an update to the value of A in one cache is immediately reflected in all other caches where A 10 Marks B.E 5 th  Semester

Upload: others

Post on 10-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

1. Discuss, with examples, how the problem of maintaining coherence of cached data manifests itself in the followingprocessing environments:

• Single processor systems• Multiprocessor systems• Distributed systems   

Let us look at the following example:Suppose an integer A which is to be incremented by 1 is located in file B, and file B resides in magnetic disk. The increment operation proceeds by first issuing an I/O operation to copy the disk block on which A resides to main memory. This operation is followed by copying A to the cache and to an internal register. Thus, the copy of Aappears in several places; on the magnetic disk, in main memory, in the cache and in an internal register (Fig below).

Once the increment takes place in the internal register, the value of A differs in the various storage systems. Thevalue of A becomes the same only after the new value of A is written from the internal register back to the magneticdisk.

Single processor systemsIn a computing environment where only one process executesat a time, this arrangement poses no difficulties, since access to integer A will always be to the copy at the highest level of hierarchy. However, in a multitasking environment, where the CPU is switched back and forth among various processes, extreme care must be taken to ensure that, if several processes wish to access A, then each process will obtain the most recently updated value of A.

Multi­processor systemsIt is a bit more complicated since each of the CPUs might contain its own local cache. In such an environment, a copy of A may exist simultaneously in several caches. Since the various CPUs can all execute concurrently, we must make sure that an update to the value of A in one cache is immediately reflected in all other caches where A

10 Marks

B.E 5th Semester

Page 2: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

resides. This situation is called cache coherency, and is usually a hardware problem.

Distributed systemsThe situation here is even more complex. In this environment, several copies of the same file can be kept on different computers that are distributed in space. Since the various replicas may be accessed and updated concurrently, some distributed systems ensure that, when areplica is updated in one place, all other replicas are brought up to date as soon as possible.

B.E 5th Semester

Page 3: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

2a. Describe the differences between symmetric and asymmetric multiprocessing. 

Asymmetric multiprocessingThere are multiple processors in the system.

Each processor is assigned a specific task.

A master processor controls the system; the other processors either look to the master for instruction or have predefined task. 

This is basically a master­slave relationship.

The master processor schedules and allocates work for the slave processors.

Symmetric multiprocessing (SMP)Each processor performs all tasks within the operating system.

SMP means that all processors are peers; there is no master­slave relationship.

Each processor has its own set of registers and private orlocal cache;

But, all processors share physical memory.

06 Marks

B.E 5th Semester

Page 4: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

2b. What are the advantages and one disadvantage of multiprocessor systems?

Multi­processor systems also known as parallel systems aretightly­coupled systems whose advantages include:

1. Increased throughput2. Economy of scale3. Increased reliability – graceful degradation or fault

tolerance

One of the disadvanges is:If the CPU has an integrated memory controller, then adding CPUs can also increase the amount of memory addressable in the system. Either way, multiprocessing cancause a system to change its memory access model from uniform memory access (UMA) to non­uniform memory access (NUMA). 

UMA is defined as the situation in which access to any RAMfrom any CPU takes the same amount of time. With NUMA, some parts of memory may take longer to access than other parts, creating a performance penalty. 

04 Marks

3 With a neat diagram, explain briefly, the different services provided by a typical operating system.

10 Marks

B.E 5th Semester

Page 5: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

One set of operating­system services provides functions that are helpful to the user:User interface ­ Almost all operating systems have a user interface (UI). Varies between Command­Line (CLI), Graphics User Interface (GUI), Batch

Program execution ­ The system must be able to load a program into memory and to run that program, end execution, either normally or abnormally (indicating error)

I/O operations ­  A running program may require I/O, whichmay involve a file or an I/O device

File­system manipulation ­  The file system is of particular interest. Programs need to read and write filesand directories, create and delete them, search them, listfile Information, permission management.

Communications – Processes may exchange information, on the same computer or between computers over a networkCommunications may be via shared memory or through messagepassing (packets moved by the OS)

Error detection – OS needs to be constantly aware of possible errors. May occur in the hardware or software. For each type of error, OS should take the appropriate action to ensure correct and consistent computing

Debugging facilities can greatly enhance the user’s and 

B.E 5th Semester

Page 6: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

programmer’s abilities to efficiently use the system

Another set of OS functions exists for ensuring the efficient operation of the system itself via resource sharing

Resource allocation ­ When  multiple users or multiple jobs running concurrently, resources must be allocated to each of themMany types of resources ­  Some (such as CPU cycles, main memory, and file storage) may have special allocation code, others (such as I/O devices) may have general request and release code

Accounting ­ To keep track of which users use how much andwhat kinds of computer resources

Protection and security ­ The owners of information storedin a multiuser or networked computer system may want to control use of that information, concurrent processes should not interfere with each other

4a Explain, with the help of a state transition diagram, the different states, a process can be in.

05 Marks

B.E 5th Semester

Page 7: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

Process StatesAs a process executes, it changes state. The state of a process is defined in part by the current activity of thatprocess. Each process may be in one of the following states:New. The process is being created.Running. Instructions are being executed.Waiting. The process is waiting for some event to occur (such as an I/0 completion or reception of a signal).Ready. The process is waiting to be assigned to a processor.Terminated. The process has finished execution.

4b. Explain what a queuing diagram is, with the help of a diagram.

05 Marks

B.E 5th Semester

Page 8: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

A common representation of process scheduling is a queueing diagram, such as that shown in Figure. Each rectangular box represents a queue. Two types of queues are present: the ready queue and a set of device queues. The circles represent the resources that serve the queues,and the arrows indicate the flow of processes in the system.

A new process is initially put in the ready queue. It waits there until it is selected for execution, or is dispatched. Once the process is allocated the CPU and is executing, one of several events could occur:

1. The process could issue an I/0 request and then be placed in an I/0 queue.

2. The process could create a new subprocess and wait for the subprocess's termination.

3. The process could be removed forcibly from the CPU, as a result of an interrupt, and be put back in the ready queue.

In the first two cases, the process eventually switches from the waiting state to the ready state and is then put back in the ready queue. A process continues this cycle until it terminates, at which time it is removed from all queues and has its PCB and resources deallocated.

B.E 5th Semester

Page 9: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

5. Describe the differences between short­term, medium­term and long­term schedulers.

Often, in a batch system, more processes are submitted than can be executed immediately. These processes are spooled to a mass­storage device (typically a disk), wherethey are kept for later execution

The long­term scheduler or job scheduler, selects processes from this pool and loads them into memory for execution. 

The short­term scheduler or CPU scheduler, selects from among the processes that are ready to execute and allocates the CPU to one of them.

Differences between the long­term and the short­term schedulersThe primary distinction between these two schedulers lies in frequency of execution. 

The short­term scheduler must select a new process for theCPU frequently. 

A process may execute for only a few milliseconds before waiting for an I/0 request. Often, the short­term scheduler executes at least once every 100 milliseconds. Because of the short time between executions, the short­term scheduler must be fast. 

The key idea behind a medium­term scheduler is that sometimes it can be advantageous to remove processes from memory (and from active contention for the CPU) and thus reduce the degree of multiprogramming. Later, the process can be reintroduced into memory, and its execution can be continued where it left off. This scheme is called swapping. The process is swapped out, and is later swappedin, by the medium­term scheduler. Swapping may be necessary to improve the process mix or because a change in memory requirements has overcommitted available memory,requiring memory to be freed up 

10 Marks

B.E 5th Semester

Page 10: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

6. With the help of a relevant code snippet, explain how the bounded buffer can be used to enable processes to share memory.

One solution to the producer­consumer problem uses shared memory. To allow producer and consumer processes to run concurrently, we must have available a buffer of items that can be filled by the producer and emptied by the 

10 Marks

B.E 5th Semester

Page 11: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

consumer. This buffer will reside in a region of memory that is shared by the producer and consumer processes. A producer can produce one item while the consumer is consuming another item. The producer and consumer must be synchronized, so that the consumer does not try to consumean item that has not yet been produced.

The bounded buffer assumes a fixed buffer size. In this case, the consumer must wait if the buffer is empty, and the producer must wait if the buffer is full.

The following variables reside in a region of memory shared by the producer and consumer processes:#define BUFFER_SIZE 10typedef struct{…}item;item buffer[BUFFER_SIZE];int in = 0;int out = 0;

The shared buffer is implemented as a circular array with two logical pointers: in and out. The variable in points to the next free position in the buffer; out points to thefirst full position in the buffer. 

When is the buffere empty? When is it full?The buffer is empty when in== out; the buffer is full when((in+ 1)% BUFFER_SIZE) == out.

item nextProduced;while (true) {   /* Produce an item in nextProduced*/        while ((in + 1) % BUFFER SIZE)  == out)

     ;   /* do nothing ­­ no free buffers */    buffer[in] = nextProduced;    in = (in + 1) % BUFFER SIZE;

     }The producer process.

item nextConsumed;while (true) {while (in == out); II do nothingnextConsumed = buffer[out];out = (out + 1) % BUFFER_SIZE;I* consume the item in nextConsumed *I }

B.E 5th Semester

Page 12: 1. 10 Marks · processing environments: • Single processor systems • Multiprocessor systems • Distributed systems Let us look at the following example: Suppose an integer A

The consumer process.

B.E 5th Semester