1 / 26

BrickOS Scheduling

BrickOS Scheduling. Solving The Low-Priority Starvation Problem. Introduction. Jon Rogers Robbie Edwards Melanie Sparks. Project Description.

zoey
Download Presentation

BrickOS Scheduling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. BrickOS Scheduling Solving The Low-Priority Starvation Problem

  2. Introduction Jon Rogers Robbie Edwards Melanie Sparks

  3. Project Description • Investigate the way the scheduling algorithm is currently implemented. Change it so that higher priority processes cannot starve the low priority processes.

  4. Project Facets 1 Researching the problem 2 Defining a solution 3 Building a development environment 4 Modifying the source code 5 Testing and verification

  5. Researching The Problem • Research the operating system scheduler • Identify the relevant source code • Determine the current scheduling implementation

  6. Researching The Problem - Results • BrickOS employs a preemptive scheduler with a prioritized round-robin algorithm for choosing the next process to run.

  7. Researching The Problem - Detailed Results • Each process is given a default time slice of 20ms to run before being interrupted by the OS and another process is allowed to run • In choosing the next process to run, the OS searches through each process queue, beginning with the highest priority queue, and runs the first READY process

  8. Hence The Problem - • If there are always processes of higher priority that are ready to run, lower priority processes will be starved out

  9. Defining A Solution • The Challenge: to prevent starvation while preserving process priority • The Solution: Chain Wait, another selection parameter • Chain Wait will numerically represent the maximum number of scheduler executions for which a particular priority chain will be exempt (e.g. no processes from this priority chain will be chosen: waiting)

  10. The Algorithm Initialization: All chain wait values will be set to zero Scheduler will do a linear search through the priority chains for runnable processes Upon running a process, the chain wait for its priority queue will be set to 20-P+1, where P is the numeric priority and scheduler will resume its linear search

  11. The Algorithm For each priority queue with a chain wait greater than zero, decrement the chain wait and move to the next queue ignoring ready processes from this queue If the linear search is complete and no runnable processes are found, all chain waits are reset to 0

  12. Building A Development Environment • Installation of Cygwin on the target Windows machine • Building the Hitachi-H8 cross-compiler : a trivial initialization followed by a very long compile process • Installing BrickOS • Installing the USB tower and drivers • Testing the environment : Hello World and Play Song • Testing the environment, part II : creating a test program that counts down and plays a song

  13. Changing The Source Code – Additions To tm.h • Implementation begins with adding a new function, "tm_clear_waits()", that will (as advertised) clear the chain waits, resetting them to zero. void tm_clear_waits() { pchain_t* priority; priority = priority_head; while((int) priority->priority >= PRIO_LOWEST) { priority->chain_wait = 0; priority = priority->next; } }

  14. Changing The Source Code – Additions To tm.c • Implementation of the solution continues with the introduction of a new field, an integer "chain_wait", to the existing data structure struct _pchain_t, in the tm.h header file struct _pchain_t { priority_t priority; // numeric priority level struct _pchain_t *next; // lower priority chain struct _pchain_t *prev; // higher priority chain struct _tdata_t *ctid; // current task in chain int chain_wait; // # of times to be ignored by scheduler };

  15. Changing The Source Code - Changes To tm.c • We modified tm.c inside the function "size_t *tm_scheduler(size_t *old_sp)" at the point where the next process must be chosen • This scheduler function is called by the process switcher which in turn is called by a yield function • Yield is called by an function that becomes a zombie [through "exit(..)"], when a process has used its timeslice [through systime_handler(..)], or when a process sleeps [through wait_event(..)].

  16. Original Code • The original code, in which we will choose the next process.. while(1) { if(next->tstate==T_SLEEPING) // if the next task is SLEEPING break; // we just run it if(next->tstate==T_WAITING) { // if it's WAITING, wake it and run it ... break; } } if(next == priority->ctid) { // if done searching this priority queue ... priority = priority->next; // search the next priority queue ... next=priority->ctid->next; // move to the next one in line in that priority } else next=next->next; // otherwise we're still searching this queue }

  17. New Code • Inside the while loop that searches for the next process, the code is modified as follows: while(1) { if(priority->chain_wait > 0) {// If there is a chain wait for this priority level --(priority->chain_wait);// then decrement the wait. if(priority->next != NULL) { if((int) priority->next->priority < PRIO_LOWEST) {// If we have ignored the lowest priority level tm_clear_waits(); // then clear all chain waits and begin the priority=priority_head; // search for a process again at the highest next=priority->ctid->next; // priority level. }

  18. New Code else { priority = priority->next; // Otherwise, next = priority->ctid->next; } //search the next priority level. } ... // debugging code omitted else priority = priority_head; ... }

  19. New Code else { if(next->tstate==T_SLEEPING)// if the next task is SLEEPING, break; // we just run it if(next->tstate==T_WAITING) { // if it's WAITING ... break; // wake it and run it } // sound familiar? } ... // the remainder of the code } // inside the while loop is unmodified

  20. Changing The Source Code • Upon exiting the while loop that selects the next process to run, set the process' priority level's chain wait. priority->chain_wait = ((int) PRIO_HIGHEST - (int) priority->priority) + 1; For example, if PRIO_HIGHEST is 20 and the process to be executed is of priority 10, then the chain wait for priority level 10 will be set to (20-10)+1 = 11.

  21. Changing The Source Code • And the last bit of code added, within the process "tid_t execi(..)" upon initializing a new priority queue the chain_wait must also be set ... newpchain->priority=priority; newpchain->chain_wait = 0; // initialize chain_wait to 0 newpchain->ctid=td; ...

  22. Testing And Verification • Loading the new operating system • Documenting the lack of starvation • Showing that all threads run no matter the priority

  23. Testing And Verification - Code • The test program: gizmo.c pid2=execi(&motor_driver, 0, NULL, 20, DEFAULT_STACK_SIZE); pid3=execi(&foo1, 0, NULL, 20, DEFAULT_STACK_SIZE); pid4=execi(&foo2, 0, NULL, 20, DEFAULT_STACK_SIZE); pid5=execi(&foo3, 0, NULL, 10, DEFAULT_STACK_SIZE);

  24. Testing And Verification - Code In the old brickOS, this process would have been starved out. But not in ours. pid6=execi(&playSong, 0, NULL, 1, DEFAULT_STACK_SIZE); You know the scheduler is working correctly when you hear the song playing.

  25. Testing And Verification - Results The song played repeatedly, indicating that the forked process with priority zero was not starved out by the higher priority processes. All processes were shown to have been scheduled.

  26. Thank You And Good Night

More Related