MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_source_intr

Function ng_source_intr

freebsd/netgraph/ng_source.c:725–767  ·  view source on GitHub ↗

* While active called every NG_SOURCE_INTR_TICKS ticks. * Sends as many packets as the interface connected to our * output hook is able to enqueue. */

Source from the content-addressed store, hash-verified

723 * output hook is able to enqueue.
724 */
725static void
726ng_source_intr(node_p node, hook_p hook, void *arg1, int arg2)
727{
728 sc_p sc = (sc_p)arg1;
729 struct ifqueue *ifq;
730 int packets;
731
732 KASSERT(sc != NULL, ("%s: null node private", __func__));
733
734 if (sc->packets == 0 || sc->output == NULL
735 || (sc->node->nd_flags & NG_SOURCE_ACTIVE) == 0) {
736 ng_source_stop(sc);
737 return;
738 }
739
740 if (sc->output_ifp != NULL) {
741 ifq = (struct ifqueue *)&sc->output_ifp->if_snd;
742 packets = ifq->ifq_maxlen - ifq->ifq_len;
743 } else
744 packets = sc->snd_queue.ifq_len;
745
746 if (sc->stats.maxPps != 0) {
747 struct timeval now, elapsed;
748 uint64_t usec;
749 int maxpkt;
750
751 getmicrotime(&now);
752 elapsed = now;
753 timevalsub(&elapsed, &sc->stats.lastTime);
754 usec = elapsed.tv_sec * 1000000 + elapsed.tv_usec;
755 maxpkt = (uint64_t)sc->stats.maxPps * usec / 1000000;
756 sc->stats.lastTime = now;
757 if (packets > maxpkt)
758 packets = maxpkt;
759 }
760
761 ng_source_send(sc, packets, NULL);
762 if (sc->packets == 0)
763 ng_source_stop(sc);
764 else
765 ng_callout(&sc->intr_ch, node, NULL, NG_SOURCE_INTR_TICKS,
766 ng_source_intr, sc, 0);
767}
768
769/*
770 * Send packets out our output hook.

Callers

nothing calls this directly

Calls 5

ng_source_stopFunction · 0.85
getmicrotimeFunction · 0.85
ng_source_sendFunction · 0.85
ng_calloutFunction · 0.70
timevalsubFunction · 0.50

Tested by

no test coverage detected