Epoll Optimisations for Reducing Context Switch Latency

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Conventional I/O event notification mechanisms introduce significant latency and jitter, especially when dealing with large sets of file descriptors that frequently change, and they are inefficient in terms of processing overhead due to frequent context switches and blocking operations.

Innovation Solution

A method that intercepts configuration calls from applications and stores parameters in a data structure, allowing for batched system calls to the kernel, reducing context switches and enabling non-blocking busy-wait loops to minimize latency and jitter, particularly by using a user-level interface to aggregate epoll_ctl() calls and invoke them as a single system call, and replacing blocking epoll_wait() with a busy-wait loop.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If epoll_ctl() calls are made individually for each configuration change, then the I/O event notification mechanism can respond to changes immediately, but the number of context switches increases and processing overhead increases

Engineering Contradiction:
Improveresponsiveness to configuration changesVSAvoidprocessing overhead
Core Design Contradiction:
ReliabilityVSProductivity

Solution Approach 1:

The patent merges multiple individual epoll_ctl() configuration calls into a single batched system call. The user-level interface aggregates configuration parameters from multiple application calls into a data structure, then invokes one system call to pass all parameters to the kernel library, which processes them in batch. This reduces the number of context switches from multiple individual calls to a single call, directly resolving the contradiction between immediate responsiveness and processing overhead.

Inventive Principle:
Principle #5Merging (Combining)

Solution Approach 2:

The patent performs preliminary aggregation of configuration parameters at the user-level interface before invoking the system call. The data structure stores sets of parameters representing operations on file descriptors, and this aggregation happens in advance of the actual kernel processing. This preliminary action allows the system to prepare all configuration changes upfront, reducing the frequency of context switches while maintaining the ability to respond to all changes.

Inventive Principle:
Principle #10Preliminary action

2Use of energy by moving object

If epoll_wait() is used to wait for I/O events, then the thread can block and conserve CPU resources, but latency and jitter are introduced due to blocking operations

Engineering Contradiction:
ImproveCPU resource consumptionVSAvoidlatency and jitter
Core Design Contradiction:
Use of energy by moving objectVSLoss of time

Solution Approach 1:

The patent replaces the blocking epoll_wait() operation with a busy-wait loop that periodically checks for I/O events without blocking. The thread actively polls the I/O event notification mechanism at frequent intervals, ensuring low latency detection of events while avoiding the long blocking periods that cause jitter. This periodic checking approach resolves the contradiction by consuming CPU resources in a controlled manner while maintaining low latency.

Inventive Principle:
Principle #19Periodic action

Solution Approach 2:

The patent introduces dynamic behavior by replacing the static blocking wait with an active busy-wait loop. The thread dynamically adjusts its behavior by continuously checking for events rather than passively blocking, allowing it to respond immediately when events occur. This dynamic approach eliminates the latency and jitter associated with blocking operations while managing CPU consumption through the polling mechanism.

Inventive Principle:
Principle #15Dynamics

3Adaptability or versatility

If the set of monitored file descriptors changes frequently, then the application can adapt to dynamic I/O requirements, but epoll_ctl() calls must be made frequently increasing context switches

Engineering Contradiction:
Improveability to handle dynamic file descriptor setsVSAvoidnumber of system calls
Core Design Contradiction:
Adaptability or versatilityVSDevice complexity

Solution Approach 1:

The patent merges multiple frequent epoll_ctl() calls into a single batched system call. The user-level interface maintains a data structure that accumulates configuration parameters from multiple application requests, then combines them into one system call invocation. This merging approach allows the application to adapt to dynamic file descriptor sets while reducing the number of context switches from multiple individual calls to a single consolidated call.

Inventive Principle:
Principle #5Merging (Combining)

Solution Approach 2:

The patent introduces a user-level interface as an intermediary between the application and the kernel. This intermediary layer aggregates configuration parameters from multiple application calls and prepares a unified data structure before invoking the system call. The intermediary absorbs the complexity of frequent changes, allowing the application to maintain high adaptability while the system call frequency is reduced, thus resolving the contradiction between adaptability and device complexity.

Inventive Principle:
Principle #24Intermediary (Mediator)

4Ease of operation

If individual system calls are used for each configuration call, then each call can be processed independently, but the latency and jitter associated with context switches increase

Engineering Contradiction:
Improveindependence of configuration callsVSAvoidcontext switch latency
Core Design Contradiction:
Ease of operationVSLoss of time

Solution Approach 1:

The patent merges multiple independent configuration calls into a single batched system call. The user-level interface maintains independence of configuration calls by accepting them individually and storing their parameters separately in a data structure, then combines them into one system call invocation. This merging eliminates the context switch latency that would occur with multiple individual calls while preserving the operational independence of each configuration request through separate parameter storage and processing.

Inventive Principle:
Principle #5Merging (Combining)

Data Source

PatentEP2506147B1Epoll optimisations
Publication Date: 2023.11.01 XILINX INC
  • EP2506147B1 patent drawingFigure 1~2
  • EP2506147B1 patent drawing
  • EP2506147B1 patent drawing

AI summary

A method for managing I/O event notifications in a data processing system, the data processing system comprising a plurality of applications and an operating system having a kernel and an I/O event notification mechanism operable to maintain a plurality of I/O event notification objects each handling a set of file descriptors associated with one or more I/O resources, the method comprising: for each of a plurality of application-level configuration calls: intercepting at a user-level interface a configuration call from an application to the I/O event notification mechanism for configuring an I/O event notification object; and storing a set of parameters of the configuration call at a data structure, each set of parameters representing an operation on the set of file descriptors handled by the I/O event notification object; and subsequently, on a predetermined criterion being met: the user-level interface causing the plurality of configuration calls to be effected by means of a first system call to the kernel.