- 论坛徽章:
- 0
|
- /**
- * reuseport_select_sock - Select a socket from an SO_REUSEPORT group.
- * @sk: First socket in the group.
- * @hash: When no BPF filter is available, use this hash to select.
- * @skb: skb to run through BPF filter.
- * @hdr_len: BPF filter expects skb data pointer at payload data. If
- * the skb does not yet point at the payload, this parameter represents
- * how far the pointer needs to advance to reach the payload.
- * Returns a socket that should receive the packet (or NULL on error).
- */
- struct sock *reuseport_select_sock(struct sock *sk,
- u32 hash,
- struct sk_buff *skb,
- int hdr_len)
- {
- struct sock_reuseport *reuse;
- struct bpf_prog *prog;
- struct sock *sk2 = NULL;
- u16 socks;
- rcu_read_lock();
- reuse = rcu_dereference(sk->sk_reuseport_cb);
- /* if memory allocation failed or add call is not yet complete */
- if (!reuse)
- goto out;
- prog = rcu_dereference(reuse->prog);
- socks = READ_ONCE(reuse->num_socks);
- if (likely(socks)) {
- /* paired with smp_wmb() in reuseport_add_sock() */
- smp_rmb();
- if (prog && skb)
- sk2 = run_bpf(reuse, socks, prog, skb, hdr_len);
- else
- sk2 = reuse->socks[reciprocal_scale(hash, socks)];
- }
- out:
- rcu_read_unlock();
- return sk2;
- }
- EXPORT_SYMBOL(reuseport_select_sock);
复制代码
为什么没有简单的轮流分配的选项? 我想优化单一udp flow啊
我打算开多个线程来收的,这个udp包五元组是一样的. 但是所有线程都能正确处理的.
这么搞的话,我创建再多线程也只能分到同一个线程上了. |
|