1 / 28

MY SOLUTION FOR THE 4330/6310 FIRST ASSIGNMENT Summer 2014

MY SOLUTION FOR THE 4330/6310 FIRST ASSIGNMENT Summer 2014. Jehan-François Pâris jfparis@uh.edu. Why?. To be able to give better guidance to students To show it can be done. How?. I wrote the program in Python 3 Greatly simplifies list management

london
Download Presentation

MY SOLUTION FOR THE 4330/6310 FIRST ASSIGNMENT Summer 2014

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. MY SOLUTION FOR THE4330/6310 FIRST ASSIGNMENTSummer 2014 Jehan-François Pârisjfparis@uh.edu

  2. Why? • To be able to give better guidance to students • To show it can be done

  3. How? • I wrote the program in Python 3 • Greatly simplifies list management • Useful refresher for my Python skills before the fall semester • The outcome • Less than 200 lines of code • Eleven functions

  4. C C S Q RQ IN SSD The model We have • One dual-core CPU • One SSD • One input device • Two queues • CPU queue "ready queue" • SSD queue

  5. Major data structures • Process list • To store input data • Event list • Core status • Ready queue • Disk status • Disk queue

  6. INPUT5100 CPU100 CPU20 CPU20 SSD0 CPU80 The process list (I) processlist[0] CPU20 processlist[1]

  7. The process list (II) • Process list • An array of linked lists • One linked list per process • Each list contains all computational steps for a process • Will pop them out while going through the steps • Array index is process ID

  8. 5ARRIVAL 0 35CORE 0 100ARRIVAL 1 100ARRIVAL 1 100ARRIVAL 1 5105INPUT 0 The event list (I) At starttime Next Next

  9. The event list (II) • Linked list containing future events • Process arrivals • CPU request completions • SSD request completions • Input request completions • Each entry contains • The event time (sort key) • The event type • The ID of the process

  10. The cores' status • An integer between 0 and 2 • 2 means both cores are free • 0 means both cores are busy • Must queue incoming processes • Will be • Decremented when a process grabs a core • Incremented when a process releases a core

  11. The ready queue • Contains processes waiting for the CPU • Each entry contains • A process ID • A request duration • FIFO queue

  12. The SSD status • An integer between 0 and 1 • 1 means SSD is free • 0 means SSD us busy • Must queue incoming processes • Will be • Decremented when a process grabs the SSD • Incremented when a process releases it

  13. The SSD queue • Contains processes waiting for the SSD • Each entry contains • A process ID • A request duration • FIFO queue

  14. A less critical data structure • The process table • Array of strings • Indexed by process IDs • The possible values: • READY • RUNNING • WAITING

  15. Program organization • Initialization • The main loop • Printing the summary

  16. Initialization • Read the input file • Populate • Event list with event notices for process arrivals • Process list with computational steps of each process

  17. Eventlist INPUT5100 CPU100 CPU20 SSD0 5ARRIVAL 0 100ARRIVAL 1 CPU80 The outcome (I) Process list= Array of lists CPU20

  18. The outcome (I) --- --- pid = 0 pid = 1 Process table "---" stands here for undefined status

  19. The main loop while eventlist is not empty :get next event from event list # it specifies a time, an event, and a process idset clock to time of eventif event == 'ARRIVAL' : arrival(pid)elif … All events are either arrivals or step completions

  20. The arrival event function def arrival(pid) : get first request from processlist[pid] # it specifies a request type and its duration if request == 'CPU': core_request(pid, duration) else : print('PANIC!')

  21. The core request function def core_request(pid, duration) : if a core is free : update number of free cores process_table[pid] = "RUNNING" schedule core completion event at time clock + duration for process pid else : process_table[pid] = "READY" enter process pid and request duration in ready queue

  22. The core completion function def core_completion(pid) : clock = time if ready queue is empty : update number of free coreselse: pick first process anotherpid in ready queue anotherduration is its request duration process_table[anotherpid] = "RUNNING" schedule core completion event at time clock + anotherduration for process anotherpidnext_request(pid)

  23. Other request/completion functions • SSD request and SSD completion functions are very similar to the core request and completion functions • There is only one SSD • Must keep track of SSD service times • Process status will always be "WAITING" • INPUT request and completion functions are trivial

  24. The nextrequest function def nextrequest(pid) : if processlist[pid] is empty : process_table[pid] = 'TERMINATED' else : get next request from processlist[pid] if request == 'CPU' : core_request(pid, duration) elif …

  25. How the functions call each other • Main loop processes an event notice and calls either a process arrival function or arequest completion function • In either case, the function ends with a call to the next request function • This function will call a resource request function • Unless the requested resource is busy, the request function will create an event notice

  26. Main funtion processes an arrival event Arrival function Next step function An example Core request function New core completion event

  27. Core completion Next step function Another example Main function processes an core completion event SSD request function New SSD completion event

  28. Main function processes an SSD completion event SSD completion Next step function A last example Core request function New core completion event

More Related