Computing runtime for dual-threaded CPUs?
Given 3 programs P0, P1, P2 and two processors, and each processor has 2 threads. The running time of the programs is 5, 10 and 20 ms, respectively. How long will it take to complete all three programs? Assuming they don't swap CPUs and don't block at runtime.
My answer is 20ms, because no matter how we organize programs on CPUs, they will execute as fast as the slowest program (P2), so 20ms. However, the solution guide gives answers 20, 25 and 30. Can anyone tell me how this answer came to be?
It says
If P0 and P2 are scheduled on one CPU and P1 is scheduled on another CPU, it will take 25ms
the question arises, why, however, shouldn't the first processor take time P2 (20ms), while the second P1 and given than P2 take longer and both processors simultaneously shouldn't respond for 20ms?
source to share
p0 - 5 ms
p1 - 10 ms
p2 - 20 ms
Scenario 1:
| P0 | | |
| P1 | | p2 |
\_____/ \____/
CPU0 CPU1
To complete both jobs, it will be required CPU0
15ms
, and CPU1
will run 20ms
before p2 is executed, they will be executed in parallel, so both jobs will be executed in 20ms
.
Scenario 2:
| P2 | | |
| P0 | | p1 |
\_____/ \____/
CPU0 CPU1
To complete both tasks will be required CPU0
25ms
and CPU1
will be performed 10ms
. They run in parallel and CPU1
goes into standby after 10ms
it takes CPU0
a extra 15ms
to finish. Thus 25ms
.
Scenario 3:
| P2 | | |
| P1 | | p0 |
\_____/ \____/
CPU0 CPU1
To complete both jobs will be required CPU0
30ms
and CPU1
will be executed 5ms
Again, they run in parallel, so while it CPU1
stops working after 5ms
, it will take CPU0
an additional one 25ms
to complete. Thus 30ms
.
Please note that the jobs remain on the same processor they were scheduled on, as per your question. If one job takes 20ms to complete and another takes 10ms, it takes 30ms to complete. If your jobs can run on different cores of the same processor, then it will still be 20ms (this is the best case), but this is not the situation provided.
source to share