> released: 03/30, 12:00 > due: 04/05, 23:59 > > Answer the following questions. > Submit your answers to Canvas assignments. > There is an entry for this homework. > > > 1. MMIO and WeensyOS (4 points) > > Below is a snippet of code from "lib.cc". > This is the new version piece of code in the final panel of handout week11b > (https://naizhengtan.github.io/23spring/notes/handout_w11b.pdf). > > Read it and answer the following questions. > > 1 inline void console_printer::putc(unsigned char c, int color) { > 2 while (cell_ >= console + CONSOLE_ROWS * CONSOLE_COLUMNS) { > 3 scroll(); > 4 } > 5 if (c == '\n') { > 6 int pos = (cell_ - console) % 80; > 7 while (pos != 80) { > 8 *cell_++ = ' ' | color; > 9 ++pos; > 10 } > 11 } else { > 12 *cell_++ = c | color; > 13 } > 14 } > > > 1.a If we want to replace all empty spaces after a new line with '_', how > should we modify the code? > That is, if printing "abc\n123" which is used to look like: > """ > abc > 123 > """ > now should be: > """ > abc_______________ > 123 > """ > > (2 points) Write down the line numbers and your modifications to > make this happen. > [answer: line 8: *cell_++ = '_' | color; ] > > > > 1.b Then, we want to fix the color of the characters to be yellow and we will > ignore the input argument "color" (line 1), meaning whatever input "color" is, > the color of the characters will be yellow. > > [ A crash course of 16-color coding > ---- > > In WeensyOS, the input "color" will look like this: > > 0x0F00 > ^^^^ > ||++-> these two should be zeros for color. > |+-> this hex digit means the color of the character. > +-> this hex digit means the color of the background. > > WeensyOS uses a 16-color system. > (why 16? a digit of hex number can only represent 16 numbers, 0x0 to 0xf.) > And here are the colors and their decimal code: > > 0 black > 1 blue > 2 green > 3 cyan > 4 red > 5 magenta > 6 brown > 7 light gray > 8 dark gray > 9 bright blue > 10 bright green > 11 bright cyan > 12 bright red > 13 bright magenta > 14 bright yellow > 15 bright white > ] > > (2 points) Write down the line numbers and your modifications to always > print yellow characters. > > [Aside, why the main body of the console doesn't change to yellow? because > main body's print does not use the above code. See k-memviewer.cc for how > WeensyOS prints the main body.] > [answer: line 12: *cell_++ = c | 0x0E00; ] > > > > 2. Disk performance (6 points) > > CS5600 staff designs a disk, CS5600-Disk: > > --Spindle Speed: 6000 RPM > note: > * this speed number is per minute. > * on average, it takes the disk to rotate half a circle to reach a sector. > * So, on average, how long does CS5600-Disk rotate to a sector? > [this is not a question you need to answer but one you should think of.] > > --Avg Seek Time, read/write: 5ms / 10 ms > (note: this is the time moving heads to the right track.) > > --Transfer rate: 64 MB/s > (note: this is the rate of reading/writing sequential data. > Assume 1MB=10^6B here. Again, this is 10^6B, not 2^20B.) > > When CS5600-Disk reads/writes a sector (512 Bytes), it needs to > (1) move the head to the right track (seeking), > (2) wait rotating to the right sector (rotation), > and (3) read/write the data (data transfer). > This means, the time finishing a job (like reading one sector) > equals to the sum of time spending on the above three phases. > > Questions: > > 2.a How long would it take to do 500 sector reads, spread out > randomly over the disk (and serviced in FIFO order)? (2 points) > Write down your calculation and write the final result in milliseconds. > [answer: For reading one sector: (1) seeking time = 5ms [given] (2) avg rotation time = 60s / 6000 / 2 = 5 ms [*on average*, it takes the disk to rotate half a circle to read a sector] (3) transfer time = 512B / (64MB/s) = 0.008 ms total time = #sectors * (seeking time + rotation time + data transfer time) = 500 * (5+5+0.008) ms = 5004 ms ] > > (b) How long would it take to do 500 sector writes, spread out > randomly over the disk (and serviced in FIFO order)? (2 points) > Write down your calculation and write the final result in milliseconds. > [answer: For writing one sector: (1) seeking time = 10ms [given] (2) avg rotation time = 60s / 6000 / 2 = 5 ms (3) transfer time = 512B / (64MB/s) = 0.008 ms total time = #sectors * (seeking time + rotation time + data transfer time) = 500 * (10+5+0.008) ms = 7504 ms ] > > > (c) How long would it take to do 500 sector reads, SEQUENTIALLY on the > CS5600-Disk? (FIFO order once more) (2 points) > [notice that seek and rotation will appear only once in sequential reads.] > Write down your calculation and write the final result in milliseconds. [answer: (1) seeking time = 5ms [this happens once] (2) avg rotation time = 5ms [this happens once] (3) data transfer time = 512 Bytes * 500 / 64 MB/s = 4ms [note: this transfer time implicitly includes the rotating time] total time = 5ms + 5ms + 4ms = 14ms ]