77
77
#define SFQ_EMPTY_SLOT 0xffff
78
78
#define SFQ_DEFAULT_HASH_DIVISOR 1024
79
79
80
- /* We use 16 bits to store allot, and want to handle packets up to 64K
81
- * Scale allot by 8 (1<<3) so that no overflow occurs.
82
- */
83
- #define SFQ_ALLOT_SHIFT 3
84
- #define SFQ_ALLOT_SIZE (X ) DIV_ROUND_UP(X, 1 << SFQ_ALLOT_SHIFT)
85
-
86
80
/* This type should contain at least SFQ_MAX_DEPTH + 1 + SFQ_MAX_FLOWS values */
87
81
typedef u16 sfq_index ;
88
82
@@ -104,7 +98,7 @@ struct sfq_slot {
104
98
sfq_index next ; /* next slot in sfq RR chain */
105
99
struct sfq_head dep ; /* anchor in dep[] chains */
106
100
unsigned short hash ; /* hash value (index in ht[]) */
107
- short allot ; /* credit for this slot */
101
+ int allot ; /* credit for this slot */
108
102
109
103
unsigned int backlog ;
110
104
struct red_vars vars ;
@@ -120,7 +114,6 @@ struct sfq_sched_data {
120
114
siphash_key_t perturbation ;
121
115
u8 cur_depth ; /* depth of longest slot */
122
116
u8 flags ;
123
- unsigned short scaled_quantum ; /* SFQ_ALLOT_SIZE(quantum) */
124
117
struct tcf_proto __rcu * filter_list ;
125
118
struct tcf_block * block ;
126
119
sfq_index * ht ; /* Hash table ('divisor' slots) */
@@ -456,7 +449,7 @@ sfq_enqueue(struct sk_buff *skb, struct Qdisc *sch, struct sk_buff **to_free)
456
449
*/
457
450
q -> tail = slot ;
458
451
/* We could use a bigger initial quantum for new flows */
459
- slot -> allot = q -> scaled_quantum ;
452
+ slot -> allot = q -> quantum ;
460
453
}
461
454
if (++ sch -> q .qlen <= q -> limit )
462
455
return NET_XMIT_SUCCESS ;
@@ -493,7 +486,7 @@ sfq_dequeue(struct Qdisc *sch)
493
486
slot = & q -> slots [a ];
494
487
if (slot -> allot <= 0 ) {
495
488
q -> tail = slot ;
496
- slot -> allot += q -> scaled_quantum ;
489
+ slot -> allot += q -> quantum ;
497
490
goto next_slot ;
498
491
}
499
492
skb = slot_dequeue_head (slot );
@@ -512,7 +505,7 @@ sfq_dequeue(struct Qdisc *sch)
512
505
}
513
506
q -> tail -> next = next_a ;
514
507
} else {
515
- slot -> allot -= SFQ_ALLOT_SIZE ( qdisc_pkt_len (skb ) );
508
+ slot -> allot -= qdisc_pkt_len (skb );
516
509
}
517
510
return skb ;
518
511
}
@@ -595,7 +588,7 @@ static void sfq_rehash(struct Qdisc *sch)
595
588
q -> tail -> next = x ;
596
589
}
597
590
q -> tail = slot ;
598
- slot -> allot = q -> scaled_quantum ;
591
+ slot -> allot = q -> quantum ;
599
592
}
600
593
}
601
594
sch -> q .qlen -= dropped ;
@@ -628,7 +621,8 @@ static void sfq_perturbation(struct timer_list *t)
628
621
rcu_read_unlock ();
629
622
}
630
623
631
- static int sfq_change (struct Qdisc * sch , struct nlattr * opt )
624
+ static int sfq_change (struct Qdisc * sch , struct nlattr * opt ,
625
+ struct netlink_ext_ack * extack )
632
626
{
633
627
struct sfq_sched_data * q = qdisc_priv (sch );
634
628
struct tc_sfq_qopt * ctl = nla_data (opt );
@@ -646,14 +640,10 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
646
640
(!is_power_of_2 (ctl -> divisor ) || ctl -> divisor > 65536 ))
647
641
return - EINVAL ;
648
642
649
- /* slot->allot is a short, make sure quantum is not too big. */
650
- if (ctl -> quantum ) {
651
- unsigned int scaled = SFQ_ALLOT_SIZE (ctl -> quantum );
652
-
653
- if (scaled <= 0 || scaled > SHRT_MAX )
654
- return - EINVAL ;
643
+ if ((int )ctl -> quantum < 0 ) {
644
+ NL_SET_ERR_MSG_MOD (extack , "invalid quantum" );
645
+ return - EINVAL ;
655
646
}
656
-
657
647
if (ctl_v1 && !red_check_params (ctl_v1 -> qth_min , ctl_v1 -> qth_max ,
658
648
ctl_v1 -> Wlog , ctl_v1 -> Scell_log , NULL ))
659
649
return - EINVAL ;
@@ -663,10 +653,8 @@ static int sfq_change(struct Qdisc *sch, struct nlattr *opt)
663
653
return - ENOMEM ;
664
654
}
665
655
sch_tree_lock (sch );
666
- if (ctl -> quantum ) {
656
+ if (ctl -> quantum )
667
657
q -> quantum = ctl -> quantum ;
668
- q -> scaled_quantum = SFQ_ALLOT_SIZE (q -> quantum );
669
- }
670
658
WRITE_ONCE (q -> perturb_period , ctl -> perturb_period * HZ );
671
659
if (ctl -> flows )
672
660
q -> maxflows = min_t (u32 , ctl -> flows , SFQ_MAX_FLOWS );
@@ -762,12 +750,11 @@ static int sfq_init(struct Qdisc *sch, struct nlattr *opt,
762
750
q -> divisor = SFQ_DEFAULT_HASH_DIVISOR ;
763
751
q -> maxflows = SFQ_DEFAULT_FLOWS ;
764
752
q -> quantum = psched_mtu (qdisc_dev (sch ));
765
- q -> scaled_quantum = SFQ_ALLOT_SIZE (q -> quantum );
766
753
q -> perturb_period = 0 ;
767
754
get_random_bytes (& q -> perturbation , sizeof (q -> perturbation ));
768
755
769
756
if (opt ) {
770
- int err = sfq_change (sch , opt );
757
+ int err = sfq_change (sch , opt , extack );
771
758
if (err )
772
759
return err ;
773
760
}
@@ -878,7 +865,7 @@ static int sfq_dump_class_stats(struct Qdisc *sch, unsigned long cl,
878
865
if (idx != SFQ_EMPTY_SLOT ) {
879
866
const struct sfq_slot * slot = & q -> slots [idx ];
880
867
881
- xstats .allot = slot -> allot << SFQ_ALLOT_SHIFT ;
868
+ xstats .allot = slot -> allot ;
882
869
qs .qlen = slot -> qlen ;
883
870
qs .backlog = slot -> backlog ;
884
871
}
0 commit comments