Q1:
-A block device is one that stores information in fixed-size blocks, each one with its own
address. Common block sizes range from 512 to 65,536 bytes. All transfers are in units of
one or more entire (consecutive) blocks. The essential property of a block device is that it
is possible to read or write each block independently of all the other ones.
-Examples: Hard disks, Blu-ray discs, and USB sticks are common block devices.
- Character device is a character device delivers or accepts a stream of characters,
without regard to any block structure. It is not addressable and does not have any seek
operation.
-Examples:Printers, network interfaces, mice (for pointing), rats (for psychology lab
experiments), and most other devices that are not disk-like can be seen as character
devices.
Q2:
Each controller has a few registers that are used for communicating with the CPU. By
writing into these registers, the operating system can command the device to deliver data,
accept data, switch itself on or off, or otherwise perform some action. By reading from
these registers, the operating system can learn what the device’s state is, whether it is
prepared to accept a new command, and so on. In addition to the control registers, many
devices have a data buffer that the operating system can read and write. For example, a
common way for computers to display pixels on the screen is to have a video RAM, which is
basically just a data buffer, available for programs or the operating system to write into.
Q3:
-Definition: The CPU can request data from an I/O controller one byte at a time, but doing
so wastes the CPU’s time, so a different scheme, called DMA (Direct Memory Access) is
often used
- It contains several registers that can be written and read by the CPU. These include a
memory address register, a byte count register, and one or more control registers.
-How DMA controller works: First the disk controller reads the block (one or more sectors)
from the drive serially, bit by bit, until the entire block is in the controller’s internal buffer.
Next, it computes the checksum to verify that no read errors have occurred. Then the
controller causes an interrupt. When the operating system starts running, it can read the
disk block from the controller’s buffer a byte or a word at a time by executing a loop, with
each iteration reading one byte or word from a controller device register and storing it in
main memory.
Q4:
-Four properties:
1. The PC (Program Counter) is saved in a known place.
2. All instructions before the one pointed to by the PC have completed.
3. No instruction beyond the one pointed to by the PC has finished.
4. The execution state of the instruction pointed to by the PC is known
-PC(Program Counter): is a register in a CPU that contains the address of the next
instruction to be executed.
-How it works:
1.when an interrupt occurs, the current location of the program (the instruction that is
about to execute) is saved so that the system knows where to return after handling the
interrupt.
2. It means that any changes made by these instructions are visible to the interrupt handler
and any subsequent instructions after the interrupt is serviced.
3. This guarantees that the interrupt handler can safely deal with the current instruction
without any ambiguity about its state.
4. This means that the system maintains enough information to understand what the
current instruction is supposed to do.
Q5:
Consider a user process that wants to print the eight-character string ‘‘ABCDE FGH’’ on
the printer via a serial interface.
1.The software first assembles the string in a buffer in user space
2. The string is transferred to the kernel space, where it is processed and sent to the
printer: The operating system then copies the buffer with the string to an array, say, p, in
kernel space, where it is more easily accessed (because the kernel may have to change the
memory map to get at user space). It then checks to see if the printer is currently available.
If not, it waits until it is. As soon as the printer is available, the operating system copies the
first character to the printer’s data register, in this example using memory-mapped I/O.
This action activates the printer.We see that the first character has been printed and that
the system has marked the ‘‘B’’ as the next character to be printed.
3. The string is printed on the page, and the process may loop back to handle additional
printing tasks: At this point the operating system waits for the printer to become ready
again. When that happens, it prints the next character. This loop continues until the entire
string has been printed. Then control returns to the user process.
Q6:
-The way to allow the CPU to do something else while waiting for the printer to become
ready is to use interrupts. When the system call to print the string is made, the buffer is
copied to kernel space, as we showed earlier, and the first character is copied to the
printer as soon as it is willing to accept a character. At that point the CPU calls the
scheduler and some other process is run. The process that asked for the string to be
printed is blocked until the entire string has printed. The work done on the system call is
shown in Fig. 5-9(a).
- When the printer has printed the character and is prepared to accept the next one, it
generates an interrupt. This interrupt stops the current process and saves its state. Then
the printer interrupt-service procedure is run. A crude version of this code is shown in Fig.
5-9(b). If there are no more characters to print, the interrupt handler takes some action to
unblock the user. Otherwise, it outputs the next char acter, acknowledges the interrupt,
and returns to the process that was running just before the interrupt, which continues from
where it left off
Q7:
-Execution of the Print System Call(figure 5.10a)
+Copy Data: The system copies the data from the user space to a buffer using
copy_from_user(buffer, p, count);.
+Set Up DMA: The DMA controller is set up with set_up_DMA_controller(); to handle the
data transfer.
+Scheduler: The system scheduler is invoked with scheduler(); to manage CPU tasks while
the DMA handles the data transfer.
- Interrupt-Service Procedure
+Acknowledge Interrupt: When the DMA transfer is complete, an interrupt is generated and
acknowledged using acknowledge_interrupt();.
+Unblock User: The user process is unblocked with unblock_user(); to continue execution.
+Return from Interrupt: The system returns from the interrupt with return_from_interrupt();.
Q8:
Aspects Device controllers Device driver
Type Hardware Software
Location Typically on the Resides in the OS (kernel
motherboard or integrated space)
with the device
Function Manages communication Provides an interface for the
between the CPU and the OS to communicate with
device the device
Example USB controller, SATA Printer driver, Graphics
controller, Network driver, Sound card driver
Interface Controller (NIC)
Q9:
1. Save any registers (including the PSW) that have not already been saved by the interrupt
hardware.
2. Set up a context for the interrupt-service procedure. Doing this may involve setting up
the TLB, MMU and a page table.
3. Set up a stack for the interrupt service-procedure.
4. Acknowledge the interrupt controller. If there is no centralized inter rupt controller,
reenable interrupts.
5. Copy the registers from where they were saved (possibly some stack) to the process
table.
6. Run the interrupt-service procedure. It will extract information from the interrupting
device controller’s registers.
7. Choose which process to run next. If the interrupt has caused some high-priority
process that was blocked to become ready, it may be chosen to run now.
8. Set up the MMU context for the process to run next. Some TLB set up may also be
needed.
9. Load the new process’ registers, including its PSW.
10. Start running the new process.
Q10:*Figure 5-15:
-Unbuffered Input (a): Data flows directly from the modem to user space, which can lead to
inefficiencies as each input must be processed immediately without any intermediate
storage.
-User Space Buffering (b): Data is buffered in user space before reaching the application.
This can cause delays if the buffer is not managed efficiently, leading to potential data loss
or overflow.
-Kernel Space Buffering(c): Data is first buffered in kernel space and then copied to user
space. This method can introduce overhead due to the additional copying step, potentially
slowing down the process.
-Double Buffering in Kernel (d): Two buffers in kernel space are used alternately. While this
can reduce delays, it requires more memory and careful management to avoid
synchronization issues.
*Figure 5-16:
-The kernel copies the packet to a kernel buffer to allow the user to proceed immediately
(step 1). At this point the user program can reuse the buffer
- When the driver is called, it copies the packet to the controller for output (step 2).
- After the packet has been copied to the controller’s internal buffer, it is copied out onto
the network (step 3).
- Next the packet is copied to the receiver’s ker nel buffer (step 4).
-Finally, it is copied to the receiving process’ buffer (step 5)
Q11:
1. RAID 0 (Striping)
It consists of viewing the virtual single disk simulated by the RAID as being divided up into
strips of k sectors each, with sectors 0 to k − 1 being strip 0, sectors k to 2k − 1 strip 1, and
so on. RAID level 0 works best with large requests, the bigger the better. If a request is
larger than the number of drives times the strip size, some drives will get multiple requests,
so that when they finish the first request they start the second one.
2.RAID 1: is a true RAID. It duplicates all the disks, so there are four primary disks and four
backup disks. On a write, every strip is written twice.
3.RAID 2: RAID level 2 works on a word basis, possibly even a byte basis. Imagine splitting
each byte of the sin gle virtual disk into a pair of 4-bit nibbles, then adding a Hamming code
to each one to form a 7-bit word, of which bits 1, 2, and 4 were parity bits.
4.RAID 3: RAID level 3 is a simplified version of RAID level 2. As in RAID level 2, the drives
must be exactly synchronized, since individual data words are spread over multiple drives.
Data is striped at the byte level across multiple disks, with one disk dedicated to storing
parity information.
5.RAID 4: Data is striped at the block level across multiple disks, with one disk dedicated
to parity. Faster data recovery compared to RAID 3, since it operates on blocks instead of
bytes. Similar to RAID 3, the dedicated parity disk can become a performance bottleneck.
6.RAID 5: Data is striped at the block level across all disks, with parity distributed among
the disks. Common in enterprise storage systems, databases, and file servers, where both
performance and fault tolerance are important. Provides fault tolerance: if one disk fails,
the data can be rebuilt using the parity information. Write performance is slower than RAID
0 due to parity calculations.
7.RAID 6: is similar to RAID level 5, except that an additional parity block is used. In other
words, the data is striped across the disks with two parity blocks instead of one. As a
result, writes are bit more expensive because of the parity calculations, but reads incur no
performance penalty.