0% found this document useful (0 votes)
12 views9 pages

lab4 osg

The document explains the differences between block devices and character devices, detailing their characteristics and examples. It also describes how the CPU interacts with control registers and data buffers, the function of a DMA controller, and the role of the program counter in instruction execution. Additionally, it covers processor interrupts, programmed I/O processes, steps following hardware interrupts, and the distinctions between device drivers and device control, along with buffering issues in data transfer.

Uploaded by

daothanhtoan0910
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

lab4 osg

The document explains the differences between block devices and character devices, detailing their characteristics and examples. It also describes how the CPU interacts with control registers and data buffers, the function of a DMA controller, and the role of the program counter in instruction execution. Additionally, it covers processor interrupts, programmed I/O processes, steps following hardware interrupts, and the distinctions between device drivers and device control, along with buffering issues in data transfer.

Uploaded by

daothanhtoan0910
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1. What are block devices and character devices?

Give example

Block devices and character devices are two types of devices in the Linux (and other
operating systems) computer system. They both provide a way for the system to interact with
hardware, but there are fundamental differences between them.

Block Devices:

 Block devices are storage devices. They access data in fixed-size blocks, often large,
and are stored in a cache memory before being written to the disk.
 Reading and writing data to block devices is usually done in a way that is not
dependent on previous data in that block.
 Some examples of block devices:
 Hard Disk Drives (HDDs) and Solid State Drives (SSDs): These are primary
block devices used to store the operating system and user data.
 USB drives, SD cards: These are also block devices, allowing data to be read
and written in blocks.

Character Devices:

 Character devices are designed to access data character by character, often as a


stream.
 Reading and writing data to character devices often requires adherence to sequence,
cannot break the order of data writing.
 Some examples of character devices:
 Keyboard and mouse: When you type from the keyboard or move the mouse,
the data is transmitted character by character and is a character device.
 Serial ports: Serial-connected devices (e.g., RS-232) transmit data character by
character, making them character devices.
 Printer: Data sent to the printer is character by character or in streams, making
it a character device.

Examples:

 Example of a block device: Hard Disk Drive (HDDs) and Solid State Drives (SSDs)
 Example of a character device: Keyboard and mouse, where data is transmitted
character by character.

2. How does the cpu coronramicale with control registers and data buffers

The CPU (Central Processing Unit) interacts with control registers and data buffers in the
following ways:

Control Registers:

 Control registers are special-purpose registers in the CPU that are used to control the
operation of the processor and manage various aspects of the system.
 These registers are used to store control information, such as flags, status bits, and
mode settings.
 The CPU uses control registers to manage tasks such as setting interrupt priorities,
enabling or disabling certain features, and controlling the flow of instructions.
 When the CPU executes instructions, it may need to access and update control
registers to perform various operations.

Data Buffers:

 Data buffers are temporary storage areas in memory (or within the CPU itself) used
to hold data temporarily while it is being transferred between different parts of the
system.
 Buffers are commonly used in input/output (I/O) operations, where data is moved
between devices and memory.
 When the CPU needs to read or write data from/to memory or devices, it often uses
data buffers to temporarily store this data during the transfer process.
 Buffers help in optimizing data transfer by allowing the CPU to continue processing
other tasks while data is being transferred in the background.

3. What does a dma controller contain? Explain how it works

A DMA (Direct Memory Access) controller is a hardware component in a computer system


that allows for efficient data transfer between peripherals (such as hard drives, SSDs, network
cards, and sound cards) and memory without involving the CPU. This offloads data transfer
tasks from the CPU, freeing it up to perform other operations. A DMA controller typically
contains the following components:

Components of a DMA Controller:

1. DMA Channels:
 DMA controllers have multiple channels, each capable of handling a separate
data transfer operation.
 Each channel can be independently programmed to perform specific data
transfer tasks.
2. Control Logic:
 The control logic of the DMA controller interprets commands from the CPU
and manages the data transfer operations.
 It handles the configuration of DMA channels, initiates data transfers, and
monitors the status of transfers.
3. Address Registers:
 DMA controllers have address registers that hold the source and destination
addresses for data transfer.
 These registers specify where the data is coming from (source) and where it
should be written to (destination) in memory.
4. Count Registers:
 Count registers store the number of data units (bytes, words, etc.) to transfer in
a single operation.
 The DMA controller uses these registers to determine how much data needs to
be transferred.
5. Status Registers:
 Status registers provide information about the current status of DMA
operations.
 They may indicate when a transfer is complete, if there was an error, or if a
channel is available for use.

How a DMA Controller Works:

1. Initialization:
 The CPU sets up the DMA controller by programming the address registers,
count registers, and other control registers with the necessary information for
the data transfer.
 It also specifies the source and destination addresses in memory, the number of
data units to transfer, and the direction of the transfer (read from source to
destination or write from source to destination).
2. Request and Acknowledge:
 When a peripheral device (such as a disk controller) needs to transfer data to or
from memory, it sends a request signal to the DMA controller.
 The DMA controller acknowledges the request and, if a channel is available,
grants permission to the peripheral to access the system bus.
3. Data Transfer:
 Once the DMA controller has control of the system bus, it transfers the
requested data directly between the peripheral and memory without involving
the CPU.
 The DMA controller increments or decrements the address registers and
decrements the count registers after each data transfer.
 This continues until the specified number of data units has been transferred, or
until the end of the requested data block.
4. Completion and Interrupt:
 After completing the data transfer, the DMA controller updates the status
registers to indicate the completion status of the operation.
 If the transfer was successful, the DMA controller may generate an interrupt to
notify the CPU that the data transfer is complete.
 The CPU can then process the interrupt, read the status registers to determine
the outcome of the transfer, and continue with other tasks.
4. What is a pc? How does it work? What are 4 properties of a preose interrupt?

A PC (Program Counter), also known as an Instruction Pointer (IP) in some architectures, is a


special register in a CPU (Central Processing Unit) that stores the memory address of the next
instruction to be executed. It is a fundamental component of the CPU's control unit and plays
a crucial role in the fetch-decode-execute cycle of instructions.

How the PC Works:

1. Fetch-Decode-Execute Cycle:
 When the CPU is executing instructions, it follows a cycle known as the fetch-
decode-execute cycle.
 The PC holds the address of the next instruction in memory to be fetched.
 During the fetch phase, the CPU reads the instruction located at the memory
address stored in the PC.
 The fetched instruction is then decoded, where the CPU determines what
operation needs to be performed.
 In the execute phase, the CPU carries out the operation specified by the
instruction.
2. Incrementing:
 After each instruction is fetched, the PC is automatically incremented to point
to the next memory location.
 This allows the CPU to fetch the next instruction in sequence during the next
cycle.
 The increment amount depends on the size of the instruction being executed
(e.g., 1 byte for some architectures, 4 bytes for others).
3. Branching:
 During program execution, the PC can be modified to branch to a different
memory address.
 Branching instructions (e.g., conditional jumps, function calls) change the
value in the PC to redirect the flow of execution to a different part of the
program.
 This allows for loops, conditional statements, and function calls in
programming languages.
4. Reset:
 At system startup or after a reset, the PC is typically set to a predefined
memory address where the system firmware (BIOS or UEFI) is located.
 This ensures that the CPU starts executing instructions from the system
firmware to initialize hardware and load the operating system.

Properties of a Processor Interrupt:

A processor interrupt is a signal sent to the CPU to temporarily suspend the currently
executing program and handle some other task. There are several properties of a processor
interrupt, and here are four key ones:

1. Asynchronous: Processor interrupts can occur asynchronously, meaning they can


happen at any time during the execution of a program, not necessarily at specific
points in the program's flow.
2. Priority Levels: Interrupts can have different priority levels. Higher priority interrupts
can interrupt lower priority interrupts, allowing critical tasks to be handled first.
3. Handling: When an interrupt occurs, the CPU saves the current state of the program
(including the PC and other registers) so that it can resume execution later. It then
jumps to an interrupt service routine (ISR) to handle the interrupt.
4. Interrupt Types:
 Hardware Interrupts: Generated by external hardware devices (like timers,
I/O devices, etc.) to request attention from the CPU.
 Software Interrupts: Also known as traps or exceptions, these are triggered
by software conditions such as divide-by-zero errors, accessing invalid
memory, or system calls.
 Maskable/Non-Maskable Interrupts: Some interrupts can be masked
(disabled), while others cannot. Non-maskable interrupts are always acted
upon, while maskable interrupts can be selectively enabled or disabled by the
CPU.
5. Explain how programmed i/o works by an example(fig 5.7)

1. Initialization:
 The CPU sends a command to the I/O device (keyboard) to request data.
 The CPU then waits for the I/O device to respond.
2. Start Data Transfer:
 Once the I/O device (keyboard) has the data ready, it signals the CPU that the
data is available.
 The CPU then reads the data by initiating a read operation on the I/O device.
3. Data Transfer:
 The CPU sends a read command to the I/O device, specifying that it wants to
read a byte of data.
 The I/O device responds by placing the data (byte) on the data bus.
4. Read Data:
 The CPU reads the data byte from the data bus into one of its registers (e.g.,
accumulator).
5. Completion:
 The CPU now has the data from the I/O device and can process it further if
needed.
Flow of Events (as per Figure 5.7):
 Step 1: The CPU initiates a read command (Read-Command Bus <- 1) to the I/O
device (keyboard).
 Step 2: The I/O device (keyboard) responds by placing the data (D0-D7) onto the data
bus.
 Step 3: The CPU reads the data (D0-D7) from the data bus into its internal registers.
Explanation:
 The CPU starts the process by sending a command to the I/O device (keyboard)
through the command bus (Read-Command Bus <- 1). This command tells the
keyboard that the CPU wants to read data.
 The keyboard, upon receiving the read command, places the data (D0-D7) onto the
data bus. The data bus is a set of wires used to transfer data between the CPU and I/O
devices.
 The CPU then reads the data from the data bus (D0-D7) into its internal registers. The
data is now available for the CPU to process further.

6. What are typical steps after hardware interrupt completes?

1. Interrupt Service Routine (ISR):


 When a hardware interrupt occurs, the CPU stops its current execution and
transfers control to an Interrupt Service Routine (ISR) associated with the
interrupting device.
 The ISR is a piece of code that handles the specific interrupt and performs
necessary actions to service it.
 The ISR is usually a short and efficient routine designed to handle the interrupt
quickly.
2. Save Current State:
 Before executing the ISR, the CPU typically saves the current state of the
program it was executing.
 This includes saving the program counter (the address of the next instruction to
be executed), processor registers, and any other necessary information.
 Saving this state allows the CPU to resume the interrupted task after the ISR is
complete.
3. Process Interrupt:
 The ISR performs the necessary actions to handle the interrupt. This could
involve reading data from an I/O device, updating system status, or initiating a
response.
 The ISR processes the interrupt and performs the required operations, such as
acknowledging the interrupt, reading data from a device, or storing data in
memory.
4. Clear Interrupt Flag:
 After the ISR has processed the interrupt, it typically clears the interrupt flag
for the device.
 Clearing the interrupt flag indicates to the interrupt controller that the interrupt
has been serviced.
 This step ensures that the same interrupt does not trigger multiple times and
avoids repeated interrupts for the same event.
5. Restore State and Resume Execution:
 After the ISR completes its task, the CPU restores the saved state, including
the program counter and processor registers, to resume the interrupted task.
 This allows the CPU to continue executing the program that was interrupted by
the hardware event.
 Once the state is restored, the CPU continues executing instructions from
where it left off before the interrupt occurred.
6. Return from Interrupt:
 Finally, the CPU executes a "return from interrupt" instruction to return control
to the main program.
 This instruction typically restores the saved program counter and other
registers, allowing the CPU to continue executing the program as if the
interrupt had not occurred.

7. What are the differences betweem devices drivers and device control?

Device Drivers:
 Device drivers are software components that allow the operating system to
communicate with hardware devices.
 They provide an interface between the operating system's generic input/output (I/O)
subsystem and the specific hardware devices.
 Device drivers are responsible for translating generic operating system commands into
device-specific commands that the hardware understands.
 They handle tasks such as initializing the device, sending commands to the device,
and receiving data from the device.
 Device drivers are specific to each hardware device, as different devices have different
communication protocols and requirements.
Device Control:
 Device control refers to the process of managing and controlling hardware devices
within a computer system.
 It involves sending commands and receiving status information from devices to
perform specific operations.
 Device control is often done through device drivers, which act as an intermediary
between the operating system and the hardware.
 Device control includes tasks such as opening and closing devices, setting device
parameters, and initiating data transfers.
 It allows the operating system and applications to interact with hardware devices in a
standardized and controlled manner.
Differences:
1. Purpose:
 Device drivers are software programs that enable the operating system to
communicate with hardware devices.
 Device control refers to the management and control of hardware devices
within the system, which can be done through device drivers.
2. Functionality:
 Device drivers translate generic operating system commands into device-
specific commands, handle data transfers, and manage the device's operation.
 Device control involves sending commands to devices (such as opening,
closing, reading, and writing), setting device parameters, and receiving status
information.
3. Scope:
 Device drivers are specific to each hardware device and are responsible for all
aspects of communication with that device.
 Device control is a broader concept that encompasses the management of
multiple devices within the system, which can be done through the respective
device drivers.
4. Interaction:
 Device drivers are directly involved in the interaction between the operating
system and hardware devices.
 Device control is the process of issuing commands and receiving responses
from hardware devices, often facilitated by device drivers

8. Explain buffering issus in fig 5.15-5.16

Figure 5.15:
 Without Buffering: This figure illustrates the scenario without buffering.
 When a process needs to read data from a device, it makes a system call to the
device driver.
 The device driver reads a block of data from the device and directly transfers it
to the process.
 However, if the process is not ready to accept the data (perhaps it's still
processing previous data), the device driver must wait.
 This can lead to inefficient use of CPU time, as the CPU is idle while waiting
for the process to be ready.
Figure 5.16:
 With Buffering: This figure shows the improvement with buffering.
 In this scenario, a buffer is introduced between the device driver and the
process.
 When the device driver reads data from the device, it stores it in the buffer
instead of directly transferring it to the process.
 The process can then read data from the buffer at its own pace, even if the
device driver has already retrieved more data from the device.
 This decouples the operation of the process from the operation of the device
driver, allowing both to work independently.
 The device driver can continue to read data from the device and store it in the
buffer, while the process consumes data from the buffer as needed.
 This improves efficiency as the CPU is no longer idle waiting for the process,
and the process can handle data as it becomes ready.

9. Decribe the 7 standard configurations of RAID(fig 5.19-5.20)

Figure 5.19 - RAID Levels 0, 1, and 2:


1. RAID Level 0 (Striping):
 Data is striped across multiple disks without redundancy.
 Offers improved performance through parallel data access.
 No fault tolerance; if one disk fails, all data is lost.
2. RAID Level 1 (Mirroring):
 Data is mirrored across pairs of disks for redundancy.
 Improved read performance, as data can be read from either disk in the mirror.
 Offers fault tolerance: if one disk fails, data is still available on the mirrored
disk.
3. RAID Level 2 (Hamming Code ECC):
 Uses Hamming code error correction to achieve fault tolerance.
 Data is striped across multiple disks at the bit level.
 Not commonly used due to complexity and overhead.

Figure 5.20 - RAID Levels 3, 4, 5, and 6:


4. RAID Level 3 (Bit-Interleaved Parity):
 Data is striped at the byte level across multiple disks.
 Parity information is stored on a dedicated disk for fault tolerance.
 Offers good performance for read operations but slower writes due to parity
calculation.
5. RAID Level 4 (Block-Interleaved Parity):
 Similar to RAID 3, but data is striped at the block level.
 Parity information is stored on a dedicated disk.
 Improved performance for random reads but slower writes due to parity
calculation.
6. RAID Level 5 (Block-Interleaved Distributed Parity):
 Data and parity information are striped across multiple disks.
 Parity is distributed across all disks, improving write performance compared to
RAID 4.
Offers good read performance and fault tolerance; can withstand the failure of
one disk.
7. RAID Level 6 (P+Q Redundancy):
 Similar to RAID 5 but with an additional level of fault tolerance.
 Uses distributed parity and an additional set of parity data (P+Q).
 Can tolerate the failure of two disks without data loss.
 Provides high fault tolerance and data protection at the cost of additional disk
space overhead.

You might also like