Skip to content

Commit dfcb63c

Browse files
tohojokuba-moo
authored andcommitted
fq_codel: generalise ce_threshold marking for subset of traffic
Commit e72aeb9 ("fq_codel: implement L4S style ce_threshold_ect1 marking") expanded the ce_threshold feature of FQ-CoDel so it can be applied to a subset of the traffic, using the ECT(1) bit of the ECN field as the classifier. However, hard-coding ECT(1) as the only classifier for this feature seems limiting, so let's expand it to be more general. To this end, change the parameter from a ce_threshold_ect1 boolean, to a one-byte selector/mask pair (ce_threshold_{selector,mask}) which is applied to the whole diffserv/ECN field in the IP header. This makes it possible to classify packets by any value in either the ECN field or the diffserv field. In particular, setting a selector of INET_ECN_ECT_1 and a mask of INET_ECN_MASK corresponds to the functionality before this patch, and a mask of ~INET_ECN_MASK allows using the selector as a straight-forward match against a diffserv code point: # apply ce_threshold to ECT(1) traffic tc qdisc replace dev eth0 root fq_codel ce_threshold 1ms ce_threshold_selector 0x1/0x3 # apply ce_threshold to ECN-capable traffic marked as diffserv AF22 tc qdisc replace dev eth0 root fq_codel ce_threshold 1ms ce_threshold_selector 0x50/0xfc Regardless of the selector chosen, the normal rules for ECN-marking of packets still apply, i.e., the flow must still declare itself ECN-capable by setting one of the bits in the ECN field to get marked at all. v2: - Add tc usage examples to patch description Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Link: https://lore.kernel.org/r/20211019174709.69081-1-toke@redhat.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 2641b62 commit dfcb63c

5 files changed

Lines changed: 25 additions & 15 deletions

File tree

‎include/net/codel.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,18 @@ static inline u32 codel_time_to_us(codel_time_t val)
102102
* @interval: width of moving time window
103103
* @mtu: device mtu, or minimal queue backlog in bytes.
104104
* @ecn: is Explicit Congestion Notification enabled
105-
* @ce_threshold_ect1: if ce_threshold only marks ECT(1) packets
105+
* @ce_threshold_selector: apply ce_threshold to packets matching this value
106+
* in the diffserv/ECN byte of the IP header
107+
* @ce_threshold_mask: mask to apply to ce_threshold_selector comparison
106108
*/
107109
struct codel_params {
108110
codel_time_t target;
109111
codel_time_t ce_threshold;
110112
codel_time_t interval;
111113
u32 mtu;
112114
bool ecn;
113-
bool ce_threshold_ect1;
115+
u8 ce_threshold_selector;
116+
u8 ce_threshold_mask;
114117
};
115118

116119
/**

‎include/net/codel_impl.h‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ static void codel_params_init(struct codel_params *params)
5454
params->interval = MS2TIME(100);
5555
params->target = MS2TIME(5);
5656
params->ce_threshold = CODEL_DISABLED_THRESHOLD;
57-
params->ce_threshold_ect1 = false;
57+
params->ce_threshold_mask = 0;
58+
params->ce_threshold_selector = 0;
5859
params->ecn = false;
5960
}
6061

@@ -250,13 +251,12 @@ static struct sk_buff *codel_dequeue(void *ctx,
250251
if (skb && codel_time_after(vars->ldelay, params->ce_threshold)) {
251252
bool set_ce = true;
252253

253-
if (params->ce_threshold_ect1) {
254-
/* Note: if skb_get_dsfield() returns -1, following
255-
* gives INET_ECN_MASK, which is != INET_ECN_ECT_1.
256-
*/
257-
u8 ecn = skb_get_dsfield(skb) & INET_ECN_MASK;
254+
if (params->ce_threshold_mask) {
255+
int dsfield = skb_get_dsfield(skb);
258256

259-
set_ce = (ecn == INET_ECN_ECT_1);
257+
set_ce = (dsfield >= 0 &&
258+
(((u8)dsfield & params->ce_threshold_mask) ==
259+
params->ce_threshold_selector));
260260
}
261261
if (set_ce && INET_ECN_set_ce(skb))
262262
stats->ce_mark++;

‎include/uapi/linux/pkt_sched.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,8 @@ enum {
840840
TCA_FQ_CODEL_CE_THRESHOLD,
841841
TCA_FQ_CODEL_DROP_BATCH_SIZE,
842842
TCA_FQ_CODEL_MEMORY_LIMIT,
843-
TCA_FQ_CODEL_CE_THRESHOLD_ECT1,
843+
TCA_FQ_CODEL_CE_THRESHOLD_SELECTOR,
844+
TCA_FQ_CODEL_CE_THRESHOLD_MASK,
844845
__TCA_FQ_CODEL_MAX
845846
};
846847

‎net/mac80211/sta_info.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
513513
sta->cparams.target = MS2TIME(20);
514514
sta->cparams.interval = MS2TIME(100);
515515
sta->cparams.ecn = true;
516-
sta->cparams.ce_threshold_ect1 = false;
516+
sta->cparams.ce_threshold_selector = 0;
517+
sta->cparams.ce_threshold_mask = 0;
517518

518519
sta_dbg(sdata, "Allocated STA %pM\n", sta->sta.addr);
519520

‎net/sched/sch_fq_codel.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ static const struct nla_policy fq_codel_policy[TCA_FQ_CODEL_MAX + 1] = {
362362
[TCA_FQ_CODEL_CE_THRESHOLD] = { .type = NLA_U32 },
363363
[TCA_FQ_CODEL_DROP_BATCH_SIZE] = { .type = NLA_U32 },
364364
[TCA_FQ_CODEL_MEMORY_LIMIT] = { .type = NLA_U32 },
365-
[TCA_FQ_CODEL_CE_THRESHOLD_ECT1] = { .type = NLA_U8 },
365+
[TCA_FQ_CODEL_CE_THRESHOLD_SELECTOR] = { .type = NLA_U8 },
366+
[TCA_FQ_CODEL_CE_THRESHOLD_MASK] = { .type = NLA_U8 },
366367
};
367368

368369
static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
@@ -409,8 +410,10 @@ static int fq_codel_change(struct Qdisc *sch, struct nlattr *opt,
409410
q->cparams.ce_threshold = (val * NSEC_PER_USEC) >> CODEL_SHIFT;
410411
}
411412

412-
if (tb[TCA_FQ_CODEL_CE_THRESHOLD_ECT1])
413-
q->cparams.ce_threshold_ect1 = !!nla_get_u8(tb[TCA_FQ_CODEL_CE_THRESHOLD_ECT1]);
413+
if (tb[TCA_FQ_CODEL_CE_THRESHOLD_SELECTOR])
414+
q->cparams.ce_threshold_selector = nla_get_u8(tb[TCA_FQ_CODEL_CE_THRESHOLD_SELECTOR]);
415+
if (tb[TCA_FQ_CODEL_CE_THRESHOLD_MASK])
416+
q->cparams.ce_threshold_mask = nla_get_u8(tb[TCA_FQ_CODEL_CE_THRESHOLD_MASK]);
414417

415418
if (tb[TCA_FQ_CODEL_INTERVAL]) {
416419
u64 interval = nla_get_u32(tb[TCA_FQ_CODEL_INTERVAL]);
@@ -552,7 +555,9 @@ static int fq_codel_dump(struct Qdisc *sch, struct sk_buff *skb)
552555
if (nla_put_u32(skb, TCA_FQ_CODEL_CE_THRESHOLD,
553556
codel_time_to_us(q->cparams.ce_threshold)))
554557
goto nla_put_failure;
555-
if (nla_put_u8(skb, TCA_FQ_CODEL_CE_THRESHOLD_ECT1, q->cparams.ce_threshold_ect1))
558+
if (nla_put_u8(skb, TCA_FQ_CODEL_CE_THRESHOLD_SELECTOR, q->cparams.ce_threshold_selector))
559+
goto nla_put_failure;
560+
if (nla_put_u8(skb, TCA_FQ_CODEL_CE_THRESHOLD_MASK, q->cparams.ce_threshold_mask))
556561
goto nla_put_failure;
557562
}
558563

0 commit comments

Comments
 (0)