1 / 47

CS 241 Section (10/28/10)

CS 241 Section (10/28/10). MP6. MP6. This MP is simple: Create a ‘make’ utility. MP6. This MP is simple: Create a ‘make’ utility. What does ‘make’ do? Reads a ‘makefile’ Determines the tasks that available to run based on dependency rules Run until all tasks are finished. MP6.

gitel
Download Presentation

CS 241 Section (10/28/10)

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. CS 241 Section(10/28/10)

  2. MP6

  3. MP6 • This MP is simple: • Create a ‘make’ utility.

  4. MP6 • This MP is simple: • Create a ‘make’ utility. • What does ‘make’ do? • Reads a ‘makefile’ • Determines the tasks that available to run based on dependency rules • Run until all tasks are finished

  5. MP6 job1: job2 job3    commandtoberun withargs    commandtoberun2 withargs job2:    othercommand job3:    finalcommand

  6. MP6 key job1: job2 job3    commandtoberun withargs    commandtoberun2 withargs job2:    othercommand job3:    finalcommand

  7. MP6 dependencies job1: job2 job3    commandtoberun withargs    commandtoberun2 withargs job2:    othercommand job3:    finalcommand

  8. MP6 job1: job2 job3    commandtoberun withargs    commandtoberun2 withargs job2:    othercommand job3:    finalcommand commands

  9. MP6 • We can show this graphically: …job1 depends on job2 and job3 being done. job2 job1 job3

  10. MP6 • In MP6, you will specify (with the –j# option) how many worker threads should run. • “-j1”: Only one worker thread • “-j2”: Two worker threads • “-j100”: One hundred worker threads

  11. MP6 • If the makefile is ran with –j2, then: [thread a]: job2 runs [thread b]: job3 runs [thread b]: job3 finishes [thread b]: idle, job1 not ready[thread a]: job2 finishes [thread a OR b]: job1 runs [thread a OR b]: job1 finishes [thread a AND b]: exit, all jobs done [main thread]: join threads, exit

  12. MP6 • We provide you some tools you can use, if you’d like: • queue.c: A queue data structure • parser.c: A parser for makefiles • parser_parse_makefile(…) takes function pointers as arguments that will be called when it reaches a key, dependency, or command.

  13. MP6 Parser Callbacks parsed_new_key(key=job1) parsed_dependency(key=job1, dep=job2) parsed_dependency(key=job1, dep=job3) parsed_command(key=job1, command=...) parsed_command(key=job1, command=...) parsed_new_key(key=job2) parsed_command(key=job2, command=...) parsed_new_key(key=job3) parsed_command(key=job3, command=...)

  14. MP6 • Some useful functions: • pthread_create(), pthread_join() • sem_init(), sem_wait(), sem_post(), sem_destroy() • system() • Does fork(), exec(), and wait() for you in one command! • Remember to check return values! You may find some weird things going on with semaphores if you don’t… Good luck!

  15. Virtual Memory

  16. Why Virtual Memory? • Use main memory as a Cache for the Disk • Address space of a process can exceed physical memory size • Sum of address spaces of multiple processes can exceed physical memory

  17. Why Virtual Memory? • Use main memory as a Cache for the Disk • Address space of a process can exceed physical memory size • Sum of address spaces of multiple processes can exceed physical memory • Simplify Memory Management • Multiple processes resident in main memory. • Each process with its own address space • Only “active” code and data is actually in memory

  18. Why Virtual Memory? • Use main memory as a Cache for the Disk • Address space of a process can exceed physical memory size • Sum of address spaces of multiple processes can exceed physical memory • Simplify Memory Management • Multiple processes resident in main memory. • Each process with its own address space • Only “active” code and data is actually in memory • Provide Protection • One process can’t interfere with another. • because they operate in different address spaces. • User process cannot access privileged information • different sections of address spaces have different permissions.

  19. Principle of Locality • Program and data references within a process tend to cluster

  20. Principle of Locality • Program and data references within a process tend to cluster • Only a few pieces of a process will be needed over a short period of time (active data or code)

  21. Principle of Locality • Program and data references within a process tend to cluster • Only a few pieces of a process will be needed over a short period of time (active data or code) • Possible to make intelligent guesses about which pieces will be needed in the future

  22. Principle of Locality • Program and data references within a process tend to cluster • Only a few pieces of a process will be needed over a short period of time (active data or code) • Possible to make intelligent guesses about which pieces will be needed in the future • This suggests that virtual memory may work efficiently

  23. n–1 p p–1 0 virtual address virtual page number page offset address translation m–1 p p–1 0 physical address physical page number page offset Page offset bits don’t change as a result of translation VM Address Translation • Parameters • P = 2p = page size (bytes). • N = 2n = Virtual address limit • M = 2m = Physical address limit

  24. Page Table • Keeps track of what pages are in memory

  25. Page Table • Keeps track of what pages are in memory • Provides a mapping from virtual address to physical address

  26. Handling a Page Fault • Page fault • Look for an empty page in RAM • May need to write a page to disk and free it

  27. Handling a Page Fault • Page fault • Look for an empty page in RAM • May need to write a page to disk and free it • Load the faulted page into that empty page

  28. Handling a Page Fault • Page fault • Look for an empty page in RAM • May need to write a page to disk and free it • Load the faulted page into that empty page • Modify the page table

  29. Handling a Page Fault • What is there’s not an empty page? • Replace a page using some Page Replacement Policy • FIFO • Least Recently Used (LRU) • Least Frequently Used (LFU) • Not Recently Used (NRU), approximation of LRU • Working Set, approximation of memory usage

  30. Addressing • 64MB RAM (2^26)

  31. Addressing • 64MB RAM (2^26) • 2^32 (4GB) total virtual memory Virtual Address (32 bits)

  32. Addressing • 64MB RAM (2^26) • 2^32 (4GB) total virtual memory • 4KB page size (2^12) Virtual Address (32 bits)

  33. Addressing • 64MB RAM (2^26) • 2^32 (4GB) total virtual memory • 4KB page size (2^12) • So we need 2^12 for the offset, we can use the remainder bits for the page Virtual Address (32 bits) Virtual Page number (20 bits) Page offset (12 bits)

  34. Addressing • 64MB RAM (2^26) • 2^32 (4GB) total virtual memory • 4KB page size (2^12) • So we need 2^12 for the offset, we can use the remainder bits for the page • 20 bits, we have 2^20 pages (1M pages) Virtual Address (32 bits) Virtual Page number (20 bits) Page offset (12 bits)

  35. Problems

  36. Problem 1 For each of the following decimal virtual addresses, compute the virtual page number and offset for a 4 KB page and for an 8 KB page: 20000, 32768, 60000. 37

  37. Problem 1 Solution

  38. Problem 2 Consider the page table of the figure. Give the physical address corresponding to each of the following virtual addresses: • 29 • 4100 • 8300 39

  39. Problem 2 Solution 29: Physical address: 8K + 29 = 8221 4100: Physical address: 4K + (4100 – 4K) = 4100 8300: Physical address: 24K + (8300 – 8K) = 24684 Consider the page table of the figure. Give the physical address corresponding to each of the following virtual addresses: • 29 • 4100 • 8300 40

  40. Problem 3 A machine has 48 bit virtual addresses and 32 bit physical addresses. Pages are 8 KB. How many entries are needed for the page table? 41

  41. Problem 3 Solution A machine has 48 bit virtual addresses and 32 bit physical addresses. Pages are 8 KB. How many entries are needed for the page table? Page size = 8 KB = 2^13 B Offset = 13 bits # of virtual pages = 2^(48 – 13) = 2^35 = # of entries in page table 42

  42. Problem 4 Consider a machine such as the DEC Alpha 21064 which has 64 bit registers and manipulates 64-bit addresses. If the page size is 8KB, how many bits of virtual page number are there? If the page table used for translation from virtual to physical addresses were 8 bytes per entry, how much memory is required for the page table and is this amount of memory feasible? 43

  43. Problem 4 Solution Page size = 8 KB = 2^13 BOffset = 13 bitsBits for virtual page number = (64 – 13) = 51 # of page table entries = 2^51Size of page table = 2^51 * 8 B =2^54 B = 2^24 GB 44

  44. Problem 5 Fill in the following table: 45

  45. Problem 5 Solution Fill in the following table: 46

  46. Problem 6 • Fill in this table with the correct page evictions. Physical memory contains 4 pages. 47

  47. Problem 6 Solution • Fill in this table with the correct page evictions. Physical memory contains 4 pages. 48

More Related