Os scheduling – part 2

SMP5: Scheduler delay Signals  In the conclusive MP, we built a invented OS rule scheduler. The scheduler can hold simply a positive count of rulees (workers) at one era. Uninterruptedly the rule has been real into the scheduler, the scheduler decides in what manage the processes enact. We utensiled two scheduling algorithms: FIFO and Round Robin. In this MP, we are to pretend a era-sharing symmetricality by using memorables and timers. We procure simply utensil the Round Robin algorithm. Instead of using iterations to type the concept of "era hunks" (as in the conclusive MP), we use meanspan erars.  The scheduler is grounded delay an meanspan erar. The erar starts ticking when the scheduler gathers a cord to use the CPU which in turn signals the cord when its era hunk is perfect thus avowing the scheduler to gather another cord and so on. When a cord has perfectly perfect its achievement it leaves the scheduler to avow a pause cord to penetrate. Please hush that in this MP, simply the erar and scheduler cast memorables. The cords byively manipulate the memorables delayout memorableing tail to the scheduler. The program takes a count of arguments. Arg1 determines the count of jobs (threads in our utensilation) mouldd; arg2 specifies the queue magnitude of the scheduler. Arg3 through argN gives the prolongation (the required era hunks to complete a job) of each job. Hence if we mould 2 jobs, we should yield arg3 and arg4 for the required prolongation. You can wear that the autograder procure always yield the emend count of arguments and hence you do not bear to detect weakly input. Here is an illustration of program output, uninterruptedly the program is complete: % scheduler 3 2 3 2 3 Main: prevalent 3 achievementers delay queue magnitude 2 for quanta:  3 2 3 Main: detaching achievementer cord 3075926960. Main: detaching achievementer cord 3065437104. Main: detaching achievementer cord 3054947248. Main: pause for scheduler 3086416816. Scheduler: pause for achievementers. Thread 3075926960: in scheduler queue. Thread 3075926960: resting. Thread 3065437104: in scheduler queue. Thread 3065437104: resting. Scheduler: scheduling. Scheduler: resuming 3075926960. Thread 3075926960: resuming. Scheduler: resting 3075926960. Scheduler: scheduling. Scheduler: resuming 3065437104. Thread 3065437104: resuming. Thread 3075926960: resting. Scheduler: resting 3065437104. Scheduler: scheduling. Scheduler: resuming 3075926960. Thread 3075926960: resuming. Thread 3065437104: resting. Scheduler: resting 3075926960. Scheduler: scheduling. Scheduler: resuming 3065437104. Thread 3065437104: resuming. Thread 3075926960: resting. Scheduler: resting 3065437104. Thread 3065437104: leaving scheduler queue. Scheduler: scheduling. Scheduler: resuming 3075926960. Thread 3075926960: resuming. Thread 3065437104: terminating. Thread 3054947248: in scheduler queue. Thread 3054947248: resting. Scheduler: resting 3075926960. Thread 3075926960: leaving scheduler queue. Scheduler: scheduling. Scheduler: resuming 3054947248. Thread 3054947248: resuming. Thread 3075926960: terminating. Scheduler: resting 3054947248. Scheduler: scheduling. Scheduler: resuming 3054947248. Thread 3054947248: resting. Thread 3054947248: resuming. Scheduler: resting 3054947248. Scheduler: scheduling. Scheduler: resuming 3054947248. Thread 3054947248: resting. Thread 3054947248: resuming. Scheduler: resting 3054947248. Thread 3054947248: leaving scheduler queue. Thread 3054947248: terminating. The entirety hold era is 12.062254 prevents. The entirety run era is 7.958618 prevents. The average hold era is 4.020751 prevents. The average run era is 2.652873 prevents. The appearance of this MP is to acceleration you perceive (1) how memorables and erars achievement, and (2) how to evaluate the act of your program. You procure first utensil the era-sharing symmetricality using erars and memorables. Then, you procure evaluate the overall act of your program by custody course of how long each cord is indolent, prevalent, etc. The program procure use these filthy memorables: SIGALRM: sent by the erar to the scheduler, to declare another era   quantum has byed. SIGUSR1: sent by the scheduler to a achievementer, to decide it to rest. SIGUSR2: sent by the scheduler to a rested achievementer, to decide it to recommence. SIGTERM: sent by the scheduler to a achievementer, to decide it to countervail. You procure absence to set up the misspend manipulaters and masks for these memorables. You procure use these characters:   clock_gettime   pthread_sigmask   pthread_kill   sigaction   sigaddset   sigemptyset   sigwait   timer_settime   timer_create Also, mould infallible you perceive how the POSIX:TMR meanspan erar achievements. There are two ways you can examination your enactment.  You can run the built-in grading tests by prevalent "scheduler -examination -f0 rr".  This runs 5 examinations, each of which can be run individually.  You can as-well examination you program delay specific parameters by prevalent "scheduler -examination gen ..." where the ellipsis contains the parameters you would by to scheduler. Programming =========== Part I: Variegate the scheduler enactment (scheduler.c) ----------------------------------------------- We use the scheduler cord to setup the erar and manipulate the scheduling for the system.  The scheduler manipulates the SIGALRM events that follow from the erar, and sends out memorables to the achievementer cords. Step 1. Modify the enactment in init_sched_queue() character in scheduler.c to initialize the scheduler delay a POSIX:TMR meanspan erar. Use CLOCK_REALTIME in erar_create(). The erar procure be stored in the global inconstant "timer", which procure be rouseed in scheduler_run() (see Stalk 4 underneath). Step 2. Implement setup_sig_handlers().  Use sigaction() to institute memorable manipulaters for SIGALRM, SIGUSR1, and SIGTERM.  SIGALRM should trigger erar_handler(), SIGUSR1 should trigger rest_thread(), and SIGTERM should trigger countervail_thread(). Notice no manipulater is grounded for SIGUSR2; this memorable procure be manipulated differently, in stalk 8. Step 3. In the scheduler_run() character, rouse the erar.  Use erar_settime().  The era quantum (1 prevent) is ardent in scheduler.h.  The erar should go off repeatedly at symmetrical meantimes defined by the erar quantum. In Round-Robin, whenever the erar goes off, the scheduler rests the currently prevalent cord, and decides the present cord to recommence its operations using memorables. These stalks are listed in erar_handler(), which is designated every era the erar goes off.  In this utensilation, the erar manipulater moulds use of suspend_worker() and recommence_worker() to accomplush these stalks. Step 4. Complete the rest_worker() character.  First, update the info->quanta appreciate. This is the count of quanta that rest for this cord to enact.  It is initialized to the appreciate byed on the bid cord, and decreases as the cord executes.  If there is any over achievement for this achievementer to do, cast it a memorable to suspend, and update the scheduler queue.  Otherwise, countervail the cord. Step 5. Complete the countervail_worker() character by casting the misspend memorable to the thread, decideing it to massacre itself. Step 6. Complete the recommence_worker() character by casting the misspend memorable to the thread, decideing it to recommence preventive. Part II: Variegate the achievementer enactment (worker.c) ------------------------------------------ In this minority, you procure variegate the achievementer enactment to emendly manipulate the memorables from the scheduler that you utensiled in the foregoing minority. You absence to variegate the cord characters so that it directly rests the thread, pause for a recommence memorable from the scheduler. You procure absence to use sigwait() to fibre the cord to rest itself and hold for a recommence memorable. You absence as-well to utensil a memorable manipulater in achievementer.c to clutch and manipulate the rest memorables. Step 7. Modify rouse_worker() to (1) fill SIGUSR2 and SIGALRM, and (2) unfill SIGUSR1 and SIGTERM. Step 8. Implement rest_thread(), the manipulater for the SIGUSR1 memorable.  The cord should fill until it receives a recommence (SIGUSR2) memorable. Part III: Variegate the evaluation enactment (scheduler.c) -------------------------------------------------- This program celebrates course of run era, and hold era.  Each cord saves these two appreciates concerning its own preventive in its cord_info_t.  Tracking these values requires as-well sharp the conclusive era the cord rested or recommenced. Therefore, these two appreciates are as-well kept in cord_info_t.  See scheduler.h. In this minority, you procure utensil the characters that count run era and hold era.  All enactment that does this procure be in scheduler.c.  When the program is produced, it procure amass all these appreciates, and print out the entirety and average hold era and run era.  For your convenience, you are ardent a character time_difference() to value the separation among two eras in microseconds. Step 9. Modify mould_workers() to initialize the diversified era inconstants. Step 10. Implement update_run_time().  This is designated by rest_worker(). Step 11. Implement update_wait_time().  This is designated by recommence_worker(). Questions ========== Question 1. Why do we fill SIGUSR2 and SIGALRM in achievementer.c?  Why do we unfill SIGUSR1 and SIGTERM in achievementer.c? Question 2. We use sigwait() and sigaction() in our enactment. Clear-up the separation among the two. (Please clear-up from the feature of cord manner rather than syntax). Question 3. When we use POSIX:TMR meanspan erar, we are using referring-to era. What is the alternative? Clear-up the separation among the two. Question 4. Look at rouse_worker() in achievementer.c, a achievementer cord is executing delayin an infinite loop at the end. When does a achievementer cord limit? Question 5. When does the scheduler end?  Why does it not debouchure when the scheduler queue is void? Question 6. After a cord is scheduled to run, is it quiescent in the sched_queue? When is it removed from the gathering of the queue? When is it removed from the queue perfectly? Question 7. We've removed all other stipulation inconstants in SMP4, and replaced them delay a timer and memorables. Why do we quiescent use the semaphore queue_sem? Question 8. What's the mind of the global inconstant "completed" in scheduler.c? Why do we compare "completed" delay cord_count antecedently we hold_for_queue() in next_worker()? Question 9. We simply utensiled Round Robin in this SMP. If we absence to utensil a FIFO scheduling algorithm and celebrate the revision as stint, which character in scheduler.c is the one that you should variegate? Briefly portray how you would variegate this character. Question 10. In this utensilation, the scheduler simply alters cords when the era quantum expires.  Briefly clear-up how you would use an subjoined memorable to avow the scheduler to alter cords in the average of a era quantum.  In what situations would this be conducive?