From: Martin KaFai Lau <martin.lau@linux.dev>
To: Amery Hung <ameryhung@gmail.com>
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
yangpeihao@sjtu.edu.cn, 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, sdf@google.com, xiyou.wangcong@gmail.com,
yepeilin.cs@gmail.com
Subject: Re: [RFC PATCH v9 10/11] selftests: Add a bpf fq qdisc to selftest
Date: Thu, 18 Jul 2024 18:54:00 -0700 [thread overview]
Message-ID: <f3ec8147-69ad-4852-be93-92a2a627229a@linux.dev> (raw)
In-Reply-To: <20240714175130.4051012-11-amery.hung@bytedance.com>
On 7/14/24 10:51 AM, Amery Hung wrote:
> +struct {
> + __uint(type, BPF_MAP_TYPE_ARRAY);
> + __type(key, __u32);
> + __type(value, struct fq_stashed_flow);
> + __uint(max_entries, NUM_QUEUE + 1);
> +} fq_stashed_flows SEC(".maps");
> +
> +#define private(name) SEC(".data." #name) __hidden __attribute__((aligned(8)))
> +
> +private(A) struct bpf_spin_lock fq_delayed_lock;
> +private(A) struct bpf_rb_root fq_delayed __contains(fq_flow_node, rb_node);
> +
> +private(B) struct bpf_spin_lock fq_new_flows_lock;
> +private(B) struct bpf_list_head fq_new_flows __contains(fq_flow_node, list_node);
> +
> +private(C) struct bpf_spin_lock fq_old_flows_lock;
> +private(C) struct bpf_list_head fq_old_flows __contains(fq_flow_node, list_node);
Potentially, multiple qdisc instances will content on these global locks. Do you
think it will be an issue in setup like the root is mq and multiple fq(s) below
the mq, like mq => (fq1, fq2, fq3...)?
I guess it could be solved by storing them into the map's value and each fq
instance uses its own lock and list/rb (?) to make it work like ".priv_size",
but just more work is needed in ".init". Not necessary the top of the things to
tackle/optimize for now though.
[ ... ]
> +SEC("struct_ops/bpf_fq_enqueue")
> +int BPF_PROG(bpf_fq_enqueue, struct sk_buff *skb, struct Qdisc *sch,
> + struct bpf_sk_buff_ptr *to_free)
> +{
> + struct fq_flow_node *flow = NULL, *flow_copy;
> + struct fq_stashed_flow *sflow;
> + u64 time_to_send, jiffies;
> + u32 hash, sk_hash;
> + struct skb_node *skbn;
> + bool connected;
> +
> + if (fq_qlen >= q_plimit)
> + goto drop;
> +
> + if (!skb->tstamp) {
> + time_to_send = ktime_cache = bpf_ktime_get_ns();
> + } else {
> + if (fq_packet_beyond_horizon(skb)) {
> + ktime_cache = bpf_ktime_get_ns();
> + if (fq_packet_beyond_horizon(skb)) {
> + if (q_horizon_drop)
> + goto drop;
> +
> + skb->tstamp = ktime_cache + q_horizon;
> + }
> + }
> + time_to_send = skb->tstamp;
> + }
> +
> + if (fq_classify(skb, &hash, &sflow, &connected, &sk_hash) < 0)
> + goto drop;
> +
> + flow = bpf_kptr_xchg(&sflow->flow, flow);
> + if (!flow)
> + goto drop;
> +
> + if (hash != PRIO_QUEUE) {
> + if (connected && flow->socket_hash != sk_hash) {
The commit message mentioned it does not handle the hash collision. Not a
request for now, I just want to understand if you hit some issues.
> + flow->credit = q_initial_quantum;
> + flow->socket_hash = sk_hash;
> + if (fq_flow_is_throttled(flow)) {
> + /* mark the flow as undetached. The reference to the
> + * throttled flow in fq_delayed will be removed later.
> + */
> + flow_copy = bpf_refcount_acquire(flow);
> + flow_copy->age = 0;
> + fq_flows_add_tail(&fq_old_flows, &fq_old_flows_lock, flow_copy);
> + }
> + flow->time_next_packet = 0ULL;
> + }
> +
> + if (flow->qlen >= q_flow_plimit) {
> + bpf_kptr_xchg_back(&sflow->flow, flow);
> + goto drop;
> + }
> +
> + if (fq_flow_is_detached(flow)) {
> + if (connected)
> + flow->socket_hash = sk_hash;
> +
> + flow_copy = bpf_refcount_acquire(flow);
> +
> + jiffies = bpf_jiffies64();
> + if ((s64)(jiffies - (flow_copy->age + q_flow_refill_delay)) > 0) {
> + if (flow_copy->credit < q_quantum)
> + flow_copy->credit = q_quantum;
> + }
> + flow_copy->age = 0;
> + fq_flows_add_tail(&fq_new_flows, &fq_new_flows_lock, flow_copy);
> + }
> + }
> +
> + skbn = bpf_obj_new(typeof(*skbn));
> + if (!skbn) {
> + bpf_kptr_xchg_back(&sflow->flow, flow)
Please post the patch that makes the bpf_kptr_xchg() work. It is easier if I can
try the selftests out.
next prev parent reply other threads:[~2024-07-19 1:54 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-14 17:51 [RFC PATCH v9 00/11] bpf qdisc Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 01/11] bpf: Support getting referenced kptr from struct_ops argument Amery Hung
2024-07-24 0:32 ` Martin KaFai Lau
2024-07-24 17:00 ` Amery Hung
2024-07-25 1:28 ` Martin KaFai Lau
2024-07-14 17:51 ` [RFC PATCH v9 02/11] selftests/bpf: Test referenced kptr arguments of struct_ops programs Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 03/11] bpf: Allow struct_ops prog to return referenced kptr Amery Hung
2024-07-24 5:36 ` Kui-Feng Lee
2024-07-24 18:27 ` Kui-Feng Lee
2024-07-24 20:44 ` Amery Hung
2024-07-26 18:22 ` Kui-Feng Lee
2024-07-26 22:45 ` Amery Hung
2024-07-24 23:57 ` Martin KaFai Lau
2024-07-14 17:51 ` [RFC PATCH v9 04/11] selftests/bpf: Test returning referenced kptr from struct_ops programs Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 05/11] bpf: net_sched: Support implementation of Qdisc_ops in bpf Amery Hung
2024-07-18 0:00 ` Amery Hung
2024-07-25 21:24 ` Martin KaFai Lau
2024-07-31 4:09 ` Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 06/11] bpf: net_sched: Add bpf qdisc kfuncs Amery Hung
2024-07-25 22:38 ` Martin KaFai Lau
2024-07-31 4:08 ` Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 07/11] bpf: net_sched: Allow more optional operators in Qdisc_ops Amery Hung
2024-07-18 0:01 ` Amery Hung
2024-07-26 1:15 ` Martin KaFai Lau
2024-07-26 18:30 ` Martin KaFai Lau
2024-07-26 22:30 ` Amery Hung
2024-07-30 0:20 ` Martin KaFai Lau
2024-07-14 17:51 ` [RFC PATCH v9 08/11] libbpf: Support creating and destroying qdisc Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 09/11] selftests: Add a basic fifo qdisc test Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 10/11] selftests: Add a bpf fq qdisc to selftest Amery Hung
2024-07-19 1:54 ` Martin KaFai Lau [this message]
2024-07-19 18:20 ` Amery Hung
2024-07-14 17:51 ` [RFC PATCH v9 11/11] selftests: Add a bpf netem " Amery Hung
2024-07-17 10:13 ` [RFC PATCH v9 00/11] bpf qdisc Donald Hunter
2024-07-17 22:04 ` Amery Hung
2024-07-19 17:21 ` [OFFLIST RFC 1/4] bpf: Search for kptrs in prog BTF structs Amery Hung
2024-07-19 17:21 ` [OFFLIST RFC 2/4] bpf: Rename ARG_PTR_TO_KPTR -> ARG_KPTR_XCHG_DEST Amery Hung
2024-07-19 17:21 ` [OFFLIST RFC 3/4] bpf: Support bpf_kptr_xchg into local kptr Amery Hung
2024-07-23 0:18 ` Alexei Starovoitov
2024-07-24 0:08 ` Amery Hung
2024-07-19 17:21 ` [OFFLIST RFC 4/4] selftests/bpf: Test bpf_kptr_xchg stashing " Amery Hung
2024-07-23 0:19 ` [RFC PATCH v9 00/11] bpf qdisc Alexei Starovoitov
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=f3ec8147-69ad-4852-be93-92a2a627229a@linux.dev \
--to=martin.lau@linux.dev \
--cc=alexei.starovoitov@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=martin.lau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sdf@google.com \
--cc=sinquersw@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox