From: Martin KaFai Lau <martin.lau@linux.dev>
To: Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
daniel@iogearbox.net, andrii@kernel.org,
alexei.starovoitov@gmail.com, martin.lau@kernel.org,
sinquersw@gmail.com, toke@redhat.com, jhs@mojatatu.com,
jiri@resnulli.us, stfomichev@gmail.com,
ekarani.silvestre@ccc.ufcg.edu.br, yangpeihao@sjtu.edu.cn,
xiyou.wangcong@gmail.com, yepeilin.cs@gmail.com,
amery.hung@bytedance.com
Subject: Re: [PATCH bpf-next v2 14/14] selftests: Add a bpf fq qdisc to selftest
Date: Thu, 9 Jan 2025 15:36:59 -0800 [thread overview]
Message-ID: <17f37206-942a-4db4-99c2-a43412a08d33@linux.dev> (raw)
In-Reply-To: <20241220195619.2022866-15-amery.hung@gmail.com>
On 12/20/24 11:55 AM, Amery Hung wrote:
> +static int fq_new_flow(void *flow_map, struct fq_stashed_flow **sflow, u64 hash)
> +{
> + struct fq_stashed_flow tmp = {};
> + struct fq_flow_node *flow;
> + int ret;
> +
> + flow = bpf_obj_new(typeof(*flow));
> + if (!flow)
> + return -ENOMEM;
> +
> + flow->credit = q.initial_quantum,
> + flow->qlen = 0,
> + flow->age = 1,
> + flow->time_next_packet = 0,
> +
> + ret = bpf_map_update_elem(flow_map, &hash, &tmp, 0);
> + if (ret == -ENOMEM) {
-E2BIG needs to be checked also to handle the flow_map is full case.
> + fq_gc();
> + bpf_map_update_elem(&fq_nonprio_flows, &hash, &tmp, 0);
> + }
> +
> + *sflow = bpf_map_lookup_elem(flow_map, &hash);
> + if (!*sflow) {
> + bpf_obj_drop(flow);
> + return -ENOMEM;
> + }
> +
> + bpf_kptr_xchg_back(&(*sflow)->flow, flow);
> + return 0;
> +}
[ ... ]
> +static int
> +fq_remove_flows(struct bpf_map *flow_map, u64 *hash,
> + struct fq_stashed_flow *sflow, struct remove_flows_ctx *ctx)
> +{
> + struct fq_flow_node *flow = NULL;
> +
> + flow = bpf_kptr_xchg(&sflow->flow, flow);
> + if (flow) {
> + if (!ctx->gc_only || fq_gc_candidate(flow)) {
> + bpf_obj_drop(flow);
afaik, the hash value (i.e. sflow here) is still in the flow_map.
Instead of xchg and then drop, I think this should be
bpf_map_delete_elem(flow_map, hash) which deletes the sflow value from the
flow_map and also takes care of the bpf_obj_drop() also.
> + ctx->reset_cnt++;
> + } else {
> + bpf_kptr_xchg_back(&sflow->flow, flow);
> + }
> + }
> +
> + return ctx->reset_cnt < ctx->reset_max ? 0 : 1;
> +}
> +
> +static void fq_gc(void)
> +{
> + struct remove_flows_ctx cb_ctx = {
> + .gc_only = true,
> + .reset_cnt = 0,
> + .reset_max = FQ_GC_MAX,
> + };
> +
> + bpf_for_each_map_elem(&fq_nonprio_flows, fq_remove_flows, &cb_ctx, 0);
> +}
> +
> +SEC("struct_ops/bpf_fq_reset")
> +void BPF_PROG(bpf_fq_reset, struct Qdisc *sch)
> +{
> + struct unset_throttled_flows_ctx utf_ctx = {
> + .unset_all = true,
> + };
> + struct remove_flows_ctx rf_ctx = {
> + .gc_only = false,
> + .reset_cnt = 0,
> + .reset_max = NUM_QUEUE,
> + };
> + struct fq_stashed_flow *sflow;
> + u64 hash = 0;
> +
> + sch->q.qlen = 0;
> + sch->qstats.backlog = 0;
> +
> + bpf_for_each_map_elem(&fq_nonprio_flows, fq_remove_flows, &rf_ctx, 0);
> +
> + rf_ctx.reset_cnt = 0;
> + bpf_for_each_map_elem(&fq_prio_flows, fq_remove_flows, &rf_ctx, 0);
> + fq_new_flow(&fq_prio_flows, &sflow, hash);
> +
> + bpf_loop(NUM_QUEUE, fq_remove_flows_in_list, NULL, 0);
> + q.new_flow_cnt = 0;
> + q.old_flow_cnt = 0;
> +
> + bpf_loop(NUM_QUEUE, fq_unset_throttled_flows, &utf_ctx, 0);
> +
> + return;
> +}
next prev parent reply other threads:[~2025-01-09 23:37 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 19:55 [PATCH bpf-next v2 00/14] bpf qdisc Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 01/14] bpf: Support getting referenced kptr from struct_ops argument Amery Hung
2025-01-23 9:57 ` Eduard Zingerman
2025-01-23 19:41 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 02/14] selftests/bpf: Test referenced kptr arguments of struct_ops programs Amery Hung
2025-01-23 9:57 ` Eduard Zingerman
2025-01-24 0:04 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 03/14] bpf: Allow struct_ops prog to return referenced kptr Amery Hung
2025-01-15 15:25 ` Ming Lei
2025-01-23 9:57 ` Eduard Zingerman
2025-01-23 18:19 ` Eduard Zingerman
2024-12-20 19:55 ` [PATCH bpf-next v2 04/14] selftests/bpf: Test returning referenced kptr from struct_ops programs Amery Hung
2025-01-23 9:58 ` Eduard Zingerman
2024-12-20 19:55 ` [PATCH bpf-next v2 05/14] bpf: net_sched: Support implementation of Qdisc_ops in bpf Amery Hung
2025-01-09 15:00 ` Amery Hung
2025-01-10 0:28 ` Martin KaFai Lau
2025-01-10 1:20 ` Jakub Kicinski
2024-12-20 19:55 ` [PATCH bpf-next v2 06/14] bpf: net_sched: Add basic bpf qdisc kfuncs Amery Hung
2025-01-10 0:24 ` Martin KaFai Lau
2025-01-10 18:00 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 07/14] bpf: Search and add kfuncs in struct_ops prologue and epilogue Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 08/14] bpf: net_sched: Add a qdisc watchdog timer Amery Hung
2025-01-09 0:20 ` Martin KaFai Lau
2025-01-09 15:00 ` Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 09/14] bpf: net_sched: Support updating bstats Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 10/14] bpf: net_sched: Support updating qstats Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 11/14] bpf: net_sched: Allow writing to more Qdisc members Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 12/14] libbpf: Support creating and destroying qdisc Amery Hung
2024-12-20 19:55 ` [PATCH bpf-next v2 13/14] selftests: Add a basic fifo qdisc test Amery Hung
2025-01-10 0:05 ` Martin KaFai Lau
2024-12-20 19:55 ` [PATCH bpf-next v2 14/14] selftests: Add a bpf fq qdisc to selftest Amery Hung
2025-01-09 23:36 ` Martin KaFai Lau [this message]
2025-01-02 17:29 ` [PATCH bpf-next v2 00/14] bpf qdisc Toke Høiland-Jørgensen
2025-01-10 1:43 ` Martin KaFai Lau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=17f37206-942a-4db4-99c2-a43412a08d33@linux.dev \
--to=martin.lau@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=amery.hung@bytedance.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=ekarani.silvestre@ccc.ufcg.edu.br \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=martin.lau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sinquersw@gmail.com \
--cc=stfomichev@gmail.com \
--cc=toke@redhat.com \
--cc=xiyou.wangcong@gmail.com \
--cc=yangpeihao@sjtu.edu.cn \
--cc=yepeilin.cs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.