- ifp->if_bw.start_seq = pkt->m_pkthdr.pkt_bwseq;
- ifp->if_bw.start_ts = mach_absolute_time();
-#else /*!MEASURE_BW */
-#pragma unused(ifp, pkt)
-#endif /* !MEASURE_BW */
-}
-
-void
-ifnet_transmit_burst_end(ifnet_t ifp, mbuf_t pkt)
-{
-#if MEASURE_BW
- uint64_t oseq, ots, bytes, ts, t;
- uint32_t flags;
-
- if (ifp == NULL || !(pkt->m_flags & M_PKTHDR))
- return;
-
- flags = OSBitOrAtomic(IF_MEASURED_BW_CALCULATION, &ifp->if_bw.flags);
-
- /* If a calculation is already in progress, just return */
- if (flags & IF_MEASURED_BW_CALCULATION)
- return;
-
- /* Check if a measurement was started at all */
- if (!(flags & IF_MEASURED_BW_INPROGRESS)) {
- /*
- * It is an error to call burst_end before burst_start.
- * Reset the calculation flag and return.
- */
- goto done;
- }
-
- oseq = pkt->m_pkthdr.pkt_bwseq;
- ots = mach_absolute_time();
-
- if (ifp->if_bw.start_seq > 0 && oseq > ifp->if_bw.start_seq) {
- ts = ots - ifp->if_bw.start_ts;
- if (ts > 0) {
- absolutetime_to_nanoseconds(ts, &t);
- bytes = oseq - ifp->if_bw.start_seq;
- ifp->if_bw.bytes = bytes;
- ifp->if_bw.ts = ts;
-
- if (t > 0) {
- uint64_t bw = 0;
-
- /* Compute bandwidth as bytes/ms */
- bw = (bytes * NSEC_PER_MSEC) / t;
- if (bw > 0) {
- if (ifp->if_bw.bw > 0) {
- u_int32_t shft;
-
- shft = if_bw_smoothing_val;
- /* Compute EWMA of bw */
- ifp->if_bw.bw = (bw +
- ((ifp->if_bw.bw << shft) -
- ifp->if_bw.bw)) >> shft;
- } else {
- ifp->if_bw.bw = bw;
- }
- }
- }
- ifp->if_bw.last_seq = oseq;
- ifp->if_bw.last_ts = ots;
- }