Lines Matching full:q
200 static bool loss_4state(struct netem_sched_data *q) in loss_4state() argument
202 struct clgstate *clg = &q->clg; in loss_4state()
265 static bool loss_gilb_ell(struct netem_sched_data *q) in loss_gilb_ell() argument
267 struct clgstate *clg = &q->clg; in loss_gilb_ell()
286 static bool loss_event(struct netem_sched_data *q) in loss_event() argument
288 switch (q->loss_model) { in loss_event()
291 return q->loss && q->loss >= get_crandom(&q->loss_cor); in loss_event()
299 return loss_4state(q); in loss_event()
307 return loss_gilb_ell(q); in loss_event()
345 static u64 packet_time_ns(u64 len, const struct netem_sched_data *q) in packet_time_ns() argument
347 len += q->packet_overhead; in packet_time_ns()
349 if (q->cell_size) { in packet_time_ns()
350 u32 cells = reciprocal_divide(len, q->cell_size_reciprocal); in packet_time_ns()
352 if (len > cells * q->cell_size) /* extra cell needed for remainder */ in packet_time_ns()
354 len = cells * (q->cell_size + q->cell_overhead); in packet_time_ns()
357 return div64_u64(len * NSEC_PER_SEC, q->rate); in packet_time_ns()
362 struct netem_sched_data *q = qdisc_priv(sch); in tfifo_reset() local
363 struct rb_node *p = rb_first(&q->t_root); in tfifo_reset()
369 rb_erase(&skb->rbnode, &q->t_root); in tfifo_reset()
373 rtnl_kfree_skbs(q->t_head, q->t_tail); in tfifo_reset()
374 q->t_head = NULL; in tfifo_reset()
375 q->t_tail = NULL; in tfifo_reset()
380 struct netem_sched_data *q = qdisc_priv(sch); in tfifo_enqueue() local
383 if (!q->t_tail || tnext >= netem_skb_cb(q->t_tail)->time_to_send) { in tfifo_enqueue()
384 if (q->t_tail) in tfifo_enqueue()
385 q->t_tail->next = nskb; in tfifo_enqueue()
387 q->t_head = nskb; in tfifo_enqueue()
388 q->t_tail = nskb; in tfifo_enqueue()
390 struct rb_node **p = &q->t_root.rb_node, *parent = NULL; in tfifo_enqueue()
403 rb_insert_color(&nskb->rbnode, &q->t_root); in tfifo_enqueue()
405 sch->q.qlen++; in tfifo_enqueue()
437 struct netem_sched_data *q = qdisc_priv(sch); in netem_enqueue() local
451 if (q->duplicate && q->duplicate >= get_crandom(&q->dup_cor)) in netem_enqueue()
455 if (loss_event(q)) { in netem_enqueue()
456 if (q->ecn && INET_ECN_set_ce(skb)) in netem_enqueue()
470 if (q->latency || q->jitter || q->rate) in netem_enqueue()
480 u32 dupsave = q->duplicate; /* prevent duplicating a dup... */ in netem_enqueue()
482 q->duplicate = 0; in netem_enqueue()
484 q->duplicate = dupsave; in netem_enqueue()
494 if (q->corrupt && q->corrupt >= get_crandom(&q->corrupt_cor)) { in netem_enqueue()
520 if (unlikely(sch->q.qlen >= sch->limit)) { in netem_enqueue()
530 if (q->gap == 0 || /* not doing reordering */ in netem_enqueue()
531 q->counter < q->gap - 1 || /* inside last reordering gap */ in netem_enqueue()
532 q->reorder < get_crandom(&q->reorder_cor)) { in netem_enqueue()
536 delay = tabledist(q->latency, q->jitter, in netem_enqueue()
537 &q->delay_cor, q->delay_dist); in netem_enqueue()
541 if (q->rate) { in netem_enqueue()
544 if (sch->q.tail) in netem_enqueue()
545 last = netem_skb_cb(sch->q.tail); in netem_enqueue()
546 if (q->t_root.rb_node) { in netem_enqueue()
550 t_skb = skb_rb_last(&q->t_root); in netem_enqueue()
556 if (q->t_tail) { in netem_enqueue()
558 netem_skb_cb(q->t_tail); in netem_enqueue()
576 delay += packet_time_ns(qdisc_pkt_len(skb), q); in netem_enqueue()
580 ++q->counter; in netem_enqueue()
588 q->counter = 0; in netem_enqueue()
590 __qdisc_enqueue_head(skb, &sch->q); in netem_enqueue()
629 static void get_slot_next(struct netem_sched_data *q, u64 now) in get_slot_next() argument
633 if (!q->slot_dist) in get_slot_next()
634 next_delay = q->slot_config.min_delay + in get_slot_next()
636 (q->slot_config.max_delay - in get_slot_next()
637 q->slot_config.min_delay) >> 32); in get_slot_next()
639 next_delay = tabledist(q->slot_config.dist_delay, in get_slot_next()
640 (s32)(q->slot_config.dist_jitter), in get_slot_next()
641 NULL, q->slot_dist); in get_slot_next()
643 q->slot.slot_next = now + next_delay; in get_slot_next()
644 q->slot.packets_left = q->slot_config.max_packets; in get_slot_next()
645 q->slot.bytes_left = q->slot_config.max_bytes; in get_slot_next()
648 static struct sk_buff *netem_peek(struct netem_sched_data *q) in netem_peek() argument
650 struct sk_buff *skb = skb_rb_first(&q->t_root); in netem_peek()
654 return q->t_head; in netem_peek()
655 if (!q->t_head) in netem_peek()
659 t2 = netem_skb_cb(q->t_head)->time_to_send; in netem_peek()
662 return q->t_head; in netem_peek()
665 static void netem_erase_head(struct netem_sched_data *q, struct sk_buff *skb) in netem_erase_head() argument
667 if (skb == q->t_head) { in netem_erase_head()
668 q->t_head = skb->next; in netem_erase_head()
669 if (!q->t_head) in netem_erase_head()
670 q->t_tail = NULL; in netem_erase_head()
672 rb_erase(&skb->rbnode, &q->t_root); in netem_erase_head()
678 struct netem_sched_data *q = qdisc_priv(sch); in netem_dequeue() local
682 skb = __qdisc_dequeue_head(&sch->q); in netem_dequeue()
689 skb = netem_peek(q); in netem_dequeue()
696 if (q->slot.slot_next && q->slot.slot_next < time_to_send) in netem_dequeue()
697 get_slot_next(q, now); in netem_dequeue()
699 if (time_to_send <= now && q->slot.slot_next <= now) { in netem_dequeue()
700 netem_erase_head(q, skb); in netem_dequeue()
701 sch->q.qlen--; in netem_dequeue()
710 if (q->slot.slot_next) { in netem_dequeue()
711 q->slot.packets_left--; in netem_dequeue()
712 q->slot.bytes_left -= qdisc_pkt_len(skb); in netem_dequeue()
713 if (q->slot.packets_left <= 0 || in netem_dequeue()
714 q->slot.bytes_left <= 0) in netem_dequeue()
715 get_slot_next(q, now); in netem_dequeue()
718 if (q->qdisc) { in netem_dequeue()
723 err = qdisc_enqueue(skb, q->qdisc, &to_free); in netem_dequeue()
736 if (q->qdisc) { in netem_dequeue()
737 skb = q->qdisc->ops->dequeue(q->qdisc); in netem_dequeue()
742 qdisc_watchdog_schedule_ns(&q->watchdog, in netem_dequeue()
744 q->slot.slot_next)); in netem_dequeue()
747 if (q->qdisc) { in netem_dequeue()
748 skb = q->qdisc->ops->dequeue(q->qdisc); in netem_dequeue()
757 struct netem_sched_data *q = qdisc_priv(sch); in netem_reset() local
761 if (q->qdisc) in netem_reset()
762 qdisc_reset(q->qdisc); in netem_reset()
763 qdisc_watchdog_cancel(&q->watchdog); in netem_reset()
806 static void get_slot(struct netem_sched_data *q, const struct nlattr *attr) in get_slot() argument
810 q->slot_config = *c; in get_slot()
811 if (q->slot_config.max_packets == 0) in get_slot()
812 q->slot_config.max_packets = INT_MAX; in get_slot()
813 if (q->slot_config.max_bytes == 0) in get_slot()
814 q->slot_config.max_bytes = INT_MAX; in get_slot()
817 q->slot_config.dist_jitter = min_t(__s64, INT_MAX, abs(q->slot_config.dist_jitter)); in get_slot()
819 q->slot.packets_left = q->slot_config.max_packets; in get_slot()
820 q->slot.bytes_left = q->slot_config.max_bytes; in get_slot()
821 if (q->slot_config.min_delay | q->slot_config.max_delay | in get_slot()
822 q->slot_config.dist_jitter) in get_slot()
823 q->slot.slot_next = ktime_get_ns(); in get_slot()
825 q->slot.slot_next = 0; in get_slot()
828 static void get_correlation(struct netem_sched_data *q, const struct nlattr *attr) in get_correlation() argument
832 init_crandom(&q->delay_cor, c->delay_corr); in get_correlation()
833 init_crandom(&q->loss_cor, c->loss_corr); in get_correlation()
834 init_crandom(&q->dup_cor, c->dup_corr); in get_correlation()
837 static void get_reorder(struct netem_sched_data *q, const struct nlattr *attr) in get_reorder() argument
841 q->reorder = r->probability; in get_reorder()
842 init_crandom(&q->reorder_cor, r->correlation); in get_reorder()
845 static void get_corrupt(struct netem_sched_data *q, const struct nlattr *attr) in get_corrupt() argument
849 q->corrupt = r->probability; in get_corrupt()
850 init_crandom(&q->corrupt_cor, r->correlation); in get_corrupt()
853 static void get_rate(struct netem_sched_data *q, const struct nlattr *attr) in get_rate() argument
857 q->rate = r->rate; in get_rate()
858 q->packet_overhead = r->packet_overhead; in get_rate()
859 q->cell_size = r->cell_size; in get_rate()
860 q->cell_overhead = r->cell_overhead; in get_rate()
861 if (q->cell_size) in get_rate()
862 q->cell_size_reciprocal = reciprocal_value(q->cell_size); in get_rate()
864 q->cell_size_reciprocal = (struct reciprocal_value) { 0 }; in get_rate()
867 static int get_loss_clg(struct netem_sched_data *q, const struct nlattr *attr) in get_loss_clg() argument
884 q->loss_model = CLG_4_STATES; in get_loss_clg()
886 q->clg.state = TX_IN_GAP_PERIOD; in get_loss_clg()
887 q->clg.a1 = gi->p13; in get_loss_clg()
888 q->clg.a2 = gi->p31; in get_loss_clg()
889 q->clg.a3 = gi->p32; in get_loss_clg()
890 q->clg.a4 = gi->p14; in get_loss_clg()
891 q->clg.a5 = gi->p23; in get_loss_clg()
903 q->loss_model = CLG_GILB_ELL; in get_loss_clg()
904 q->clg.state = GOOD_STATE; in get_loss_clg()
905 q->clg.a1 = ge->p; in get_loss_clg()
906 q->clg.a2 = ge->r; in get_loss_clg()
907 q->clg.a3 = ge->h; in get_loss_clg()
908 q->clg.a4 = ge->k1; in get_loss_clg()
957 struct netem_sched_data *q = qdisc_priv(sch); in netem_change() local
969 /* backup q->clg and q->loss_model */ in netem_change()
970 old_clg = q->clg; in netem_change()
971 old_loss_model = q->loss_model; in netem_change()
974 ret = get_loss_clg(q, tb[TCA_NETEM_LOSS]); in netem_change()
976 q->loss_model = old_loss_model; in netem_change()
980 q->loss_model = CLG_RANDOM; in netem_change()
984 ret = get_dist_table(sch, &q->delay_dist, in netem_change()
991 ret = get_dist_table(sch, &q->slot_dist, in netem_change()
999 q->latency = PSCHED_TICKS2NS(qopt->latency); in netem_change()
1000 q->jitter = PSCHED_TICKS2NS(qopt->jitter); in netem_change()
1001 q->limit = qopt->limit; in netem_change()
1002 q->gap = qopt->gap; in netem_change()
1003 q->counter = 0; in netem_change()
1004 q->loss = qopt->loss; in netem_change()
1005 q->duplicate = qopt->duplicate; in netem_change()
1010 if (q->gap) in netem_change()
1011 q->reorder = ~0; in netem_change()
1014 get_correlation(q, tb[TCA_NETEM_CORR]); in netem_change()
1017 get_reorder(q, tb[TCA_NETEM_REORDER]); in netem_change()
1020 get_corrupt(q, tb[TCA_NETEM_CORRUPT]); in netem_change()
1023 get_rate(q, tb[TCA_NETEM_RATE]); in netem_change()
1026 q->rate = max_t(u64, q->rate, in netem_change()
1030 q->latency = nla_get_s64(tb[TCA_NETEM_LATENCY64]); in netem_change()
1033 q->jitter = nla_get_s64(tb[TCA_NETEM_JITTER64]); in netem_change()
1036 q->ecn = nla_get_u32(tb[TCA_NETEM_ECN]); in netem_change()
1039 get_slot(q, tb[TCA_NETEM_SLOT]); in netem_change()
1042 q->jitter = min_t(s64, abs(q->jitter), INT_MAX); in netem_change()
1048 * q->clg and q->loss_model were modified in netem_change()
1051 q->clg = old_clg; in netem_change()
1052 q->loss_model = old_loss_model; in netem_change()
1059 struct netem_sched_data *q = qdisc_priv(sch); in netem_init() local
1062 qdisc_watchdog_init(&q->watchdog, sch); in netem_init()
1067 q->loss_model = CLG_RANDOM; in netem_init()
1076 struct netem_sched_data *q = qdisc_priv(sch); in netem_destroy() local
1078 qdisc_watchdog_cancel(&q->watchdog); in netem_destroy()
1079 if (q->qdisc) in netem_destroy()
1080 qdisc_put(q->qdisc); in netem_destroy()
1081 dist_free(q->delay_dist); in netem_destroy()
1082 dist_free(q->slot_dist); in netem_destroy()
1085 static int dump_loss_model(const struct netem_sched_data *q, in dump_loss_model() argument
1094 switch (q->loss_model) { in dump_loss_model()
1102 .p13 = q->clg.a1, in dump_loss_model()
1103 .p31 = q->clg.a2, in dump_loss_model()
1104 .p32 = q->clg.a3, in dump_loss_model()
1105 .p14 = q->clg.a4, in dump_loss_model()
1106 .p23 = q->clg.a5, in dump_loss_model()
1115 .p = q->clg.a1, in dump_loss_model()
1116 .r = q->clg.a2, in dump_loss_model()
1117 .h = q->clg.a3, in dump_loss_model()
1118 .k1 = q->clg.a4, in dump_loss_model()
1137 const struct netem_sched_data *q = qdisc_priv(sch); in netem_dump() local
1146 qopt.latency = min_t(psched_time_t, PSCHED_NS2TICKS(q->latency), in netem_dump()
1148 qopt.jitter = min_t(psched_time_t, PSCHED_NS2TICKS(q->jitter), in netem_dump()
1150 qopt.limit = q->limit; in netem_dump()
1151 qopt.loss = q->loss; in netem_dump()
1152 qopt.gap = q->gap; in netem_dump()
1153 qopt.duplicate = q->duplicate; in netem_dump()
1157 if (nla_put(skb, TCA_NETEM_LATENCY64, sizeof(q->latency), &q->latency)) in netem_dump()
1160 if (nla_put(skb, TCA_NETEM_JITTER64, sizeof(q->jitter), &q->jitter)) in netem_dump()
1163 cor.delay_corr = q->delay_cor.rho; in netem_dump()
1164 cor.loss_corr = q->loss_cor.rho; in netem_dump()
1165 cor.dup_corr = q->dup_cor.rho; in netem_dump()
1169 reorder.probability = q->reorder; in netem_dump()
1170 reorder.correlation = q->reorder_cor.rho; in netem_dump()
1174 corrupt.probability = q->corrupt; in netem_dump()
1175 corrupt.correlation = q->corrupt_cor.rho; in netem_dump()
1179 if (q->rate >= (1ULL << 32)) { in netem_dump()
1180 if (nla_put_u64_64bit(skb, TCA_NETEM_RATE64, q->rate, in netem_dump()
1185 rate.rate = q->rate; in netem_dump()
1187 rate.packet_overhead = q->packet_overhead; in netem_dump()
1188 rate.cell_size = q->cell_size; in netem_dump()
1189 rate.cell_overhead = q->cell_overhead; in netem_dump()
1193 if (q->ecn && nla_put_u32(skb, TCA_NETEM_ECN, q->ecn)) in netem_dump()
1196 if (dump_loss_model(q, skb) != 0) in netem_dump()
1199 if (q->slot_config.min_delay | q->slot_config.max_delay | in netem_dump()
1200 q->slot_config.dist_jitter) { in netem_dump()
1201 slot = q->slot_config; in netem_dump()
1220 struct netem_sched_data *q = qdisc_priv(sch); in netem_dump_class() local
1222 if (cl != 1 || !q->qdisc) /* only one class */ in netem_dump_class()
1226 tcm->tcm_info = q->qdisc->handle; in netem_dump_class()
1234 struct netem_sched_data *q = qdisc_priv(sch); in netem_graft() local
1236 *old = qdisc_replace(sch, new, &q->qdisc); in netem_graft()
1242 struct netem_sched_data *q = qdisc_priv(sch); in netem_leaf() local
1243 return q->qdisc; in netem_leaf()