Question

In: Computer Science

(Five Users - DOIO – Two Device drivers – Two Disks) 1.- In this assignment you...

(Five Users - DOIO – Two Device drivers – Two Disks)

1.- In this assignment you will implement a simulation of the interaction of user programs with the OS to execute an I/O operation on two different devices.

User programs:

User programs will communicate with DOIO (OS) to request an I/O operation. (This will simulate a system call)

User programs will give to DOIO three parameters: User id, device number (dev is a random number in the range 1 and 2 that represents device one or device two) and an address (addr is a random number in the range 1 and 20.) (addr is an integer that represents a track number in the hard drive).

User programs will pass the parameters to DOIO through three buffers of size one each (bufid, bufdev, and bufaddr).

Once the parameters are stored in the buffers, user programs executes a p(request_served[ “index” ]) operation to wait for the completion of the I/O operation. You will need a semaphore array request_served[id].

There will be four users running concurrently and each will execute 4 I/O operations.

DOIO:

DOIO will collect and id, device(dev), and address(addr) from bufid, bufdev, and bufaddr to assemble the IORB.

DOIO will check on device number to decide which one of the two devices will get the IORB.

Once the device has been selected, DOIO will store the IORB (id and addr) into the two buffers that represent the IORQ (iorqid and iorqaddr) of the selected device. Notice that you need separate buffers (one for each device: iorqid and iorqaddr and iorqid2 and iorqaddr2). IORQ size four.

DOIO must wait to receive signals from Device drivers indicating that all request have been served. Then DOIO will shut down both Disks.

Device drivers (1 and 2):

Device drivers will collect an IORB (made up of id and addr) from iorqid and iorqaddr (or iorqid2 and iorqaddr2) and then initiate the physical I/O operation on the hard drive it controls and wait for the I/O operation to be completed: p(operation_complete).

The device driver initiates the physical I/O operation by storing addr into a buffer of length one. The buffer name is “pio” (physical I/O).

When the I/O operation completes a signal is received, the Device driver will identify the User that issued the I/O request using the id, and will signal the semaphore “request_served[id]” associated to the User.

When the last request has been served, both drivers have to signal DOIO to indicate that all requests have been handled and both drivers will emit a message: “Driver 1 (2) stops”

Disk (1 and 2):

The Disk processes simulates the access to a track in the hard drive.

The Disk process gets the addr from pio and stores it in a variable called “seek” and iterates in a dummy loop from 1 to “seek”.

Once out of the loop, disk will execute a v on the semaphore “operation_complete

Disk will operate continuously until DOIO shuts them down.

Note:

  1. Define all semaphores that you need according to the number of buffers used.
  2. Each user will make 5 system calls to initiate I/O operations
  3. DOIO will create 20 IORB
  4. The sum of the I/O operations executed by drivers must add up 20. You will need a shared variable to control the total number of I/O operations because it is not known before hand the numbers of I/O operations initiated by each Device driver.
  5. Once Drivers have served all request they have to signal DOIO.
  6. Once DOIO receives signals from Drivers indicating all request have been served. DOIO will shut down both Disks.   

Project Direction:

You will write the program C--based on the BACI interpreter


lol, this is the whole assignment. theres bo more info to post.

Solutions

Expert Solution

The below code might resolve the problem provided above. Please go through the code and try to understand the details of every line by which the code is invoking different modules and functions.

const int bufferSize = 5;
const int loopAmount = 25;

semaphore FULL1, FULL2, FULL3;
semaphore MUTEX1, MUTEX2, MUTEX3;
semaphore PRINT;
semaphore PIO, SIO;
semaphore operationComplete;
semaphore requestPending;
semaphore requestService[bufferSize];

int IORQid[bufferSize];
int IORQaddr[bufferSize];
int bufferAddress = 0, bufferID = 0, track = 0;

void User (int userID) {
int i, j, address = 0;
for(j = 0; j < bufferSize; j++){
address = random(i+1) % 200; /* notice the range of random number is not same as the problem above */
p(FULL1);
p(MUTEX1);
bufferID = userID;
bufferAddress = address;
p(PRINT);
cout << "User " << userID + 1 << " executes system call SIO" << endl;
v(PRINT);
v(MUTEX1);
v(SIO);
p(requestService[userID]);
}
}

void DOIO() {
int i = 0, tempID, tempAddr, index;

for (index = 0; index < loopAmount; index++){
p(SIO);
p(MUTEX1);

tempID = bufferID;
tempAddr = bufferAddress;
v(MUTEX1);
v(FULL1);

p(FULL2);
p(MUTEX2);

IORQid[i] = tempID;
IORQaddr[i] = tempAddr;

i = (i+1) % 5;

p(PRINT);
cout << "DOIO assembles IORB for user " << tempID + 1 <<
" and inserts it in IORQ" << endl;
v(PRINT);

v(MUTEX2);
v(requestPending);
}

}

void DeviceDriver() {
int j = 0, driverAddress = 0, driverID = 0, i;
for (i = 0; i < loopAmount; i++){
p(requestPending);
p(MUTEX2);

driverID = IORQid[j];
driverAddress = IORQaddr[j];

j = (j+1) % 5;

v(MUTEX2);
v(FULL2);
p(FULL3);
p(MUTEX3);

track = driverAddress;
v(MUTEX3);
v(PIO);

p(PRINT);
cout << "Driver initiates I/O operation for user " << driverID + 1<< endl;
v(PRINT);


p(operationComplete);
v(requestService[driverID]);


p(PRINT);
cout << "Driver signal user " << driverID + 1 <<" to informed that I/O request is served."<< endl;
v(PRINT);
}
}

void Disk() {
int i = 0, seek = 0, diskAddress = 0, j;
for (j = 0; j < loopAmount; j++){
p(PIO);
p(MUTEX3);
seek = track;
v(MUTEX3);
diskAddress = seek * 20;
for (i = 1; i <= diskAddress; i++){} //Dummy Loop
v(operationComplete);
p(PRINT);
cout << "Disk signal driver(operation complete)" << endl;
v(PRINT);
v(FULL3);
}
}

main () {

initialsem (MUTEX1, 1);
initialsem (MUTEX2, 1);
initialsem (MUTEX3, 1);
initialsem (PRINT,1);
initialsem (FULL1, 1);
initialsem (FULL2, 5);
initialsem (FULL3, 1);
initialsem (SIO, 0);
initialsem (PIO, 0);
initialsem (requestPending, 0);
initialsem (operationComplete, 0);
initialsem (requestService[0], 0);
initialsem (requestService[1], 0);
initialsem (requestService[2], 0);
initialsem (requestService[3], 0);
initialsem (requestService[4], 0);

cobegin {
User(0);
User(1);
User(2);
User(3);
User(4);
DOIO();
DeviceDriver();
Disk();

}
}


Related Solutions

1. Company B, manufactures a unique device that is used by internet users to boost internet...
1. Company B, manufactures a unique device that is used by internet users to boost internet signals. The following data relates to the first month of operation: Beginning inventory: 0 units Units produced: 40,000 units Units sold: 35,000 units Selling price: $120 per unit Marketing and administrative expenses: Variable marketing and administrative expenses per unit: $4 Fixed marketing and administrative expenses per month: $1,120,000 Manufacturing costs: Direct materials cost per unit: $30 Direct labor cost per unit: $14 Variable manufacturing...
For this assignment you are required to build a system using BBC Micro:bit device. You will...
For this assignment you are required to build a system using BBC Micro:bit device. You will use the Micro:bit to gather data automatically using its sensors; and make it available on the internet. You are to deliver this data in a rigorous fashion to a PC attached via USB using the onboard Python, and then to run a local Python server on the PC with appropriate web pages to serve the result locally. Remote access to the PC is not...
1.) Why do we have to install different Device Drivers for different Operating Systems for a...
1.) Why do we have to install different Device Drivers for different Operating Systems for a particular I/O device? 2.) A process can share all or part of its PCB data with other processes. List and explain two methods can be used to accomplish this task. 3.) List the memory units inside and outside of the CPU, along with short descriptions of their purposes.
1. You have the choice of selecting a networking device with WEP or a device with...
1. You have the choice of selecting a networking device with WEP or a device with WPA. Which offers better      security and why? 2. The term association is characterized by which of the following? a. Describe the MAC address of the client. b. Prevent excessive routing. c. Describe that a wireless connection has been obtained. d. Prevent unauthorized network access. 3. Wi-Fi is which of the following? a. The Wi-Fi Alliance, which is an organization that tests and certifies...
A batch of 500 disks contains 5 defectiv disks. Two are selected randonly without replacement, from...
A batch of 500 disks contains 5 defectiv disks. Two are selected randonly without replacement, from the batch. Let A and B denote the events that the first and the second selected disks are defective, respectively. a) Are A and B independents events? b) If the samplins was done with replacement, would A and B be independent?
. Company B, manufactures a unique device that is used by internet users to boost internet...
. Company B, manufactures a unique device that is used by internet users to boost internet signals. The following data relates to the first month of operation: Beginning inventory: 0 units Units produced: 40,000 units Units sold: 35,000 units Selling price: $120 per unit Marketing and administrative expenses: Variable marketing and administrative expenses per unit: $4 Fixed marketing and administrative expenses per month: $1,120,000 Manufacturing costs: Direct materials cost per unit: $30 Direct labor cost per unit: $14 Variable manufacturing...
Two metal disks, one with radius ?1 = 2.50 cm and mass ?1 = 0.800 kg...
Two metal disks, one with radius ?1 = 2.50 cm and mass ?1 = 0.800 kg and the other with radius ?2 = 5.00 cm and mass ?2 = 1.60 kg are welded together and mounted on a frictionless axis through their common center as shown to the right. a) A light string is wrapped around the edge of the smaller disk and a 1.50 kg block is suspended from the free end of the string. How far will the...
Do you believe it is confusing to users for there to be two sets of financial...
Do you believe it is confusing to users for there to be two sets of financial statements for state and local governments--one set under modified accrual accounting and the other set under accrual accounting? Why or why not?
True or False (xvi) Device drivers are a part of user interface. (xvii) Star networks are...
True or False (xvi) Device drivers are a part of user interface. (xvii) Star networks are same as networks of computers used to process data about stars in the sky. (xviii) 1 petabyte equals 253 bits. (xix) Auditing software in the context of operating systems is a software that creates a software during an attack on a computer/computers, to defend the computer/computers. (xx) A dispatcher in the context of operating systems chooses the activities to consider for execution.
C++ Assignment 1: Make two classes practice For each of the two classes you will create...
C++ Assignment 1: Make two classes practice For each of the two classes you will create for this assignment, create an *.h and *.cpp file that contains the class definition and the member functions. You will also have a main file 'main.cpp' that obviously contains the main() function, and will instantiate the objects and test them. Class #1 Ideas for class one are WebSite, Shoes, Beer, Book, Song, Movie, TVShow, Computer, Bike, VideoGame, Car, etc Take your chosen class from...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT