CS202: HW 9: mmap(), context switches, disk performance, file systems

CS202: HW 9: mmap(), context switches, disk performance, file systems

These problems should be done on your own. We're not going to be grading them strictly (we'll mainly look at whether you attempted them). But they will be reinforcing knowledge and skills, so you should totally work through them carefully.

Context switches

In this question, you will implement swtch(), which switches between two user-level threads. You will do so for a user-level threading package, running on the TeensyArch processor. TeensyArch has 4 general registers, %r0-%r3, a stack pointer, a base (or frame) pointer, and an instruction pointer %rip. Assume the same stack frame structure as the architecture we’ve been covering in class (x86); further, all registers need to be saved by a function’s callee (that is, registers are callee-saved, also known as call-preserved).

Fill out swtch(). Below are definitions, declarations, and utility functions that you can use.

struct thread {
    int thread_id;
    uint64_t stack;
    /* ... */
};

enum register {
    R0,
    R1,
    R2,
    R3,
    RBP,
    RSP
};

// Push CPU's register r to the stack
void push_register(register r);

// Pop from the stack and into the CPU's register r
void pop_register(register r);

// Returns the CPU's current value of register r. 
uint64_t read_register(register r);

// Update the CPU's register r so it holds value `value`.
void write_register(register r, uint64_t value);


// Context switch from thread t1 to thread t2.
void swtch(struct thread *t1, struct thread *t2) {
    // On entry this function is run by thread t1.

    // Your code here. We have started it for you.
    push_register(RBP);
    push_register(R0);

    // YOUR CODE HERE

















    return; // The function should return to the
            // point where thread t2 called swtch().
}

Disk performance

Consider a disk with the following characteristics:

  1. What is the storage capacity of the disk in bytes or gigabytes? (Explain briefly.)
  2. What is the sequential transfer bandwidth, expressed in bytes/second or megabytes/second? (Explain briefly.)
  3. Now assume that the disk with the above characteristics is given a never-ending stream of requests to read one sector at a time, with each request chosen randomly from all possible sectors on the disk. Assume that these read requests are scheduled in FIFO order. State the effective long-term transfer rate that the disk can sustain, expressed in bytes/second or kilobytes/second, and explain briefly.

In doing the third question, the following may be useful:

  • You can (and probably should) make several percentage point approximations, for example 4096 can be represented as 4000, and 13 × 7.5 is approximately 100.
  • The term "long-term transfer rate" refers to R/X, where R is the number of bytes to transfer in each read, and X is the average length of time that a read takes.

Disk scheduling

Disk requests come into the disk driver for tracks 10, 22, 20, 2, 40, 6, and 38, in that order. A seek takes 6 msec per track moved (note that, among other simplifications, we are not taking into account the length of the seek). How much seek time is needed for the following scheduling algorithms?

(a) SSTF

(b) LOOK (SCAN, but doesn't move to the end)

In all cases, the arm is initially at track 20. (Note that SCAN is a synonym for the elevator algorithm.)

Adapted from Tanenbaum Chapter 5 Number 24.

File systems

Consider a file system that has the following description:

  1. State the maximum file size, and explain briefly, for example by showing your work. You may express your answer as a sum of powers-of-two.
  2. State the maximum number of files in a directory, and explain briefly, for example by showing your work. Again, you may express your answer as a sum of powers-of-two.

Handing in the homework

Use Gradescope; you can enroll in our course with entry code B2DEZW 4J462V.