Canonical Device (Concept)- Polling and Programmed I/O (PIO)

 

1. Canonical Device (Concept)

🔷 What is a Canonical Device?

A canonical device is a simplified model (abstraction) used to understand how the OS interacts with hardware.

👉 It is not a real device, but a teaching model.


🔷 Two Main Parts

1. Device Interface (Visible to OS)

This is how the OS communicates with the device using registers:

  • Status Register → tells if device is busy/ready/error

  • Command Register → tells device what to do

  • Data Register → sends/receives data

📌 Key idea:
👉 OS controls the device only through this interface


2. Device Internals (Hidden from OS)

This is implementation-specific and may include:

  • Microcontroller (mini CPU)

  • Memory (SRAM/DRAM)

  • Firmware (embedded software)

  • Device-specific logic

📌 Example:

  • RAID controller = complex internal system with firmware


🎯 Key Insight

👉 The OS interacts with devices through a standard interface, ignoring internal complexity

🔄 2. Canonical Protocol (Device Interaction)

This defines how the OS communicates step-by-step with a device. The protocol is follows

While (STATUS == BUSY)
; // wait until device is not busy
Write data to DATA register
Write command to COMMAND register
(Doing so starts the device and executes the command)
While (STATUS == BUSY)
; // wait until device is done with your request

🔷 Steps in the Protocol

Step 1: Wait until device is ready ( Polling)

while (STATUS == BUSY);

Step 2: Send data

write DATA register;

Step 3: Issue command

write COMMAND register;

Step 4: Wait for completion ( Polling)

while (STATUS == BUSY);


🔁 3. Polling (Core Concept)

🔷 What is Polling?

Polling is a technique used by the operating system to monitor the status of an I/O device by repeatedly checking its status register in a loop. The CPU continuously asks the device whether it is ready or has completed its task, instead of doing other useful work. While polling is simple and easy to implement, it is inefficient because it wastes CPU time in busy waiting, especially when dealing with slow devices, reducing overall system performance.

👉 Polling = repeatedly checking the device status register

  • OS keeps asking:

    “Are you done? Are you ready?”


🔷 Where Polling Occurs

  • Before sending command → check readiness

  • After issuing command → check completion


🔷 Why It’s Used

  • Simple to implement

  • Works for all devices


Problems with Polling

🔴 1. CPU Wastage

  • CPU sits in a loop doing nothing useful

  • Cannot execute other processes


🔴 2. Inefficient for Slow Devices

  • Disk, network, etc. are slow

  • CPU is much faster → huge idle time


🔴 3. Poor System Performance

  • Reduces multitasking efficiency


🔄 4. Programmed I/O (PIO)

Programmed I/O (PIO) is a method of device communication in which the CPU is directly responsible for transferring data between memory and an I/O device. The operating system writes data to the device’s data register and continuously checks the device status (polling) to control the operation. While PIO is simple to implement, it is inefficient because the CPU remains actively involved in the entire transfer process, wasting valuable processing time—especially when dealing with slow devices or large amounts of data.

🔷 What is PIO?

👉 When CPU itself moves data to/from device

  • Data written via DATA register

  • CPU actively involved in transfer


🔴 Limitation

  • High CPU overhead for large data transfers


5. Teaching Analogy

👉 Think of polling like:

  • A student repeatedly asking:

    “Sir, is my paper corrected?”

Instead of:

  • Teacher informing when done (interrupt)


6. Key Takeaways 

  • Canonical device = abstraction with:

    • Interface (registers)

    • Internals (hidden)

  • Polling:

    • Continuous checking of status register

    • Simple but inefficient

  • Protocol:

    1. Wait (poll)

    2. Send data

    3. Issue command

    4. Wait again (poll)

  • Main drawback:
    👉 Wastes CPU time → motivates interrupts and DMA

Comments

Popular posts from this blog

Operating Systems OS PCCST403 Semester 4 BTech KTU CS 2024 Scheme

Introduction to Operating System -Virtualization, Concurrency, and Persistence

Operating Systems PCCST403 Scheme and Syllabus