Microcontrollers and DSP - Mock Exam 5
Questa pagina non ha ancora la versione ripasso: qui sotto c'è il testo completo.
In questa pagina 8
Official format (from the course description): a written test with some theoretical questions and some application exercises (programming of microcontrollers and peripherals, DSP); an additional oral exam may follow. The tests of this course are not public, so this mock exam is built only on the notes of the course: the questions and the data are new and it is not a copy of any real test. The distribution of the points is a proposal of this site: 4 theory questions of 3 points and 3 exercises of 6 points, for a total of 30 points, in 2 hours. The notes of the course do not yet cover the peripheral units of a microcontroller (timers, converters, serial modules) and the DSP part, so the exercises use the ARM programming, the memory systems and the external memories that the notes describe.
Conventions: numbers with the prefix 0x are hexadecimal; a space inside a binary number only separates groups of four bits; in the assembly code r0-r12 are registers, labels end with a colon and comments start with @. Memory is byte-addressed and little endian.
How to use it: work with a timer, write the formula or the idea in words before the numbers, and look at the "Result" only when a question is finished.
Question 1 (points 3)
MIPS instruction formats. (a) Give the three 32-bit MIPS formats R, I and J, with the fields and their widths, and say what each format is used for. (b) Why do the register fields have 5 bits, and how many registers can be named? Which range has the 16-bit immediate of format I, and how is it extended to 32 bits? Give the value of the field 0xFF00 after the extension. (c) The address field of a jump instruction contains 0x4C30: what does it represent, and which byte address does it designate? How many bytes can the 26-bit field reach?
Show the result
- R: op 6, rs 5, rt 5, rd 5, shamt 5, funct 6 (register operations); I: op 6, rs 5, rt 5, immediate 16 (immediates, load/store, conditional branches); J: op 6, address 26 (unconditional jump); each is bits.
- registers; the immediate is sign-extended: range ;
0xFF00becomes0xFFFFFF00, that is . - The J address is a word address, multiplied by (shifted left by ):
0x4C30designates the byte address0x130C0. - words, that is bytes MB.
Show the full solution
The three MIPS formats are all bits wide (Instruction Formats and Addressing ModesAddressing modes (immediate, direct, indirect, register, register indirect, displacement, PC-relative, scaled indexed, stack) with effective address and a numeric example, fixed versus variable instruction formats, the MIPS R, I and J formats and the 32-bit ARM data-processing format with the encodable-constant rule.Instruction Formats and Addressing Modes →). Format R (register operations such as add $1, $2, $3): op , rs , rt , rd , shamt , funct bits, and . Format I (immediates, load/store, conditional branches): op , rs , rt and a -bit immediate. Format J (unconditional jump): op and a -bit address. A register field has bits because there are registers. The immediate is sign-extended to bits, so it ranges from to ; 0xFF00 has sign bit and becomes 0xFFFFFF00, that is . The J address is a word address, multiplied by (shifted left by ) because instructions are -byte aligned: 0x4C30 designates 0x130C0, and the field reaches bytes MB.
Typical mistakes: using the jump field as a byte address without multiplying by ; zero-extending the immediate and getting instead of ; saying that a register field with bits names registers.
Question 2 (points 3)
The N-bit ALU. (a) Starting from the 1-bit ALU (AND, OR, full adder, multiplexer), say how the N-bit ALU performs subtraction, NOR, set less than and zero detection, and how overflow is detected. (b) With the ALU computes for and : give the second operand of the adder, the carry in, the result and the flags N, Z, C, V, with their meaning. (c) What is the result of NOR on the 4-bit patterns 1010 and 0110, and which signals produce it?
Show the result
- Subtraction: Binvert passes the complement of and sets , so ; NOR: Ainvert and Binvert invert both inputs of the AND (); set less than: sign bit of (corrected for overflow) in bit 0; zero: NOR of all the result bits; overflow .
- , carry in : , that is .
- N , Z , C (no carry out: a borrow, unsigned), V (operands of the same sign in a subtraction).
- NOR of
1010and0110is0001.
Show the full solution
In the N-bit ALU (Arithmetic Logic UnitRole of the ALU, its inputs and the N Z C V flags, the 1-bit ALU built from AND, OR, a full adder and a multiplexer, the N-bit ALU with subtraction, NOR, set-less-than, zero and overflow detection, comparators, bus sharing with tri-state outputs, and the other computation units.Arithmetic Logic Unit →) one-bit ALUs are chained by the carries. For subtraction the signal Binvert passes the complement of and sets , so . For NOR, Ainvert and Binvert both invert the inputs of the AND gate: (De Morgan). Set less than computes and puts the sign bit, corrected for overflow, in bit . The zero detection is the NOR of all the result bits, and overflow is . For () and (): , and , that is . N (the most significant bit), Z , C (no carry out: a borrow occurred, as unsigned numbers), V (a subtraction of two numbers of the same sign cannot overflow). NOR of 1010 and 0110 is 0001.
Typical mistakes: forgetting the carry in (the result would be , one less); reading C in a subtraction as an error instead of a borrow; computing the zero flag as an AND of the result bits.
Question 3 (points 3)
ROM and non-volatile memories. (a) For ROM, PROM, EPROM, EEPROM and flash say how each one is written and how it is erased. (b) Which type do you choose for: firmware that is identical in every device and never changes; a memory that the user programs once, electrically; a program that is erased with ultraviolet light before being rewritten; a table of constants that is rewritten electrically one byte at a time; a program that is updated by erasing whole blocks quickly? (c) Which of these technologies is used in SSDs and USB sticks, and what are the typical uses of non-volatile memories?
Show the result
- ROM: written at the factory with the chip mask, cannot be erased; PROM: written once electrically by the user, cannot be erased; EPROM: written electrically, erased with ultraviolet light (whole chip); EEPROM: written and erased electrically byte by byte (slow); flash: written electrically, erased electrically by blocks (fast).
- Choices: ROM, PROM, EPROM, EEPROM, flash in the order of the list of part b.
- SSDs and USB sticks use flash; uses: firmware and BIOS, microprograms, function tables, programs of embedded systems.
Show the full solution
A ROM is written at the factory with the chip mask and cannot be erased (Semiconductor MemoryMemory cell and operations; dynamic RAM (capacitor, refresh) and static RAM (flip-flop) compared; ROM, PROM, EPROM, EEPROM and flash; organisation of chips and modules with calculation of address lines and number of chips; synchronous DRAM and DDR; errors and correcting codes.Semiconductor Memory →). A PROM is written once, electrically, by the user, and cannot be erased. An EPROM is written electrically and erased with ultraviolet light, the whole chip at once. An EEPROM is written and erased electrically, byte by byte (slow). Flash is written electrically and erased electrically by blocks (fast). So the firmware identical in every device is a ROM, the memory programmed once is a PROM, the program erased with ultraviolet light is an EPROM, the table rewritten byte by byte is an EEPROM, the program updated by blocks is flash. Flash is the technology of SSDs and USB sticks. Typical uses: firmware and BIOS, microprograms, function tables, programs of embedded systems.
Typical mistakes: exchanging EEPROM and flash (byte by byte against blocks); saying that an EPROM is erased electrically; saying that a PROM can be rewritten.
Question 4 (points 3)
The status register and the supervisor bit. (a) Which are the control and status registers of a processor, and are they usually directly accessible to the programmer? (b) What does the program status word (PSW) contain? Explain the role of the supervisor bit and what happens when a user program tries to execute a privileged instruction. (c) At bits in two's complement the processor adds 0x64 and 0x32: give the result and the flags N, Z, C, V, and explain the value of V.
Show the result
- PC, IR, MAR, MBR and the PSW (called CPSR in ARM): usually not directly accessible.
- PSW: flags N, Z, C, V; interrupt enable bits; supervisor bit (privileged mode: the CPU is running operating-system code); privileged instructions (memory management, I/O, changing the PSW) are allowed only in that mode, and a user program that attempts them raises an exception.
0x640x320x96: N , Z , C , V .- V : two positive numbers give a negative result (the sum does not fit in two's complement); C because no carry leaves the most significant bit.
Show the full solution
The control and status registers are the PC, the IR, the MAR, the MBR and the program status word (PSW, called CPSR in ARM); they are usually not directly accessible (CPU Structure and RegistersArchitecture versus organization, the stored-program (von Neumann) machine, the internal components of a CPU (ALU, control unit, register file, internal bus), user-visible and control/status registers, the status word with flags and supervisor bit, and how many registers are worth having.CPU Structure and Registers →). The PSW contains the flags N (the most significant bit of the result), Z (zero), C (carry) and V (overflow), the interrupt enable bits and the supervisor bit, which says whether the CPU is running operating-system code. Only in this privileged mode are privileged instructions allowed (memory management, I/O, changing the PSW itself); a user program that attempts them raises an exception. For the sum, 0x96 : the most significant bit is , so N ; Z ; , so no carry leaves the most significant bit and C ; two positive operands give a negative result, so V (Binary ArithmeticBinary addition and two's complement subtraction, overflow for unsigned (carry) and signed (sign change) numbers, the N Z C V flags, multiplication by shifts and additions, Booth's algorithm with a worked example, division, and logical, arithmetic and rotate shifts.Binary Arithmetic →).
Typical mistakes: believing that a user program can freely change the supervisor bit; reading C as "no error" (V is the flag of the signed overflow); treating the PC as a general register.
Exercise 1 (points 6)
Load and store in ARM. In parts a and b r1 = 0x2400, r2 = 5, r3 = 0x0000003F, and the memory contains the words 0x23F8 0x0000AA01, 0x240C 0x00000B02, 0x2410 0x000CC003, 0x2414 0x0000D004.
a) The following six instructions are executed in this order. For each one give the effective address, the value loaded (or stored) and the value of r1 afterwards (2 points).
LDR r0, [r1, #12]
LDR r4, [r1, #-8]
LDR r5, [r1, r2, LSL #2]
LDR r6, [r1, #16]!
LDR r7, [r1], #4
STR r3, [r1, #-4]!b) The word 0x8C73F2A5 is stored at address 0x2500 and r5 = 0x2500. Give the contents of the destination register r4 (in hexadecimal and in decimal) after LDR r4, [r5], LDRB r4, [r5], LDRSB r4, [r5, #1], LDRSB r4, [r5, #3], LDRH r4, [r5, #2] and LDRSH r4, [r5, #2] (2 points).
c) The function copysum copies words from the array whose address is in r0 to the array whose address is in r1 and returns in r0 the sum of the words; the count is in r2. Complete the three missing parts, marked with underscores (2 points).
LDR r0, =src
______ r1, =dst @ (3) address of dst
MOV r2, #4
BL copysum
...
copysum: MOV r3, #0 @ sum
loop: CMP r2, #0
BEQ end
LDR r12, ______ @ (1) read a word of src and advance the pointer
______ r12, [r1], #4 @ (2) write it in dst and advance the pointer
ADD r3, r3, r12
SUB r2, r2, #1
B loop
end: MOV r0, r3
BX lr
.data
src: .word 12, -5, 40, 7
dst: .word 9, 0, 0, 0Suppose that the assembler places src at 0x2000 and dst at 0x2010. Fill a table with the address read, the value, the address written and the sum for each iteration, and give the final values of r0 (on return), r1 (just before the MOV) and of the four words of dst. Finally, if the programmer wrote by mistake LDR r12, [r0, #4]! in part (1), which addresses would be read, and what would the function return?
Show the result
a) (1) EA 0x240C, r0 = 0x00000B02, r1 = 0x2400; (2) EA 0x23F8, r4 = 0x0000AA01, r1 = 0x2400; (3) EA 0x2414, r5 = 0x0000D004, r1 = 0x2400; (4) EA 0x2410, r6 = 0x000CC003, r1 = 0x2410; (5) EA 0x2410 (the old r1), r7 = 0x000CC003, r1 = 0x2414; (6) EA 0x2410, the word 0x0000003F is stored there, r1 = 0x2410.
b) LDR: 0x8C73F2A5; LDRB: 0x000000A5 ; LDRSB [r5, #1]: 0xFFFFFFF2 ; LDRSB [r5, #3]: 0xFFFFFF8C ; LDRH [r5, #2]: 0x00008C73 ; LDRSH [r5, #2]: 0xFFFF8C73 .
c) (1) [r0], #4; (2) STR; (3) LDR. Iterations: , , , . Final: r0 = 54, r1 = 0x2020 (r0 was 0x2010 before the MOV), dst . With [r0, #4]!: addresses 0x2004, 0x2008, 0x200C, 0x2010; the last word is the one written by the first iteration (), so the sum is .
Show the full solution
a) The addressing modes (ARM Memory-Access InstructionsLDR and STR for words, bytes and half-words with and without sign; addressing modes with immediate or scaled-register offset, pre-indexed with write-back and post-indexed, with effective address examples; loading addresses and constants; LDM and STM.ARM Memory-Access Instructions →). A pre-indexed access with ! computes the address, accesses and then updates the base; a post-indexed access uses the base as it is and updates it afterwards; the other forms leave r1 unchanged. The scaled index LSL #2 multiplies the index by .
| # | instruction | effective address | value | r1 afterwards |
|---|---|---|---|---|
| 1 | LDR r0, [r1, #12] |
0x240C |
r0 = 0x00000B02 |
0x2400 |
| 2 | LDR r4, [r1, #-8] |
0x23F8 |
r4 = 0x0000AA01 |
0x2400 |
| 3 | LDR r5, [r1, r2, LSL #2] |
0x2414 |
r5 = 0x0000D004 |
0x2400 |
| 4 | LDR r6, [r1, #16]! |
0x2410 |
r6 = 0x000CC003 |
0x2410 |
| 5 | LDR r7, [r1], #4 |
0x2410 (the base before the update) |
r7 = 0x000CC003 |
0x2414 |
| 6 | STR r3, [r1, #-4]! |
0x2410 |
memory 0x2410 0x0000003F |
0x2410 |
In instruction 3, 0x14. Instructions 4 and 5 read the same word, but they leave different values in r1 (0x2410 after the first, 0x2414 after the second, because the second starts from 0x2410). In instruction 6 the first register of STR is the source: it is read, and its value 0x0000003F overwrites the word at 0x2410, which was 0x000CC003.
b) Bytes and half-words. The memory is little endian (The ARM Core ArchitectureThe 32-bit ARM core as the reference microcontroller core: registers r0-r15 with SP, LR and PC, the status register CPSR with flags NZCV, processor modes, the load/store model, conditional execution, the flexible second operand, Thumb, and the main differences of 64-bit ARMv8.The ARM Core Architecture →): the least significant byte of the word is at the lowest address, so the four bytes are 0xA5 at 0x2500, 0xF2 at 0x2501, 0x73 at 0x2502 and 0x8C at 0x2503.
LDR r4, [r5]reads the whole word:0x8C73F2A5.LDRB r4, [r5]reads the byte at0x2500and extends it with zeros:0x000000A5.LDRSB r4, [r5, #1]reads the byte0xF2at0x2501, whose sign bit is , and extends the sign:0xFFFFFFF2, that is .LDRSB r4, [r5, #3]reads0x8Cat0x2503:0xFFFFFF8C, that is .LDRH r4, [r5, #2]reads the half-word at0x2502, made of the bytes0x73(low) and0x8C(high), that is0x8C73, zero-extended:0x00008C73.LDRSH r4, [r5, #2]reads the same half-word with the sign extension:0xFFFF8C73, that is .
Check on the sign: in a signed load the bit (byte) or the bit (half-word) is copied into all the upper bits; with LDRB or LDRH the upper bits are always zeros.
c) The copy loop (Arrays, Strings and Structures in ARM AssemblyArrays in memory and the address of an element; walking with an index or with a pointer; worked examples (sum, maximum, copy); zero-terminated strings and length computation; row-major matrices; structs with field offsets and alignment.Arrays, Strings and Structures in ARM Assembly → for the walk with a pointer). Part (1) must read the word at the address held in r0 and then advance the pointer by bytes, a word: LDR r12, [r0], #4 (post-indexed). Part (2) writes the word with the same step in dst: STR r12, [r1], #4. Part (3) must put in r1 the address of dst: LDR r1, =dst, the pseudo-instruction that loads an address; LDR r1, dst would read the contents.
Trace, with src at 0x2000 and dst at 0x2010:
| iteration | r2 at the start |
address read | value | address written | r3 after the ADD |
|---|---|---|---|---|---|
| 1 | 0x2000 |
0x2010 |
|||
| 2 | 0x2004 |
0x2014 |
|||
| 3 | 0x2008 |
0x2018 |
|||
| 4 | 0x200C |
0x201C |
After the fourth iteration r2 , so CMP r2, #0 sets Z and BEQ end is taken. The pointer r0 has advanced by bytes, from 0x2000 to 0x2010 (it now points to dst, which follows src in memory); r1 is 0x2010 0x2020; the function returns r0 (); the words of dst are (the initial was overwritten).
With the pre-indexed LDR r12, [r0, #4]! the address is updated before the access: the reads are at 0x2004, 0x2008, 0x200C and 0x2010. The first element is skipped and one word is read after the end of src, which is the first word of dst; but the first iteration has already written at 0x2010, so that word is and not the initial . The sum is . Typical mistakes: using step instead of for an array of words; confusing the pre-indexed and post-indexed forms (the address read is different); writing LDR r1, dst to get the address; answering for the last word read in the pre-indexed case, forgetting that dst has just been modified.
Exercise 2 (points 6)
A byte-addressed memory has 16-bit addresses (a word is one byte). A cache of bytes has blocks of bytes, is -way set associative with LRU replacement and is initially empty. Ten accesses are made (R = read, W = write, addresses in hexadecimal):
| # | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| op | R | W | W | W | W | R | W | R | W | R |
| address | 1208 |
1209 |
120A |
120B |
3A0C |
5A08 |
3A0D |
1208 |
3A0E |
3A0C |
a) Compute the number of lines and of sets and the widths of the fields tag, set and word. What is the maximum memory that a cache with the same set and word fields and a -bit tag could manage? For each access give tag, set and word. How many different blocks are accessed, and how many of them compete for the same set? (2 points)
b) The cache uses write-through and no-write-allocate (a write to memory is one word). Trace the accesses: hit or miss, content of the set (from the least recently used), accesses to memory. Give hits, block loads and writes to memory. (2 points)
c) Repeat the trace with write-back and write-allocate (dirty blocks are written back as a whole block). Compare the two policies on the number of accesses to memory and on the bytes exchanged. Finally, classify each miss of this trace as compulsory or conflict, and say what removes the conflict miss and what that remedy costs. (2 points)
Show the result
a) lines, sets; word bits, set bits, tag bits; with a -bit tag the memory is bytes. All ten accesses are in set : 1208, 1209, 120A, 120B have tag 0x090, word ; 3A0C, 3A0D, 3A0E, 3A0C have tag 0x1D0, word ; 5A08 has tag 0x2D0, word . Three different blocks, all in set , which has only lines.
b) Write-through, no-write-allocate: M, H, H, H, M, M, M, H, M, M; hits; block loads (accesses , , ); writes of one word to memory (accesses , , , , , ). Final set : 0x090, 0x1D0 (most recent last).
c) Write-back, write-allocate: M, H, H, H, M, M, H, M, H, H; hits; block loads (accesses , , , ); write-back of a block (0x090 at access ). Accesses to memory: against (a dirty block 0x1D0 is still in the cache). Bytes: against . Misses , , are compulsory (first access to the blocks 0x090, 0x1D0, 0x2D0); miss is a conflict miss (0x090 was replaced at access although only of the lines are in use): more ways remove it (it disappears with full associativity), at the cost of more tags compared in parallel and a longer access cycle.
Show the full solution
a) Fields (Cache MemoryBlocks, lines and tags; address decomposition; direct, fully associative and set-associative mapping with field calculation; replacement policies (LRU, FIFO, random); write policies (write-through, write-back with dirty bit, write-allocate); block size; multilevel and split caches; reducing misses; typical address-field questions.Cache Memory →). With capacity bytes and blocks of bytes:
If the tag had bits, the address would have bits and the memory managed would be bytes KB. Example of decomposition: 0x1209 ; the last bits are (word ), the next bits are (set ), the first bits are 0x090 (tag). The block address is the address divided by (without the word field), and the set is the block address modulo :
| # | address | block | tag | set | word |
|---|---|---|---|---|---|
| 1 | 1208 |
0x241 |
0x090 |
1 | 0 |
| 2 | 1209 |
0x241 |
0x090 |
1 | 1 |
| 3 | 120A |
0x241 |
0x090 |
1 | 2 |
| 4 | 120B |
0x241 |
0x090 |
1 | 3 |
| 5 | 3A0C |
0x741 |
0x1D0 |
1 | 4 |
| 6 | 5A08 |
0xB41 |
0x2D0 |
1 | 0 |
| 7 | 3A0D |
0x741 |
0x1D0 |
1 | 5 |
| 8 | 1208 |
0x241 |
0x090 |
1 | 0 |
| 9 | 3A0E |
0x741 |
0x1D0 |
1 | 6 |
| 10 | 3A0C |
0x741 |
0x1D0 |
1 | 4 |
The blocks are (0x241, 0x741, 0xB41), all in set (they have the same set bits and different tags), and set has only lines: the conflict is built into the sequence. Accesses to and accesses , , , share a block: the word field does not decide hit or miss.
b) Write-through, no-write-allocate. The list shows set from the least recently used block to the most recently used (the other sets stay empty).
| # | access | result | set 1 after | memory |
|---|---|---|---|---|
| 1 | R 1208 |
miss | 090 |
load block |
| 2 | W 1209 |
hit | 090 |
write 1 word |
| 3 | W 120A |
hit | 090 |
write 1 word |
| 4 | W 120B |
hit | 090 |
write 1 word |
| 5 | W 3A0C |
miss | 090 |
write 1 word only (no allocation) |
| 6 | R 5A08 |
miss | 090, 2D0 |
load block |
| 7 | W 3A0D |
miss | 090, 2D0 |
write 1 word only |
| 8 | R 1208 |
hit | 2D0, 090 |
none |
| 9 | W 3A0E |
miss | 2D0, 090 |
write 1 word only |
| 10 | R 3A0C |
miss | 090, 1D0 |
load block, replaces 2D0 (the least recently used) |
On a write hit the datum goes to the cache and to memory, so memory is always up to date and a replaced block is never written back. On a write miss with no-write-allocate the write goes only to memory and the block is not brought in: that is why accesses , and to the block 0x1D0 all miss. Result: hits (accesses , , , ), misses, block loads and writes of one word.
c) Write-back, write-allocate. A write hit changes only the cache and sets the dirty bit (marked ); on a write miss the block is first loaded and then written.
| # | access | result | set 1 after | memory |
|---|---|---|---|---|
| 1 | R 1208 |
miss | 090 |
load block |
| 2 | W 1209 |
hit | 090* |
none |
| 3 | W 120A |
hit | 090* |
none |
| 4 | W 120B |
hit | 090* |
none |
| 5 | W 3A0C |
miss | 090*, 1D0* |
load block, then write in the cache |
| 6 | R 5A08 |
miss | 1D0*, 2D0 |
the set is full and the least recently used is 090*, dirty: write back the whole block, then load |
| 7 | W 3A0D |
hit | 2D0, 1D0* |
none |
| 8 | R 1208 |
miss | 1D0*, 090 |
the least recently used is 2D0, clean: no write-back; load block |
| 9 | W 3A0E |
hit | 090, 1D0* |
none |
| 10 | R 3A0C |
hit | 090, 1D0* |
none |
Result: hits (accesses , , , , , ), block loads and write-back; the dirty block 0x1D0 stays in the cache and would be written back only when it is replaced.
Comparison. Accesses to memory: write-through loads writes ; write-back loads write-back : the three writes to 0x090 and the three to 0x1D0 become one single transfer each time the block is replaced. The price is that a write-back moves a whole block: bytes exchanged are for write-through and for write-back (as a count of transfers write-back is better, in bytes it is not in this short sequence: the pending dirty block would add more). Write-allocate is also why accesses , and hit.
Kinds of misses (write-back trace). A miss is compulsory when it is the first access to the block: accesses , and (blocks 0x090, 0x1D0, 0x2D0). Access asks again for 0x090, which was already in the cache and was replaced at access ; but the cache has lines and has held only blocks, so the block was lost because too many blocks compete for the same set: it is a conflict miss. With full associativity it would not occur (the three blocks fit in the lines, and access would be a hit). The remedy is higher associativity (more ways, or a victim cache); its cost is that more tags are compared in parallel and the access cycle gets longer.
Typical mistakes: using the word field to decide hit or miss; computing the tag as and forgetting the set field; allocating the block on a write miss with write-through; forgetting that a replaced dirty block is written back whole (all bytes), and writing back the clean ones.
Exercise 3 (points 6)
a) A storage system needs disks of data. For RAID levels , , , and give the total number of disks and the number of failures tolerated. Which level has a dedicated parity disk with a write bottleneck, and how does RAID remove it? Which level can survive the failure of any two disks? (2 points)
b) In a RAID level with four data disks, the blocks in the same position are , , , . Compute the parity block . The third disk fails: reconstruct from the other blocks and the parity. (2 points)
c) A disk turns at revolutions per minute; a track holds KB and the average seek time is ms. Compute the revolution time and the average rotational latency. Compute the access time to read KB stored in consecutive sectors of one track. Then compute it if the same KB are spread over the tracks of a cylinder of surfaces read in parallel, and the fraction of the time due to positioning and latency in the two cases. (2 points)
Show the result
a) RAID : disks, failures; RAID : , per mirrored pair; RAID and RAID : , ; RAID : , . RAID has the dedicated parity disk, a write bottleneck; RAID distributes the parity over all the disks. Only RAID survives any two failures.
b) ; .
c) ms, latency ms. One track: transfer ms, ms; cylinder of surfaces: transfer ms, ms. Positioning and latency: per cent and per cent.
Show the full solution
a) RAID levels. RAID needs the following disks for disks of data (the table of the note): level (striping, no redundancy) , no failure tolerated; level (mirroring) , one failure per pair; levels , , (one parity disk, or parity distributed) , one failure; level (two independent redundancy computations) , two failures. The level with block striping and a dedicated parity disk is level : every write must also update the parity disk, which becomes the bottleneck. Level is like level but with the parity distributed over all the disks, so the parity writes are spread. The failure of any two disks is survived only by level (level survives two failures only if they are not in the same mirrored pair, so it does not guarantee it).
b) Parity and reconstruction. The parity is the XOR of the data blocks, bit by bit:
If the third disk fails, each of its blocks is the XOR of the corresponding blocks of the other disks, parity included:
Check: this is exactly the lost block. The same procedure reconstructs any other single failed disk (the parity disk too).
c) Access time. One revolution lasts ms, and the average latency is half a revolution:
Reading KB on a track of KB takes a fraction of a revolution:
With the data spread over a cylinder of surfaces read in parallel the transfer is divided by : ms, so ms. The fraction due to positioning and latency is , about per cent, in the first case, and , about per cent, in the second: positioning and latency dominate, so reading contiguous data is far more efficient than reading scattered data.
Typical mistakes: using the time of a whole revolution ( ms) as latency instead of half; forgetting that the dedicated parity disk belongs to levels and and that RAID distributes it; computing the parity with OR or AND instead of XOR; forgetting that the seek time is paid once whatever the amount of data.
Self-assessment grid
| Item | Points | What must be there for full points | Typical mistakes |
|---|---|---|---|
| Question 1 | 3 | formats R, I, J with all field widths and uses (1); registers, sign extension and (1); word address times , 0x130C0, MB (1) |
jump field taken as a byte address; zero extension of the immediate |
| Question 2 | 3 | Binvert with carry in , NOR with Ainvert and Binvert, slt, zero, overflow (1); , result and flags N, Z, C, V (1.5); NOR result 0001 (0.5) |
carry in forgotten; borrow read as error; zero as AND of the bits |
| Question 3 | 3 | how each of the five types is written and erased (1); the five choices (1); flash in SSDs and USB sticks, typical uses (1) | EEPROM and flash exchanged; PROM rewritable |
| Question 4 | 3 | the five registers, usually not directly accessible (0.5); contents of the PSW, supervisor bit, exception (1.5); result and flags N, Z, C, V with the reason for V (1) | supervisor bit changed by a user program; carry read as overflow |
| Exercise 1 | 6 | a) 2 points: six effective addresses, values and r1; b) 2 points: six register contents in hexadecimal and decimal; c) 2 points: three missing parts, trace table, final values, pre-indexed case with |
pre-indexed and post-indexed confused; LDRB for a signed byte; step instead of ; LDR r1, dst |
| Exercise 2 | 6 | a) 2 points: lines, sets, fields , KB, table, three blocks in set ; b) 2 points: write-through trace, hits, loads, writes; c) 2 points: write-back trace, hits, loads, write-back, comparison and accesses, and bytes, compulsory and conflict misses | word field used to decide a hit; allocation on a write miss in write-through; missing write-back |
| Exercise 3 | 6 | a) 2 points: disks and failures of the five levels, RAID against RAID , level ; b) 2 points: and ; c) 2 points: ms, ms, ms, ms, and per cent | revolution time as latency; OR instead of XOR; RAID with a dedicated parity disk |
| Total | 30 |