Skip to content

Commit

Permalink
Add some queue counters
Browse files Browse the repository at this point in the history
  • Loading branch information
idigdoug committed Dec 29, 2023
1 parent 18bcadc commit 8cad2ad
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 31 deletions.
46 changes: 40 additions & 6 deletions drivers/net/dwc_eqos/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ struct DeviceContext
UINT32 dpcTx; // Updated only in DPC.
UINT32 dpcAbnormalStatus; // Updated only in DPC.
UINT32 dpcFatalBusError; // Updated only in DPC.
UINT32 rxOwnDescriptors; // Updated only during RxQueueAdvance.
UINT32 rxDoneFragments; // Updated only during RxQueueAdvance.
UINT32 txOwnDescriptors; // Updated only during TxQueueAdvance.
UINT32 txDoneFragments; // Updated only during TxQueueAdvance.
};
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DeviceContext, DeviceGetContext)

Expand Down Expand Up @@ -416,7 +420,7 @@ AdapterCreateTxQueue(
auto const context = DeviceGetContext(AdapterGetContext(adapter)->device);
NT_ASSERT(context->txQueue == nullptr);
return TxQueueCreate(
adapter,
context,
queueInit,
context->dma,
&context->regs->Dma_Ch[0],
Expand All @@ -433,7 +437,7 @@ AdapterCreateRxQueue(
auto const context = DeviceGetContext(AdapterGetContext(adapter)->device);
NT_ASSERT(context->rxQueue == nullptr);
return RxQueueCreate(
adapter,
context,
queueInit,
context->dma,
&context->regs->Dma_Ch[0]);
Expand Down Expand Up @@ -993,13 +997,13 @@ DeviceReleaseHardware(
return STATUS_SUCCESS;
}

_IRQL_requires_max_(PASSIVE_LEVEL)
void
DeviceSetNotificationRxQueue(
_In_ NETADAPTER adapter,
_Inout_ DeviceContext* context,
_In_opt_ NETPACKETQUEUE rxQueue)
{
// PASSIVE_LEVEL, nonpaged (resume path, raises IRQL)
auto const context = DeviceGetContext(AdapterGetContext(adapter)->device);

WdfSpinLockAcquire(context->queueLock); // PASSIVE_LEVEL --> DISPATCH_LEVEL
context->rxQueue = rxQueue;
Expand All @@ -1015,13 +1019,13 @@ DeviceSetNotificationRxQueue(
}
}

_IRQL_requires_max_(PASSIVE_LEVEL)
void
DeviceSetNotificationTxQueue(
_In_ NETADAPTER adapter,
_Inout_ DeviceContext* context,
_In_opt_ NETPACKETQUEUE txQueue)
{
// PASSIVE_LEVEL, nonpaged (resume path, raises IRQL)
auto const context = DeviceGetContext(AdapterGetContext(adapter)->device);

WdfSpinLockAcquire(context->queueLock); // PASSIVE_LEVEL --> DISPATCH_LEVEL
context->txQueue = txQueue;
Expand All @@ -1038,6 +1042,30 @@ DeviceSetNotificationTxQueue(

}

_IRQL_requires_max_(DISPATCH_LEVEL)
void
DeviceAddStatisticsRxQueue(
_Inout_ DeviceContext* context,
UINT32 ownDescriptors,
UINT32 doneFragments)
{
// DISPATCH_LEVEL
context->rxOwnDescriptors += ownDescriptors;
context->rxDoneFragments += doneFragments;
}

_IRQL_requires_max_(DISPATCH_LEVEL)
void
DeviceAddStatisticsTxQueue(
_Inout_ DeviceContext* context,
UINT32 ownDescriptors,
UINT32 doneFragments)
{
// DISPATCH_LEVEL
context->txOwnDescriptors += ownDescriptors;
context->txDoneFragments += doneFragments;
}

__declspec(code_seg("PAGE"))
static void
DeviceCleanup(WDFOBJECT Object)
Expand Down Expand Up @@ -1235,6 +1263,10 @@ PerfDataInit(
data->DpcTx = context->dpcTx;
data->DpcAbnormalStatus = context->dpcAbnormalStatus;
data->DpcFatalBusError = context->dpcFatalBusError;
data->RxOwnDescriptors = context->rxOwnDescriptors;
data->RxDoneFragments = context->rxDoneFragments;
data->TxOwnDescriptors = context->txOwnDescriptors;
data->TxDoneFragments = context->txDoneFragments;
}

// Implements the performance counter callback for a given DataType.
Expand Down Expand Up @@ -1291,6 +1323,7 @@ PerfCallback(
return STATUS_SUCCESS;
}

_IRQL_requires_max_(PASSIVE_LEVEL)
__declspec(code_seg("INIT"))
void
DevicePerfRegister(_In_ WDFDRIVER driver)
Expand Down Expand Up @@ -1340,6 +1373,7 @@ DevicePerfRegister(_In_ WDFDRIVER driver)
TraceEntryExitWithStatus(DevicePerfRegister, LEVEL_INFO, status);
}

_IRQL_requires_max_(PASSIVE_LEVEL)
__declspec(code_seg("PAGE"))
void
DevicePerfUnregister()
Expand Down
26 changes: 24 additions & 2 deletions drivers/net/dwc_eqos/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,52 @@ Device behavior. Includes adapter and interrupt since they are 1:1 with the devi
*/
#pragma once

struct DeviceContext;

// Referenced in driver.cpp DriverEntry.
// Called by WDF.
__declspec(code_seg("PAGE"))
EVT_WDF_DRIVER_DEVICE_ADD
DeviceAdd;

// Called by driver.cpp DriverEntry.
_IRQL_requires_max_(PASSIVE_LEVEL)
__declspec(code_seg("INIT"))
void
DevicePerfRegister(_In_ WDFDRIVER driver);

// Called by driver.cpp DriverUnload.
_IRQL_requires_max_(PASSIVE_LEVEL)
__declspec(code_seg("PAGE"))
void
DevicePerfUnregister();

// Called by rxqueue.cpp RxQueueSetNotificationEnabled.
_IRQL_requires_max_(PASSIVE_LEVEL)
void
DeviceSetNotificationRxQueue(
_In_ NETADAPTER adapter,
_Inout_ DeviceContext* context,
_In_opt_ NETPACKETQUEUE rxQueue);

// Called by txqueue.cpp TxQueueSetNotificationEnabled.
_IRQL_requires_max_(PASSIVE_LEVEL)
void
DeviceSetNotificationTxQueue(
_In_ NETADAPTER adapter,
_Inout_ DeviceContext* context,
_In_opt_ NETPACKETQUEUE txQueue);

// Called by rxqueue.cpp RxQueueAdvance.
_IRQL_requires_max_(DISPATCH_LEVEL)
void
DeviceAddStatisticsRxQueue(
_Inout_ DeviceContext* context,
UINT32 ownDescriptors,
UINT32 doneFragments);

// Called by txqueue.cpp TxQueueAdvance.
_IRQL_requires_max_(DISPATCH_LEVEL)
void
DeviceAddStatisticsTxQueue(
_Inout_ DeviceContext* context,
UINT32 ownDescriptors,
UINT32 doneFragments);
36 changes: 36 additions & 0 deletions drivers/net/dwc_eqos/dwc_eqos_perf.man
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,42 @@
type="perf_counter_rawcount"
uri="uri:opensource/dwc_eqos/perf/debug/DpcFatalBusError"
/>
<counter
detailLevel="standard"
field="RxOwnDescriptors"
id="7"
name="RxOwnDescriptors"
nameID="274"
type="perf_counter_rawcount"
uri="uri:opensource/dwc_eqos/perf/debug/RxOwnDescriptors"
/>
<counter
detailLevel="standard"
field="RxDoneFragments"
id="8"
name="RxDoneFragments"
nameID="276"
type="perf_counter_rawcount"
uri="uri:opensource/dwc_eqos/perf/debug/RxDoneFragments"
/>
<counter
detailLevel="standard"
field="TxOwnDescriptors"
id="9"
name="TxOwnDescriptors"
nameID="278"
type="perf_counter_rawcount"
uri="uri:opensource/dwc_eqos/perf/debug/TxOwnDescriptors"
/>
<counter
detailLevel="standard"
field="TxDoneFragments"
id="10"
name="TxDoneFragments"
nameID="280"
type="perf_counter_rawcount"
uri="uri:opensource/dwc_eqos/perf/debug/TxDoneFragments"
/>
</counterSet>

</provider>
Expand Down
4 changes: 4 additions & 0 deletions drivers/net/dwc_eqos/dwc_eqos_perf_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ struct PERF_DEBUG_DATA
UINT32 DpcTx;
UINT32 DpcAbnormalStatus;
UINT32 DpcFatalBusError;
UINT32 RxOwnDescriptors;
UINT32 RxDoneFragments;
UINT32 TxOwnDescriptors;
UINT32 TxDoneFragments;
};

// Each value corresponds directly to a register in the device.
Expand Down
24 changes: 14 additions & 10 deletions drivers/net/dwc_eqos/rxqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct RxQueueContext
{
ChannelRegisters* channelRegs;

NETADAPTER adapter;
DeviceContext* deviceContext;
NET_RING* packetRing;
NET_RING* fragmentRing;
WDFCOMMONBUFFER descBuffer;
Expand Down Expand Up @@ -88,7 +88,7 @@ RxQueueAdvance(_In_ NETPACKETQUEUE queue)
auto const fragEnd = context->fragmentRing->EndIndex;
auto const descMask = context->descCount - 1u;
UINT32 descIndex, pktIndex, fragIndex;
UINT32 donePkts = 0, queuedPkts = 0;
UINT32 ownDescriptors = 0, doneFrags = 0, queuedFrags = 0;

/*
Fragment indexes:
Expand Down Expand Up @@ -127,6 +127,7 @@ RxQueueAdvance(_In_ NETPACKETQUEUE queue)
TraceWrite("RxQueueAdvance-own", LEVEL_WARNING,
TraceLoggingUInt32(descIndex, "descIndex"),
TraceLoggingHexInt32(reinterpret_cast<UINT32 const*>(&descWrite)[3], "RDES3"));
ownDescriptors = 1;
break;
}

Expand Down Expand Up @@ -170,7 +171,7 @@ RxQueueAdvance(_In_ NETPACKETQUEUE queue)

pktIndex = NetRingIncrementIndex(context->packetRing, pktIndex);
fragIndex = NetRingIncrementIndex(context->fragmentRing, fragIndex);
donePkts += 1;
doneFrags += 1;
}

context->descBegin = descIndex;
Expand Down Expand Up @@ -207,7 +208,7 @@ RxQueueAdvance(_In_ NETPACKETQUEUE queue)
context->descVirtual[descIndex].Read = descRead;

fragIndex = NetRingIncrementIndex(context->fragmentRing, fragIndex);
queuedPkts += 1;
queuedFrags += 1;
}

// In some error cases, the device may stall until we write to the tail pointer
Expand All @@ -232,9 +233,12 @@ RxQueueAdvance(_In_ NETPACKETQUEUE queue)
context->fragmentRing->BeginIndex = fragEnd;
}

DeviceAddStatisticsRxQueue(context->deviceContext, ownDescriptors, doneFrags);

TraceEntryExit(RxQueueAdvance, LEVEL_VERBOSE,
TraceLoggingUInt32(donePkts),
TraceLoggingUInt32(queuedPkts));
TraceLoggingUInt32(ownDescriptors),
TraceLoggingUInt32(doneFrags),
TraceLoggingUInt32(queuedFrags));
}

static EVT_PACKET_QUEUE_SET_NOTIFICATION_ENABLED RxQueueSetNotificationEnabled;
Expand All @@ -245,7 +249,7 @@ RxQueueSetNotificationEnabled(
{
// PASSIVE_LEVEL, nonpaged (resume path)
auto const context = RxQueueGetContext(queue);
DeviceSetNotificationRxQueue(context->adapter, notificationEnabled ? queue : nullptr);
DeviceSetNotificationRxQueue(context->deviceContext, notificationEnabled ? queue : nullptr);
TraceEntryExit(RxQueueSetNotificationEnabled, LEVEL_VERBOSE,
TraceLoggingBoolean(notificationEnabled, "enabled"));
}
Expand Down Expand Up @@ -278,7 +282,7 @@ RxQueueStop(_In_ NETPACKETQUEUE queue)
PAGED_CODE();
auto const context = RxQueueGetContext(queue);

DeviceSetNotificationRxQueue(context->adapter, nullptr);
DeviceSetNotificationRxQueue(context->deviceContext, nullptr);

TraceEntryExit(RxQueueStop, LEVEL_INFO);
}
Expand All @@ -300,7 +304,7 @@ RxQueueCleanup(_In_ WDFOBJECT queue)

_Use_decl_annotations_ NTSTATUS
RxQueueCreate(
NETADAPTER adapter,
DeviceContext* deviceContext,
NETRXQUEUE_INIT* queueInit,
WDFDMAENABLER dma,
ChannelRegisters* channelRegs)
Expand Down Expand Up @@ -338,7 +342,7 @@ RxQueueCreate(
auto const context = RxQueueGetContext(queue);
context->channelRegs = channelRegs;

context->adapter = adapter;
context->deviceContext = deviceContext;
context->packetRing = NetRingCollectionGetPacketRing(rings);
context->fragmentRing = NetRingCollectionGetFragmentRing(rings);
context->descCount = QueueDescriptorCount(context->fragmentRing->NumberOfElements);
Expand Down
3 changes: 2 additions & 1 deletion drivers/net/dwc_eqos/rxqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Receive queue behavior. Similar to the transmit queue.
*/
#pragma once

struct DeviceContext;
struct ChannelRegisters;
auto constexpr RxBufferSize = 2048u;

Expand All @@ -11,7 +12,7 @@ _IRQL_requires_same_
_IRQL_requires_(PASSIVE_LEVEL)
NTSTATUS
RxQueueCreate(
_In_ NETADAPTER adapter,
_Inout_ DeviceContext* deviceContext,
_Inout_ NETRXQUEUE_INIT* queueInit,
_In_ WDFDMAENABLER dma,
_Inout_ ChannelRegisters* channelRegs);
Loading

0 comments on commit 8cad2ad

Please sign in to comment.