Polling - aryanjoshi0823/5143-Operating-System GitHub Wiki

Polling

Polling, also known as interrogation, refers to actively and synchronously sampling the status of an external device by a client program. It is commonly used in input/output (I/O) operations and is also referred to as polled I/O or software-driven I/O.


Description

Polling involves a computer or controlling device waiting to check the readiness or state of an external device, often interacting with low-level hardware. For example:

  • A computer connected to a printer through a parallel port waits for the printer to signal that it is ready to receive the next character.
  • Polling often examines a single bit to determine the device’s state.

This process is sometimes synonymous with busy-wait polling, where the computer does nothing but check the device status until it is ready. However, in other scenarios, the computer alternates between checking the device and performing other tasks, which is more efficient than busy-waiting but still less optimal than interrupt-driven I/O.

Polling is commonly used in single-purpose systems or in scenarios with simple hardware or non-multitasking operating systems.


Algorithm for Polling

Host Actions:

  1. Repeatedly check the busy bit in the controller until it is clear (value = 0).
  2. Once clear:
    • If sending output:
      • Write the command to the command register.
      • Set the write bit and place data in the data-out register.
    • If receiving input:
      • Read the data from the data-in register.
      • Clear the read bit as the next command.
  3. Set the command-ready bit to 1.

Controller Actions:

  1. Detect the command-ready bit is set and set the busy bit to 1.
  2. Read the command register:
    • If the write bit is set, read data from the data-out register and perform I/O operations.
    • If the read bit is set, load data into the data-in register for the host to access.
  3. Upon completion:
    • Clear the command-ready bit.
    • Reset the error bit to indicate success.
    • Clear the busy bit.

Types of Polling

  1. Roll Call Polling:

    • Queries each device or element in a fixed sequence.
    • Requires a timing mechanism to handle non-responsive elements.
    • Inefficient for systems with many inactive elements.
  2. Hub Polling (Token Polling):

    • Devices poll one another in a fixed sequence.
    • The cycle repeats when the first device is reached again.

Polling is used in multitasking operating systems, networks, and other contexts to manage execution or transmission sequences. For instance:

  • Allocating processor time and resources in multitasking systems.
  • Managing network node access or routing protocol information.