Given , page fault service time = 500 cycles
page fault rate = 2% = 0.02
TLB access time = 1 cycle
TLB hit rate = 90 % = 0.9
Cache access time = 1 cycle
Cache hit rate = 80 % = 0.8
Main memory access time = 20 cycles
Let us break the solution into subproblems .
Case 1 : Page fault does not occur
This has further cases :
a) TLB hit occurs :
In this case , page tables need not be accessed hence we check that there may be cache hit or cache miss , so again 2 cases within it.
So effective time when TLB hit occurs = TLB hit rate* [TLB access time + Cache hit rate(Cache access time) +
Cache miss rate * (Cache access time + Main memory access time) ]
= 0.9 * [1 + 0.8*1 + 0.2*(1 + 20) ]
= 0.9 * [1 + 0.8 + 4.2]
= 0.9 * 6
= 5.4 cycles ............(1)
Now
b) TLB miss occurs :
So in this case the page tables access time which are in main memory are also going to be counted .Since nothing is given about level of paging so we assume we have 1 level of paging only , so 1 main memory access time is required since page tables are stored in main memory.
So effective time when TLB miss occurs = TLB miss rate* [TLB access time + 1 main memory access time(due to page table) + Cache hit rate(Cache access time) + Cache miss rate * (Cache access time + Main memory access time) ]
= 0.1 * [ 1 + 20 + 0.8 + 0.2 * 21 ]
= 0.1 * [ 1 + 20 + 5]
= 0.1 * 26
= 2.6 cycles ...............(2)
So combining (1) and (2) ,
Effective time if page fault does not occur = 5.4 + 2.6
= 8 cycles .................(3)
Now we come to case 2)
Case 2 : Page fault occurs :
If page fault occurs , then in addition to what have we done in earlier steps , we also require page fault service time
So time required in this case : Page fault service time + effective time calculated in case a) [as we come to know later that page fault has occured , so we have accessed TLB , page tables , cache memory , main memory as required and as the case may be before knowing that page fault has occured ]
So ,
Time required in case page fault occurs = 500 + 8
= 508 cycles ...............(4)
But page fault occurs only 2 % of the time.Hence,
Effective time required = Page hit rate * time calculated in case 1 + page fault rate(or miss rate) * time found in case 2
= 0.98 * 8 + 0.02 * 508
= 7.84 + 10.16
= 18 cycles
Hence no of cycles required effectively = 18 cycles