Lines Matching refs:cl
244 struct rm_class *cl;
290 cl = zalloc(rmc_zone);
291 if (cl == NULL)
294 bzero(cl, rmc_size);
295 CALLOUT_INIT(&cl->callout_);
300 cl->children_ = NULL;
301 cl->parent_ = parent;
302 cl->borrow_ = borrow;
303 cl->leaf_ = 1;
304 cl->ifdat_ = ifd;
305 cl->pri_ = pri;
306 cl->allotment_ = RM_NS_PER_SEC / nsecPerByte; /* Bytes per sec */
307 cl->depth_ = 0;
308 cl->qthresh_ = 0;
309 cl->ns_per_byte_ = nsecPerByte;
319 _qinit(&cl->q_, Q_DROPHEAD, maxq);
321 cl->flags_ = flags;
323 cl->minidle_ = (minidle * (int)nsecPerByte) / 8;
324 if (cl->minidle_ > 0)
325 cl->minidle_ = 0;
327 cl->maxidle_ = (maxidle * nsecPerByte) / 8;
328 if (cl->maxidle_ == 0)
329 cl->maxidle_ = 1;
331 cl->avgidle_ = cl->maxidle_;
332 cl->offtime_ = ((offtime * nsecPerByte) / 8) >> RM_FILTER_GAIN;
333 if (cl->offtime_ == 0)
334 cl->offtime_ = 1;
336 cl->overlimit = action;
341 cl->qflags_ = 0;
344 cl->qflags_ |= BLUEF_ECN;
346 cl->qflags_ |= SFBF_ECN;
348 cl->qflags_ |= REDF_ECN;
350 cl->qflags_ |= RIOF_ECN;
354 cl->qflags_ |= SFBF_FLOWCTL;
358 cl->qflags_ |= REDF_FLOWVALVE;
362 cl->qflags_ |= RIOF_CLEARDSCP;
369 cl->red_ = red_alloc(ifp, 0, 0,
370 qlimit(&cl->q_) * 10/100,
371 qlimit(&cl->q_) * 30/100,
372 cl->qflags_, pkttime);
373 if (cl->red_ != NULL)
374 qtype(&cl->q_) = Q_RED;
379 cl->rio_ =
380 rio_alloc(ifp, 0, NULL, cl->qflags_, pkttime);
381 if (cl->rio_ != NULL)
382 qtype(&cl->q_) = Q_RIO;
387 cl->blue_ = blue_alloc(ifp, 0, 0, cl->qflags_);
388 if (cl->blue_ != NULL)
389 qtype(&cl->q_) = Q_BLUE;
393 if (!(cl->flags_ & RMCF_LAZY))
394 cl->sfb_ = sfb_alloc(ifp, qid,
395 qlimit(&cl->q_), cl->qflags_);
396 if (cl->sfb_ != NULL || (cl->flags_ & RMCF_LAZY))
397 qtype(&cl->q_) = Q_SFB;
406 cl->peer_ = peer;
409 peer->peer_ = cl;
411 ifd->active_[pri] = cl;
412 cl->peer_ = cl;
415 if (cl->parent_) {
416 cl->next_ = parent->children_;
417 parent->children_ = cl;
425 rmc_depth_compute(cl);
432 ifd->alloc_[pri] += cl->allotment_;
435 return (cl);
439 rmc_modclass(struct rm_class *cl, u_int32_t nsecPerByte, int maxq,
446 ifd = cl->ifdat_;
447 old_allotment = cl->allotment_;
449 cl->allotment_ = RM_NS_PER_SEC / nsecPerByte; /* Bytes per sec */
450 cl->qthresh_ = 0;
451 cl->ns_per_byte_ = nsecPerByte;
453 qlimit(&cl->q_) = maxq;
455 cl->minidle_ = (minidle * nsecPerByte) / 8;
456 if (cl->minidle_ > 0)
457 cl->minidle_ = 0;
459 cl->maxidle_ = (maxidle * nsecPerByte) / 8;
460 if (cl->maxidle_ == 0)
461 cl->maxidle_ = 1;
463 cl->avgidle_ = cl->maxidle_;
464 cl->offtime_ = ((offtime * nsecPerByte) / 8) >> RM_FILTER_GAIN;
465 if (cl->offtime_ == 0)
466 cl->offtime_ = 1;
472 ifd->alloc_[cl->pri_] += cl->allotment_ - old_allotment;
491 struct rm_class *cl, *clh;
512 clh = cl = ifd->active_[i];
516 cl->w_allotment_ = 0;
518 cl->w_allotment_ =
519 cl->allotment_ / ifd->M_[i];
521 cl = cl->peer_;
522 } while ((cl != NULL) && (cl != clh));
538 * rmc_depth_compute(struct rm_class *cl) - This function computes the
539 * appropriate depth of class 'cl' and its ancestors.
545 rmc_depth_compute(struct rm_class *cl)
547 rm_class_t *t = cl, *p;
564 * rmc_depth_recompute(struct rm_class *cl) - This function re-computes
571 rmc_depth_recompute(rm_class_t *cl)
575 p = cl;
601 * rmc_delete_class(struct rm_ifdat *ifdat, struct rm_class *cl) - This
609 rmc_delete_class(struct rm_ifdat *ifd, struct rm_class *cl)
613 VERIFY(cl->children_ == NULL);
615 if (cl->sleeping_)
616 CALLOUT_STOP(&cl->callout_);
623 rmc_dropall(cl);
629 if (cl->parent_ != NULL) {
630 head = cl->parent_->children_;
633 VERIFY(head == cl);
634 cl->parent_->children_ = NULL;
635 cl->parent_->leaf_ = 1;
637 if (p == cl) {
638 if (cl == head)
639 cl->parent_->children_ = cl->next_;
641 previous->next_ = cl->next_;
642 cl->next_ = NULL;
654 if ((p = ifd->active_[cl->pri_]) != NULL) {
657 * level, then look for class(cl) in the priority level.
660 while (p->peer_ != cl)
662 p->peer_ = cl->peer_;
664 if (ifd->active_[cl->pri_] == cl)
665 ifd->active_[cl->pri_] = cl->peer_;
667 VERIFY(p == cl);
668 ifd->active_[cl->pri_] = NULL;
676 ifd->alloc_[cl->pri_] -= cl->allotment_;
677 ifd->num_[cl->pri_]--;
684 rmc_depth_recompute(cl->parent_);
689 if (cl->qalg_.ptr != NULL) {
691 if (q_is_rio(&cl->q_))
692 rio_destroy(cl->rio_);
695 if (q_is_red(&cl->q_))
696 red_destroy(cl->red_);
699 if (q_is_blue(&cl->q_))
700 blue_destroy(cl->blue_);
702 if (q_is_sfb(&cl->q_) && cl->sfb_ != NULL)
703 sfb_destroy(cl->sfb_);
704 cl->qalg_.ptr = NULL;
705 qtype(&cl->q_) = Q_DROPTAIL;
706 qstate(&cl->q_) = QS_RUNNING;
708 zfree(rmc_zone, cl);
809 * rmc_queue_packet(struct rm_class *cl, struct mbuf *m) - Add packet given by
810 * mbuf 'm' to queue for resource class 'cl'. This routine is called
819 rmc_queue_packet(struct rm_class *cl, struct mbuf *m, struct pf_mtag *t)
822 struct rm_ifdat *ifd = cl->ifdat_;
823 int cpri = cl->pri_;
824 int is_empty = qempty(&cl->q_);
829 if (TV_LT(&cl->undertime_, &now)) {
830 if (ifd->cutoff_ > cl->depth_)
831 ifd->cutoff_ = cl->depth_;
832 CBQTRACE(rmc_queue_packet, 'ffoc', cl->depth_);
839 struct rm_class *borrow = cl->borrow_;
854 ret = _rmc_addq(cl, m, t);
863 CBQTRACE(rmc_queue_packet, 'type', cl->stats_.handle);
867 if (qlen(&cl->q_) > qlimit(&cl->q_)) {
869 rmc_drop_action(cl);
908 rmc_satisfied(struct rm_class *cl, struct timeval *now)
912 if (cl == NULL)
914 if (TV_LT(now, &cl->undertime_))
916 if (cl->depth_ == 0) {
917 if (!cl->sleeping_ && (qlen(&cl->q_) > cl->qthresh_))
922 if (cl->children_ != NULL) {
923 p = cl->children_;
935 * Return 1 if class 'cl' is under limit or can borrow from a parent,
941 rmc_under_limit(struct rm_class *cl, struct timeval *now)
943 rm_class_t *p = cl;
945 struct rm_ifdat *ifd = cl->ifdat_;
949 * If cl is the root class, then always return that it is
952 if (cl->parent_ == NULL)
955 if (cl->sleeping_) {
956 if (TV_LT(now, &cl->undertime_))
959 CALLOUT_STOP(&cl->callout_);
960 cl->sleeping_ = 0;
961 cl->undertime_.tv_sec = 0;
966 while (cl->undertime_.tv_sec && TV_LT(now, &cl->undertime_)) {
967 if (((cl = cl->borrow_) == NULL) ||
968 (cl->depth_ > ifd->cutoff_)) {
970 if (cl != NULL)
984 if (cl != NULL) {
989 top = cl;
1002 top = cl;
1005 if (cl != p)
1006 ifd->borrowed_[ifd->qi_] = cl;
1030 struct rm_class *cl = NULL, *first = NULL;
1043 cl = ifd->pollcache_;
1044 cpri = cl->pri_;
1047 if (cl->undertime_.tv_sec != 0 &&
1048 rmc_under_limit(cl, &now) == 0)
1049 first = cl;
1071 * "M[cl->pri_])" times "cl->allotment" is greater than
1075 cl = ifd->active_[cpri];
1076 VERIFY(cl != NULL);
1078 if ((deficit < 2) && (cl->bytes_alloc_ <= 0))
1079 cl->bytes_alloc_ += cl->w_allotment_;
1080 if (!qempty(&cl->q_)) {
1081 if ((cl->undertime_.tv_sec == 0) ||
1082 rmc_under_limit(cl, &now)) {
1083 if (cl->bytes_alloc_ > 0 || deficit > 1)
1091 } else if (first == NULL && cl->borrow_ != NULL)
1092 first = cl; /* borrowing candidate */
1095 cl->bytes_alloc_ = 0;
1096 cl = cl->peer_;
1097 } while (cl != ifd->active_[cpri]);
1129 cl = first;
1130 cpri = cl->pri_;
1132 if (cl->sleeping_)
1133 CALLOUT_STOP(&cl->callout_);
1134 cl->sleeping_ = 0;
1135 cl->undertime_.tv_sec = 0;
1137 ifd->borrowed_[ifd->qi_] = cl->borrow_;
1138 ifd->cutoff_ = cl->borrow_->depth_;
1145 m = _rmc_getq(cl);
1149 if (qempty(&cl->q_))
1155 if (cl->bytes_alloc_ > 0)
1156 cl->bytes_alloc_ -= m_pktlen(m);
1158 if ((cl->bytes_alloc_ <= 0) || first == cl)
1159 ifd->active_[cl->pri_] = cl->peer_;
1161 ifd->active_[cl->pri_] = cl;
1163 ifd->class_[ifd->qi_] = cl;
1170 m = _rmc_pollq(cl);
1171 ifd->pollcache_ = cl;
1187 struct rm_class *cl, *first = NULL;
1197 cl = ifd->pollcache_;
1198 cpri = cl->pri_;
1212 cl = ifd->active_[cpri];
1213 VERIFY(cl != NULL);
1215 if (!qempty(&cl->q_)) {
1216 if ((cl->undertime_.tv_sec == 0) ||
1217 rmc_under_limit(cl, &now))
1219 if (first == NULL && cl->borrow_ != NULL)
1220 first = cl;
1222 cl = cl->peer_;
1223 } while (cl != ifd->active_[cpri]);
1245 cl = first;
1246 cpri = cl->pri_;
1248 if (cl->sleeping_)
1249 CALLOUT_STOP(&cl->callout_);
1250 cl->sleeping_ = 0;
1251 cl->undertime_.tv_sec = 0;
1253 ifd->borrowed_[ifd->qi_] = cl->borrow_;
1254 ifd->cutoff_ = cl->borrow_->depth_;
1261 m = _rmc_getq(cl);
1265 if (qempty(&cl->q_))
1268 ifd->active_[cpri] = cl->peer_;
1270 ifd->class_[ifd->qi_] = cl;
1277 m = _rmc_pollq(cl);
1278 ifd->pollcache_ = cl;
1326 rm_class_t *cl, *borrowed;
1333 if ((cl = ifd->class_[ifd->qo_]) == NULL)
1340 PKTCNTR_ADD(&cl->stats_.xmit_cnt, 1, pktlen);
1387 while (cl != NULL) {
1388 TV_DELTA(&ifd->ifnow_, &cl->last_, idle);
1394 cl->avgidle_ = cl->maxidle_;
1398 pkt_time = pktlen * cl->ns_per_byte_;
1401 pkt_time = pktlen * cl->ns_per_byte_ / 1000;
1405 avgidle = cl->avgidle_;
1407 cl->avgidle_ = avgidle;
1412 cl->stats_.handle);
1417 if (avgidle < cl->minidle_)
1418 avgidle = cl->avgidle_ = cl->minidle_;
1423 TV_ADD_DELTA(nowp, tidle, &cl->undertime_);
1424 ++cl->stats_.over;
1426 cl->avgidle_ =
1427 (avgidle > cl->maxidle_) ? cl->maxidle_ : avgidle;
1428 cl->undertime_.tv_sec = 0;
1429 if (cl->sleeping_) {
1430 CALLOUT_STOP(&cl->callout_);
1431 cl->sleeping_ = 0;
1436 if (borrows != cl)
1437 ++cl->stats_.borrows;
1441 cl->last_ = ifd->ifnow_;
1442 cl->last_pkttime_ = pkt_time;
1445 if (cl->parent_ == NULL) {
1447 PKTCNTR_ADD(&cl->stats_.xmit_cnt, 1, pktlen);
1451 cl = cl->parent_;
1457 cl = ifd->class_[ifd->qo_];
1459 if ((qlen(&cl->q_) <= 0) ||
1481 * rmc_drop_action(struct rm_class *cl) - Generic (not protocol-specific)
1490 rmc_drop_action(struct rm_class *cl)
1492 struct rm_ifdat *ifd = cl->ifdat_;
1494 VERIFY(qlen(&cl->q_) > 0);
1496 _rmc_dropq(cl);
1497 if (qempty(&cl->q_))
1498 ifd->na_[cl->pri_]--;
1502 rmc_drop(struct rm_class *cl, u_int32_t flow, u_int32_t *packets,
1505 struct rm_ifdat *ifd = cl->ifdat_;
1509 if ((qlen = qlen(&cl->q_)) != 0) {
1512 if (q_is_rio(&cl->q_))
1513 rio_purgeq(cl->rio_, &cl->q_, flow, &pkt, &len);
1517 if (q_is_red(&cl->q_))
1518 red_purgeq(cl->red_, &cl->q_, flow, &pkt, &len);
1522 if (q_is_blue(&cl->q_))
1523 blue_purgeq(cl->blue_, &cl->q_, flow, &pkt, &len);
1526 if (q_is_sfb(&cl->q_) && cl->sfb_ != NULL)
1527 sfb_purgeq(cl->sfb_, &cl->q_, flow, &pkt, &len);
1529 _flushq_flow(&cl->q_, flow, &pkt, &len);
1532 VERIFY(qlen(&cl->q_) == (qlen - pkt));
1534 PKTCNTR_ADD(&cl->stats_.drop_cnt, pkt, len);
1540 if (qempty(&cl->q_))
1541 ifd->na_[cl->pri_]--;
1551 rmc_dropall(struct rm_class *cl)
1553 rmc_drop(cl, 0, NULL, NULL);
1558 * rmc_delay_action(struct rm_class *cl) - This function is the generic CBQ
1569 rmc_delay_action(struct rm_class *cl, struct rm_class *borrow)
1573 cl->stats_.overactions++;
1574 TV_DELTA(&cl->undertime_, &cl->overtime_, ndelay);
1576 ndelay += cl->offtime_;
1579 if (!cl->sleeping_) {
1580 CBQTRACE(rmc_delay_action, 'yled', cl->stats_.handle);
1586 extradelay = cl->offtime_;
1596 extradelay -= cl->last_pkttime_;
1598 TV_ADD_DELTA(&cl->undertime_, extradelay,
1599 &cl->undertime_);
1603 cl->sleeping_ = 1;
1604 cl->stats_.delays++;
1618 t = hzto(&cl->undertime_) + 1;
1622 CALLOUT_RESET(&cl->callout_, t,
1623 (timeout_t *)rmc_restart, (caddr_t)cl);
1643 rmc_restart(struct rm_class *cl)
1645 struct rm_ifdat *ifd = cl->ifdat_;
1647 if (cl->sleeping_) {
1648 cl->sleeping_ = 0;
1649 cl->undertime_.tv_sec = 0;
1652 CBQTRACE(rmc_restart, 'trts', cl->stats_.handle);
1660 * rmc_root_overlimit(struct rm_class *cl) - This the generic overlimit
1666 rmc_root_overlimit(struct rm_class *cl,
1669 #pragma unused(cl, borrow)
1680 _rmc_addq(rm_class_t *cl, struct mbuf *m, struct pf_mtag *t)
1683 if (q_is_rio(&cl->q_))
1684 return (rio_addq(cl->rio_, &cl->q_, m, t));
1688 if (q_is_red(&cl->q_))
1689 return (red_addq(cl->red_, &cl->q_, m, t));
1693 if (q_is_blue(&cl->q_))
1694 return (blue_addq(cl->blue_, &cl->q_, m, t));
1697 if (q_is_sfb(&cl->q_)) {
1698 if (cl->sfb_ == NULL) {
1699 struct ifclassq *ifq = cl->ifdat_->ifq_;
1702 VERIFY(cl->flags_ & RMCF_LAZY);
1705 cl->sfb_ = sfb_alloc(ifp, cl->stats_.handle,
1706 qlimit(&cl->q_), cl->qflags_);
1707 if (cl->sfb_ == NULL) {
1709 qtype(&cl->q_) = Q_DROPTAIL;
1710 cl->flags_ &= ~RMCF_SFB;
1711 cl->qflags_ &= ~(SFBF_ECN | SFBF_FLOWCTL);
1716 cl->stats_.handle, cl->pri_);
1719 if (cl->sfb_ != NULL)
1720 return (sfb_addq(cl->sfb_, &cl->q_, m, t));
1721 } else if (cl->flags_ & RMCF_CLEARDSCP)
1725 _addq(&cl->q_, m);
1731 _rmc_dropq(rm_class_t *cl)
1735 if ((m = _rmc_getq(cl)) != NULL)
1740 _rmc_getq(rm_class_t *cl)
1743 if (q_is_rio(&cl->q_))
1744 return (rio_getq(cl->rio_, &cl->q_));
1748 if (q_is_red(&cl->q_))
1749 return (red_getq(cl->red_, &cl->q_));
1753 if (q_is_blue(&cl->q_))
1754 return (blue_getq(cl->blue_, &cl->q_));
1757 if (q_is_sfb(&cl->q_) && cl->sfb_ != NULL)
1758 return (sfb_getq(cl->sfb_, &cl->q_));
1760 return (_getq(&cl->q_));
1764 _rmc_pollq(rm_class_t *cl)
1766 return (qhead(&cl->q_));
1770 rmc_updateq(rm_class_t *cl, cqev_t ev)
1773 if (q_is_rio(&cl->q_))
1774 return (rio_updateq(cl->rio_, ev));
1777 if (q_is_red(&cl->q_))
1778 return (red_updateq(cl->red_, ev));
1781 if (q_is_blue(&cl->q_))
1782 return (blue_updateq(cl->blue_, ev));
1784 if (q_is_sfb(&cl->q_) && cl->sfb_ != NULL)
1785 return (sfb_updateq(cl->sfb_, ev));