1. Homepage
  2. Programming
  3. CS 480 OPERATING SYSTEMS Assignment 01: Page Trace

CS 480 OPERATING SYSTEMS Assignment 01: Page Trace

Engage in a Conversation
SDSUCS480OPERATING SYSTEMSPage TraceMemory ManagementMemory SpacePage TableC++

CS 480 OPERATING SYSTEMS (FALL 2024) CourseNana.COM

Assignment 01 (80 points)
Due: Beginning of class, 09/10/2024 CourseNana.COM

Late Due: Beginning of class, 9/12/2024 CourseNana.COM

You must work on your own. CourseNana.COM

The UnixTM operating system is mostly written in C, as is true for other modern operating systems including Windows, etc. As a major part of your learning activities for this course, you are required to use C or C++ for doing the programming assignments. It is assumed that you had some form of training in C or C++ programming prior to this class. Should that not be the case, you are recommended to seriously reconsider your enrollment. CourseNana.COM

This first assignment is designed for you to reacquaint yourself with C/C++ programming, particularly around the pointer use, number representation and arithmetic, as well as the tree data structure, which is often used in representing OS entities, e.g., the organization of a file system, Unix process tree, multi-level paging table for memory management, multi-level indexed file allocation table, etc. CourseNana.COM

Task CourseNana.COM

Operating systems manage memory space in pages or blocks, this is done for many reasons that we will discuss in the memory management topic later in the class. For this assignment, you are asked to implement a tree data structure to store the memory page (block) information and use it to track the memory page access stats in simulating memory accesses from a memory trace file. Assume a 32-bit system, each memory address has 32 bits. CourseNana.COM

Your code must satisfy the requirements specified for this assignment, see coding specifications below. CourseNana.COM

Functionality CourseNana.COM

Upon start, your program creates an empty page table (only the level 0 / root node should be allocated). The program should read addresses one at a time from a memory trace file for simulating a series of access attempts to memory addresses. CourseNana.COM

For each address read in: CourseNana.COM

  • extract the memory page number based on the numbers of bits for the page levels CourseNana.COM

    from command line arguments, CourseNana.COM

  • store (insert) the page number along a page tree path, CourseNana.COM

  • update the number of accesses to the page at the leaf node level, and CourseNana.COM

  • print to the standard output one address per line: memory address, its page indices CourseNana.COM

    along page levels, number of accesses to the page so far. CourseNana.COM

    Compilation CourseNana.COM

1) You must create and submit a Makefile for compiling your source code. Makefiles are CourseNana.COM

program compilation specifications. See appendix below (also refer to the Programming 1|Page CourseNana.COM

reference page in Canvas) for details on how to create a makefile. A makefile example is CourseNana.COM

also provided to you.
2) The make file must create the executable with a name as
pagetrace; otherwise, auto- CourseNana.COM

grading will automatically fail. CourseNana.COM

Program Inputs CourseNana.COM

Command line arguments CourseNana.COM

The executable uses two mandatory command line arguments: CourseNana.COM

The first mandatory argument is the name of the trace file consisting of memory reference traces for simulating a series of attempts of accessing addresses. CourseNana.COM

o trace.tr from the prompt is given for your testing.
o Auto-grading on Gradescope will use all or part of trace.tr.
o Appropriate error handling should be present if the file is not existent or cannot CourseNana.COM

be opened. It must print to standard error output (stderr) or standard output the following error messages:
Unable to open <<trace.tr>> CourseNana.COM

The second mandatory argument is a string that specifies the numbers of bits of page table levels. For example, “4 8 8” means to construct a 3-level page table with 4 bits for level 0, 8 bits for level 1, and 8 bits for level 2. CourseNana.COM

o With a 32-bit system, the total number of bits from all levels should be less than 32. In this assignment, you do NOT need to worry about checking the argument on this constraint. CourseNana.COM

See appendix below for how to process command line arguments in C/C++. CourseNana.COM

Memory trace file CourseNana.COM

The traces were collected from a Pentium II running Windows 2000 and are courtesy of the Brigham Young University Trace Distribution Center. The files tracereader.h and tracereader.c (for C++, change the file name to tracereader.cpp) implement a small program to read and print address trace files. You can include these files in your compilation and use the functionality to read the trace file. The file trace.tr is a sample of the trace of an executing process. See appendix below for an example of reading trace file. CourseNana.COM

Program Outputs (required) CourseNana.COM

Use functions from the given log.h and log.c (for C++, change log.c to log.cpp) for printing program output. Important: Do NOT implement your own output functions, autograding is strictly dependent on the output formats from the provided output functions. CourseNana.COM

Before reading addresses, print to the standard output: CourseNana.COM

  • the bitmasks for each level starting with the lowest tree level (root node is at level 0), one level per line. CourseNana.COM

  • use the given log_bitmasks function from log.c.
    For each address read in, print to the standard output one address per line:
    CourseNana.COM

  • memory address, its page indices along page levels, number of accesses to the page so far, CourseNana.COM

  • use the given log_pgindices_numofaccesses function from log.c. Sample Invocation CourseNana.COM

    Note these samples not necessarily will be used for the autograding test cases CourseNana.COM

    ./pagetrace trace.tr “4 8 8” CourseNana.COM

    Constructs a 3-level page table with 4 bits for level 0, 8 bits for level 1, and 8 bits for level 2. The remaining 12 bits would be for the offset in each page. CourseNana.COM

    Processes addresses from the trace file and prints the output as specified above. CourseNana.COM

    See the expected output in trace_4_8_8_output.txt. ./pagetrace trace.tr “7 15” CourseNana.COM

    Constructs a 2-level page table with 7 bits for level 0, and 15 bits for level 1. The remaining 10 bits would be for the offset in each page. CourseNana.COM

    Processes addresses from the trace file and prints the output as specified above. See the expected output in trace_7_15_output.txt. CourseNana.COM

    Before getting into code specifications for the assignment, let’s first give a background on how memory address information is represented and managed by the operating system. CourseNana.COM

    Representation of memory addresses CourseNana.COM

    OS views the memory space as an array of bytes. Assuming byte addressable, the array index of each byte represents a location of the memory, i.e., the memory address. A memory address is basically a number starting from 0. CourseNana.COM

    For example, 0x8A2E6745 is a 32-bit address in hexadecimal form (8 bytes). In binary form, it would be 0b10001010001011100110011101000101. This address has an offset of 0x8A2E6745 from the 0th memory address location. CourseNana.COM

    Manage memory space in pages (or blocks) CourseNana.COM

    For various reasons, OS manages the memory allocation in blocks. A memory block is conventionally called a memory page. With a particular page size, a memory address can be decomposed into the combination of a memory page number and an offset into the memory page the address belongs to: CourseNana.COM

  • memory address = page number * page size + offset into the page. CourseNana.COM

  • page number = memory address / page size CourseNana.COM

  • offset into the page = memory address mod page size CourseNana.COM

    For example, with a page size of 4K (2^12) bytes, memory address 0x8A2E6745 can be expressed by: CourseNana.COM

page number = memory address / page size = 0x8A2E6745 / 2^12 = 0x8A2E6745 / 0x1000 = 0x8A2E6 CourseNana.COM

o Using bitwise operations, this operation can be accomplished by bit masking and right shifting (0x8A2E6745 & 0xFFFFF000) >> 12, or just 0x8A2E6745 >> 12 CourseNana.COM

offset into the page = memory address mod page size = 0x8A2E6745 mod 0x1000 = 0x745 CourseNana.COM

o Using bitwise operations, this operation can be accomplished by bit masking 0x8A2E6745 & 0x00000FFF CourseNana.COM

  • This translates to the 0x8A2E6745 address is in the 0x8A2E6th (zero-based) page and at the 0x745th offset into that page. CourseNana.COM

  • With the page size as 2^12, offset would use the bottom 12 bits, and page number would use the top 20 bits. CourseNana.COM

    Store the memory page number hierarchically into a tree CourseNana.COM

    In the memory management discussion later for the class, we will investigate how to efficiently (or save space) store the memory page number information. CourseNana.COM

    One strategy is to store the memory page number in a tree along multiple levels, you will write a basic implementation of it in this assignment. CourseNana.COM

    Let’s use an example to demonstrate the idea. CourseNana.COM

    Continuing from the example above, with a page size of 2^12 (4K) bytes, the page number would be encoded in the top 20 bits of the address. Suppose we would like to store this 20-bit number to a multi-level page tree, the number of tree levels and the number of bits for the levels could have many possibilities: CourseNana.COM

    split the 20 bits along a 3-levels page tree with 4 bits for level 0, 8 bits for level 1, and 8 bits for level 2, or CourseNana.COM

    split the 20 bits to 2 levels with 8 bits for level 0 and 12 bits for level 1, or
    split the 20 bits to 4 levels with 4 bits for level 0, 6 bits for level 1, 5 bits for level 2, and CourseNana.COM

    5 bits for level 3,
    and so on and so forth. CourseNana.COM

    We can use bit masking and shifting to extract page numbers (indices) from the address for insertion along the tree levels. CourseNana.COM

    Again, using address 0x8A2E6745 as an example, with page size 2^12, page number would be 0x8A2E6. Suppose we want to store this page number to a 3-levels page table tree with number of bits for levels as 4 8 8, to extract the page numbers (indices) for the 3 levels: CourseNana.COM

  • First construct Level bit masks Level 0 mask: 0xF0000000 Level 1 mask: 0x0FF00000 Level 2 mask: 0x000FF000 CourseNana.COM

  • Next, calculate number of right shifting to get the page number for each level: Level 0, total number of bits (32) number of bits of level 0 = 28
    Level 1, total number of bits (32)
    number of bits of level 0 and 1 = 20 CourseNana.COM

Level 2, total number of bits (32) number of bits of level 0 and 1 and 2 = 12 CourseNana.COM

Apply bitwise AND operation using mask, then right shifting:
Level 0 page number
0x8A2E6745 & 0xF0000000 >> 280x8 Level 1 page number0x8A2E6745 & 0x0FF00000 >> 200xA2 Level 2 page number0x8A2E6745 & 0x000FF000 >> 120xE6 CourseNana.COM

See pagetable.pdf diagrams for demonstrations of how the address page number is stored to a multi-level tree. CourseNana.COM

Coding - Tree specifications for storing page information CourseNana.COM

Please pay attention to the implementation requirements below for the page table structures and operation. CourseNana.COM

Page table structures CourseNana.COM

  • ▪  See pagetable.pdf for a sample data structure for N-level page tables CourseNana.COM

  • ▪  PageTable A descriptor containing the attributes of a N level page table and a pointer CourseNana.COM

    to the root level (Level 0) object. CourseNana.COM

    • ▪  PageTable stores the multi-level paging information which is used for each Level CourseNana.COM

      or tree node object: number of levels, the bit mask and shift information for extracting the part of page number pertaining to each level, number of entries to the next level objects, etc. CourseNana.COM

    • ▪  Since the tree operations start from root node, it would be convenient to have the PageTable have a reference / pointer to the root node (Level) of the page tree. CourseNana.COM

  • ▪  Level (or PageNode) An entry for an arbitrary level, this is the structure (or class in c++) which represents a node of one of the levels in the page tree/table. CourseNana.COM

    • ▪  Level is essentially the structure for the multi-level page tree NODE. Multi-level paging is about splitting and storing the page number information into a tree data structure along the tree paths. Starting from the root node, each tree path (the root node to a leaf node) stores a page number. CourseNana.COM

    • ▪  Level (or Node) contains an array of pointers (entries) to the next level or page. Implementationrequirements: CourseNana.COM

      YoumustimplementthisLevelstructureasatreeandusethe double Level ** pointer for storing the array of next Level* pointers. CourseNana.COM

Do NOT use any collection data structure from the STL (standard template library), such as vector, list, etc. CourseNana.COM

Violatingtheaboverequirementwouldresultinazeropoint for a1 assignment. CourseNana.COM

  • ▪  You may add other data members to your node structure as you see needed, such as node depth / level, number of how many times a node has been visited, etc. CourseNana.COM

  • ▪  Programmingtips: CourseNana.COM

Sample code for instantiating a double pointer array, CourseNana.COM

  • ▪  nextLevelPtr=newLevel*[numOfEntries];//C++ CourseNana.COM

  • ▪  nextLevelPtr = (struct Level**) CourseNana.COM

    malloc(numOfEntries*sizeof(struct Level*)); // C
    As a best practice, after instantiation, always explicitly initialize all CourseNana.COM

    entries in the array to NULL or nullptr. And in C and C++, it is always a best practice to explicitly initialize all variables before using them. CourseNana.COM

    The “run in one environment but not in another” problem is often caused by non or improper initializations. CourseNana.COM

    Page table mandatory interfaces CourseNana.COM

    Implementation requirements (violation would incur 50% penalty of autograding): You must implement similar functions for multi-level paging as proposed below. Your exact function signatures may vary, but the functionality should be the same. CourseNana.COM

    All other interfaces may be developed as you see fit. CourseNana.COM

    unsigned int recordPageAccess(unsigned int address) CourseNana.COM

  • ▪  Record the access to the page of the given address by traversing the CourseNana.COM

    corresponding page path in the tree CourseNana.COM

    • ▪  insert entries to the page table tree if needed, CourseNana.COM

      • ▪  note when inserting a page, do not re-create and add the level / node if the page entry already exists at the level, just continue to the next level, and CourseNana.COM

      • ▪  only create the next level nodes as needed based on the page being inserted, do not create all nodes at the beginning for all levels CourseNana.COM

    • ▪  increment the number of accesses to the page at the leaf node level and return it after reaching the leaf node. CourseNana.COM

    • ▪  You could use a field numOfAccesses in Level class for tracking the number of accesses to the page / node. CourseNana.COM

  • ▪  Givenanaddress,applythegivenbitmaskandshiftrightbythegivennumber of bits. Returns the page number or index. This function can be used to extract the page number (index) of any page level or the full-page number by supplying the appropriate parameters. CourseNana.COM

  • ▪  Example: With a 32-bit system, suppose the level 1 pages occupied bits 22 through 27, and we wish to extract the level 1 page number of address 0x3c654321. CourseNana.COM

    • ▪  Mask is 0b00001111110000000000, shift is 22. The invocation would be extractPageNumberFromAddress(0x3c654321, 0x0FC00000, 22) which should return 0x31 (decimal 49). CourseNana.COM

    • ▪  First take the bitwise ‘and’ operation between 0x3c654321 and 0x0FC00000, which is 0x0C400000, then shift right by 22 bits. The last CourseNana.COM

unsigned int extractPageNumberFromAddress(unsigned int address, unsigned int CourseNana.COM

mask, unsigned int shift) CourseNana.COM

five hexadecimal zeros take up 20 bits, and the bits higher than this are 1100 0110 (C6). We shift by two more bits to have the 22 bits, leaving us with 11 0001, or 0x31. CourseNana.COM

Check out the given bitmasking-demo.c for an example of bit masking and shifting for extracting bits in a hexadecimal number. CourseNana.COM

Note: to get the full-Page Number from all page levels, you would construct the bit mask for all bits preceding the offset bits, take the bitwise and of the address and the mask, then shift right for the number of offset bits. CourseNana.COM

Programming reference and testing: CourseNana.COM

  • Please refer to C/C++ programming in Linux / Unix page. CourseNana.COM

  • You may use C++ 11 standard for this assignment, see appendix below and the sample CourseNana.COM

    Makefile. CourseNana.COM

  • We strongly recommend you set up your local development environment under a Linux CourseNana.COM

    environment (e.g., Ubuntu 20.04 or 22.04), develop and test your code there first, then port your code to Edoras (e.g., filezilla or winscp) to compile and test to verify. The gradescope autograder will use an Ubuntu system to compile and autograde your code. CourseNana.COM

    Turning Into Gradescope CourseNana.COM

    Make sure that all files mentioned below (Source code files and Makefile) contain your name and Red ID! Do NOT compress / zip files into a ZIP file and submit, submit all files separately. CourseNana.COM

  • Source code files (.h, .hpp, .cpp, .c, .C or .cc files, etc.) CourseNana.COM

  • Makefile CourseNana.COM

  • A sample output (in a text file) from a test of your program. (use > to export standard CourseNana.COM

    output to a file, e.g., ./pagetrace trace.tr “6 8 8” > testoutput.txt) CourseNana.COM

  • Single Programmer Affidavit with your name and RED ID as signature, use Single CourseNana.COM

    Programmer Affidavit.docx from Canvas Module Assignments. CourseNana.COM

  • Number of submissions: CourseNana.COM

a. Please note the autograder counts the number of your submissions. For this assignment, you will be allowed 99 submissions, but future assignments will be limited to around 10 submissions. As stressed in the class, you are supposed to do the testing in your own dev environment instead of using the autograder for testing your code. It is also the responsibility of you as the programmer to sort out the test cases based on the requirement specifications instead of relying on the autograder to give the test cases. CourseNana.COM

Grading CourseNana.COM

Passing 100% autograding may NOT give you a perfect score on the assignment. The structure, coding style, and commenting will also be part of the rubrics for the final grade (see Syllabus Course Design - assignments). Your code shall follow industry best practices: CourseNana.COM

  • Be sure to comment on your code appropriately. Code with no or minimal comments are automatically lowered one grade category. CourseNana.COM

  • Design and implement clean interfaces between modules. CourseNana.COM

  • Meaningful variable names. CourseNana.COM

  • NO global variables. CourseNana.COM

  • NO hard code Magic numbers, etc. CourseNana.COM

  • Have proper code structure between .h and .c / .cpp files, do not #include .cpp files. CourseNana.COM

    Test data including the correct program output are given to you, any hardcoding to generate the correct output without implementing the tree will automatically result in a zero grade of the assignment. CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
SDSU代写,CS480代写,OPERATING SYSTEMS代写,Page Trace代写,Memory Management代写,Memory Space代写,Page Table代写,C++代写,SDSU代编,CS480代编,OPERATING SYSTEMS代编,Page Trace代编,Memory Management代编,Memory Space代编,Page Table代编,C++代编,SDSU代考,CS480代考,OPERATING SYSTEMS代考,Page Trace代考,Memory Management代考,Memory Space代考,Page Table代考,C++代考,SDSUhelp,CS480help,OPERATING SYSTEMShelp,Page Tracehelp,Memory Managementhelp,Memory Spacehelp,Page Tablehelp,C++help,SDSU作业代写,CS480作业代写,OPERATING SYSTEMS作业代写,Page Trace作业代写,Memory Management作业代写,Memory Space作业代写,Page Table作业代写,C++作业代写,SDSU编程代写,CS480编程代写,OPERATING SYSTEMS编程代写,Page Trace编程代写,Memory Management编程代写,Memory Space编程代写,Page Table编程代写,C++编程代写,SDSUprogramming help,CS480programming help,OPERATING SYSTEMSprogramming help,Page Traceprogramming help,Memory Managementprogramming help,Memory Spaceprogramming help,Page Tableprogramming help,C++programming help,SDSUassignment help,CS480assignment help,OPERATING SYSTEMSassignment help,Page Traceassignment help,Memory Managementassignment help,Memory Spaceassignment help,Page Tableassignment help,C++assignment help,SDSUsolution,CS480solution,OPERATING SYSTEMSsolution,Page Tracesolution,Memory Managementsolution,Memory Spacesolution,Page Tablesolution,C++solution,