提交 5df0ddfb 编写于 作者: D Daniel Borkmann 提交者: David S. Miller

net: packet: add randomized fanout scheduler

We currently allow for different fanout scheduling policies in pf_packet
such as scheduling by skb's rxhash, round-robin, by cpu, and rollover.
Also allow for a random, equidistributed selection of the socket from the
fanout process group.
Signed-off-by: NDaniel Borkmann <dborkman@redhat.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 48859488
...@@ -56,6 +56,7 @@ struct sockaddr_ll { ...@@ -56,6 +56,7 @@ struct sockaddr_ll {
#define PACKET_FANOUT_LB 1 #define PACKET_FANOUT_LB 1
#define PACKET_FANOUT_CPU 2 #define PACKET_FANOUT_CPU 2
#define PACKET_FANOUT_ROLLOVER 3 #define PACKET_FANOUT_ROLLOVER 3
#define PACKET_FANOUT_RND 4
#define PACKET_FANOUT_FLAG_ROLLOVER 0x1000 #define PACKET_FANOUT_FLAG_ROLLOVER 0x1000
#define PACKET_FANOUT_FLAG_DEFRAG 0x8000 #define PACKET_FANOUT_FLAG_DEFRAG 0x8000
......
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
#include <linux/virtio_net.h> #include <linux/virtio_net.h>
#include <linux/errqueue.h> #include <linux/errqueue.h>
#include <linux/net_tstamp.h> #include <linux/net_tstamp.h>
#include <linux/reciprocal_div.h>
#ifdef CONFIG_INET #ifdef CONFIG_INET
#include <net/inet_common.h> #include <net/inet_common.h>
#endif #endif
...@@ -1158,6 +1158,13 @@ static unsigned int fanout_demux_cpu(struct packet_fanout *f, ...@@ -1158,6 +1158,13 @@ static unsigned int fanout_demux_cpu(struct packet_fanout *f,
return smp_processor_id() % num; return smp_processor_id() % num;
} }
static unsigned int fanout_demux_rnd(struct packet_fanout *f,
struct sk_buff *skb,
unsigned int num)
{
return reciprocal_divide(prandom_u32(), num);
}
static unsigned int fanout_demux_rollover(struct packet_fanout *f, static unsigned int fanout_demux_rollover(struct packet_fanout *f,
struct sk_buff *skb, struct sk_buff *skb,
unsigned int idx, unsigned int skip, unsigned int idx, unsigned int skip,
...@@ -1215,6 +1222,9 @@ static int packet_rcv_fanout(struct sk_buff *skb, struct net_device *dev, ...@@ -1215,6 +1222,9 @@ static int packet_rcv_fanout(struct sk_buff *skb, struct net_device *dev,
case PACKET_FANOUT_CPU: case PACKET_FANOUT_CPU:
idx = fanout_demux_cpu(f, skb, num); idx = fanout_demux_cpu(f, skb, num);
break; break;
case PACKET_FANOUT_RND:
idx = fanout_demux_rnd(f, skb, num);
break;
case PACKET_FANOUT_ROLLOVER: case PACKET_FANOUT_ROLLOVER:
idx = fanout_demux_rollover(f, skb, 0, (unsigned int) -1, num); idx = fanout_demux_rollover(f, skb, 0, (unsigned int) -1, num);
break; break;
...@@ -1284,6 +1294,7 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags) ...@@ -1284,6 +1294,7 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
case PACKET_FANOUT_HASH: case PACKET_FANOUT_HASH:
case PACKET_FANOUT_LB: case PACKET_FANOUT_LB:
case PACKET_FANOUT_CPU: case PACKET_FANOUT_CPU:
case PACKET_FANOUT_RND:
break; break;
default: default:
return -EINVAL; return -EINVAL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册