-
Notifications
You must be signed in to change notification settings - Fork 1
/
chapter01.html
2447 lines (1715 loc) · 78.5 KB
/
chapter01.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Introduction to Operating Systems</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="css/slides.css" rel="stylesheet" type="text/css" />
</head>
<body>
<textarea id="source">
class: center, middle, title-slide
## CSCI 340 Operating Systems
<br>
## Chapter 1: Introduction
.author[
Stewart Weiss<br>
]
.license[
Copyright 2020 Stewart Weiss. Unless noted otherwise all content is released under a
[Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/).
Background image: roof of the EPIC Museum, Dublin, by Stewart Weiss.
]
---
name: cc-notice
template: default
layout: true
.bottom-left[© Stewart Weiss. CC-BY-SA.]
---
name: tinted-slide
template: cc-notice
layout: true
class: tinted
---
name:toc
### Table of Contents
[What Is This Course About?](#overview)<br>
[This Chapter's Objectives](#objectives)<br>
[Computer System Components](#computer-system-components)<br>
[Layered Structure of Computer System](#layered-view)<br>
[Operating System Requirements](#opsys-requirements)<br>
[Other Considerations](#opsys-requirements2)<br>
[Additional Operating System Requirements](#opsys-requirements3)<br>
[Operating System Services](#opsys-service-categories)<br>
[Trying to Define "Operating System"](#opsys-defs)<br>
[System Programs](#system-programs)<br>
[The General Structure of a Typical Computer](#computer-org-overview)<br>
[Main Components](#computer-components-1)<br>
[Main Components (Continued)](#computer-components-2)<br>
[Device Drivers](#device-drivers)<br>
[Computer System Operations](#computer-operations)<br>
[Typical I/O Read Operation](#read-operation)<br>
[Interrupt Overview](#interrupt-overview)<br>
[Interrupts Visualized](#interrupt-visualized)<br>
[Interrupts Step-By-Step](#interrupt-mechanism1)<br>
[Finding and Running the Interrupt Service Routine](#interrupt-service-routine)<br>
[Interrupt Masking](#interrupt-masking)<br>
---
### Table of Contents
[Interrupt Priorities](#interrupt-priorities)<br>
[Traps and Exceptions](#exceptions)<br>
[Interrupt-Driven I/O](#io-cycle)<br>
[Storage Concepts](#storage-concepts)<br>
[Measuring Storage: Bits, Bytes, and Words](#storage-measurements-1)<br>
[Measuring Storage: Larger Amounts](#storage-multiples)<br>
[The Different Types of Storage](#storage-components)<br>
[The Memory Hierarchy](#memory-hierarchy)<br>
[Storage in the CPU](#storage-cpu)<br>
[Random Access Memory](#storage-ram)<br>
[Magnetic Disk Drives and Solid-State Drives](#storage-magnetic-disk)<br>
[Tertiary Storage Media](#storage-tertiary)<br>
[Caches and Caching](#storage-cache)<br>
[Processor Cache](#processor-cache)<br>
[I/O and Direct Memory Access](#dma)<br>
[DMA Operation](#dma-steps)<br>
[Single Processor Systems](#single-processor)<br>
[Multicomputers and Multiprocessors](#multiprocessors)<br>
[A Multicomputer Architecture](#multicomputer)<br>
[Symmetric Multiprocessors](#smp)<br>
[Multi-core SMP](#multicore-smp)<br>
[Non-Uniform Memory Access Multiprocessors](#numa)<br>
[Clustered Systems](#clusters)<br>
---
### Table of Contents
[System Start-Up: Stage 1](#booting)<br>
[System Start-Up: Stage 2](#opsys-services)<br>
[Origins of Multiprogramming](#multiprogramming-1)<br>
[Multiprogramming](#multiprogramming-2)<br>
[Batch Processing](#multiprogramming-3)<br>
[Interactive Computing](#interactive-computing)<br>
[Time-sharing Infrastructure](#timesharing)<br>
[Multitasking](#multitasking)<br>
[Protection Levels](#protection-levels)<br>
[Use of Dual-Mode Operation](#dual-mode2)<br>
[System Call Schematic in Linux](#syscall-graphic)<br>
[Timers](#timers)<br>
[Process Management: What are Processes?](#processes)<br>
[Process Management](#process-management)<br>
[The Memory Resource](#memory-resource)<br>
[Memory Management](#mem-management-tasks)<br>
[Files and File Systems](#file-systems)<br>
[File System Management](#file-systems-2)<br>
[Storage Management](#storage-management)<br>
[Caching Revisited](#caching)<br>
[Cache Management](#cache-management)<br>
[The I/O Subsystem](#io-subsystem)<br>
[Protection and Security](#security)<br>
---
### Table of Contents
[Protection and Security Management](#security-management)<br>
[Distributed Systems](#distributed-systems)<br>
[Network and Distributed Operating Systems](#network-opsys)<br>
[Free and Open Source Software](#foss)<br>
[Free and Open Source Operating Systems](#foss-opsys)<br>
[References](#references)<br>
<!--TOC_END-->
---
name: overview
### What Is This Course About?
This is an overview of .greenbold[ computer operating systems].
.redbold[It is not an in-depth study of them.]
The major topics that it covers are
- What operating systems do
- How computer systems are organized and structured, including the
software-hardware interface
- How operating systems are structured
- .greenbold[Processes] and their relationship to operating systems:
process management, concurrency and parallelism, process synchronization, and deadlocks
- The .greenbold[memory hierarchy] and its relationship to operating systems,
including the operating system's role in managing memory
- .greenbold[Secondary storage] and .greenbold[I/O devices] and their
relationship with operating systems
- A bit of the history of operating systems and how open source operating
systems have influenced their development.
.footnote[
These slides are intended to accompany reading of the textbook,
_Operating System Concepts, 10th Edition_ by Silberschatz, Gagne, and Galvin.
]
---
name: objectives
### This Chapter's Objectives
The goals of this chapter are to make sure that you understand
- .redbold[what] operating systems actually do and what they do not do,
- .redbold[how] operating systems do what they do,
- how operating systems .redbold[are structured], and
- enough about the underlying hardware to give context to the tasks an
operating system must perform, and how it interacts with that hardware layer, including
- general organization of a computer system, including multiprocessor systems,
- interrupts and their relationship to operating system functionality,
- dual mode operation, and
- storage and memory technologies and their impact on operating systems.
---
name: computer-system-components
### Computer System Components
In general, a .bluebold[system] is a cohesive collection of interrelated and interdependent
parts.
A .bluebold[computer system] includes the .greenbold[hardware] and the .greenbold[software] that together
make the aggregate usable by .greenbold[users], which include not just people, but
machines or other .greenbold["things"].
--
- .bluebold[Hardware] includes processors, I/O devices, all types of memory and
secondary storage.
--
- .bluebold[Software] includes the .greenbold[operating system] and the software
that uses it, which is called the .greenbold[application layer].
--
- The <span class=bluebold>operating system </span> is the software that interacts directly
with the hardware; applications do not.
--
- <span class=bluebold> The application layer </span> includes software development tools, web
browsers, all types of media editors and viewers, shells, commands, etc.
<span class=redbold>_User data is part of the application layer_ </span>.
---
name: layered-view
### Layered Structure of Computer System
The components of a computer system form a sequence of .greenbold[layers]:
.center[
<img src="figures/layers.png" width=45% alt="layered view"/>
]
Only adjacent layers have interactions with each other. .redbold[For example],
- applications do not directly communicate with or control hardware, and
- users only interact with the application layer (which includes shells like
.fixedblue[bash] in Linux.)
---
name: opsys-requirements
### Operating System Requirements
The layered structure of a computer system implies that an operating
system has three important responsibilities:
1. The operating system alone must .redbold[control the hardware resources].
--
1. The operating system alone must enable and
.redbold[control the execution] of all other software on the computer.
--
1. The operating system must give users the ability to
.redbold[develop, run, and manage applications and their data].
--
.redbold[But these are not the only things for which operating systems are responsible].
---
name: opsys-requirements2
### Other Considerations
There are other considerations that affect what else operating systems
is required to do.
--
There are requirements coming from .redbold[what users want]:
--
- Users want their time on the computer to be spent .redbold[efficiently].
- Users want their data to be .redbold[secure].
- Users want using the computer to be as .redbold[convenient] and easy as possible.
- Users may want to be able to .redbold[share] data and applications .redbold[selectively with other users].
--
A computer, on some level, exists to produce value, directly or indirectly,
for its owner.
The more productive it is, the more value is created for the owner.
This leads to additional requirements:
--
- The computer resources should be .redbold[utilized as efficiently as possible],
maximizing the amount of work it performs per unit time.
- The computer resources should be .redbold[protected] from all possible intentional and unintentional
abuses.
- It should be possible to .redbold[allocate resources as needed] among various users.
---
name: opsys-requirements3
### Additional Operating System Requirements
Preceding considerations lead to these additional tasks that operating
systems must perform:
--
- An operating system should manage the resources of a computer system in such as way
as to allow .redbold[reliable sharing of data and applications].
--
- An operating system should provide .redbold[security and protection] of all hardware and
software on the computer system.
--
- An operating system should provide robust .redbold[error handling and recovery].
--
- An operating system should allocate resources fairly to users while trying to
.redbold[maximize overall throughput, minimize response time] to as many users as possible,
and .redbold[maximize the utilization] of all hardware resources in the system.
---
name: opsys-service-categories
### Operating System Services
The most common services performed by operating systems can be categorized as follows.
--
- .greenbold[Program execution] - loading and executing programs; providing synchronization,
communication, and security
--
- .greenbold[I/O operations] - providing all I/O services to users and applications
--
- .greenbold[File systems] - creating and maintaining file systems and means of manipulating them
--
- .greenbold[Communication] - providing mechanisms that allow programs to communicate
with each other
--
- .greenbold[Error detection and recovery] - detecting and handling error conditions
--
- .greenbold[Protection and security] - preventing unauthorized or improper access to all
resources, and protecting users from each other's attempts to invade privacy or
corrupt data.
--
- .greenbold[Accounting] - monitoring and recording various performance and
utilization metrics, for both users and the system.
---
name: opsys-defs
### Trying to Define "Operating System"
People disagree about the definition of the term "operating system."
--
- Some say it is just the program, often called
the .greenbold[kernel], that is loaded into memory on
start-up and remains in memory, controlling the computer, until it is shut down.
--
- Others say it is the collection of programs, including the kernel, that provide
services to applications and users, including all .greenbold[system programs].
We discuss system programs shortly.
--
To remove all ambiguity in this course, we make the following definition:
the .redbold[operating system is the kernel program and nothing more.]
---
name: system-programs
### System Programs
.redbold[This is a fuzzy concept at best].
.bluebold[System programs] are typically programs shipped or
downloaded when the operating system is installed. .redbold[For example]:
- .greenbold[Software updaters/package managers] - programs that track, download, and install
updates to your operating system or other software or install new software.
- .greenbold[Compilers, linkers, loaders, debuggers, etc.] - programs that enable you to build your
own software.
- .greenbold[File management commands] such as commands to navigate the file system,
list directories, and so on.
--
On a .greenbold[Linux system], system programs include most of the commands that
you typically type on the command line. To be more precise, these are commands that are found
in the directories,
.fixedblue[/bin],
.fixedblue[/usr/bin],
.fixedblue[/usr/sbin], and
.fixedblue[/sbin].
Almost all of these programs can only be invoked as commands on the
command line in a terminal window, but there are some that can (also) be invoked through a graphical
user interface such as .fixedblue[Gnome] using menus or clickable icons.
--
.redbold[Do not confuse system programs with applications.] Applications are usually
programs that you install. Some applications come "bundled" with the operating
system for your convenience. Applications are typically installed in the directories
.fixedblue[/usr/local/bin] or .fixedblue[/opt].
---
name: system-prog-activity
count: false
class: breakout
### System Program Activity
Take a look in the .fixedblue[/bin] directory on .fixedblue[eniac.cs.hunter.cuny.edu]
to see what commands are in it:
- Login to .fixedblue[eniac.cs.hunter.cuny.edu]
- Type the command
```bash
ls /bin
```
and record three different commands that you see there. These are system programs.
---
name: computer-organization
layout: false
class: center, middle, inverse
## Computer Organization
We examine the physical components of a computer system and how they
interact with each other.
---
template: tinted-slide
layout: true
---
name: computer-org-overview
### The General Structure of a Typical Computer
A modern, general-purpose computer consists of one or more .greenbold[CPUs], one or more
.greenbold[memory units], and a set of .greenbold[device controllers], all of which are connected
by a common .greenbold[bus], usually called the .greenbold[system bus].
The figure below illustrates how these components interconnect. Notice that there
is a separate line labeled "interrupts", to be discussed shortly.
.center[
<img src="figures/os-layout.png" width=100% alt="interrupt timeline"/>
]
---
name: computer-components-1
### Main Components
#### CPUs
Most modern computers contain more than one processor. When several processors are integrated
into a single chip, each one is called a .bluebold[core] and the machine itself
is called a .bluebold[multi-core processor].
--
#### System Bus
The .bluebold[system bus] is a single communication path that connects the
major components of a computer system, combining the functionality of a
.greenbold[data bus], an .greenbold[address bus], and a .greenbold[control bus].
A system bus typically consists of many parallel wires. The number of wires
is called the .bluebold[width] of the bus.
--
#### Memory
.bluebold[Memory units] are self-contained primary storage, i.e. random-access,
devices. They are usually .redbold[volatile] and are connected directly to the system bus.
Memory units are controlled by a .bluebold[memory controller], which
synchronizes access to the memory from the devices that want to access it,
and responds to requests to transfer data
to and from memory.
---
name: computer-components-2
### Main Components (Continued)
#### Device Controllers
A .bluebold[device controller] is a special-purpose processor that controls a
specific type of device, such as a disk or a keyboard. It may be connected to
multiple instances of this type of device, or just one.
It typically has a number
of special-purpose registers, buffer memory, and control logic that responds to
specific instructions.
A device controller is responsible for moving data between the devices
that it controls and its local memory. It responds to instructions submitted
to it through the bus, and can query the status of the attached devices.
--
Because device controllers are special-purpose microprocessors with their
own unique instruction sets, the software to control them is also highly
specialized and specific to each different one. For example, the code needed for an
Ultra320 SCSI disk controller is very different from the code needed for
a Parallel ATA disk controller.
--
This is why the code written to control each controller is separated
from the rest of the operating system and placed into its own module
called a .greenbold[device driver].
---
name: device-drivers
### Device Drivers
In a modern operating system,
.redbold[every device controller has an associated device driver.]
--
A .bluebold[device driver] is a program or software module that can "drive" that
controller in much the same way that a person can drive a car. It "knows" the
controller's instruction set and its interface and can send instructions to the
device to perform actions, such as to read a number of blocks of data from a disk to transfer to a
memory location, or to stop or start the device.
--
Most operating systems have the ability to detect which device drivers they need
and integrate them into the operating system itself as separate modules.
.blue[_The primary purpose of device drivers
is to provide a layer of abstraction, so that the operating system programmers do not
need to know the details of the device controllers to write code to perform tasks
using those devices._]
--
.redbold[For example], a serial port might only present two "public" functions,
one to send data and one to receive data.
A device driver that implements these functions would communicate with the
particular serial port controller installed on the computer.
.redbold[Different serial ports have different instruction sets and architectures],
so each serial port may have a different device driver,
but each device driver hides the hardware-specific differences and
presents the same software interface to the software layer above.
The operating system programmer just needs to know the common software
interface that the device drivers present to them.
---
name: computer-operations
### Computer System Operations
Peripheral devices such as keyboards, mice, network interfaces, and external
storage devices can operate concurrently with the processors.
.redbold[For example], a program might be running on a CPU while a user types on a keyboard,
or moves a mouse, or while data is arriving from the local network.
--
These concurrent activities usually involve moving data to or from memory,
and/or may require that the CPU take some specific action in response to specific
events.
.redbold[Example]. When the user types a "Control-C" on the keyboard while a terminal
window has focus and a program is running in the terminal's command line (the shell),
that program is typically terminated. Somehow, that Control-C must be detected
and the fact of its occurrence transmitted to a program that can terminate the
running program. A lot has to happen to make this work.
--
- What part of this is done by hardware? Which hardware?
- What part of this is done by software? Which software?
--
The key to all of this is the use of
.greenbold[interrupts].
.redbold[All modern operating systems are interrupt-driven];
after the boot completes, they run only as a result of interrupts.
---
name: read-operation
### Typical I/O Read Operation
To illustrate, we discuss what happens when a running program issues a request
to read data from a hard disk. The program's .greenbold[read request] causes a
device driver to run. We ignore the steps leading to this for now.
--
- The device driver loads the appropriate registers in the device controller
in order to start the read operation. When it has done this,
some other program is chosen to run on the CPU.
--
- The device controller responds by examining the contents of these registers
and it determines (1) that it is a read operation and
(2) which data must be read.
--
- The controller starts the transfer of the data from the device to its local buffer.
--
- When the transfer of data is complete,
.redbold[the device controller informs the device driver that it has finished its operation].
--
- The device driver runs again. It is responsible for the remainder of the work, which
includes notifying the operating system that the I/O is complete and
transferring the data to an appropriate place in memory.
--
.redbold[
How does the controller inform the device driver that it has finished its operation?
]
--
By issuing an .greenbold[interrupt request].
---
name: interrupt-overview
### Interrupt Overview
What are interrupts and interrupt requests?
An .bluebold[interrupt] is a temporary break in the continuity of the process running
on the processor in order to respond to some condition needing attention.
When an interrupt takes place, the state of the processor is saved, and
special code runs that .greenbold[handles] the specific condition requiring
attention. This code is called either an .bluebold[interrupt service routine]
(.bluebold[ISR]) or an .bluebold[interrupt handler].
A device needing attention can request an interrupt by sending a signal to the processor. This
signal is called an .bluebold[interrupt request]. The acronym .bluebold[IRQ]
is short for interrupt request.
.redbold[The distinction between interrupts, interrupt requests, and the events requiring attention is often blurred],
and people may call any of them an .bluebold[interrupt] for short.
Thus, if a hard disk completed a read operation
and issued an IRQ as a result of it, we might say it issued an interrupt, or it
raised an interrupt, and we might also say the read event itself caused an
interrupt.
---
name: interrupt-visualized
### Interrupts Visualized
Every computer has a clock or timer that causes interrupts at regular intervals.
Every 1 millisecond or so, the clock sends an interrupt request so that the system
can keep track of the time or do maintenance.
The running program is interrupted and a routine runs that increments the count of
ticks. When it finishes, the interrupted program resumes execution, as shown below.
.center[
<img src="figures/interrupt_timeline_walpha.png" width=100% alt="interrupt timeline"/>
]
---
name: interrupt-mechanism1
### Interrupts Step-By-Step
A simplification of what happens is as follows.
1. A device issues an interrupt request by sending a signal on the system bus.
--
1. The signal is received by the CPU.
--
1. The CPU saves the value of the program counter (PC).
--
1. It loads the PC with the starting address of the interrupt service routine
for that device.
--
1. The contents of the remaining registers are saved in an appropriate place.
--
1. The interrupt service routine (ISR) runs.
--
1. When the ISR finishes, the saved registers are restored
and the PC is loaded with the saved value; the interrupted computation is resumed.
--
.redbold[Step 4 suggests that the CPU knows which device caused the interrupt.
How does it know this?]
--
.redbold[In step 4, how does the system know the starting address to load ino the PC?]
---
name: interrupt-service-routine
### Finding and Running the Interrupt Service Routine
There are two different methods of determining which device caused the interrupt
and where the starting address of its interrupt service routine is stored.
--
.left-column[
#### Method 1: .bluebold[Polling the Devices] (Rarely Used)
An IRQ is received by the CPU but it does not indicate which device caused the
interrupt.
There is a single ISR that runs when an interrupt occurs.
This ISR sends a signal to each device that amounts
to the question, "did you just send an IRQ?". The first device to answer "yes"
is the one that will be serviced. The ISR has code that causes a jump
to the correct device driver.
]
---
name: interrupt-service-routine
count: false
### Finding and Running the Interrupt Service Routine
There are two different methods of determining which device caused the interrupt
and where the starting address of its interrupt service routine is stored.
.left-column[
#### Method 1: .bluebold[Polling the Devices] (Rarely Used)
An IRQ is received by the CPU but it does not indicate which device caused the
interrupt.
There is a single ISR that runs when an interrupt occurs.
This ISR sends a signal to each device that amounts
to the question, "did you just send an IRQ?". The first device to answer "yes"
is the one that will be serviced. The ISR has code that causes a jump
to the correct device driver.
This method is called .bluebold[polling] because it polls each device.
.redbold[It is inefficient].
]
--
.right-column[
#### Method 2: .bluebold[Vectored Interrupts] (Almost Always Used)
]
---
name: interrupt-service-routine
count: false
### Finding and Running the Interrupt Service Routine
There are two different methods of determining which device caused the interrupt
and where the starting address of its interrupt service routine is stored.
.left-column[
#### Method 1: .bluebold[Polling the Devices] (Rarely Used)
An IRQ is received by the CPU but it does not indicate which device caused the
interrupt.
There is a single ISR that runs when an interrupt occurs.
This ISR sends a signal to each device that amounts
to the question, "did you just send an IRQ?". The first device to answer "yes"
is the one that will be serviced. The ISR has code that causes a jump
to the correct device driver.
This method is called .bluebold[polling] because it polls each device.
.redbold[It is inefficient].
]
.right-column[
#### Method 2: .bluebold[Vectored Interrupts] (Almost Always Used)
The interrupt lines on the bus are .greenbold[vectored]: each device can send its
identity along with the IRQ. When the CPU receives the IRQ, it can extract the identity
of the device that needs service. The identity is an integer value.
The system maintains a table, usually in low memory, that maps each integer
device identity to the starting address of its ISR. This table is called the
.bluebold[interrupt vector] or the .bluebold[interrupt vector table].
If there are many devices, sometimes the table is a linked list of ISR addresses.
]
---
name: interrupt-masking
### Interrupt Masking
There are two types of interrupts: .greenbold[maskable] and .greenbold[non-maskable].
A .bluebold[maskable interrupt] is one that can be disabled temporarily.
There is a register that contains a bit for each interrupt type, and that bit is
used to determine whether or not to disable (i.e., mask) the interrupt. Maskable
interrupts are non-critical.
A .bluebold[non-maskable interrupt] is one that cannot be disabled. It
must be serviced. It is not affected by the interrupt mask register. Examples
are errors from memory and timer interrupts.
In some systems, disabling an interrupt means ignoring it completely. In others,
it is possible to .greenbold[defer] processing the interrupt if it is disabled.
Deferred interrupts are saved, usually in a queue, and handled in a specific order
at a future time.
---
name: interrupt-priorities
### Interrupt Priorities
Some interrupts have higher priorities than others:
if the CPU is in the middle of servicing an interrupt request, and a higher priority
request occurs, it should interrupt the current ISR.
On the other hand, if an interrupt request has lower priority than the one being
serviced by the CPU, it should be ignored.
Most systems have a method of .greenbold[prioritizing interrupts], either in hardware alone,
or in both hardware and software.
--
#### .redbold[Example]
The .greenbold[mask register] can be used to set the interrupt priority level of the
processor using a left-to-right ordering of the mask bits.
- Each device has an associated priority level, and the ISR for that device runs
at that priority level. The priority level is an integer corresponding to a bit position.
- .redbold[If an interrupt occurs whose bit is to the left of another one, it has higher priority].
If its mask bit is on, it is enabled, otherwise it is disabled.
- By turning off all bits to the right of a given bit, the processor masks all
interrupts whose priority is lower than the given one.
- If a lower priority interrupt occurs, it is ignored.
If one occurs that is at equal or higher priority, the currently running ISR is
interrupted and the ISR for the new one runs.
---
name: exceptions
### Traps and Exceptions
In English, an .greenbold[exception] is an uncommon event. In computing it is supposed to be
an uncommon event.
An .bluebold[exception] is a software-generated interrupt. It is caused by the
execution of a software instruction. Examples of exceptions are
- floating-point errors such as divide-by-zero,
- attempts to execute invalid opcodes, and
- attempts to access memory locations outside of the process's allowed memory.
--
The term .bluebold[trap] is often used as a synonym for exception, but it is not.
Traps are a specific type of exception.
- The Intel 80x86 architecture defines a trap as follows:
A .bluebold[trap] is a programmer-initiated (and consequently expected)
transfer of control to a handler routine. (The .fixedblue[int] assembly instruction is a trap.)
- In the Linux kernel, a trap is a specific type of exception. There are other types of
exceptions as well. On Intel chips, the .fixedblue[eip] register is queried to decide the type.
In short, traps are actual instructions coded into programs intentionally that cause an
interrupt, whereas exceptions are any interrupts generated by software.
We will see how traps are used in the next chapter, when we discuss
.bluebold[system calls].
---
name: io-cycle
### Interrupt-Driven I/O
.left-column[
Recall that modern operating systems are interrupt-driven; they
only run as a result of interrupts.
All I/O occurs as a result of interrupts.
To illustrate this, in the figure to the right, we have augmented the
sequence of steps described in the slide, [Typical Read Operation](#read-operation)
to show how interrupts are used in the read operation.
]
.right-column[
<img src="figures/read-io-a.gif" width=100% alt="read i/o"/>
]
---
name: interrupt-activity
count: false
class: breakout
### Interrupt Activity
Take a look in the .fixedblue[/proc] directory on .fixedblue[eniac.cs.hunter.cuny.edu]
to see what types of interrupts are hitting the CPUs recently:
- Login to .fixedblue[eniac.cs.hunter.cuny.edu]
- Navigate to the .fixedblue[/proc] directory:
```bash
cd /proc
```
- Make your terminal window as wide as possible.
- Then, using a command such as .fixedblue[more], view the contents of the file
named .fixedblue[interrupts]. There is a column for each logical CPU and a row for
different interrupts.
- Which type of interrupt has occurred the most and on which CPU.
Write what you find as instructed in class.
---
template: default
layout: true
---
name: storage
background-image: url(figures/storage.jpg)
class: center, middle
# Storage
We review concepts of storage and the various types of storage used
in computer systems.
.bottom-left[
image (cropped): [Smuconlaw](https://commons.wikimedia.org/wiki/File:Archaeology_storage_room,_Heritage_Conservation_Centre,_Singapore_-_20141125-01.jpg),
[CC-BY-SA](https://creativecommons.org/licenses/by-sa/4.0/).
]
---
template: tinted-slide
layout: true
---
name: storage-concepts
### Storage Concepts
Storage media and devices can be characterized in many ways, such as by their
cost, reliability, capacity, and so on. We define the key properties of interest.
--
- .bluebold[Capacity] is total amount of stored information that a storage medium
or device can hold. It is measured in either .greenbold[bits] or .greenbold[bytes], both of
which are defined in the next slide.
--
- .bluebold[Volatility] refers to whether or not the information stored on a
storage medium is retained when power is not continuously supplied to that medium.
A .greenbold[non-volatile] storage medium retains the information whereas a