12.07.2015 Views

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

ALTQ (9) <strong>NetBSD</strong> <strong>Kernel</strong> Developer’s <strong>Manual</strong> ALTQ (9)if (ifp->if_snd.ifq_head != NULL) | if (IFQ_IS_EMPTY(&ifp->if_snd) == 0)|Note that IFQ_POLL() can be used for the same purpose, but IFQ_POLL() could be costly for a complexscheduling algorithm since IFQ_POLL() needs to run the scheduling algorithm to select the next packet. Onthe other hand, IFQ_IS_EMPTY() checks only if there is any packet stored in the queue. Another differenceis that even when IFQ_IS_EMPTY() is false, IFQ_DEQUEUE() could still return NULL if the queue isunder rate-limiting.Dequeue operationReplace IF_DEQUEUE() by IFQ_DEQUEUE(). Always check whether the dequeued mbuf is NULL or not.Note that even when IFQ_IS_EMPTY() is false, IFQ_DEQUEUE() could return NULL due to rate-limiting.##old-style####new-style##|IF_DEQUEUE(&ifp->if_snd, m);| IFQ_DEQUEUE(&ifp->if_snd, m);| if (m == NULL)| return;|Adriver issupposed to call if_start() from transmission complete interrupts in order to trigger the nextdequeue.Poll-and-dequeue operationIf the code polls the packet at the head of the queue and actually uses the packet before dequeueing it, useIFQ_POLL() and IFQ_DEQUEUE().##old-style####new-style##|m = ifp->if_snd.ifq_head;| IFQ_POLL(&ifp->if_snd, m);if (m != NULL) { | if (m != NULL) {|/∗ use m to get resources ∗/ | /∗ use m to get resources ∗/if (something goes wrong) | if (something goes wrong)return; | return;|IF_DEQUEUE(&ifp->if_snd, m); | IFQ_DEQUEUE(&ifp->if_snd, m);|/∗ kick the hardware ∗/ | /∗ kick the hardware ∗/} | }|It is guaranteed that IFQ_DEQUEUE() immediately after IFQ_POLL() returns the same packet. Note thatthey need to be guarded by splimp() if called from outside of if_start().Eliminating IF_PREPENDIf the code uses IF_PREPEND(), you have to eliminate it since the prepend operation is not possible formany queueing disciplines. Acommon use of IF_PREPEND() is to cancel the previous dequeue operation.Youhave to convert the logic into poll-and-dequeue.##old-style####new-style##|IF_DEQUEUE(&ifp->if_snd, m);| IFQ_POLL(&ifp->if_snd, m);if (m != NULL) { | if (m != NULL) {|<strong>NetBSD</strong> 3.0 October 12, 2006 5

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!