Lines Matching refs:cl

200 	struct rm_class	*cl;
223 cl = malloc(sizeof(struct rm_class), M_DEVBUF, M_WAITOK|M_ZERO);
224 if (cl == NULL)
226 CALLOUT_INIT(&cl->callout_);
228 cl->q_ = malloc(sizeof(class_queue_t), M_DEVBUF, M_WAITOK|M_ZERO);
229 if (cl->q_ == NULL) {
230 free(cl, M_DEVBUF);
237 cl->children_ = NULL;
238 cl->parent_ = parent;
239 cl->borrow_ = borrow;
240 cl->leaf_ = 1;
241 cl->ifdat_ = ifd;
242 cl->pri_ = pri;
243 cl->allotment_ = RM_NS_PER_SEC / nsecPerByte; /* Bytes per sec */
244 cl->depth_ = 0;
245 cl->qthresh_ = 0;
246 cl->ns_per_byte_ = nsecPerByte;
248 qlimit(cl->q_) = maxq;
249 qtype(cl->q_) = Q_DROPHEAD;
250 qlen(cl->q_) = 0;
251 cl->flags_ = flags;
254 cl->minidle_ = (minidle * (int)nsecPerByte) / 8;
255 if (cl->minidle_ > 0)
256 cl->minidle_ = 0;
258 cl->minidle_ = minidle;
260 cl->maxidle_ = (maxidle * nsecPerByte) / 8;
261 if (cl->maxidle_ == 0)
262 cl->maxidle_ = 1;
264 cl->avgidle_ = cl->maxidle_;
265 cl->offtime_ = ((offtime * nsecPerByte) / 8) >> RM_FILTER_GAIN;
266 if (cl->offtime_ == 0)
267 cl->offtime_ = 1;
269 cl->avgidle_ = 0;
270 cl->offtime_ = (offtime * nsecPerByte) / 8;
272 cl->overlimit = action;
290 cl->red_ = red_alloc(0, 0,
291 qlimit(cl->q_) * 10/100,
292 qlimit(cl->q_) * 30/100,
294 if (cl->red_ != NULL)
295 qtype(cl->q_) = Q_RED;
299 cl->red_ = (red_t *)rio_alloc(0, NULL,
301 if (cl->red_ != NULL)
302 qtype(cl->q_) = Q_RIO;
314 cl->peer_ = peer;
317 peer->peer_ = cl;
319 ifd->active_[pri] = cl;
320 cl->peer_ = cl;
323 if (cl->parent_) {
324 cl->next_ = parent->children_;
325 parent->children_ = cl;
333 rmc_depth_compute(cl);
340 ifd->alloc_[pri] += cl->allotment_;
344 return (cl);
348 rmc_modclass(struct rm_class *cl, u_int nsecPerByte, int maxq, u_int maxidle,
355 ifd = cl->ifdat_;
356 old_allotment = cl->allotment_;
359 cl->allotment_ = RM_NS_PER_SEC / nsecPerByte; /* Bytes per sec */
360 cl->qthresh_ = 0;
361 cl->ns_per_byte_ = nsecPerByte;
363 qlimit(cl->q_) = maxq;
366 cl->minidle_ = (minidle * nsecPerByte) / 8;
367 if (cl->minidle_ > 0)
368 cl->minidle_ = 0;
370 cl->minidle_ = minidle;
372 cl->maxidle_ = (maxidle * nsecPerByte) / 8;
373 if (cl->maxidle_ == 0)
374 cl->maxidle_ = 1;
376 cl->avgidle_ = cl->maxidle_;
377 cl->offtime_ = ((offtime * nsecPerByte) / 8) >> RM_FILTER_GAIN;
378 if (cl->offtime_ == 0)
379 cl->offtime_ = 1;
381 cl->avgidle_ = 0;
382 cl->offtime_ = (offtime * nsecPerByte) / 8;
389 ifd->alloc_[cl->pri_] += cl->allotment_ - old_allotment;
409 struct rm_class *cl, *clh;
429 clh = cl = ifd->active_[i];
433 cl->w_allotment_ = 0;
435 cl->w_allotment_ = cl->allotment_ /
437 cl = cl->peer_;
438 } while ((cl != NULL) && (cl != clh));
454 * rmc_depth_compute(struct rm_class *cl) - This function computes the
455 * appropriate depth of class 'cl' and its ancestors.
461 rmc_depth_compute(struct rm_class *cl)
463 rm_class_t *t = cl, *p;
480 * rmc_depth_recompute(struct rm_class *cl) - This function re-computes
487 rmc_depth_recompute(rm_class_t *cl)
492 p = cl;
517 if (cl->depth_ >= 1) {
518 if (cl->children_ == NULL) {
519 cl->depth_ = 0;
520 } else if ((t = cl->children_) != NULL) {
527 rmc_depth_compute(cl);
534 * rmc_delete_class(struct rm_ifdat *ifdat, struct rm_class *cl) - This
542 rmc_delete_class(struct rm_ifdat *ifd, struct rm_class *cl)
547 ASSERT(cl->children_ == NULL);
549 if (cl->sleeping_)
550 CALLOUT_STOP(&cl->callout_);
558 rmc_dropall(cl);
564 if (cl->parent_ != NULL) {
565 head = cl->parent_->children_;
568 ASSERT(head == cl);
569 cl->parent_->children_ = NULL;
570 cl->parent_->leaf_ = 1;
572 if (p == cl) {
573 if (cl == head)
574 cl->parent_->children_ = cl->next_;
576 previous->next_ = cl->next_;
577 cl->next_ = NULL;
589 if ((p = ifd->active_[cl->pri_]) != NULL) {
592 * level, then look for class(cl) in the priority level.
595 while (p->peer_ != cl)
597 p->peer_ = cl->peer_;
599 if (ifd->active_[cl->pri_] == cl)
600 ifd->active_[cl->pri_] = cl->peer_;
602 ASSERT(p == cl);
603 ifd->active_[cl->pri_] = NULL;
611 ifd->alloc_[cl->pri_] -= cl->allotment_;
612 ifd->num_[cl->pri_]--;
620 rmc_depth_recompute(cl->parent_);
630 if (cl->red_ != NULL) {
632 if (q_is_rio(cl->q_))
633 rio_destroy((rio_t *)cl->red_);
636 if (q_is_red(cl->q_))
637 red_destroy(cl->red_);
640 free(cl->q_, M_DEVBUF);
641 free(cl, M_DEVBUF);
737 * rmc_queue_packet(struct rm_class *cl, mbuf_t *m) - Add packet given by
738 * mbuf 'm' to queue for resource class 'cl'. This routine is called
747 rmc_queue_packet(struct rm_class *cl, mbuf_t *m)
750 struct rm_ifdat *ifd = cl->ifdat_;
751 int cpri = cl->pri_;
752 int is_empty = qempty(cl->q_);
756 if (TV_LT(&cl->undertime_, &now)) {
757 if (ifd->cutoff_ > cl->depth_)
758 ifd->cutoff_ = cl->depth_;
759 CBQTRACE(rmc_queue_packet, 'ffoc', cl->depth_);
768 struct rm_class *borrow = cl->borrow_;
781 else if ((ifd->cutoff_ > 1) && cl->borrow_) {
782 if (TV_LT(&cl->borrow_->undertime_, &now)) {
783 ifd->cutoff_ = cl->borrow_->depth_;
785 cl->borrow_->depth_);
791 if (_rmc_addq(cl, m) < 0)
796 CBQTRACE(rmc_queue_packet, 'ytpe', cl->stats_.handle);
800 if (qlen(cl->q_) > qlimit(cl->q_)) {
802 rmc_drop_action(cl);
841 rmc_satisfied(struct rm_class *cl, struct timeval *now)
845 if (cl == NULL)
847 if (TV_LT(now, &cl->undertime_))
849 if (cl->depth_ == 0) {
850 if (!cl->sleeping_ && (qlen(cl->q_) > cl->qthresh_))
855 if (cl->children_ != NULL) {
856 p = cl->children_;
868 * Return 1 if class 'cl' is under limit or can borrow from a parent,
874 rmc_under_limit(struct rm_class *cl, struct timeval *now)
876 rm_class_t *p = cl;
878 struct rm_ifdat *ifd = cl->ifdat_;
882 * If cl is the root class, then always return that it is
885 if (cl->parent_ == NULL)
888 if (cl->sleeping_) {
889 if (TV_LT(now, &cl->undertime_))
892 CALLOUT_STOP(&cl->callout_);
893 cl->sleeping_ = 0;
894 cl->undertime_.tv_sec = 0;
899 while (cl->undertime_.tv_sec && TV_LT(now, &cl->undertime_)) {
900 if (((cl = cl->borrow_) == NULL) ||
901 (cl->depth_ > ifd->cutoff_)) {
903 if (cl != NULL)
915 if (cl != NULL) {
917 top = cl;
930 top = cl;
933 if (cl != p)
934 ifd->borrowed_[ifd->qi_] = cl;
958 struct rm_class *cl = NULL, *first = NULL;
971 cl = ifd->pollcache_;
972 cpri = cl->pri_;
975 if (cl->undertime_.tv_sec != 0 &&
976 rmc_under_limit(cl, &now) == 0)
977 first = cl;
1000 * "M[cl->pri_])" times "cl->allotment" is greater than
1004 cl = ifd->active_[cpri];
1005 ASSERT(cl != NULL);
1007 if ((deficit < 2) && (cl->bytes_alloc_ <= 0))
1008 cl->bytes_alloc_ += cl->w_allotment_;
1009 if (!qempty(cl->q_)) {
1010 if ((cl->undertime_.tv_sec == 0) ||
1011 rmc_under_limit(cl, &now)) {
1012 if (cl->bytes_alloc_ > 0 || deficit > 1)
1021 else if (first == NULL && cl->borrow_ != NULL)
1022 first = cl; /* borrowing candidate */
1025 cl->bytes_alloc_ = 0;
1026 cl = cl->peer_;
1027 } while (cl != ifd->active_[cpri]);
1059 cl = first;
1060 cpri = cl->pri_;
1062 if (cl->sleeping_)
1063 CALLOUT_STOP(&cl->callout_);
1064 cl->sleeping_ = 0;
1065 cl->undertime_.tv_sec = 0;
1067 ifd->borrowed_[ifd->qi_] = cl->borrow_;
1068 ifd->cutoff_ = cl->borrow_->depth_;
1075 m = _rmc_getq(cl);
1078 if (qempty(cl->q_))
1084 if (cl->bytes_alloc_ > 0)
1085 cl->bytes_alloc_ -= m_pktlen(m);
1087 if ((cl->bytes_alloc_ <= 0) || first == cl)
1088 ifd->active_[cl->pri_] = cl->peer_;
1090 ifd->active_[cl->pri_] = cl;
1092 ifd->class_[ifd->qi_] = cl;
1099 m = _rmc_pollq(cl);
1100 ifd->pollcache_ = cl;
1116 struct rm_class *cl, *first = NULL;
1126 cl = ifd->pollcache_;
1127 cpri = cl->pri_;
1141 cl = ifd->active_[cpri];
1142 ASSERT(cl != NULL);
1144 if (!qempty(cl->q_)) {
1145 if ((cl->undertime_.tv_sec == 0) ||
1146 rmc_under_limit(cl, &now))
1148 if (first == NULL && cl->borrow_ != NULL)
1149 first = cl;
1151 cl = cl->peer_;
1152 } while (cl != ifd->active_[cpri]);
1174 cl = first;
1175 cpri = cl->pri_;
1177 if (cl->sleeping_)
1178 CALLOUT_STOP(&cl->callout_);
1179 cl->sleeping_ = 0;
1180 cl->undertime_.tv_sec = 0;
1182 ifd->borrowed_[ifd->qi_] = cl->borrow_;
1183 ifd->cutoff_ = cl->borrow_->depth_;
1190 m = _rmc_getq(cl);
1193 if (qempty(cl->q_))
1196 ifd->active_[cpri] = cl->peer_;
1198 ifd->class_[ifd->qi_] = cl;
1205 m = _rmc_pollq(cl);
1206 ifd->pollcache_ = cl;
1254 rm_class_t *cl, *borrowed;
1261 if ((cl = ifd->class_[ifd->qo_]) == NULL)
1268 PKTCNTR_ADD(&cl->stats_.xmit_cnt, pktlen);
1315 while (cl != NULL) {
1316 TV_DELTA(&ifd->ifnow_, &cl->last_, idle);
1322 cl->avgidle_ = cl->maxidle_;
1326 pkt_time = pktlen * cl->ns_per_byte_;
1329 pkt_time = pktlen * cl->ns_per_byte_ / 1000;
1333 avgidle = cl->avgidle_;
1335 cl->avgidle_ = avgidle;
1339 CBQTRACE(rmc_update_class_util, 'milo', cl->stats_.handle);
1345 if (avgidle < cl->minidle_)
1346 avgidle = cl->avgidle_ = cl->minidle_;
1351 TV_ADD_DELTA(nowp, tidle, &cl->undertime_);
1352 ++cl->stats_.over;
1354 cl->avgidle_ =
1355 (avgidle > cl->maxidle_) ? cl->maxidle_ : avgidle;
1356 cl->undertime_.tv_sec = 0;
1357 if (cl->sleeping_) {
1358 CALLOUT_STOP(&cl->callout_);
1359 cl->sleeping_ = 0;
1364 if (borrows != cl)
1365 ++cl->stats_.borrows;
1369 cl->last_ = ifd->ifnow_;
1370 cl->last_pkttime_ = pkt_time;
1373 if (cl->parent_ == NULL) {
1375 PKTCNTR_ADD(&cl->stats_.xmit_cnt, pktlen);
1379 cl = cl->parent_;
1385 cl = ifd->class_[ifd->qo_];
1388 if ((qlen(cl->q_) <= 0) || TV_LT(nowp, &borrowed->undertime_)) {
1396 if ((qlen(cl->q_) <= 1) || TV_LT(&now, &borrowed->undertime_)) {
1420 * rmc_drop_action(struct rm_class *cl) - Generic (not protocol-specific)
1429 rmc_drop_action(struct rm_class *cl)
1431 struct rm_ifdat *ifd = cl->ifdat_;
1433 ASSERT(qlen(cl->q_) > 0);
1434 _rmc_dropq(cl);
1435 if (qempty(cl->q_))
1436 ifd->na_[cl->pri_]--;
1440 rmc_dropall(struct rm_class *cl)
1442 struct rm_ifdat *ifd = cl->ifdat_;
1444 if (!qempty(cl->q_)) {
1445 _flushq(cl->q_);
1447 ifd->na_[cl->pri_]--;
1468 * rmc_delay_action(struct rm_class *cl) - This function is the generic CBQ
1479 rmc_delay_action(struct rm_class *cl, struct rm_class *borrow)
1483 cl->stats_.overactions++;
1484 TV_DELTA(&cl->undertime_, &cl->overtime_, ndelay);
1486 ndelay += cl->offtime_;
1489 if (!cl->sleeping_) {
1490 CBQTRACE(rmc_delay_action, 'yled', cl->stats_.handle);
1496 extradelay = cl->offtime_;
1507 extradelay -= cl->last_pkttime_;
1510 TV_ADD_DELTA(&cl->undertime_, extradelay, &cl->undertime_);
1514 cl->sleeping_ = 1;
1515 cl->stats_.delays++;
1527 t = tvhzto(&cl->undertime_);
1530 t = tvhzto(&cl->undertime_) + 1;
1534 CALLOUT_RESET(&cl->callout_, t,
1535 (timeout_t *)rmc_restart, (void *)cl);
1557 rmc_restart(struct rm_class *cl)
1559 struct rm_ifdat *ifd = cl->ifdat_;
1563 if (cl->sleeping_) {
1564 cl->sleeping_ = 0;
1565 cl->undertime_.tv_sec = 0;
1568 CBQTRACE(rmc_restart, 'trts', cl->stats_.handle);
1577 * rmc_root_overlimit(struct rm_class *cl) - This the generic overlimit
1584 rmc_root_overlimit(struct rm_class *cl,
1597 _rmc_addq(rm_class_t *cl, mbuf_t *m)
1600 if (q_is_rio(cl->q_))
1601 return rio_addq((rio_t *)cl->red_, cl->q_, m, cl->pktattr_);
1604 if (q_is_red(cl->q_))
1605 return red_addq(cl->red_, cl->q_, m, cl->pktattr_);
1608 if (cl->flags_ & RMCF_CLEARDSCP)
1609 write_dsfield(m, cl->pktattr_, 0);
1611 _addq(cl->q_, m);
1617 _rmc_dropq(rm_class_t *cl)
1621 if ((m = _getq(cl->q_)) != NULL)
1626 _rmc_getq(rm_class_t *cl)
1629 if (q_is_rio(cl->q_))
1630 return rio_getq((rio_t *)cl->red_, cl->q_);
1633 if (q_is_red(cl->q_))
1634 return red_getq(cl->red_, cl->q_);
1636 return _getq(cl->q_);
1640 _rmc_pollq(rm_class_t *cl)
1642 return qhead(cl->q_);