Repository navigation
PSA switches use the QueueScheduler too - #132
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 callsInitQueueScheduler(capacity, queues per port)in its constructor, which sets the default scheduler, andStartQueueScheduler()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
P4StrictPrioritySchedulersends the same frames at the same times as the oldegress_buffer.set_queue_depthandset_queue_ratename 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 ofingress_timestamp, andbytes, 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, soFindMetadataField()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
model/p4-switch-core.h,.cc: the scheduler block (public),InitQueueScheduler(),StartQueueScheduler()(protected),ResolveSchedulerFields()(private), and the call inTrySwap(). The functions are moved from the v1model core unchanged, except the abort when a core has no queues and the skipped PSA copies inFindMetadataField().model/p4-core-v1model.h,.cc: the moved parts removed; the constructor callsInitQueueScheduler(),start_and_return_()callsStartQueueScheduler().model/p4-core-psa.h,.cc:egress_bufferreplaced by the scheduler inEnqueueNow()(priority, clock, length, input fields, drops),EventDrivenEgressDequeue()(output fields after the egress parser),ScheduleEgressIfNeeded(),EgressDone(),PortTxComplete(),HandleEgressPipeline(), and the queue commands.model/p4-switch-net-device.cc: PSA allowed; the PSA core gets the scheduler before its program and flow table.test/p4-queue-scheduler-test-suite.cc, programtest/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 inPifoRankFieldTestCase.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 inutils/p4-pifo-tree-scheduler.h,.cc.Scope
QueueScheduler; the scheduler plumbing in the base class.class_of_serviceto 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).run-tests.shpasses 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.PsaPifoTestCasecatches 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 inFindMetadataField()and two wrong statements in the docs; all three are fixed.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