There is a $5$ stage Instruction pipeline, which takes $1$ $ns$ to execute each cycle. There are $4000$ branch instructions with a delay of $2$ clock cycles and $6000$ normal instructions ( They get completed in $5$ stages). What will be the total execution time taken by a pipelined processor?
Answer:
$P$ = total no. of normal instructions,
$Q$ = total no. of branch instructions,
$S$ = No. of cycles required to execute first instruction then,
In pipelined processor time to execute $6000$ instructions will be = $S - 1 + P$ = $4 + 6000$ = $6004$ $ns$
My branch instruction takes $2$ stalls per instruction => It means it will require total of $7$ cycles to complete.
Therefore, Time taken to execute branch instruction will be = $S - 1 + Q$ = $4006$ $ns$
Hence the total time for execution will be $6004 + 4006 = 10010$ $ns$
Is this a correct answer and right way to solve such problem?