pre-fill the tx ring with bogus empty packets

This commit is contained in:
JackDoan
2025-12-18 15:18:19 -06:00
parent 726e282d0a
commit 111efc0779
7 changed files with 57 additions and 50 deletions

View File

@@ -168,12 +168,12 @@ func (dt *DescriptorTable) releaseBuffers() error {
return nil
}
func (dt *DescriptorTable) CreateDescriptorForOutputs() (uint16, error) {
func (dt *DescriptorTable) CreateDescriptorForOutputs() (uint16, uint32, error) {
//todo just fill the damn table
// Do we still have enough free descriptors?
if 1 > dt.freeNum {
return 0, ErrNotEnoughFreeDescriptors
return 0, 0, ErrNotEnoughFreeDescriptors
}
// Above validation ensured that there is at least one free descriptor, so
@@ -216,7 +216,7 @@ func (dt *DescriptorTable) CreateDescriptorForOutputs() (uint16, error) {
dt.descriptors[dt.freeHeadIndex].next = next
}
return head, nil
return head, desc.length, nil
}
func (dt *DescriptorTable) createDescriptorForInputs() (uint16, error) {

View File

@@ -301,7 +301,6 @@ func (sq *SplitQueue) BlockAndGetHeadsCapped(ctx context.Context, maxToTake int)
// and any further calls to [SplitQueue.OfferDescriptorChain] will stall.
func (sq *SplitQueue) OfferInDescriptorChains() (uint16, error) {
// Create a descriptor chain for the given buffers.
var (
head uint16
err error
@@ -350,18 +349,6 @@ func (sq *SplitQueue) SetDescSize(head uint16, sz int) {
sq.descriptorTable.descriptors[int(head)].length = uint32(sz)
}
func (sq *SplitQueue) OfferDescriptor(chain uint16, kick bool) error {
// Make the descriptor chain available to the device.
sq.availableRing.offerSingle(chain)
// Notify the device to make it process the updated available ring.
if kick {
return sq.Kick()
}
return nil
}
func (sq *SplitQueue) OfferDescriptorChains(chains []uint16, kick bool) error {
// Make the descriptor chain available to the device.
sq.availableRing.offer(chains)

View File

@@ -153,11 +153,7 @@ func (r *UsedRing) takeOne() (UsedElement, bool) {
}
// InitOfferSingle is only used to pre-fill the used queue at startup, and should not be used if the device is running!
func (r *UsedRing) InitOfferSingle(x uint16, size int) {
//always called under lock
//r.mu.Lock()
//defer r.mu.Unlock()
func (r *UsedRing) InitOfferSingle(x uint16, size uint32) {
offset := 0
// Add descriptor chain heads to the ring.
@@ -166,10 +162,8 @@ func (r *UsedRing) InitOfferSingle(x uint16, size int) {
// size) is always a power of 2 and smaller than the highest possible
// 16-bit value.
insertIndex := int(*r.ringIndex+uint16(offset)) % len(r.ring)
r.ring[insertIndex] = UsedElement{
DescriptorIndex: uint32(x),
Length: uint32(size),
}
r.ring[insertIndex].DescriptorIndex = uint32(x)
r.ring[insertIndex].Length = size
// Increase the ring index by the number of descriptor chains added to the ring.
*r.ringIndex += 1