Operating Systems · Problem type

Cost of a context switch

Use this for “The time slice is 10 ms and a context switch takes 0.1 ms. What share of the CPU time does useful work?”
This is an example. Type your own values to start a new problem.
η
%
=
100
×
q (ms)
q (ms)
+
s (ms)
o
Share lost to switching
worked out (not typed) · %

Formulas

η
=
100
×
q
q
+
s
99.0099
=
100
×
10
10 + 0.1
o
=
100
×
s
q
+
s
0.9901
=
100
×
0.1
10 + 0.1

Assumptions

•
Every process uses its whole time slice, so each slice is followed by one context switch.
•
During a switch the CPU saves one process’s registers and loads the next one’s, doing no useful work.
•
The cycle repeats: one slice of work, then one switch, so the shares come from one cycle.

Step-by-step

WE KNOW
q = 10 ms, s = 0.1 ms
FIND
useful share of CPU time (η), share lost to switching (o)
Step 1 · Find useful share of CPU time (η)
Use η = 100 × q ÷ (q + s)
Of
each
cycle
of
q
+
s
,
only
the
slice
q
does
useful
work;
×
100
gives
a
percent.
η
=
100
×
10
10 + 0.1
η
=
100
×
10
10.1
η
=
1,000
10.1
η
=
99.0099%
Step 2 · Find share lost to switching (o)
Use o = 100 × s ÷ (q + s)
The
switch
takes
the
other
part
of
each
cycle,
s
out
of
q
+
s
.
o
=
100
×
0.1
10 + 0.1
o
=
100
×
0.1
10.1
o
=
10
10.1
o
=
0.9901%
Check
Put the numbers back in. Both sides should match.
99.0099
=
100
×
10
10 + 0.1
✓
0.9901
=
100
×
0.1
10 + 0.1
✓
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.

Related lessons

© 2026 SME. All rights reserved.