Skip to content

Commit

Permalink
adopting stalled packets logic from IntelMausi; introducing likely/un…
Browse files Browse the repository at this point in the history
…likely macros
  • Loading branch information
donatengit committed Feb 26, 2022
1 parent 7edb889 commit 385f8d4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
52 changes: 23 additions & 29 deletions AppleIGB/AppleIGB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ static int netif_carrier_ok(IOEthernetController* netdev)

static void netif_wake_queue(IOEthernetController* netdev)
{
pr_debug("netif_wake_queue().\n");
DEBUGFUNC("netif_wake_queue().\n");
netif_tx_wake_all_queues(netdev);
}

static void netif_stop_queue(IOEthernetController* netdev)
{
pr_debug("netif_stop_queue().\n");
DEBUGFUNC("netif_stop_queue().\n");
netif_tx_stop_all_queues(netdev);
}

Expand Down Expand Up @@ -9634,8 +9634,8 @@ UInt32 AppleIGB::outputPacket(mbuf_t skb, void * param)
struct igb_adapter *adapter = &priv_adapter;
UInt32 result = kIOReturnOutputDropped;

if (!(enabledForNetif && linkUp) || !txMbufCursor
|| test_bit(__IGB_DOWN, &adapter->state)) {
if (unlikely(!(enabledForNetif && linkUp) || !txMbufCursor
|| test_bit(__IGB_DOWN, &adapter->state))) {
pr_debug("output: Dropping packet on disabled device\n");
goto error;
}
Expand All @@ -9658,7 +9658,8 @@ UInt32 AppleIGB::outputPacket(mbuf_t skb, void * param)
* + 1 desc for context descriptor,
* otherwise try next time */
txNumFreeDesc = igb_desc_unused(tx_ring);
if (txNumFreeDesc < MAX_SKB_FRAGS + 3) //igb_maybe_stop_tx
if (txNumFreeDesc < MAX_SKB_FRAGS + 3 //igb_maybe_stop_tx
|| stalled) /** even if we have free desc we should exit in stalled mode as queue is enabled by threadsafe interrupts -> native igb code (see igb_poll) */
{
/* this is a hard error */
netStats->outputErrors += 1;
Expand All @@ -9670,9 +9671,9 @@ UInt32 AppleIGB::outputPacket(mbuf_t skb, void * param)
* are not ready for this (kernel panic) further on mbuf_pkthdr_len
* so just error as in some other drivers hoping that upper layers will be able to
* handle this properly */
// result = kIOReturnOutputStall;
// stalled = true;
goto error;
result = kIOReturnOutputStall;
stalled = true;
goto done;
}
/* record the location of the first descriptor for this packet */
first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Expand Down Expand Up @@ -9707,7 +9708,7 @@ UInt32 AppleIGB::outputPacket(mbuf_t skb, void * param)

if(useTSO)
tso = igb_tso(tx_ring, first, &hdr_len);
if (tso < 0){
if (unlikely(tso < 0)){
igb_unmap_and_free_tx_resource(tx_ring, first);
break;
} else if (!tso)
Expand Down Expand Up @@ -10338,9 +10339,9 @@ void AppleIGB::interruptOccurred(IOInterruptEventSource * src, int count)
// /* guard against interrupt when we're going down */
// if (!test_bit(__IGB_DOWN, &adapter->state))
// watchdogSource->setTimeoutMS(1);
}
igb_poll(q_vector, 64);
} else {
igb_poll(q_vector, 64);
}
}

void AppleIGB::interruptHandler(OSObject * target, IOInterruptEventSource * src, int count)
Expand Down Expand Up @@ -10385,19 +10386,6 @@ void AppleIGB::watchdogTask()
}
}

if (stalled) {
pr_debug("Restart stalled queue free=%u, needed=%u\n", txNumFreeDesc, DESC_NEEDED);
transmitQueue->service(IOBasicOutputQueue::kServiceAsync);
stalled = FALSE;
// if (txNumFreeDesc >= DESC_NEEDED) {
// pr_debug("Enough free descriptors (%u), restart stalled queue\n", txNumFreeDesc);
// transmitQueue->service(IOBasicOutputQueue::kServiceAsync);
// stalled = FALSE;
// } else {
// pr_debug("Keeping queue stalled, free=%u (%u)\n", txNumFreeDesc, DESC_NEEDED);
// }
}

watchdogSource->setTimeoutMS(200);
}

Expand Down Expand Up @@ -10536,10 +10524,16 @@ UInt32 AppleIGB::getFeatures() const {

void AppleIGB::startTxQueue()
{
pr_debug("AppleIGB::startTxQueue()\n");
txMbufCursor = IOMbufNaturalMemoryCursor::withSpecification(_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN, MAX_SKB_FRAGS);
if(txMbufCursor && transmitQueue)
transmitQueue->start();
DEBUGFUNC("AppleIGB::startTxQueue\n");
if (likely(stalled && txMbufCursor && transmitQueue)) {
pr_debug("Assuming wake queue called.\n");
transmitQueue->service(IOBasicOutputQueue::kServiceAsync);
} else {
txMbufCursor = IOMbufNaturalMemoryCursor::withSpecification(_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN, MAX_SKB_FRAGS);
if(txMbufCursor && transmitQueue)
transmitQueue->start();
}
stalled = false;
}

void AppleIGB::stopTxQueue()
Expand Down
2 changes: 1 addition & 1 deletion AppleIGB/AppleIGB.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class AppleIGB: public super
IOMbufNaturalMemoryCursor * txCursor(){ return txMbufCursor; }
void rxChecksumOK( mbuf_t, UInt32 flag );
bool running(){return enabledForNetif;}
bool queueStopped(){return txMbufCursor == NULL;}
bool queueStopped(){return txMbufCursor == NULL || stalled;}
bool carrier();
void setCarrier(bool);

Expand Down
10 changes: 8 additions & 2 deletions AppleIGB/kcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,10 @@ typedef void AppleIGB;

#define prefetch(x)
#define prefetchw(x)
#define unlikely(x) (x)
#define likely(x) (x)
//#define unlikely(x) (x)
#define unlikely(x) __builtin_expect(!!(x), 0)
//#define likely(x) (x)
#define likely(x) __builtin_expect(!!(x), 1)
#define BUG()

#define wmb() mb()
Expand Down Expand Up @@ -346,7 +348,11 @@ extern os_log_t igb_logger;

#else

#ifdef DEBUG
#define pr_debug(args...) IOLog(PFX args)
#else
#define pr_debug(args...)
#endif
#define pr_err(args...) IOLog(PFX args)
#define dev_warn(dev,args...) IOLog(PFX args)
#define dev_info(dev,args...) IOLog(PFX args)
Expand Down

0 comments on commit 385f8d4

Please sign in to comment.