Lines Matching refs:bw
909 bandwidth_limit_init(struct bwlimit *bw, u_int64_t kbps, size_t buflen) in bandwidth_limit_init() argument
911 bw->buflen = buflen; in bandwidth_limit_init()
912 bw->rate = kbps; in bandwidth_limit_init()
913 bw->thresh = bw->rate; in bandwidth_limit_init()
914 bw->lamt = 0; in bandwidth_limit_init()
915 timerclear(&bw->bwstart); in bandwidth_limit_init()
916 timerclear(&bw->bwend); in bandwidth_limit_init()
921 bandwidth_limit(struct bwlimit *bw, size_t read_len) in bandwidth_limit() argument
926 if (!timerisset(&bw->bwstart)) { in bandwidth_limit()
927 gettimeofday(&bw->bwstart, NULL); in bandwidth_limit()
931 bw->lamt += read_len; in bandwidth_limit()
932 if (bw->lamt < bw->thresh) in bandwidth_limit()
935 gettimeofday(&bw->bwend, NULL); in bandwidth_limit()
936 timersub(&bw->bwend, &bw->bwstart, &bw->bwend); in bandwidth_limit()
937 if (!timerisset(&bw->bwend)) in bandwidth_limit()
940 bw->lamt *= 8; in bandwidth_limit()
941 waitlen = (double)1000000L * bw->lamt / bw->rate; in bandwidth_limit()
943 bw->bwstart.tv_sec = waitlen / 1000000L; in bandwidth_limit()
944 bw->bwstart.tv_usec = waitlen % 1000000L; in bandwidth_limit()
946 if (timercmp(&bw->bwstart, &bw->bwend, >)) { in bandwidth_limit()
947 timersub(&bw->bwstart, &bw->bwend, &bw->bwend); in bandwidth_limit()
950 if (bw->bwend.tv_sec) { in bandwidth_limit()
951 bw->thresh /= 2; in bandwidth_limit()
952 if (bw->thresh < bw->buflen / 4) in bandwidth_limit()
953 bw->thresh = bw->buflen / 4; in bandwidth_limit()
954 } else if (bw->bwend.tv_usec < 10000) { in bandwidth_limit()
955 bw->thresh *= 2; in bandwidth_limit()
956 if (bw->thresh > bw->buflen * 8) in bandwidth_limit()
957 bw->thresh = bw->buflen * 8; in bandwidth_limit()
960 TIMEVAL_TO_TIMESPEC(&bw->bwend, &ts); in bandwidth_limit()
968 bw->lamt = 0; in bandwidth_limit()
969 gettimeofday(&bw->bwstart, NULL); in bandwidth_limit()