COSS - Contact Session - 4 - With Annotaton
COSS - Contact Session - 4 - With Annotaton
Software Systems
Locality of Reference
During the course of the execution of a
program, memory references tend to
cluster
• Temporal locality: Locality in time
• If an item is referenced, it will tend
to be referenced again soon
• Spatial locality: Locality in space
• If an item is referenced, items
whose addresses are close by will
tend to be referenced soon.
Example
product = 1;
for ( i = 0; i < n-1; i++)
product = product * a[i] ;
•Data :
• Access array elements in succession – spatial locality
• Reference to “product” “i” and “n” in each iteration –
Temporal locality
•Instructions :
• Reference instructions in sequence : Spatial locality
• Looping through : Temporal locality
Performance enhancement -Motivation
Cache
Cache
1 1 2
• Simple
• Inexpensive
• Fixed location for given block
- If a program accesses 2 blocks that map to the same line repeatedly,
cache misses are very high
Problem 1 : Direct Mapped Cache
•Given :
• Cache of 64KByte, Cache block of 4 bytes
• 16MBytes main memory
•Find out
a) Number of bits required to address the main memory
b) Number of blocks in main memory
c) Number of cache lines
d) Number of bits required to identify a word (byte) in a block
e) Number of bits to identify a block
f) Tag, Line, Word
Solution 1
•Given :
• Cache of 64kByte, Cache block of 4 bytes
• 16MBytes main memory
•Find out
a) Number of bits required to address the main memory
•Find out
•d) Number of bits required to identify a word (byte) in a block?
8 14 2
Problem 2
Solution 2
Solution 2
Solution 2
Problem 3
• Consider a direct-mapped cache with 64
cache lines and a block size of 16 bytes and
main memory of 8K (Byte addressable
memory) . To what line number does byte
address 1200H map?
Problem 4
• The system uses a L1 cache with
direct mapping and 32-bit address
format is as follows:
• bits 0 - 3 = offset (word)
• bits 4 - 14 = index bits (Line)
• bits15 - 31 = tag
a) What is the size of cache line?
b) How many Cache lines are there?
c) How much space is required to
store the tags in the L1 cache?
d) What is the total Capacity of
cache including tag storage?
Problem 5
•0 2 0 2 2 0 0 2 0 0 0 2 1
0 2 0 2 2 0 0 2 0 0 0 2 1
Problem 6
• Suppose a 1024-byte cache has an access time of 0.1 microseconds and the main memory stores
1 Mbytes with an access time of 1 microsecond. A referenced memory block that is not in cache
must be loaded into cache .
• Answer the following questions:
a) What is the number of bits needed to address the main memory?
a) If the cache hit ratio is 95%, what is the average access time for a memory reference?
Avg access time = hit ratio * cache access + (1- hit ratio) * (cache access + memory access)
Associative Mapping
•Given :
• Cache of 128KByte, Cache block of 8 bytes
• 32 MBytes main memory
•Find out
a) Number of bits required to address the memory
e) Tag, Word
Problem 8
•Cache of 64KByte, Cache block of 4 bytes , 16 M Bytes main memory and
associative mapping.
Fill in the blanks:
0 2 0 2 2 0 0 2 0 0 0 2 1