Another way to solve could be like this :
They’re asking average number of stalls per instructions , so we need to only find extra cycles taken due to misses.
And hit rate or miss rate is always w.r.t memory references and not instructions.
And for 500 memory references , no. of instructions = 500/2.5 = 200 instructions
Keeping these things in mind :
Miss rate of l1 = 50/500 = 1/10 = 0.1
Miss rate of l2 = 20/50 = 0.4
So , 500 memory references will take = 500 (10 + 0.1( 20 + 0.4 * 100 )) = 500* 16 cycles
And if these were only hits then 500 memory references would’ve taken = 500*10 cycles.
So, extra cycles taken (stalls) = 500*16 – 500*10 = 3000 cycles
These are total no. of stalls and we needed to find the average per instruction , so dividing it just by total no. of instructions :
Average stalls per instruction = 3000/200 = 15 cycles