Skip to content

PSA switches use the QueueScheduler too - #132

Merged
Mingyumaz merged 2 commits into
mainfrom
feat/psa-scheduler
Dec 2, 2026
Merged

Mingyumaz merged 2 commits into
mainfrom
feat/psa-scheduler

Conversation

@Mingyumaz

@Mingyumaz Mingyumaz commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

QueueScheduler (strict priority, PIFOs, PIFO trees with shaping and token buckets) works with v1model switches only: a PSA switch with another scheduler stops the simulation ("works with v1model switches only"). The PSA core keeps its own copy of the strict-priority queues (P4CorePsa::egress_buffer), which is the same BMv2 queue logic as the default scheduler of v1model. This PR gives PSA switches the same scheduler interface, so a PSA program can use PIFOs and PIFO trees too, and the default stays exactly as it was.

How it works

One place for the plumbing. The scheduler and what goes with it move from the v1model core to their base class P4SwitchCore: SetQueueScheduler(), GetQueueScheduler(), the names of the scheduler's input and output fields, and how they are found in the program (ResolveSchedulerFields(), FindMetadataField()). A core with output queues calls InitQueueScheduler(capacity, queues per port) in its constructor, which sets the default scheduler, and StartQueueScheduler() when it starts, which finds the fields. After a program swap, TrySwap() finds them again for the new program, so neither core has to.

PSA queues as psa_switch. psa_switch serves priority 0 first: it puts a packet of priority p into queue 7 − p, and the highest queue goes first. The PSA core gives the scheduler that queue as the packet's priority, so the default P4StrictPriorityScheduler sends the same frames at the same times as the old egress_buffer. set_queue_depth and set_queue_rate name the queue, as before. A PSA program has no priority field, so all packets use queue 7.

What the scheduler gets in PSA. As in v1model, each packet comes with the switch's clock and its length (P4QueueMetadata::timestamp, the clock of ingress_timestamp, and bytes, the frame as it entered the switch), which PIFO-tree shaping (ShapingFields) and token buckets (NodeRates) use. The switch reads the scheduler's input fields when a packet enters the queues, after the ingress, and writes its output fields after the egress parser and before the egress control: the egress parser may write the user metadata, and the egress control should see the scheduler's values. p4c puts the user metadata of the ingress and the egress into the same fields when they have the same type (metadata_t.rank), so a rank that the ingress writes is found as in v1model. p4c-bm2-psa also puts copies of the PSA standard metadata next to the user metadata; nothing reads or writes them, so FindMetadataField() skips them.

Drops. When a full queue drops a packet, the PSA core now checks a pending program swap, as v1model does (before, the swap waited for the next event).

Review guide

  1. model/p4-switch-core.h, .cc: the scheduler block (public), InitQueueScheduler(), StartQueueScheduler() (protected), ResolveSchedulerFields() (private), and the call in TrySwap(). The functions are moved from the v1model core unchanged, except the abort when a core has no queues and the skipped PSA copies in FindMetadataField().
  2. model/p4-core-v1model.h, .cc: the moved parts removed; the constructor calls InitQueueScheduler(), start_and_return_() calls StartQueueScheduler().
  3. model/p4-core-psa.h, .cc: egress_buffer replaced by the scheduler in EnqueueNow() (priority, clock, length, input fields, drops), EventDrivenEgressDequeue() (output fields after the egress parser), ScheduleEgressIfNeeded(), EgressDone(), PortTxComplete(), HandleEgressPipeline(), and the queue commands.
  4. model/p4-switch-net-device.cc: PSA allowed; the PSA core gets the scheduler before its program and flow table.
  5. Tests (test/p4-queue-scheduler-test-suite.cc, program test/p4src/pifo/fields_psa.p4): the fields case for PSA, which now also checks the clock and the length (v1model and PSA); PsaQueuesTestCase; PsaPifoTestCase (second commit: a PIFO and a PIFO tree whose root has a rate of 10 Mbps in a PSA switch, by rank and at the rate of the frames' bytes); the PSA copies in PifoRankFieldTestCase.
  6. Docs: switch.md, event-driven-tm-scheduler.md, README.md, TODO.md, test/Readme.md, utils/p4-queue-scheduler.h, and the PSA names of the clock and the length in utils/p4-pifo-tree-scheduler.h, .cc.

Scope

  • In: PSA switches with any QueueScheduler; the scheduler plumbing in the base class.
  • Out: the PNA NIC and the pipeline core (queues of their own); mapping PSA's class_of_service to a queue (psa_switch does not); finding PSA's fields once per program (as v1model does since v1model core: find PHV fields and P4 objects once per program #129).
  • Tested (ns-3.39 and ns-3.49, Docker, on main 96b230b): the build has no warnings; run-tests.sh passes 24 suites with 271 test cases and 48 example runs on both versions, and every example (the three PSA examples too) prints the same as on main except its wall-clock times. Mutation testing: 12 mutants (the queue of a priority, the input fields, the output fields, the output fields before the egress parser, no field lookup at the start, no lookup after a swap, the size check after a transmission, the device not giving PSA its scheduler, the PSA copies found as fields, no swap check at a full queue; after the rebase onto PIFO trees: shaping (ShapingFields) #128 and PIFO trees: token buckets and backlog limits per node #130, no clock and no length in PSA); 11 are caught. The missed one (no swap check at a full queue) changes nothing that a test can see except with a queue of capacity 0, where the dropped packet was the last one in the switch and a pending swap would wait for the next event. PsaPifoTestCase catches the missing length on its own too (with the fields case's length check removed): the tree then sends back to back, 17.6 µs apart instead of 171.68 µs. An independent review (before the rebase) found the PSA copies in FindMetadataField() and two wrong statements in the docs; all three are fixed.
  • Not tested: a PSA program with shaping times (ShapingFields) or a tree of several leaves: the scheduler gets the same metadata as in v1model (the fields case checks the clock in PSA), and both are tested with v1model. A program swap of a PSA switch with scheduler fields (the code path is the base class's, tested with v1model).

Two reviews are needed before merging.

🤖 Generated with Claude Code

Mingyumaz and others added 2 commits December 2, 2026 21:42
QueueScheduler (strict priority, PIFOs, PIFO trees) worked with v1model
switches only; the PSA core kept its own copy of the strict-priority queues
(egress_buffer). The scheduler plumbing moves from the v1model core to
P4SwitchCore, and the PSA core uses it, so a PSA switch takes any scheduler
and its default stays as it was.

- P4SwitchCore: SetQueueScheduler(), GetQueueScheduler(), the scheduler's
  input and output fields, ResolveSchedulerFields(), FindMetadataField()
  (moved from P4CoreV1model); InitQueueScheduler() sets the default in a
  core's constructor, StartQueueScheduler() finds the fields at the start,
  TrySwap() finds them again after a swap.
- FindMetadataField() skips the copies of the PSA standard metadata that
  p4c-bm2-psa puts next to the user metadata and nothing reads or writes.
- P4CorePsa: priority p goes to queue nbQueues - 1 - p, as in a psa_switch
  with priority queues, so the default scheduler sends the same frames at
  the same times as before; the scheduler gets the switch's clock and the
  packet's length (P4QueueMetadata::timestamp and bytes, which PIFO-tree
  shaping and token buckets use), as in v1model; the input fields are read
  when a packet is queued, the output fields written after the egress parser
  and before the egress control; a drop at a full queue checks a pending
  swap, as v1model.
- P4SwitchNetDevice: QueueScheduler works with PSA switches.
- Tests (p4-queue-scheduler): the fields case for PSA (program
  pifo/fields_psa, whose egress parser writes an output field too), which
  also checks the clock and the length in v1model and PSA; the queue that
  PSA priority 0 uses, and the PSA copies in FindMetadataField.
- Docs: switch.md, event-driven-tm-scheduler.md, README.md, TODO.md,
  test/Readme.md (270 cases).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The suite p4-queue-scheduler checked PSA switches with the default
scheduler and with the test scheduler of the fields case only. The new
case sends the burst through a PSA switch (program fields_psa, the rank in
meta.a) with P4PifoScheduler and with a PIFO tree whose root has a rate of
10 Mbps: both send by rank, the PIFO back to back and the tree at the
bucket's rate, which needs the frame's length from the PSA switch.
test/Readme.md: 271 cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Mingyumaz
Mingyumaz merged commit e128901 into main Dec 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant