Os scheduling 2 | Computer Science homework help

5. QUESTIONS

============ Q 1 What are some pros and cons of using the struct of function pointers approach as we did in the MP to link different modules? Does it significantly affect performance? Give some examples of when you would and wouldn't use this approach, and why. The pros and cons are roughly the same. We get some overhead in calling function pointers, but it can open the door to polymorphic classes. No it does not significantly affect the performance. We will use it when we are interested in polymarphic classes, otherwise we don't want to use it. Q 2 Briefly describe the synchronization constructs you needed to implement this MP--i.e., how you mediated admission of threads to the scheduler queue and how you made sure only the scheduled thread would run at any given time. I used synchronous threading to make sure that everythread is executing at its given time. Q 3 Why is the dummy scheduling implementation provided potentially unsafe (i.e. could result in invalid memory references)? How does your implementation avoid this problem? Yes, it is resulting in invalid memory references. My implementation is totally dynamic and allocating memories according to the command line arguments so there is no chance of invalid references. Q 4 When using the FIFO or Round Robin scheduling algorithm, can sched_proc() ever "miss" any threads and exit early before all threads have been scheduled and run to completion? If yes, give an example; if no, explain why not. No, it won't exit without completing all threads. Because all threads are joined and program will execute all the threads before exiting. Q 5 Why are the three variables in scheduler.h declared 'extern'? What would happen if they were not declared 'extern'? What would happen if they were not declared without the 'extern' in any file? Because we want to retain their values for complete execution, and we want to access those variables anywhere in the program with the same value everywhere. Q 6 Describe the behavior of exit_error() function in scheduler.c. Why does exit_error() not use errno? It will just print the error statement along with error_num passed as parameter and exits the program. Q 7 Does it matter whether the call to sched_ops->wait_for_queue(queue) in sched_proc() actually does anything? How would it affect correctness if it just returned right away? How about performance? yes, it matters. If it returns right away, then it will be conflicting with some other thread, so it will harm the correctness. Q 8 Explain how worker_proc() is able to call the appropriate implementation of wait_for_cpu() corresponding to the scheduling policy selected by the user on the command line. Start from main() and briefly explain each step along the way. The main will call the method create_workers along with the information in the command line arguments. create_workers will set the values for worker_args_t object and call the method worker_proc in threads along with the object parameter of worker_args_t which we just set. worker_proc will the call the wait_for_cpu() along with the information of thread in worker_args_t. Q 9 Is it possible that a worker thread would never proceed past the call to wa->ops->wait_for_cpu(&wa->info) when using one of the scheduling policies implemented in this MP? yes, it is possible. For example if all the processes are of 1 unit time and number of maximum processes at one time are less than or equal to the number of threads then they will be finished right away. Q 10 Explain how you would alter the program to demonstrate the "convoy" effect, when a large compute bound job that never yields to another thread slows down all other jobs in a FIFO scheduled system? See Page 402, Stallings, the paragraph starting "Another difficulty with FCFS is that it tends to favor processor-bound processes over I/O bound processes". Why is it difficult to show the benefits of Round Robin scheduling in this case using the current implementation in the machine problem? We can do this by altering the concept of FIFO a little. Like we can have a threshold that a process can maximum stay n time units for the execution, after that the process must wait again for its turn. SMP5: Scheduler with Signals ============================ This MP is a variation of SMP4. In the last MP, we built a simulated OS process scheduler. The scheduler can hold only a certain number of processes (workers) at one time. Once the process has been accepted into the scheduler, the scheduler decides in what order the processes execute. We implemented two scheduling algorithms: FIFO and Round Robin. In this MP, we are to simulate a time-sharing system by using signals and timers. We will only implement the Round Robin algorithm. Instead of using iterations to model the concept of "time slices" (as in the last MP), we use interval timers. The scheduler is installed with an interval timer. The timer starts ticking when the scheduler picks a thread to use the CPU which in turn signals the thread when its time slice is finished thus allowing the scheduler to pick another thread and so on. When a thread has completely finished its work it leaves the scheduler to allow a waiting thread to enter. Please note that in this MP, only the timer and scheduler send signals. The threads passively handle the signals without signaling back to the scheduler. The program takes a number of arguments. Arg1 determines the number of jobs (threads in our implementation) created; arg2 specifies the queue size of the scheduler. Arg3 through argN gives the duration (the required time slices to complete a job) of each job. Hence if we create 2 jobs, we should supply arg3 and arg4 for the required duration. You can assume that the autograder will always supply the correct number of arguments and hence you do not have to detect invalid input.

Here is an example of program output, once the program is complete:

% scheduler 3 2 3 2 3

Main: running 3 workers with queue size 2 for quanta:

3 2 3 Main: detaching worker thread 3075926960. Main: detaching worker thread 3065437104. Main: detaching worker thread 3054947248. Main: waiting for scheduler 3086416816. Scheduler: waiting for workers. Thread 3075926960: in scheduler queue. Thread 3075926960: suspending. Thread 3065437104: in scheduler queue. Thread 3065437104: suspending. Scheduler: scheduling. Scheduler: resuming 3075926960. Thread 3075926960: resuming. Scheduler: suspending 3075926960. Scheduler: scheduling. Scheduler: resuming 3065437104. Thread 3065437104: resuming. Thread 3075926960: suspending. Scheduler: suspending 3065437104. Scheduler: scheduling. Scheduler: resuming 3075926960. Thread 3075926960: resuming. Thread 3065437104: suspending. Scheduler: suspending 3075926960. Scheduler: scheduling. Scheduler: resuming 3065437104. Thread 3065437104: resuming. Thread 3075926960: suspending. Scheduler: suspending 3065437104. Thread 3065437104: leaving scheduler queue. Scheduler: scheduling. Scheduler: resuming 3075926960. Thread 3075926960: resuming. Thread 3065437104: terminating. Thread 3054947248: in scheduler queue. Thread 3054947248: suspending. Scheduler: suspending 3075926960. Thread 3075926960: leaving scheduler queue. Scheduler: scheduling. Scheduler: resuming 3054947248. Thread 3054947248: resuming. Thread 3075926960: terminating. Scheduler: suspending 3054947248. Scheduler: scheduling. Scheduler: resuming 3054947248. Thread 3054947248: suspending. Thread 3054947248: resuming. Scheduler: suspending 3054947248. Scheduler: scheduling. Scheduler: resuming 3054947248. Thread 3054947248: suspending. Thread 3054947248: resuming. Scheduler: suspending 3054947248. Thread 3054947248: leaving scheduler queue. Thread 3054947248: terminating. The total wait time is 12.062254 seconds. The total run time is 7.958618 seconds. The average wait time is 4.020751 seconds. The average run time is 2.652873 seconds. The goal of this MP is to help you understand (1) how signals and timers work, and (2) how to evaluate the performance of your program. You will first implement the time-sharing system using timers and signals. Then, you will evaluate the overall performance of your program by keeping track of how long each thread is idle, running, etc.

The program will use these four signals:

SIGALRM: sent by the timer to the scheduler, to indicate another time quantum has passed. SIGUSR1: sent by the scheduler to a worker, to tell it to suspend. SIGUSR2: sent by the scheduler to a suspended worker, to tell it to resume. SIGTERM: sent by the scheduler to a worker, to tell it to cancel. You will need to set up the appropriate handlers and masks for these signals.

You will use these functions:

clock_gettime pthread_sigmask pthread_kill sigaction sigaddset sigemptyset sigwait timer_settime timer_create Also, make sure you understand how the POSIX:TMR interval timer works. There are two ways you can test your code. You can run the built-in grading tests by running "scheduler -test -f0 rr". This runs 5 tests, each of which can be run individually. You can also test you program with specific parameters by running "scheduler -test gen ..." where the ellipsis contains the parameters you would pass to scheduler. Programming =========== Part I: Modify the scheduler code (scheduler.c) ----------------------------------------------- We use the scheduler thread to setup the timer and handle the scheduling for the system. The scheduler handles the SIGALRM events that come from the timer, and sends out signals to the worker threads. Step 1. Modify the code in init_sched_queue() function in scheduler.c to initialize the scheduler with a POSIX:TMR interval timer. Use CLOCK_REALTIME in timer_create(). The timer will be stored in the global variable "timer", which will be started in scheduler_run() (see Step 4 below). Step 2. Implement setup_sig_handlers(). Use sigaction() to install signal handlers for SIGALRM, SIGUSR1, and SIGTERM. SIGALRM should trigger timer_handler(), SIGUSR1 should trigger suspend_thread(), and SIGTERM should trigger cancel_thread(). Notice no handler is installed for SIGUSR2; this signal will be handled differently, in step 8. Step 3. In the scheduler_run() function, start the timer. Use timer_settime(). The time quantum (1 second) is given in scheduler.h. The timer should go off repeatedly at regular intervals defined by the timer quantum. In Round-Robin, whenever the timer goes off, the scheduler suspends the currently running thread, and tells the next thread to resume its operations using signals. These steps are listed in timer_handler(), which is called every time the timer goes off. In this implementation, the timer handler makes use of suspend_worker() and resume_worker() to accomplush these steps. Step 4. Complete the suspend_worker() function. First, update the info->quanta value. This is the number of quanta that remain for this thread to execute. It is initialized to the value passed on the command line, and decreases as the thread executes. If there is any more work for this worker to do, send it a signal to suspend, and update the scheduler queue. Otherwise, cancel the thread. Step 5. Complete the cancel_worker() function by sending the appropriate signal to the thread, telling it to kill itself. Step 6. Complete the resume_worker() function by sending the appropriate signal to the thread, telling it to resume execution. Part II: Modify the worker code (worker.c) ------------------------------------------ In this section, you will modify the worker code to correctly handle the signals from the scheduler that you implemented in the previous section. You need to modify the thread functions so that it immediately suspends the thread, waiting for a resume signal from the scheduler. You will need to use sigwait() to force the thread to suspend itself and wait for a resume signal. You need also to implement a signal handler in worker.c to catch and handle the suspend signals. Step 7. Modify start_worker() to (1) block SIGUSR2 and SIGALRM, and (2) unblock SIGUSR1 and SIGTERM. Step 8. Implement suspend_thread(), the handler for the SIGUSR1 signal. The thread should block until it receives a resume (SIGUSR2) signal. Part III: Modify the evaluation code (scheduler.c) -------------------------------------------------- This program keeps track of run time, and wait time. Each thread saves these two values regarding its own execution in its thread_info_t. Tracking these values requires also knowing the last time the thread suspended or resumed. Therefore, these two values are also kept in thread_info_t. See scheduler.h. In this section, you will implement the functions that calculate run time and wait time. All code that does this will be in scheduler.c. When the program is done, it will collect all these values, and print out the total and average wait time and run time. For your convenience, you are given a function time_difference() to compute the difference between two times in microseconds. Step 9. Modify create_workers() to initialize the various time variables. Step 10. Implement update_run_time(). This is called by suspend_worker(). Step 11. Implement update_wait_time(). This is called by resume_worker().

Questions

==========

5,371views
4.8
(115 ratings)

Related Study Guides

3 Assignment Remote Work Environments in a Global Corporation. | CSIS 343 - Cybersecurity

3. Endpoint Security Measures: Propose endpoint security measures to ensure the security of devices used for remote work. Discuss strategies for securing both corporate-owned and employee-owned device...

computer-sciencepolitical-science

3 Assignment Remote Work Environments in a Global Corporation. | CSIS 343 - Cybersecurity

2. Secure Remote Access Solutions: Recommend secure remote access solutions for employees working from various locations. Discuss the importance of Virtual Private Networks (VPNs), multi-factor authen...

educationhuman-resources

4 questions | Applied Sciences homework help

5. Prospective clients should receive a detailed list of all fees and costs. A study of 31 people whose photograph and testi- monial had appeared in newspaper ads for a weight-loss clinic found that 2...

communicationeducation

4 questions | Applied Sciences homework help

73. Fleiger K. A skeptic’s guide to medical “breakthroughs.” FDA Consumer 21(9):13, 1987. Part One Dynamics of the Health Marketplace32 Frauds and Quackery There is nothing men will not do . . . to re...

art-designhuman-resources

4 questions | Applied Sciences homework help

6. The patient has a basic right to have available adequate health care. Physicians, along with the rest of society, should continue to work toward this goal. Fulfillment of this right is dependent on...

art-designnursing

Assignment 10 Blockchain Security Audit for a Supply Chain Company.docx | CSIS 343 - Cybersecurity

2. Potential Weaknesses and Attack Vectors: a. 51% Attacks: If an entity controls more than 50% of a blockchain network's computing power (in PoW blockchains), it can potentially manipulate transactio...

educationhuman-resources

Assignment 2 Physical Security for a National Data Center. | CSIS 343 - Cybersecurity

1. Access Control and Biometric Security: Assess the current access control measures for the national data center. Propose enhancements, including the implementation of biometric access controls, smar...

art-designphysics

Assignment 3 Mobile Device Security Policy and Implementation | CSIS 343 - Cybersecurity

1. Introduction to Mobile Device Security: Provide an introduction to the importance of mobile device security, especially in the context of BYOD policies, and why it's crucial for protecting corporat...

political-sciencehuman-resources

Need Help With A Similar Question?

Our experts deliver perfect solutions with guaranteed A+ grades

A+
Student Grade
98%
Success Rate
12h
Delivery Time
Join 1,000+ students who got their perfect solutions
Rated 4.9/5 by satisfied students

Need Help With This Question?

Academic Expert

Subject Matter Specialist

98%
Success Rate
24/7
Support

Why Students Trust Us

  • PhD-Level Expertise
  • Original Work Guarantee
  • Better Grade or Free

"Got an A+ on my assignment. Exactly what I needed!"

Recent Student