Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming #2 (Concurrency and the I/O subsystem) (User - DOIO – Device driver

ID: 3910471 • Letter: P

Question


Programming #2 (Concurrency and the I/O subsystem) (User - DOIO – Device driver - Disk) Due June 29th, 2018 (11:59 p.m.) 1.- In this assignment you will implement a simulation of the interaction of user programs with the OS to execute an I/O operation. 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 two parameters: User id 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 two buffers of size one each (bufid and bufaddr). Once the parameters are stored in the buffers, user programs executes a P(request served) operation to wait for the completion of the I/O operation. There will be only one user running and it will execute 5 I/O operations. DOIO: DOIO will collect an id and address(addr) from bufid and bufaddr to assemble the IORB. DOIO will store the IORB (id and addr) into two buffers that represent the IORQ (iorqid and iorqaddr). Device driver: Device driver will collect an IORB (pair id and addr) from iorqid and iorqaddr and then initiates the physical I/O operation on the hard drive and wait for the I/O operation to be completed: P(operation complete). The device driver initiate 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 driver will identify the user that issued the I/O request using the id, and will signal the semaphore “request served” associated to the user. Disk: The disk process 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” a) Define all semaphores that you need according to the number of buffers used. The user will make 5 system calls to initiate I/O operations DOIO will create 5 IORB Project Direction You will write a C-- program based on the BACI interpreter that you used in programming project 1. Test your solution You must run and test your solution and comment on the results emitted. Project Submission What to submit? Submit the source code(.cm file) and the output file showing the results: Example for the print out of results is: User 1 executes system call SIO or DOIO DOIO assembles IORB and inserts it in IORQ Driver initiates I/O operation for user 1 Disk Completes I/O operation (disk does not know what process initiated the I/O operation) Driver signal user 1 (operation complete) User 1 executes system call SIO or DOIO DOIO assembles IORB and inserts it in IORQ And so on… Note: Your output does not need to be exactly to the one presented above
Programming #2 (Concurrency and the I/O subsystem) (User - DOIO – Device driver - Disk) Due June 29th, 2018 (11:59 p.m.) 1.- In this assignment you will implement a simulation of the interaction of user programs with the OS to execute an I/O operation. 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 two parameters: User id 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 two buffers of size one each (bufid and bufaddr). Once the parameters are stored in the buffers, user programs executes a P(request served) operation to wait for the completion of the I/O operation. There will be only one user running and it will execute 5 I/O operations. DOIO: DOIO will collect an id and address(addr) from bufid and bufaddr to assemble the IORB. DOIO will store the IORB (id and addr) into two buffers that represent the IORQ (iorqid and iorqaddr). Device driver: Device driver will collect an IORB (pair id and addr) from iorqid and iorqaddr and then initiates the physical I/O operation on the hard drive and wait for the I/O operation to be completed: P(operation complete). The device driver initiate 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 driver will identify the user that issued the I/O request using the id, and will signal the semaphore “request served” associated to the user. Disk: The disk process 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” a) Define all semaphores that you need according to the number of buffers used. The user will make 5 system calls to initiate I/O operations DOIO will create 5 IORB Project Direction You will write a C-- program based on the BACI interpreter that you used in programming project 1. Test your solution You must run and test your solution and comment on the results emitted. Project Submission What to submit? Submit the source code(.cm file) and the output file showing the results: Example for the print out of results is: User 1 executes system call SIO or DOIO DOIO assembles IORB and inserts it in IORQ Driver initiates I/O operation for user 1 Disk Completes I/O operation (disk does not know what process initiated the I/O operation) Driver signal user 1 (operation complete) User 1 executes system call SIO or DOIO DOIO assembles IORB and inserts it in IORQ And so on… Note: Your output does not need to be exactly to the one presented above
Programming #2 (Concurrency and the I/O subsystem) (User - DOIO – Device driver - Disk) Due June 29th, 2018 (11:59 p.m.) 1.- In this assignment you will implement a simulation of the interaction of user programs with the OS to execute an I/O operation. 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 two parameters: User id 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 two buffers of size one each (bufid and bufaddr). Once the parameters are stored in the buffers, user programs executes a P(request served) operation to wait for the completion of the I/O operation. There will be only one user running and it will execute 5 I/O operations. DOIO: DOIO will collect an id and address(addr) from bufid and bufaddr to assemble the IORB. DOIO will store the IORB (id and addr) into two buffers that represent the IORQ (iorqid and iorqaddr). Device driver: Device driver will collect an IORB (pair id and addr) from iorqid and iorqaddr and then initiates the physical I/O operation on the hard drive and wait for the I/O operation to be completed: P(operation complete). The device driver initiate 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 driver will identify the user that issued the I/O request using the id, and will signal the semaphore “request served” associated to the user. Disk: The disk process 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” a) Define all semaphores that you need according to the number of buffers used. The user will make 5 system calls to initiate I/O operations DOIO will create 5 IORB Project Direction You will write a C-- program based on the BACI interpreter that you used in programming project 1. Test your solution You must run and test your solution and comment on the results emitted. Project Submission What to submit? Submit the source code(.cm file) and the output file showing the results: Example for the print out of results is: User 1 executes system call SIO or DOIO DOIO assembles IORB and inserts it in IORQ Driver initiates I/O operation for user 1 Disk Completes I/O operation (disk does not know what process initiated the I/O operation) Driver signal user 1 (operation complete) User 1 executes system call SIO or DOIO DOIO assembles IORB and inserts it in IORQ And so on… Note: Your output does not need to be exactly to the one presented above

Explanation / Answer

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();

}
}