]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/net/classq/classq_fq_codel.c
xnu-4903.270.47.tar.gz
[apple/xnu.git] / bsd / net / classq / classq_fq_codel.c
index f004be34074b36a72180754388db4f9fb97a500c..75a568d2c521be2ac2063ca5cf58fd98c458151f 100644 (file)
 #include <net/pktsched/pktsched_fq_codel.h>
 #include <net/classq/classq_fq_codel.h>
 
-static uint32_t flowq_size;                    /* size of flowq */
-static struct mcache *flowq_cache = NULL;      /* mcache for flowq */
+static uint32_t flowq_size;                     /* size of flowq */
+static struct mcache *flowq_cache = NULL;       /* mcache for flowq */
 
-#define        FQ_ZONE_MAX     (32 * 1024)     /* across all interfaces */
+#define FQ_ZONE_MAX     (32 * 1024)     /* across all interfaces */
 
-#define        DTYPE_NODROP    0       /* no drop */
-#define        DTYPE_FORCED    1       /* a "forced" drop */
-#define        DTYPE_EARLY     2       /* an "unforced" (early) drop */
+#define DTYPE_NODROP    0       /* no drop */
+#define DTYPE_FORCED    1       /* a "forced" drop */
+#define DTYPE_EARLY     2       /* an "unforced" (early) drop */
 
 void
 fq_codel_init(void)
 {
-       if (flowq_cache != NULL)
+       if (flowq_cache != NULL) {
                return;
+       }
 
-       flowq_size = sizeof (fq_t);
-       flowq_cache = mcache_create("fq.flowq", flowq_size, sizeof (uint64_t),
+       flowq_size = sizeof(fq_t);
+       flowq_cache = mcache_create("fq.flowq", flowq_size, sizeof(uint64_t),
            0, MCR_SLEEP);
        if (flowq_cache == NULL) {
                panic("%s: failed to allocate flowq_cache", __func__);
@@ -84,7 +85,7 @@ fq_alloc(classq_pkt_type_t ptype)
        fq = mcache_alloc(flowq_cache, MCR_SLEEP);
        if (fq == NULL) {
                log(LOG_ERR, "%s: unable to allocate from flowq_cache\n");
-               return (NULL);
+               return NULL;
        }
 
        bzero(fq, flowq_size);
@@ -92,7 +93,7 @@ fq_alloc(classq_pkt_type_t ptype)
        if (ptype == QP_MBUF) {
                MBUFQ_INIT(&fq->fq_mbufq);
        }
-       return (fq);
+       return fq;
 }
 
 void
@@ -111,8 +112,9 @@ fq_detect_dequeue_stall(fq_if_t *fqs, fq_t *flowq, fq_if_classq_t *fq_cl,
        u_int64_t maxgetqtime;
        if (FQ_IS_DELAYHIGH(flowq) || flowq->fq_getqtime == 0 ||
            fq_empty(flowq) ||
-           flowq->fq_bytes < FQ_MIN_FC_THRESHOLD_BYTES)
+           flowq->fq_bytes < FQ_MIN_FC_THRESHOLD_BYTES) {
                return;
+       }
        maxgetqtime = flowq->fq_getqtime + fqs->fqs_update_interval;
        if ((*now) > maxgetqtime) {
                /*
@@ -133,15 +135,17 @@ fq_head_drop(fq_if_t *fqs, fq_t *fq)
        struct ifclassq *ifq = fqs->fqs_ifq;
 
        _PKTSCHED_PKT_INIT(&pkt);
-       if (fq_getq_flow_internal(fqs, fq, &pkt) == NULL)
+       if (fq_getq_flow_internal(fqs, fq, &pkt) == NULL) {
                return;
+       }
 
        pktsched_get_pkt_vars(&pkt, &pkt_flags, &pkt_timestamp, NULL, NULL,
            NULL, NULL);
 
        *pkt_timestamp = 0;
-       if (pkt.pktsched_ptype == QP_MBUF)
+       if (pkt.pktsched_ptype == QP_MBUF) {
                *pkt_flags &= ~PKTF_PRIV_GUARDED;
+       }
 
        IFCQ_DROP_ADD(ifq, 1, pktsched_get_pkt_len(&pkt));
        IFCQ_CONVERT_LOCK(ifq);
@@ -184,7 +188,7 @@ fq_addq(fq_if_t *fqs, pktsched_pkt_t *pkt, fq_if_classq_t *fq_cl)
                /* drop the packet if we could not allocate a flow queue */
                fq_cl->fcl_stat.fcl_drop_memfailure++;
                IFCQ_CONVERT_LOCK(fqs->fqs_ifq);
-               return (CLASSQEQ_DROP);
+               return CLASSQEQ_DROP;
        }
        VERIFY(fq->fq_ptype == pkt->pktsched_ptype);
 
@@ -215,7 +219,6 @@ fq_addq(fq_if_t *fqs, pktsched_pkt_t *pkt, fq_if_classq_t *fq_cl)
                        }
                        fq_cl->fcl_stat.fcl_drop_early++;
                }
-
        }
 
        /* Set the return code correctly */
@@ -290,14 +293,14 @@ fq_addq(fq_if_t *fqs, pktsched_pkt_t *pkt, fq_if_classq_t *fq_cl)
                fq_if_is_flow_heavy(fqs, fq);
        } else {
                IFCQ_CONVERT_LOCK(fqs->fqs_ifq);
-               return ((ret != CLASSQEQ_SUCCESS) ? ret : CLASSQEQ_DROP);
+               return (ret != CLASSQEQ_SUCCESS) ? ret : CLASSQEQ_DROP;
        }
 
        /*
         * If the queue is not currently active, add it to the end of new
         * flows list for that service class.
         */
-       if ((fq->fq_flags & (FQF_NEW_FLOW|FQF_OLD_FLOW)) == 0) {
+       if ((fq->fq_flags & (FQF_NEW_FLOW | FQF_OLD_FLOW)) == 0) {
                VERIFY(STAILQ_NEXT(fq, fq_actlink) == NULL);
                STAILQ_INSERT_TAIL(&fq_cl->fcl_new_flows, fq, fq_actlink);
                fq->fq_flags |= FQF_NEW_FLOW;
@@ -306,7 +309,7 @@ fq_addq(fq_if_t *fqs, pktsched_pkt_t *pkt, fq_if_classq_t *fq_cl)
 
                fq->fq_deficit = fq_cl->fcl_quantum;
        }
-       return (ret);
+       return ret;
 }
 
 void *
@@ -318,8 +321,9 @@ fq_getq_flow_internal(fq_if_t *fqs, fq_t *fq, pktsched_pkt_t *pkt)
        struct ifclassq *ifq = fqs->fqs_ifq;
 
        fq_dequeue(fq, p);
-       if (p == NULL)
-               return (NULL);
+       if (p == NULL) {
+               return NULL;
+       }
 
        pktsched_pkt_encap(pkt, fq->fq_ptype, p);
        plen = pktsched_get_pkt_len(pkt);
@@ -334,10 +338,11 @@ fq_getq_flow_internal(fq_if_t *fqs, fq_t *fq, pktsched_pkt_t *pkt)
        IFCQ_DEC_BYTES(ifq, plen);
 
        /* Reset getqtime so that we don't count idle times */
-       if (fq_empty(fq))
+       if (fq_empty(fq)) {
                fq->fq_getqtime = 0;
+       }
 
-       return (p);
+       return p;
 }
 
 void *
@@ -352,8 +357,9 @@ fq_getq_flow(fq_if_t *fqs, fq_t *fq, pktsched_pkt_t *pkt)
        uint64_t *pkt_timestamp;
 
        p = fq_getq_flow_internal(fqs, fq, pkt);
-       if (p == NULL)
-               return (NULL);
+       if (p == NULL) {
+               return NULL;
+       }
 
        pktsched_get_pkt_vars(pkt, &pkt_flags, &pkt_timestamp, NULL, NULL,
            NULL, &pkt_tx_start_seq);
@@ -362,17 +368,20 @@ fq_getq_flow(fq_if_t *fqs, fq_t *fq, pktsched_pkt_t *pkt)
        now = (now_ts.tv_sec * NSEC_PER_SEC) + now_ts.tv_nsec;
 
        /* this will compute qdelay in nanoseconds */
-       if (now > *pkt_timestamp)
+       if (now > *pkt_timestamp) {
                qdelay = now - *pkt_timestamp;
+       }
        fq_cl = &fqs->fqs_classq[fq->fq_sc_index];
 
        if (fq->fq_min_qdelay == 0 ||
-           (qdelay > 0 && (u_int64_t)qdelay < fq->fq_min_qdelay))
+           (qdelay > 0 && (u_int64_t)qdelay < fq->fq_min_qdelay)) {
                fq->fq_min_qdelay = qdelay;
+       }
        if (now >= fq->fq_updatetime) {
                if (fq->fq_min_qdelay > fqs->fqs_target_qdelay) {
-                       if (!FQ_IS_DELAYHIGH(fq))
+                       if (!FQ_IS_DELAYHIGH(fq)) {
                                FQ_SET_DELAY_HIGH(fq);
+                       }
                } else {
                        FQ_CLEAR_DELAY_HIGH(fq);
                }
@@ -398,8 +407,9 @@ fq_getq_flow(fq_if_t *fqs, fq_t *fq, pktsched_pkt_t *pkt)
        fq_if_is_flow_heavy(fqs, fq);
 
        *pkt_timestamp = 0;
-       if (pkt->pktsched_ptype == QP_MBUF)
+       if (pkt->pktsched_ptype == QP_MBUF) {
                *pkt_flags &= ~PKTF_PRIV_GUARDED;
+       }
 
-       return (p);
+       return p;
 }