You are on page 1of 83

Operating

Systems
INPUT / OUTPUT
Hardware I / O Principles
For Electronic Engineers the I / O are chips, cables, power
supplies, motors and everything physical.
Programmers see it as the commands the software accepts,
the functions it performs, and the bugs it can support.
Hardware programming is important because it allows you
to work with the devices connected to the computer.

LUIS H. CRUZ A.
OPERATING SYSTEMS
2
I / O devices
Block devices: They store information in blocks of fixed size.
oBlock sizes range from 512 bytes to 32,768 bytes.
oEach block can be read or written independently.
oHard drives, CD-ROMs, and USB sticks are the most common.
oDisk drives and magnetic tape drives are disappearing to make
way for other technologies.

LUIS H. CRUZ A.
OPERATING SYSTEMS
3
I / O devices
Character devices: Send or accept a stream of characters,
regardless of the block structure.
◦ Printers, network interfaces, and mice are examples of character
devices.
◦ Displays (monitors) meet some characteristics but commonly receive
signals that are converted into images.
The OS operates and control a lot of devices, some of
which work independently.

LUIS H. CRUZ A.
OPERATING SYSTEMS
4
I / O devices

LUIS H. CRUZ A.
OPERATING SYSTEMS
5
Device drivers
I / O units typically have a mechanical and an electronic component
called a device driver or adapter.
It can be a chip on the main card or an integrated circuit card connected
to an expansion slot (PCI).
The controller card contains a connector that may have a cable to the
device. Many controllers handle 2, 4 or 8 identical devices.
The interface between the controller and the device can be an ANSI,
IEEE or ISO standard.
Manufacturers produce devices that match IDE, SATA, SCSI, USB or
FireWire interfaces.
The interface between the controller and the device is very low level.

LUIS H. CRUZ A.
OPERATING SYSTEMS
6
Device drivers
With the controller the OS manages
devices using characters or pixels per
line, lines per screen, etc.
◦ A hard disk reads and writes a serial
stream of bits.
◦ Each block of bytes, bit by bit, is stored in
a buffer within the controller to arm it as
a larger block that can be copied to main
memory.
◦ In a monitor, the bits are put together
into bytes that become light signals for
the screen.

LUIS H. CRUZ A.
OPERATING SYSTEMS
7
I / O memory allocation
Each controller has registers that it uses to communicate
with the CPU, the OS send or accept data, turn it on, turn
off or any other action.
Many devices have a data buffer where the OS can read or
write.
Each control register is assigned an 8-bit to 16-bit I / O port,
the set of all is the I / O port space and is protected for user
programs.

LUIS H. CRUZ A.
OPERATING SYSTEMS
8
I / O memory allocation
Examples of IBM / 360 instructions:
IN REG, PORT,
OUT PORT,REG
Once read, it is recalled:
IN R0, 4
MOV R0, 4

LUIS H. CRUZ A.
OPERATING SYSTEMS
9
I / O memory allocation
Another method is called memory-mapped
I / O (mapped-memory) is to map all control
registers to memory space.
Each register is assigned a unique memory
address.
PDP / 11 computers use this method.

LUIS H. CRUZ A.
OPERATING SYSTEMS
10
I / O memory allocation
IBM PCs use addresses from 640K to 1Mb
for data buffers, and 0 to 64K for I / O ports.
These areas are reserved and if they are not
used, they are wasted.

LUIS H. CRUZ A.
OPERATING SYSTEMS
11
I / O memory allocation
For both methods, when the CPU requests to read data, in
memory or on an I / O port, it places the address on the bus
and sends a READ signal.
Another signal is sent to require I / O or memory space.
If memory is available, the request is answered, with the
following implications:
1. There is overhead to control the I / O.
2. User process protection is not required.
3. Memory or control register can be read.

LUIS H. CRUZ A.
OPERATING SYSTEMS
12
I / O memory allocation
When using I / O, the cache is disabled to avoid conflicts.
Having only one bus for data and I / O devices can make it
slow.
One solution is to have a dedicated bus.

LUIS H. CRUZ A.
OPERATING SYSTEMS
13
Direct Memory Access (DMA)
The CPU requests data from an I / O controller one bit at a time, but
time is wasted, so Direct Memory Access (DMA) is used.
There is regularly a DMA on the main card to regulate transfers from
multiple devices concurrently.
The DMA has access to the system bus independently of the CPU.
Contains multiple registers that can be read or written.
The disk controller reads one block, bit for bit, until it places the entire
block into an internal buffer.
Then it calculates the checksum to check for read errors.
Then there is an outage.

LUIS H. CRUZ A.
OPERATING SYSTEMS
14
Direct Memory Access (DMA)
The OS can read the block from the controller buffer, byte
for byte, to be stored in main memory.
The DMA programs the controller defining what to transfer
and where.
A command is also issued to the disk controller to tell it to
read data.
The DMA initiates the transfer by sending a read request to
the disk controller over the bus.
Data is transferred and written to memory, the DMA
increases the memory address and decreases the byte
count.

LUIS H. CRUZ A.
OPERATING SYSTEMS
15
Direct Memory Access (DMA)

LUIS H. CRUZ A.
OPERATING SYSTEMS
16
Direct Memory Access (DMA)
After it finishes transferring data from one device, the DMA uses the
round-robin algorithm to access another device.
The data bus can operate with one word at a time or with a block of
words. First, the DMA interrupts the CPU to read words in cycle steal
mode. With blocks, the interrupt is made to transfer the words of a
block and is called a burst mode.
This way of working, where the DMA transfers data from I / O devices to
memory, is called “fly-by”.
The DMA works in conjunction with the CPU to obtain and convert the
physical memory numbers that it will use to store the data.
The controller's internal buffer is used to verify what is to be read
before doing so. Not all computers use DMA, the argument is that the
CPU can do its functions faster, but it hangs.

LUIS H. CRUZ A.
OPERATING SYSTEMS
17
Review of interruptions
When an I / O device has finished its assigned work, it
produces an interrupt.
The signal is passed to the bus and then detected by the
interrupt driver chip.

LUIS H. CRUZ A.
OPERATING SYSTEMS
18
Review of interruptions
If there are no pending interrupts, the controller processes the next one
immediately. If another previous request is attended or if there is
priority, the device that issues it is ignored, but it continues to send the
signal until the CPU responds to it.
The interrupt vector is used to point to the corresponding program used
by the I / O device. The location of the interrupt vector can be statically
on the machine (hardwired) or in memory.
The program counter must be saved to restart the interrupted process.
If the vector is saved in the internal registers of the OS there is a risk of
overwriting them when there is a new interruption.
The kernel stack that points to the next instruction in memory can be
used.

LUIS H. CRUZ A.
OPERATING SYSTEMS
19
Review of interruptions
To avoid stack errors pointing to the next instruction in
memory, a precise interrupt with 4 properties is used:
1. The program counter (PC) is stored in a known place.
2. All instructions before the instruction pointed to by the PC
have been fully executed.
3. No instruction beyond the instruction pointed to by the PC has
been executed.
4. The execution status of the instruction pointed to by the PC is
known.

LUIS H. CRUZ A.
OPERATING SYSTEMS
20
Review of interruptions
The instructions up to the program counter (316) have been
completed and none beyond has started, this is a precise
interrupt.
The one that does not meet the requirements is an
imprecise interrupt.

LUIS H. CRUZ A.
OPERATING SYSTEMS
21
Review of interruptions
The imprecise interrupt has different advance states that
slow down the interrupts.
Having precise interrupts requires storing more information
about what is being done and keeping "shadow" copies of
the registers so that the CPU is not lost.
If precise interrupts are not required, memory space can be
saved.
Interruptions make the OS to be complicated and slow.

LUIS H. CRUZ A.
OPERATING SYSTEMS
22
Objectives of the I / O Software
A key concept is device independence which means that
programs can access any I / O device without having to
specify it in advance.
A program must read a file from hard disk, CD-ROM, DVD or
USB memory without having to be modified for each device.
The uniform naming is having any name made up of letters
or numbers to identify a device.

LUIS H. CRUZ A.
OPERATING SYSTEMS
23
Objectives of the I / O Software
With the uniform naming, on UNIX, a USB stick can be
identified by the name of a directory such as usr/ast/backup
instead of a disk H:/>.
Device error handling should be done as close to the
hardware as possible, if the driver detects an error, it should
try to correct it right there.
If the controller cannot do it, the software must treat it so
as not to pass it on to the OS.

LUIS H. CRUZ A.
OPERATING SYSTEMS
24
Objectives of the I / O Software
Another key issue is synchronous
(blocking) versus asynchronous
(interrupting) transfers.
In a synchronous call a user program is
suspended until there is data available
in the buffer.
Most I / O operations are
asynchronous, the CPU initiates
transfer and something else will be
done until an interrupt arrives.

LUIS H. CRUZ A.
OPERATING SYSTEMS
25
Objectives of the I / O Software
Buffer usage is another important issue, frequently data read from a
device cannot be stored at the final destination.
For example, reading from a digital audio device, on some computers,
requires to be stored in an output buffer in advance to synchronize the
rate at which it fills and empties to avoid overflows.
Shared devices are those that can be used by multiple users at the same
time. Different users can have files open on the same hard drive in an
instant.
Dedicated devices are those that a user uses exclusively.
A magnetic tape does not allow multiple users to read and write at the
same time. Its use favors deadlocks.

LUIS H. CRUZ A.
OPERATING SYSTEMS
26
Programmed I / O
Programmed I / O is where the CPU does all the work. To print the
letters "ABCDEFGH" a user process first assembles the string in a buffer.
Then the process acquires the printer to write by making a system call.
If the printer is busy, the call will fail and block until the printer is free.
The OS copies the string to user space and from there to the kernel
where it can get faster. When the printer is available, it is passed
character by character and this activates it.

LUIS H. CRUZ A.
OPERATING SYSTEMS
27
Programmed I / O
Scheduled I / O is simple but occupies the CPU full time until I / O
operations are complete.
In systems where the CPU has nothing else to do, it is reasonable to
have busy waiting.
But in systems where the CPU has other jobs to do, the I / O method
needs to be improved so that the CPU can work with other processes.

LUIS H. CRUZ A.
OPERATING SYSTEMS
28
I / O with interruptions
Another option is to print each
character as it arrives instead of storing
them in a buffer.
If the print speed is slower than the
transfer speed, the CPU will be idle for
some time.
The printer generates an interrupt
when printing the first character and is
waiting for the next one.
The CPU calls the scheduler to run
another process.

LUIS H. CRUZ A.
OPERATING SYSTEMS
29
I / O with interruptions
The interrupt stops the current process and saves its state.
If there are no more characters to print, the user process is
unlocked.
Otherwise the next character is printed and returns to the
process that was running before the interruption.
This allows the CPU to attend to other processes while
printing.

LUIS H. CRUZ A.
OPERATING SYSTEMS
30
I / O using DMA
In printing, the DMA takes care of sending the characters to the printer
one at a time, without the CPU bothering.
DMA is programmed I / O, all work is done without CPU intervention.
While the I / O operation is being performed, the special hardware (the
DMA controller) frees the CPU from work to occupy other processes.
The advantage of DMA is to reduce the number of interrupts from one
for each character to one for each printed buffer.
The DMA controller is slower than the CPU.
If the DMA cannot control the device at full speed, then it may be better
to use interrupt controlled I / O or programmed I / O.
In any case, DMA is worth using.

LUIS H. CRUZ A.
OPERATING SYSTEMS
31
I / O Software Layers
The I / O software is organized in 4 layers:

LUIS H. CRUZ A.
OPERATING SYSTEMS
32
Interrupt handlers
The 10 steps to handling interruptions:
1. Registers (including PSW) that have not been stored by the interrupt hardware
are saved.
2. Establish a context for the interrupt service procedure, using memory registers
and a page table.
3. Create a stack for the interrupt service procedure.
4. Recognize the interrupt handler. If there is no centralized controller, re-enable
interrupts.
5. Copy the records from where they were saved (possibly on some stack) to the
process table.
6. Run the interrupt service procedure. This will extract from the logs of the device
driver that caused the interrupt.
7. Choose the process to run next. If a high priority process is blocked, it can be
chosen to run by setting it to Ready.
8. Set the memory context for the process to be executed next.
9. Load the logs of the new process, including its PSW.
10. Start running the new process.

LUIS H. CRUZ A.
OPERATING SYSTEMS
33
Interrupt handlers
The interrupt processing occupies a considerable number of
CPU instructions, machines that use virtual memory require
establishing page tables.
On some machines, data is moved from the user area to the
kernel, requiring CPU cycles.

LUIS H. CRUZ A.
OPERATING SYSTEMS
34
Device Drivers
Each I / O device connected to the computer needs a
certain code to control it.
It is software that is written by the device manufacturer and
is called a driver.
In order to use the device hardware (the physical controller
registers) the driver must be part of the OS kernel.
There are drivers that run in the user area, which avoids
problems with the kernel.

LUIS H. CRUZ A.
OPERATING SYSTEMS
35
Device Drivers
OS classifies controllers, the most common is for block
devices but there are also for character devices.
On some systems like UNIX, the OS which is binary code, it
contains all the drivers needed.
MS-DOS personal computers use another scheme which is
to dynamically load the driver into the system during
execution.

LUIS H. CRUZ A.
OPERATING SYSTEMS
36
Device Drivers

LUIS H. CRUZ A.
OPERATING SYSTEMS
37
Device Drivers
A device driver has several functions, the most obvious of which is to
accept abstract read and write requests from the software, as well as
initialize the device if necessary, and more.
Commonly the controller receives data, checks it for validity, verifies
that the device is available, turns it on if it is off, receives the data, and
controls the device when it is transmitted.
The controller locks if the device is busy and unlocks on receiving the
interrupt when the device finished.
Another activity of the controller is to check for errors, in this case it
reports them.
If there are more requests waiting for use of the device, the controller
can select the next one and start executing it.
The controller must be reentrant, while executing one call it must
receive the next one.
LUIS H. CRUZ A.
OPERATING SYSTEMS
38
Device Drivers
A controller has several functions:
o Accept read and write requests that come from the OS and run them.
o Check that the device is in use, if so, the request will be put on hold to be processed later.
o The controller receives a script depending on what the device should do.
o Send interruptions to OS once the device is busy or idle.
o If there are errors, it detects them and reports them to the OS.

In a “hot-plug” system, devices can be added or removed while the


computer is running.
When a device is removed, the driver must complete the current I / O
transfer without damaging the kernel and any pending device requests
must be removed.
When adding a device the OS assigns a resource and removes it from
those retired.

LUIS H. CRUZ A.
OPERATING SYSTEMS
39
Independent I / O software
Parts of the I / O software are device specific and other
parts are independent.
There are certain functions that drivers perform that are
device independent:

LUIS H. CRUZ A.
OPERATING SYSTEMS
40
Uniform interface
The interface between the controllers and the OS it must be
uniform. There are two cases:
o Each device has a different interface with the OS this requires a lot of
programming.
o Each device has an interface compatible with the OS, the drivers are
identical.

LUIS H. CRUZ A.
OPERATING SYSTEMS
41
Buffer usage
Buffer usage can have implications:
o Without buffering, the data passes directly but one by one, it is time consuming.
o With a buffer of n characters, it fills up and goes into user space, takes less time.
o With a buffer in the kernel, an entire page is passed into user space.
o With double buffers in the kernel, they alternate, one passes data to user space
while the other receives data.

LUIS H. CRUZ A.
OPERATING SYSTEMS
42
Buffer usage
Buffering on a network allows more data to be sent, but
performance is reduced.
o From the user area, the data goes to the kernel buffer, from there it is sent to the
network controller to keep the CPU busy, and the buffer can also be reused.
o The packet is put on the network and upon receipt it is placed in another buffer, the
acknowledgment is sent and another packet can be sent.

LUIS H. CRUZ A.
OPERATING SYSTEMS
43
Error reporting
Some errors are specific to certain devices.
There are I / O programming errors such as writing an input
device, reading an output device, or using a non-existent
disk drive. In that case the error is reported.
Real mistakes are using a video camera turned off or writing
a damaged disk block. It is up to the controller to try again
or kill the calling process.

LUIS H. CRUZ A.
OPERATING SYSTEMS
44
Dedicated Devices
Dedicated devices can only be used once per process, the
OS accept or reject requests if the device is available or not.
Another option is to block the calling process while the
dedicated device is busy, placing the process in a queue
until it can acquire the device for use.

LUIS H. CRUZ A.
OPERATING SYSTEMS
45
Block Size
For disks that can have different sector sizes, the same block
size is required for all makes and models.
The same thing happens with character devices, some
receive byte for byte and others a block like the network
interface.
These differences must be hidden by making the OS works
with all devices equally using a uniform block size.

LUIS H. CRUZ A.
OPERATING SYSTEMS
46
I / O software in user area
Although most of the I / O software is in the OS there are
small libraries linked to user programs, like the case of printf
in C language that constructs a string and then writes it
using write.
The use of rows (spooling) is a solution to work with
dedicated devices with multiprogramming, such as the
printer.
A daemon can take files from the print queue and protect
them from direct user use before printing.

LUIS H. CRUZ A.
OPERATING SYSTEMS
47
I / O software in user area
Rows can also be used in data transmission on a network.

LUIS H. CRUZ A.
OPERATING SYSTEMS
48
Disks
There are different types of discs: CD-ROM, CD-recordable,
and DVD.
In IDE (Integrated Drive Electronics) and SATA (Serial ATA)
magnetic drives the drive contains a microcontroller that
works with the device.
An interesting function is overlapping search, while the
controller waits to complete a search, it can initiate another
search on a different drive.

LUIS H. CRUZ A.
OPERATING SYSTEMS
49
Disks
Differences between an IBM PC floppy disk and a hard disk
20 years later:

LUIS H. CRUZ A.
OPERATING SYSTEMS
50
Disks
The discs have 2 zones, in this case the outer one has 32
sectors per track and the inner one has 16 sectors.
There are other disks that handle x cylinders, y heads, and z
sectors.

LUIS H. CRUZ A.
OPERATING SYSTEMS
51
RAID
RAID (Redundant Array of Inexpensive Disks) is a set of
magnetic disks that allow redundant backup systems.
It consists of a disk cage and a 15-capacity SCSI controller
that uses a single controller.
For software RAID it appears as a single disk although the
data is distributed among the units operating in parallel.

LUIS H. CRUZ A.
OPERATING SYSTEMS
52
RAID
In RAID level 0 there is a band of 2 sectors, data is written
using round robin on each disk.
The process of distributing data over several units is called
striping.

LUIS H. CRUZ A.
OPERATING SYSTEMS
53
RAID
In RAID 1 the data is mirrored on the disks, there are 4
primary disks and 4 secondary backup disks.
A write is done 2 times, a read can be made of one or the
other, if a copy fails the copy is used.

LUIS H. CRUZ A.
OPERATING SYSTEMS
54
RAID
RAID 2 works with words instead of sectors from RAID 0 and
1.
One byte is divided into 2 (4-bit nibbles) and 3 parity bits
are added to each one, the 7 bits are synchronized and
recorded in the 7 units.

LUIS H. CRUZ A.
OPERATING SYSTEMS
55
RAID
RAID 3 is a simplification of RAID 2.
A parity bit is added to each nibble that is written to a single
drive.
Synchronization must be exact as individual bytes are in
multiple units.
RAID 2 and RAID 3 offer very high data transfer speeds.

LUIS H. CRUZ A.
OPERATING SYSTEMS
56
RAID
RAID 4 is similar to RAID 0 using blocks instead of words or
bytes.
Per band parity is added in an additional drive.
If a drive fails, the lost bytes are recalculated from the parity
bit, reading all drives, it is slow to update.

LUIS H. CRUZ A.
OPERATING SYSTEMS
57
RAID
The problem with RAID 4 is the parity drive that becomes a bottleneck.
In RAID 5 this is solved by distributing the parity bits evenly across all
drives that are read by round-robin.
In the event of a failure, rebuilding the contents of a drive is complex.

LUIS H. CRUZ A.
OPERATING SYSTEMS
58
CD-ROM
Optical (laser) discs have a higher recording density than a
magnetic disc.
A CD uses a high-powered infrared laser to form holes that
allow light to be reflected from within or from the surface.
The pits and smooth areas are written in a single continuous
spiral that has a length of 5.6 km.

LUIS H. CRUZ A.
OPERATING SYSTEMS
59
CD-ROM
To play at a uniform speed, the read head passes over the hole lines.
The inner part moves at 530 RPM and the outer part slows down to 200
RPM.

LUIS H. CRUZ A.
OPERATING SYSTEMS
60
DVD
The evolution of the CD and the demand to store more data
led to the creation of the DVD (Digital Video Disk).
FEATURE DVD CD
Hole size 0.4 microns 0.8 microns
Spiral width 0.74 microns 1.6 microns
Laser distance 0.65 microns 0.78 microns

DVD capacity is 4.7 Gb compared to 700 Mb for a CD.

LUIS H. CRUZ A.
OPERATING SYSTEMS
61
DVD
In addition, a DVD can be recorded in MPEG-2 compression
format to store more data. There are 4 DVD formats:Un solo
lado, una sola capa (4.7 Gb).
◦ Single sided, double layer (8.5Gb).
◦ Double sided, single layer (9.4 Gb).
◦ Double side, double layer (17 Gb).

LUIS H. CRUZ A.
OPERATING SYSTEMS
62
DVD
New Blu-ray devices use a 0.405 micron (blue) laser to pack
25 Gb in single layer and 50 Gb in double layer.
The HD DVD format uses the same blue laser with a capacity
of 15Gb in one layer and 30Gb in double layer.
This format war created by manufacturers has the
disadvantage of not using a standard, this affects the
consumer.

LUIS H. CRUZ A.
OPERATING SYSTEMS
63
Disk formatting
The hard drive uses a row of glass or steel platters covered
by a layer of magnetizable metal oxide.
The low-level format using software consists of creating a
series of concentric tracks that each contain sectors, the
format contains:

The preamble contains the bits that identify the sector, each
one 512 bytes in size.
The 16-byte ECC field contains redundant information that
can be used to recover from read errors.

LUIS H. CRUZ A.
OPERATING SYSTEMS
64
Disk formatting

LUIS H. CRUZ A.
OPERATING SYSTEMS
65
Disk formatting
To continuously read sectors while the disk is spinning, a
buffer is required.
After reading a sector, the data is being passed from the
buffer to the memory, at which time the next sector goes
through the read head and is read at the same time.
Interlaced sectors are used to avoid more searching time
while rotating the disk:

LUIS H. CRUZ A.
OPERATING SYSTEMS
66
Disk formatting
With interlaced sectors the copying process is slow, there
are buffer disks with the capacity to store a complete track,
with the use of a DMA chip or with the CPU, the disk
controller can send the read data to memory.
By formatting a partition can be created on the disk, this
means that the same disk can be used as two separate
ones.
This is known as a high-level format.

LUIS H. CRUZ A.
OPERATING SYSTEMS
67
Disk Arm Scheduling
Algorithms
The reading or writing time of a disk block is given by:
1. Seek time (the time to move the arm to the appropriate cylinder).
2. Rotational delay (the time for the appropriate sector to get under the
head).
3. Current data transfer time.
By reducing average seek times, you improve system performance
considerably.
The First-Come First-Served (FCFS) algorithm searches for the requested
data in order.
When the disk is heavily loaded it is possible to use an indexed table
with the cylinder number of pending requests, allowing the playhead to
make half the movements compared to FCFS.
The algorithm is called Shortest Seek First (SSF).

LUIS H. CRUZ A.
OPERATING SYSTEMS
68
Disk Arm Scheduling
Algorithms
The SSF algorithm has the disadvantage of continuing to
serve the smallest requests as they continue to arrive, the
largest then remain unattended for longer.

LUIS H. CRUZ A.
OPERATING SYSTEMS
69
Disk Arm Scheduling
Algorithms
On the other hand, the elevator algorithm is used with the
reader arm.
oIf the arm moves in one direction on the disk, the next
requests to attend are those in that direction.
oWhen finishing in one direction, it moves to the opposite and
all requests in that direction are attended.

LUIS H. CRUZ A.
OPERATING SYSTEMS
70
Error Handling
In case of errors in disk sectors, these are replaced by
additional sectors.
oA sector is bad within a set of sectors on a disk.
oIf sector 7 is faulty, a new additional sector with that number is
reassigned.
oAnother option is to move all sectors up one position.

LUIS H. CRUZ A.
OPERATING SYSTEMS
71
Error Handling
If the problem with the sectors cannot be solved by the
controller, then it goes to the OS.
Through software the OS can create a file with bad sectors
that does not get into the file system so that it cannot be
read by the user by accident.
But the problem that arises when backing up is that the file
is copied with bad sectors, it can be avoided if the program
detects it and does not save it.

LUIS H. CRUZ A.
OPERATING SYSTEMS
72
Stable Storage
The disk should work all the time without errors.
The stable storage algorithm must write the data correctly or do
nothing in case of errors leaving the existing data intact.
Stable storage uses two identical disks where the corresponding blocks
form an error-free block.
To achieve this, proceed with:
o Stable writes. The data is saved on disk 1, if there is an error it is tried as
many times as necessary until it is successful, after being written to disk 1 it
is written to disk 2, in the same way until the operation is successful.
o Stable readings. The data from disk 1 is read, if there are errors it is tried n
times, if the problem persists, it is read from disk 2, less likely to fail.
o Failure recovery. After a failure, the 2 blocks read are compared, if one is
wrong it is replaced by the other, if they are good and different, the block
from disk 1 replaces the block from disk 2.

LUIS H. CRUZ A.
OPERATING SYSTEMS
73
Clocks
Also known as timers they are essential for
multiprogramming.
The ancient clock was connected to electricity and
generated a pulse for each voltage cycle.
The current clock has an oscillator, a counter and a register,
the quartz crystal generates a pulse.

LUIS H. CRUZ A.
OPERATING SYSTEMS
74
Clocks
The watch software should do the following:
1. Keep the time of day.
2. Prevent processes from running for longer than
allowed.
3. Accounting for CPU usage.
4. Handle the alarm call of user processes.
5. Provide watchdog timers for certain parts of the
system.
6. Perform profiling, monitoring and compilation of
statistics.

LUIS H. CRUZ A.
OPERATING SYSTEMS
75
User interfaces
Depending on the type of device, the OS works with user
interfaces:
oThe terminals use special characters that can be entered and
printed.
oKeyboards that are input devices work with special libraries
that allow you to view cursor movement and text display.
oThe graphical interface uses the WIMP (Windows Icons Menus
Pointer) paradigm to process the events that occur.

LUIS H. CRUZ A.
OPERATING SYSTEMS
76
Keyboard Software
Keyboard software works character oriented or
line oriented, they were referred to as raw
mode and cooked mode, respectively.
If the keyboard is in canonical (cooked) mode,
characters must be stored until an entire line
has been accumulated, because the user may
subsequently decide to erase part of it.

Although the keyboard and monitor are


logically separate devices, many users have
grown accustomed to seeing the characters
they have just typed appear on the screen. This
process is called echoing.

LUIS H. CRUZ A.
OPERATING SYSTEMS
77
Mouse Software
Most PCs have a mouse, or sometimes a trackball. One common type of
mouse has a rubber ball inside that rotates as the mouse is moved over
a rough surface. As the ball rotates, it rubs against rubber rollers placed
on orthogonal shafts.
Another popular type is the optical mouse, equipped with light-emitting
diodes and photodetectors on the bottom. Whenever a mouse has
moved a certain minimum distance in either direction or a button is
depressed or released, a message is sent to the computer. The
minimum distance is about 0.1 mm.
The message to the computer contains three items: Δx, Δy, buttons. The
first item is the change in x position since the last message. Then comes
the change in y position since the last message.

LUIS H. CRUZ A.
OPERATING SYSTEMS
78
Output Software
Output is simpler than input when
the output is sequentially in a single
font, size, and color. The program
sends characters to the current
window and they are displayed there.
Usually, a block of characters, for
example, a line, is written in one
system call.
Screen editors need to be able to
update the screen in complex ways
such as replacing one line in the
middle of the screen. There are
output drivers that support a series of
commands to move the cursor, insert
and delete characters or lines at the
cursor, and so on.

LUIS H. CRUZ A.
OPERATING SYSTEMS
79
Graphical User Interface
The screen is a rectangular area
called a window. A window’s
position and size are uniquely
determined by giving the
coordinates (in pixels) of two
diagonally opposite corners.
The main window produced by
most programs can be moved,
resized, and scrolled. Programs
must be informed about changes
to the size of their windows and
must be prepared to redraw the
contents of their windows at any
time, even when they least
expect it.
LUIS H. CRUZ A.
OPERATING SYSTEMS
80
Thin Clients
They have advantages compared to
standard PCs such as simplicity and
less need for maintenance by users.
The objective is that the client
machine does not have the
intelligence or the software and that
it is simply like a screen, all the
computation is done on the server
side.
The THINC thin client has shown that
with 5 operations it is possible to
build a good performing client.

LUIS H. CRUZ A.
OPERATING SYSTEMS
81
Thin Clients

LUIS H. CRUZ A.
OPERATING SYSTEMS
82
Power Management
Very important issue for laptops as batteries are limited.
The OS employs various techniques to reduce energy
consumption.
Programs can also help by sacrificing quality for longer
battery life.

LUIS H. CRUZ A.
OPERATING SYSTEMS
83

You might also like