Page MenuHomeFreeBSD

if_epair: fix race condition on multi-core systems
ClosedPublic

Authored by grembo on Mar 15 2022, 5:48 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 12 2024, 9:31 AM
Unknown Object (File)
Dec 22 2023, 3:59 AM
Unknown Object (File)
Dec 20 2023, 4:52 AM
Unknown Object (File)
Dec 12 2023, 1:24 AM
Unknown Object (File)
Nov 6 2023, 1:43 AM
Unknown Object (File)
Oct 15 2023, 2:57 PM
Unknown Object (File)
Oct 5 2023, 12:39 AM
Unknown Object (File)
Sep 9 2023, 11:16 AM

Details

Summary

As an unwanted side effect of the performance improvements in
24f0bfbad57b9, epair interfaces stop forwarding traffic on higher
load levels when running on multi-core systems.

This happens due to a race condition in the logic that decides when to
place work in the task queue(s) responsible for processing the content
of ring buffers.

In order to fix this, a field named state is added to the epair_queue
structure. This field is used by the affected functions to signal each
other that something happened in the underlying ring buffers that might
require work to be scheduled in task queue(s), replacing the existing
logic, which relies on checking if ring buffers are empty or not.

epair_menq() does:
  - set BIT_MBUF_QUEUED
  - queue mbuf
  - if testandset BIT_QUEUE_TASK:
      enqueue task

epair_tx_start_deferred() does:
  - swap ring buffers
  - process mbufs
  - clear BIT_QUEUE_TASK
  - if testandclear BIT_MBUF_QUEUED
      enqueue task

As 13.1-PRERELEASE is affected, MFCing is imperative.

PR: 262571
Reported by: Johan Hendriks <joh.hendriks@gmail.com>
MFC after: 3 days

Test Plan

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This looks good to me. I'll give bz@ another day to comment and then I'll commit.

I've run my previous benchmarks, and I'm not seeing major performance effects of this patch.

This revision was not accepted when it landed; it landed in state Needs Review.Mar 16 2022, 11:30 PM
This revision was automatically updated to reflect the committed changes.