Monday, April 15, 2013

Disk Performance Calculation



  • A disk is double interleaved, as in the figure bellow. 

It has 8 sectors of 512 bytes per track, and a rotation rate of 300 rpm

a)How long does it take to read all the sectors of a
track in order, assuming the arm is already
correctly positioned , and 1/2 rotation is needed to
get a sector 0 under the head?
b) What's the data rate?
c) Now repeat the problem for a non-interleaved disk with the same characteristics
d) How much does the data rate degrade due to interleaving?



300 rpm means that one complete turn
takes (60 sec * 1000 ms) / 300 rpm = 200 ms
Thus one sector needs 200 ms / 8 = 25 ms
To read all the sectors in order the head has to
go over 22 sectors starting from sector 0 (0-
3-6-1-4-7-2-5-0-3-6-1-4-7-2-5-0-3-6-1-4-7)
what takes 22*25 ms = 550 ms

a) 550 ms + 200 ms / 2 = 650 ms
Effective access time = seek time + latency time +
data transfer time = 0 + 200 ms / 2 + 550 ms = 650
ms, thus
b) data rate = (8 * 512 bytes / 650 ms) * 1000 ms/sec
˜ 6302 bytes / sec
c) read all the sectors: 8*25 ms + 200 ms / 2 = 300 ms
data rate = (8 * 512 bytes / 300 ms) * 1000 ms/sec =
13653 bytes / sec
d) the difference in data rate is 13653 bytes / sec –
6302 bytes / sec = 7351 bytes / sec

http://disi.unitn.it/~ilya/Download/os_course/input_output_lab.pdf




  • Disk Performance


Given the following Disk Parameters:
– Average seek time is 5 ms
– Disk spins at 10,000 RPM
– Transfer rate is 40 MB/sec

What is Average Disk read or write time for a 512-byte Sector?

Ave. seek + ave. rot delay + transfer time + controller overhead
5 ms + 0.5/(10000 RPM/60) + 0.5 KB/40 MB/s + 0.1 ms
 5 + 3 + 0.13 + 0.1 = 8.23 ms

 http://meseec.ce.rit.edu/eecc551-winter2003/551-exam-review-winter2003.pdf




  • Performance Example

How long does it take to read a 512 byte block from the disk?
How long does it take to read two 512 byte blocks from the disk?
http://williams.comp.ncat.edu/comp375/disk.pdf


  • Disk Performance Example


• Calculate time to read 512-byte sector for a disk.
Average seek time is 5ms,
the transfer rate is 40 MB/sec,
it rotates at 10,000 RPM, and
the controller overhead is 0.1 ms.
• Disk latency = average seek time +
average rotational delay + transfer time +
controller overhead

= 5 ms+ 0.5 * 1/(10000 RPM) + 512 B / (40 MB/s) + 0.1 ms
=5+3+0.013+0.1=8.11ms

https://docs.google.com/presentation/d/1zBhbZZoejmApfDjDkBvYg50DJ_4Aoq4EzGB_e_AYeLU/edit#slide=id.p5




  1. Disk Performance


Average Disk Access Time= average rotation time+ average seek time+data transfer time+controller overhead time.

For a disk with 7200RPM, the average rotation time= 0.5 rotations/7200RPM= 0.00415 sec

What is the average time to read/write a 512 byte sector for a typical disk:

average seeek time=9ms,
data transfer rate is 4MB/s,
RPM=7200,
controller overhead=1 ms.
Assume no queueing delay.

Ans: 9ms+(0.5/(7200/60))*1000 ms+0.5KB/4.0MB/s+1ms=9+4.15+0.125+1=14.3 ms.
http://cs.uccs.edu/~cs520/S99ch6.PDF



How does Assembly Code run on a microprocessor?


every program that is run on a computer is being executed inside the processor
The microprocessor or Central Processing Unit (CPU) is the heart of the computer
it is the piece of hardware that carries out the tasks or instructions sent to it by the user or operating system

 A program is a set of instructions that are written in a higher-level language, like C/C++ and Java, and translated to a lower-level language by the compiler to assembly and then object or machine code, 1’s and 0’s
 assembler and compiler maps the human readable instructions to machine code, in order to be read by the computer.

 the only language the computer hardware, including the processor, understands is Machine Language

 To code in machine language directly would be problematic and very confusing, so programmers invented a lower-level language called assembly language. Assembly language is just machine language translated to a human readable format that is standardized.

 Just like English there are many different types of assembly languages and each one is specific to the processor it is running on

 The simplest and widely used assembly language is MIPS.
 The MIPS architecture uses only three formats to organize its 128 different types of instructions.
 In a 32-bit architecture each instruction is 32 bits wide and the first six bits (opcode) represent the instruction the processor needs to execute.


 There are three stages in the cycle of the programs execution: Fetch, Decode, and Execute

 The first stage, Fetch, fetches the current instruction from the memory and stores it into the PC or program counter.
 In the decode stage, the instruction is decoded so the processor knows what to do
 The last stage, execute, executes the current decoded instruction.

 This cycle then repeats after PC is incremented by 4, to load the next instruction.
 Once all instructions are done executing the program is done executing.

 http://www.personal.psu.edu/scb5156/assignment5.html

Binary Arithmetic Operations



  • Rules of Binary Addition


0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 0, and carry 1 to the next more significant bit
For example,

00011010 + 00001100 = 00100110                1  1 carries
  0  0  0  1  1  0  1  0   =   26(base 10)
+ 0  0  0  0  1  1  0  0
   =   12(base 10)
  0  0  1  0  0  1  1  0   =   38(base 10)


00010011 + 00111110 = 01010001         1  1  1  1  1 carries
  0  0  0  1  0  0  1  1   =   19(base 10)
+ 0  0  1  1  1  1  1  0
   =   62(base 10)
  0  1  0  1  0  0  0  1   =   81(base 10)
Note:  The rules of binary addition (without carries) are the same as the truths of the XOR gate.

http://academic.evergreen.edu/projects/biophysics/technotes/misc/bin_math.htm#add



  • Binary Subtraction Examples

It's almost exactly the same as decimal subtraction except that when you need to borrow, you borrow 2 instead of 10.

Here are some examples of binary subtraction. These are computed without regard to the word size, hence there can be no sense of "overflow" or "underflow". Work the columns right to left subtracting in each column. If you must subtract a one from a zero, you need to “borrow” from the left, just as in decimal subtraction.

http://sandbox.mc.edu/~bennet/cs110/pm/sub.html

two's complement

  • two's complement is the way every computer I know of chooses to represent integers. To get the two's complement negative notation of an integer, you write out the number in binary. You then invert the digits, and add one to the result.


Suppose we're working with 8 bit quantities (for simplicity's sake) and suppose we want to find how -28 would be expressed in two's complement notation. First we write out 28 in binary form.

00011100
Then we invert the digits. 0 becomes 1, 1 becomes 0.

11100011
Then we add 1.

11100100
That is how one would write -28 in 8 bit binary.



Example 2

Now suppose we want to subtract 12 from 69. Now, 69 - 12 = 69 + (-12). To get the negative of 12 we take its binary representation, invert, and add one.

0000 0000 0000 0000 0000 0000 0000 1100
Invert the digits.

1111 1111 1111 1111 1111 1111 1111 0011
And add one.

1111 1111 1111 1111 1111 1111 1111 0100
The last is the binary representation for -12. As before, we'll add the two numbers together.

1111 1111 1111 1111 1111 1111 1    1
Carry Row
  0000 0000 0000 0000 0000 0000 0100 0101
(69)
+ 1111 1111 1111 1111 1111 1111 1111 0100
(-12)
  0000 0000 0000 0000 0000 0000 0011 1001
(57)

We result in 57, which is 69-12.

Example 3

Lastly, we'll subtract 69 from 12. Similar to our operation in example 2, 12 - 69 = 12 + (- 69). The two's complement representation of 69 is the following. I assume you've had enough illustrations of inverting and adding one.

1111 1111 1111 1111 1111 1111 1011 1011
So we add this number to 12.
111  
Carry Row
  0000 0000 0000 0000 0000 0000 0000 1100
(12)
+ 1111 1111 1111 1111 1111 1111 1011 1011
(-69)
  1111 1111 1111 1111 1111 1111 1100 0111
(-57)

This results in 12 - 69 = -57, which is correct.

http://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html





  • Arithmetic operations


Addition
Adding two's-complement numbers requires no special processing if the operands have opposite signs: the sign of the result is determined automatically. For example, adding 15 and −5:
 11111 111   (carry)
  0000 1111  (15)
+ 1111 1011  (−5)
==================
  0000 1010  (10)
This process depends upon restricting to 8 bits of precision; a carry to the (nonexistent) 9th most significant bit is ignored, resulting in the arithmetically correct result of 1010.

http://en.wikipedia.org/wiki/Two's_complement






  • Calculation of 2's Complement


To calculate the 2's complement of an integer, invert the binary equivalent of the number by changing all of the ones to zeroes and all of the zeroes to ones (also called 1's complement), and then add one.

For example,

0001 0001(binary 17)      1110 1111(two's complement -17)

NOT(0001 0001) = 1110 1110  (Invert bits)
1110 1110 + 0000 0001 = 1110 1111  (Add 1)


2's Complement Addition

Two's complement addition follows the same rules as binary addition.

For example,

5 + (-3)  =  2    0000 0101 = +5
+ 1111 1101
 = -3
  0000 0010 = +2



 2's Complement Subtraction

Two's complement subtraction is the binary addition of the minuend to the 2's complement of the subtrahend (adding a negative number is the same as subtracting a positive one).

For example,

7 - 12  =  (-5)    0000 0111 = +7
+ 1111 0100
 = -12
  1111 1011 = -5



2's Complement Multiplication
Two's complement multiplication follows the same rules as binary multiplication.


2's Complement Division
Two's complement division is repeated 2's complement subtraction. The 2's complement of the divisor is calculated, then added to the dividend. For the next subtraction cycle, the quotient replaces the dividend. This repeats until the quotient is too small for subtraction or is zero, then it becomes the remainder. The final answer is the total of subtraction cycles plus the remainder
http://academic.evergreen.edu/projects/biophysics/technotes/program/2s_comp.htm#calculate



  • two's complement notation
If you have -30, and want to represent it in 2's complement,

you take the binary representation of 30
0000 0000 0000 0000 0000 0000 0001 1110

Invert the digits.
1111 1111 1111 1111 1111 1111 1110 0001

And add one.
1111 1111 1111 1111 1111 1111 1110 0010


Suppose we're working with 8 bit quantities
suppose we want to find how -28 would be expressed in two's complement notation

First we write out 28 in binary form.
00011100

Then we invert the digits. 0 becomes 1, 1 becomes 0.
11100011

Then we add 1.
11100100

That is how one would write -28 in 8 bit binary.


Two's Complement
Begin with the number in one's complement.
Add 1 if the number is negative

12 would be represented as 00001100 and -12 as 11110100.

To verify this, let's subtract 1 from 11110100, to get 11110011. If we flip the bits, we get 00001100, or 12 in decimal.

http://www.math.grin.edu/~rebelsky/Courses/152/97F/Readings/student-binary#sign

Flip Flops



  • In the electronics world, a flip-flop is a type of circuit that contains two states and are often used to store state information. By sending a signal to the flip-flop, the state can be changed. In sequential logic, it is the basic element of storage. Flip-flops are used in a number of electronics, including computers and communications equipment.

http://www.computerhope.com/jargon/f/flipflop.htm


  • In electronics, a flip-flop or latch is a circuit that has two stable states and can be used to store state information. 

The circuit can be made to change state by signals applied to one or more control inputs and will have one or two outputs. It is the basic storage element in sequential logic. Flip-flops and latches are a fundamental building block of digital electronics systems used in computers, communications, and many other types of systems.

http://en.wikipedia.org/wiki/Flip-flop_(electronics)#Flip-flop_types



  • Flip-flops are heavily used for digital data storage and transfer and are commonly used in banks called "registers" for the storage of binary numerical data.

http://hyperphysics.phy-astr.gsu.edu/hbase/electronic/flipflop.html

Flip Flops basics:
•Storage elements for synchronous circuits (what is synchronous?)
•Typical configurations:
•SR (set_reset)
•D
•JK
•T (toggle)
http://www.engr.uky.edu/~elias/lectures/ln_13.pdf