P3L1 Scheduling - Timeslices Flashcards

1
Q

A ________ is the maximum amount of uninterrupted time that can be given to a task.

A task may run for a ________ amount of time than what the timeslice specifies.

The use of timeslices allows for the tasks to be ____________ . That is, they will be timesharing the CPU.

For _____ bound tasks, this is not super critical, as these tasks will often be placed on wait queues. However, for _____ bound tasks, timeslices are the only way that we can achieve timesharing.

A

A timeslice is the maximum amount of uninterrupted time that can be given to a task.

A task may run for a shorter amount of time than what the timeslice specifies.

The use of timeslices allows for the tasks to be interleaved. That is, they will be timesharing the CPU.

For I/O bound tasks, this is not super critical, as these tasks will often be placed on wait queues. However, for CPU bound tasks, timeslices are the only way that we can achieve timesharing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define ‘timeslice’

A

A timeslice is the maximum amount of uninterrupted time that can be given to a task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Specify 2 ways a task may run for a shorter amount of time than specified.

A
  1. Task has to wait on I/O
  2. Another higher priority task becomes runnable and preempts
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Use of timeslicing is more important for CPU bound tasks or I/O bound tasks?

A

CPU bound tasks because I/O tasks get stopped anyway. CPU bound tasks would just hog the CPU if nothing stops them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

For these tasks that all arrive at the same time, same priority:

  • T1 , exec time 1 sec
  • T2, exec time 10 sec
  • T3, exec time 1 sec

Using timeslice (1 sec) scheduling, calculate

  1. throughput
  2. average wait time
  3. average completion time
A
  1. throughput = 3/(1 + 2 + 1+8) = 3/12 sec 0.25 tasks/sec
  2. average wait time - (0 + 1 + 2)/3 = 1 sec
  3. average completion time = (1 + 12 + 3)/3 = 5.33 sec
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What’s the advantage of timeslicing scheduling algorithm over SJF?

A

Don’t need prior knowledge of execution times.

Even though according to previous metric question, our throughput stays the same, and our average wait and average completion time are on par with SJF.

But a priori knowledge of execution times, is not feasible in real systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

List 3 advantages of Timeslicing algorithm in general

A
  1. Short tasks finish sooner
  2. More responsive
  3. Lengthy I/O tasks initiated sooner
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. List one disadvantage of Timeslice scheduling
  2. How can this disadvantage be mitigated?
A
  1. Overhead of context switch.
    * Depends on length of timeslice in comparison to context switching overhead
  2. Choose the length of timeslice ‘enough’ longer than the overhead.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How long should a timeslice be?

Timeslices provide benefits to the system, but also come with certain ________. The ________ of the _______ and the overheads will inform the length of the timeslice.

The answer is different for _____ bound tasks vs. ______bound tasks.

A

Timeslices provide benefits to the system, but also come with certain overheads. The balance of the benefits and the overheads will inform the length of the timeslice.

The answer is different for I/O bound tasks vs. CPU bound tasks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Two tasks that are only CPU bound, exec. time of each is 10 seconds, context switch time is 0.1 seconds

Calculate for timeslice = 1 sec

  • Throughput
  • Average Wait Time
  • Average Completion Time
A

Calculate for timeslice = 1 sec

  • Throughput = 2/(10 + 10 + 19*0.1) = 0.091 tasks/second
  • Average Wait Time = (0 + 0.1 + 1.0) /2 = 0.55 seconds. Note that wait time for the 2nd task includes context switch time.
  • Average Completion Time = (19 + 18*0.1 + 20 + 19*0.1)/2 = 42.7/2 = 21.35 sec

Note the short wait time

Note the long completion time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Two tasks that are only CPU bound, exec. time of each is 10 seconds, context switch time is 0.1 seconds

Calculate for timeslice = 5 sec

  • Throughput
  • Average Wait Time
  • Average Completion Time
A

Calculate for timeslice = 5 sec

  • Throughput = 2/(10 + 10 + 3*0.1) = 0.098 tasks/second
  • Average Wait Time =(0 + (5+0.1)) / 2​ = 2.55 seconds
  • Average Completion Time = (15 + 2*0.1 + 20 + 3*0.1)/2 = 17.75
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Two tasks that are only CPU bound, exec. time of each is 10 seconds, context switch time is 0.1 seconds

Calculate for timeslice = = infinite (run to completion)

  • Throughput
  • Average Wait Time
  • Average Completion Time
A

Calculate for timeslice = infinity - NO PREEMPTION

  • Throughput = 2/(10 + 10) = 0.1 tasks/second
  • Average Wait Time =(0 + 10) / 2​ = 5 seconds
  • Average Completion Time = (10 + 20)/2 = 15 seconds

(Note no context switch overhead!)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

With a smaller timeslice value, we have to pay the time cost of context switching more frequently.

With smaller timeslices is

  1. throughput higher or lower?
  2. completion time shorter or longer?
  3. average wait time shorter or longer?
A

With a smaller timeslice value, we have to pay the time cost of context switching more frequently.

With smaller timeslices is

  1. throughput lower
  2. completion longer
  3. average wait time shorter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Smaller timeslices mean that tasks are started ________, so our average wait time is _______ when we have smaller timeslices.

Average wait time for CPU bound tasks is important for the user. True or False?

A

Smaller timeslices mean that tasks are started sooner, so our average wait time is better when we have smaller timeslices.

False. The user cannot really perceive when a CPU bound task starts, so average wait time is not super important for CPU bound tasks. The user cares when a CPU bound task completes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

For CPU bound tasks, we are better off choosing a _________ timeslice.

If our timeslice value was infinite - that is to say we never ________ tasks - our metrics would be _____.

A

For CPU bound tasks, we are better off choosing a larger timeslice.

In fact, if our timeslice value was infinite - that is to say we never preempt tasks - our metrics would be best.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Consider the case:

  1. Tasks T1 and T2 each need 10 seconds to complete
  2. T1 is CPU bound
  3. T2 is I/O bound -it waits on I/O after 1 second.
  4. Consider timeslice of 5 seconds

Describe how the tasks are scheduled

A
  1. T1 runs until its timeslice expires at T=5.
  2. T2 then runs for only 1 second until it issues its I/O request.
  3. T1 then runs again for 5 seconds and completes.
  4. Finally T1 runs and completes.

T1: _____ _____

T2: _ _________

17
Q

With a larger timeslice, I/O latency can no longer be hidden.

  1. So total execution time is ______________.
  2. Average throughput is _____________.
  3. Average wait time is _______________
  4. Average completion time is ______________
A

Note that the I/O latency of T2 can no longer be hidden, which means that the

  1. Total execution time of these operations is longer
  2. which means that the throughput is less.
  3. The average wait time is longer because T2 now has to wait 5 seconds for T1’s timeslice to expire.
  4. Average completion time is improved, as T1 can completely exhaust its timeslice and finish quickly.
18
Q

For I/O bound tasks, we want a _______ timeslice.

We can keep _______ up and average ______ time down with a ________ timeslice.

As well, we can maximize device ________ with a smaller timeslice, as we can quickly switch between different tasks issuing I/O requests.

A

For I/O bound tasks, we want a smaller timeslice.

We can keep throughput up and average wait time down with a smaller timeslice.

As well, we can maximize device utilization with a smaller timeslice, as we can quickly switch between different tasks issuing I/O requests.

19
Q

CPU bound tasks prefer longer or shorter timeslices?

Explain why.

A

CPU bound tasks prefer longer timeslices

Limits the number of context switching overheads that the scheduling will introduce.

This ensures that CPU utilization and throughput will be as high as possible

20
Q

I/O bound tasks prefer longer or shorter timeslices?

Why?

A

I/O bound tasks prefer short timeslices.

This allows I/O bound tasks to issue I/O requests as soon as possible

This keeps CPU and device utilization high

Improves user-perceived performance (remember wait times are low).

21
Q

Timeslice Quiz:

On a single CPU system, consider the following workload and conditions:

  • 10 I/O bound tasks, issues I/O operation every 1 ms of CPU computing
  • I/O ops take 10ms to complete
  • There is 1 CPU bound task
  • All tasks are long running
  • Context switching takes 0.1 msec overhead

Calculate CPU utilization for timeslices of 1ms

Calculate CPU utilization for timeslice of 10ms

A

CPU utilization in percent: (CPU run time /([CPU run time + ctx. switch overhead)) * 100

Timeslice 1ms: If the CPU bound task is running, it will be context switched every 1ms. If the I/O bound task is running, it will also be context switched every 1ms (because of I/O or because of timeslice - whatever). So for every 1ms of useful work, there is 0.1 ms of overhead:

(1 ms/1 + 0.1ms)*100 = 1/1.1 * 100 –> 91%

Timeslice 10 ms: looking at this over 20ms, here’s a possible scenario:

_ _ _ _ _ _ _ _ _ _ _______________

The 10 I/O bound tasks wil run for 1 ms each , then CPU bound run straight to completion for 10 ms.

Underlined the time of the I/O bound work

(10*1 + 10 )/ (10 + 10*0.1 + 0.1 + 10) = 20/(20 +11*0.1) * 100 = 95 –> 95%