^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2016 Qualcomm Atheros, Inc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Based on net/sched/sch_fq_codel.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef __NET_SCHED_FQ_IMPL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define __NET_SCHED_FQ_IMPL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <net/fq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) /* functions that are embedded into includer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static void fq_adjust_removal(struct fq *fq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct fq_flow *flow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct fq_tin *tin = flow->tin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) tin->backlog_bytes -= skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) tin->backlog_packets--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) flow->backlog -= skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) fq->backlog--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) fq->memory_usage -= skb->truesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static void fq_rejigger_backlog(struct fq *fq, struct fq_flow *flow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct fq_flow *i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (flow->backlog == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) list_del_init(&flow->backlogchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) i = flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) list_for_each_entry_continue(i, &fq->backlogs, backlogchain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (i->backlog < flow->backlog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) list_move_tail(&flow->backlogchain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) &i->backlogchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static struct sk_buff *fq_flow_dequeue(struct fq *fq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct fq_flow *flow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) lockdep_assert_held(&fq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) skb = __skb_dequeue(&flow->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) fq_adjust_removal(fq, flow, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) fq_rejigger_backlog(fq, flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static struct sk_buff *fq_tin_dequeue(struct fq *fq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct fq_tin *tin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) fq_tin_dequeue_t dequeue_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct fq_flow *flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct list_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) lockdep_assert_held(&fq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) begin:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) head = &tin->new_flows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (list_empty(head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) head = &tin->old_flows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (list_empty(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) flow = list_first_entry(head, struct fq_flow, flowchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (flow->deficit <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) flow->deficit += fq->quantum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) list_move_tail(&flow->flowchain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) &tin->old_flows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) goto begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) skb = dequeue_func(fq, tin, flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* force a pass through old_flows to prevent starvation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if ((head == &tin->new_flows) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) !list_empty(&tin->old_flows)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) list_move_tail(&flow->flowchain, &tin->old_flows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) list_del_init(&flow->flowchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) flow->tin = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) goto begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) flow->deficit -= skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) tin->tx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) tin->tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static u32 fq_flow_idx(struct fq *fq, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) u32 hash = skb_get_hash(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return reciprocal_scale(hash, fq->flows_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static struct fq_flow *fq_flow_classify(struct fq *fq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct fq_tin *tin, u32 idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) fq_flow_get_default_t get_default_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct fq_flow *flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) lockdep_assert_held(&fq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) flow = &fq->flows[idx];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (flow->tin && flow->tin != tin) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) flow = get_default_func(fq, tin, idx, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) tin->collisions++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) fq->collisions++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (!flow->tin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) tin->flows++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static void fq_recalc_backlog(struct fq *fq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct fq_tin *tin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct fq_flow *flow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct fq_flow *i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (list_empty(&flow->backlogchain))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) list_add_tail(&flow->backlogchain, &fq->backlogs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) i = flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) list_for_each_entry_continue_reverse(i, &fq->backlogs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) backlogchain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (i->backlog > flow->backlog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) list_move(&flow->backlogchain, &i->backlogchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static void fq_tin_enqueue(struct fq *fq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct fq_tin *tin, u32 idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) fq_skb_free_t free_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) fq_flow_get_default_t get_default_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct fq_flow *flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) bool oom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) lockdep_assert_held(&fq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) flow = fq_flow_classify(fq, tin, idx, skb, get_default_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) flow->tin = tin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) flow->backlog += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) tin->backlog_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) tin->backlog_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) fq->memory_usage += skb->truesize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) fq->backlog++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) fq_recalc_backlog(fq, tin, flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (list_empty(&flow->flowchain)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) flow->deficit = fq->quantum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) list_add_tail(&flow->flowchain,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) &tin->new_flows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) __skb_queue_tail(&flow->queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) oom = (fq->memory_usage > fq->memory_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) while (fq->backlog > fq->limit || oom) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) flow = list_first_entry_or_null(&fq->backlogs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct fq_flow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) backlogchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (!flow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) skb = fq_flow_dequeue(fq, flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) free_func(fq, flow->tin, flow, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) flow->tin->overlimit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) fq->overlimit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (oom) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) fq->overmemory++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) oom = (fq->memory_usage > fq->memory_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static void fq_flow_filter(struct fq *fq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) struct fq_flow *flow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) fq_skb_filter_t filter_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) void *filter_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) fq_skb_free_t free_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct fq_tin *tin = flow->tin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct sk_buff *skb, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) lockdep_assert_held(&fq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) skb_queue_walk_safe(&flow->queue, skb, tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (!filter_func(fq, tin, flow, skb, filter_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) __skb_unlink(skb, &flow->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) fq_adjust_removal(fq, flow, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) free_func(fq, tin, flow, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) fq_rejigger_backlog(fq, flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static void fq_tin_filter(struct fq *fq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct fq_tin *tin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) fq_skb_filter_t filter_func,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) void *filter_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) fq_skb_free_t free_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct fq_flow *flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) lockdep_assert_held(&fq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) list_for_each_entry(flow, &tin->new_flows, flowchain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) fq_flow_filter(fq, flow, filter_func, filter_data, free_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) list_for_each_entry(flow, &tin->old_flows, flowchain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) fq_flow_filter(fq, flow, filter_func, filter_data, free_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static void fq_flow_reset(struct fq *fq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct fq_flow *flow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) fq_skb_free_t free_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) while ((skb = fq_flow_dequeue(fq, flow)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) free_func(fq, flow->tin, flow, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (!list_empty(&flow->flowchain))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) list_del_init(&flow->flowchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (!list_empty(&flow->backlogchain))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) list_del_init(&flow->backlogchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) flow->tin = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) WARN_ON_ONCE(flow->backlog);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) static void fq_tin_reset(struct fq *fq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct fq_tin *tin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) fq_skb_free_t free_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct list_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct fq_flow *flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) head = &tin->new_flows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (list_empty(head)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) head = &tin->old_flows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (list_empty(head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) flow = list_first_entry(head, struct fq_flow, flowchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) fq_flow_reset(fq, flow, free_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) WARN_ON_ONCE(tin->backlog_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) WARN_ON_ONCE(tin->backlog_packets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static void fq_flow_init(struct fq_flow *flow)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) INIT_LIST_HEAD(&flow->flowchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) INIT_LIST_HEAD(&flow->backlogchain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) __skb_queue_head_init(&flow->queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static void fq_tin_init(struct fq_tin *tin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) INIT_LIST_HEAD(&tin->new_flows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) INIT_LIST_HEAD(&tin->old_flows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static int fq_init(struct fq *fq, int flows_cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) memset(fq, 0, sizeof(fq[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) INIT_LIST_HEAD(&fq->backlogs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) spin_lock_init(&fq->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) fq->flows_cnt = max_t(u32, flows_cnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) fq->quantum = 300;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) fq->limit = 8192;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) fq->memory_limit = 16 << 20; /* 16 MBytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) fq->flows = kvcalloc(fq->flows_cnt, sizeof(fq->flows[0]), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (!fq->flows)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) for (i = 0; i < fq->flows_cnt; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) fq_flow_init(&fq->flows[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static void fq_reset(struct fq *fq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) fq_skb_free_t free_func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) for (i = 0; i < fq->flows_cnt; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) fq_flow_reset(fq, &fq->flows[i], free_func);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) kvfree(fq->flows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) fq->flows = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) #endif