netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] pf_packet updates
@ 2013-08-28 20:13 Daniel Borkmann
  2013-08-28 20:13 ` [PATCH net-next 1/3] net: packet: add randomized fanout scheduler Daniel Borkmann
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Daniel Borkmann @ 2013-08-28 20:13 UTC (permalink / raw)
  To: davem; +Cc: netdev

Daniel Borkmann (3):
  net: packet: add random fanout scheduler
  net: packet: use reciprocal_divide in fanout_demux_hash
  net: packet: document available fanout policies

 Documentation/networking/packet_mmap.txt |  8 ++++++++
 include/uapi/linux/if_packet.h           |  1 +
 net/packet/af_packet.c                   | 15 +++++++++++++--
 3 files changed, 22 insertions(+), 2 deletions(-)

-- 
1.7.11.7

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH net-next 1/3] net: packet: add randomized fanout scheduler
  2013-08-28 20:13 [PATCH net-next 0/3] pf_packet updates Daniel Borkmann
@ 2013-08-28 20:13 ` Daniel Borkmann
  2013-08-28 20:13 ` [PATCH net-next 2/3] net: packet: use reciprocal_divide in fanout_demux_hash Daniel Borkmann
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Daniel Borkmann @ 2013-08-28 20:13 UTC (permalink / raw)
  To: davem; +Cc: netdev

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: Daniel Borkmann <dborkman@redhat.com>
---
 include/uapi/linux/if_packet.h |  1 +
 net/packet/af_packet.c         | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/if_packet.h b/include/uapi/linux/if_packet.h
index b950c02..dbf0666 100644
--- a/include/uapi/linux/if_packet.h
+++ b/include/uapi/linux/if_packet.h
@@ -56,6 +56,7 @@ struct sockaddr_ll {
 #define PACKET_FANOUT_LB		1
 #define PACKET_FANOUT_CPU		2
 #define PACKET_FANOUT_ROLLOVER		3
+#define PACKET_FANOUT_RND		4
 #define PACKET_FANOUT_FLAG_ROLLOVER	0x1000
 #define PACKET_FANOUT_FLAG_DEFRAG	0x8000
 
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 6c53dd9..91596f5 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -88,7 +88,7 @@
 #include <linux/virtio_net.h>
 #include <linux/errqueue.h>
 #include <linux/net_tstamp.h>
-
+#include <linux/reciprocal_div.h>
 #ifdef CONFIG_INET
 #include <net/inet_common.h>
 #endif
@@ -1158,6 +1158,13 @@ static unsigned int fanout_demux_cpu(struct packet_fanout *f,
 	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,
 					  struct sk_buff *skb,
 					  unsigned int idx, unsigned int skip,
@@ -1215,6 +1222,9 @@ static int packet_rcv_fanout(struct sk_buff *skb, struct net_device *dev,
 	case PACKET_FANOUT_CPU:
 		idx = fanout_demux_cpu(f, skb, num);
 		break;
+	case PACKET_FANOUT_RND:
+		idx = fanout_demux_rnd(f, skb, num);
+		break;
 	case PACKET_FANOUT_ROLLOVER:
 		idx = fanout_demux_rollover(f, skb, 0, (unsigned int) -1, num);
 		break;
@@ -1284,6 +1294,7 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
 	case PACKET_FANOUT_HASH:
 	case PACKET_FANOUT_LB:
 	case PACKET_FANOUT_CPU:
+	case PACKET_FANOUT_RND:
 		break;
 	default:
 		return -EINVAL;
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 2/3] net: packet: use reciprocal_divide in fanout_demux_hash
  2013-08-28 20:13 [PATCH net-next 0/3] pf_packet updates Daniel Borkmann
  2013-08-28 20:13 ` [PATCH net-next 1/3] net: packet: add randomized fanout scheduler Daniel Borkmann
@ 2013-08-28 20:13 ` Daniel Borkmann
  2013-08-29  1:47   ` Cong Wang
  2013-08-28 20:13 ` [PATCH net-next 3/3] net: packet: document available fanout policies Daniel Borkmann
  2013-08-29  5:39 ` [PATCH net-next 0/3] pf_packet updates David Miller
  3 siblings, 1 reply; 10+ messages in thread
From: Daniel Borkmann @ 2013-08-28 20:13 UTC (permalink / raw)
  To: davem; +Cc: netdev

Instead of hard-coding reciprocal_divide function, use the inline
function from reciprocal_div.h.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
---
 net/packet/af_packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 91596f5..130e2ea 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1135,7 +1135,7 @@ static unsigned int fanout_demux_hash(struct packet_fanout *f,
 				      struct sk_buff *skb,
 				      unsigned int num)
 {
-	return (((u64)skb->rxhash) * num) >> 32;
+	return reciprocal_divide(skb->rxhash, num);
 }
 
 static unsigned int fanout_demux_lb(struct packet_fanout *f,
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH net-next 3/3] net: packet: document available fanout policies
  2013-08-28 20:13 [PATCH net-next 0/3] pf_packet updates Daniel Borkmann
  2013-08-28 20:13 ` [PATCH net-next 1/3] net: packet: add randomized fanout scheduler Daniel Borkmann
  2013-08-28 20:13 ` [PATCH net-next 2/3] net: packet: use reciprocal_divide in fanout_demux_hash Daniel Borkmann
@ 2013-08-28 20:13 ` Daniel Borkmann
  2013-08-29  5:39 ` [PATCH net-next 0/3] pf_packet updates David Miller
  3 siblings, 0 replies; 10+ messages in thread
From: Daniel Borkmann @ 2013-08-28 20:13 UTC (permalink / raw)
  To: davem; +Cc: netdev

Update documentation to add fanout policies that are available.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
---
 Documentation/networking/packet_mmap.txt | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Documentation/networking/packet_mmap.txt b/Documentation/networking/packet_mmap.txt
index 8572796..c012236 100644
--- a/Documentation/networking/packet_mmap.txt
+++ b/Documentation/networking/packet_mmap.txt
@@ -543,6 +543,14 @@ TPACKET_V2 --> TPACKET_V3:
 In the AF_PACKET fanout mode, packet reception can be load balanced among
 processes. This also works in combination with mmap(2) on packet sockets.
 
+Currently implemented fanout policies are:
+
+  - PACKET_FANOUT_HASH: schedule to socket by skb's rxhash
+  - PACKET_FANOUT_LB: schedule to socket by round-robin
+  - PACKET_FANOUT_CPU: schedule to socket by CPU packet arrives on
+  - PACKET_FANOUT_RND: schedule to socket by random selection
+  - PACKET_FANOUT_ROLLOVER: if one socket is full, rollover to another
+
 Minimal example code by David S. Miller (try things like "./test eth0 hash",
 "./test eth0 lb", etc.):
 
-- 
1.7.11.7

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 2/3] net: packet: use reciprocal_divide in fanout_demux_hash
  2013-08-28 20:13 ` [PATCH net-next 2/3] net: packet: use reciprocal_divide in fanout_demux_hash Daniel Borkmann
@ 2013-08-29  1:47   ` Cong Wang
  0 siblings, 0 replies; 10+ messages in thread
From: Cong Wang @ 2013-08-29  1:47 UTC (permalink / raw)
  To: netdev

On Wed, 28 Aug 2013 at 20:13 GMT, Daniel Borkmann <dborkman@redhat.com> wrote:
> Instead of hard-coding reciprocal_divide function, use the inline
> function from reciprocal_div.h.
>

Then you should #include <linux/reciprocal_div.h> directly?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 0/3] pf_packet updates
  2013-08-28 20:13 [PATCH net-next 0/3] pf_packet updates Daniel Borkmann
                   ` (2 preceding siblings ...)
  2013-08-28 20:13 ` [PATCH net-next 3/3] net: packet: document available fanout policies Daniel Borkmann
@ 2013-08-29  5:39 ` David Miller
  2013-08-29  6:20   ` Daniel Borkmann
  2013-08-29 10:25   ` Eric Dumazet
  3 siblings, 2 replies; 10+ messages in thread
From: David Miller @ 2013-08-29  5:39 UTC (permalink / raw)
  To: dborkman; +Cc: netdev

From: Daniel Borkmann <dborkman@redhat.com>
Date: Wed, 28 Aug 2013 22:13:08 +0200

> Daniel Borkmann (3):
>   net: packet: add random fanout scheduler
>   net: packet: use reciprocal_divide in fanout_demux_hash
>   net: packet: document available fanout policies

Please add the missing reciprocal_divide.h include to the second
patch, as per Eric Dumazet's feedback, and resubmit this series.

Thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 0/3] pf_packet updates
  2013-08-29  5:39 ` [PATCH net-next 0/3] pf_packet updates David Miller
@ 2013-08-29  6:20   ` Daniel Borkmann
  2013-08-29 20:43     ` David Miller
  2013-08-29 10:25   ` Eric Dumazet
  1 sibling, 1 reply; 10+ messages in thread
From: Daniel Borkmann @ 2013-08-29  6:20 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Cong Wang

On 08/29/2013 07:39 AM, David Miller wrote:
> From: Daniel Borkmann <dborkman@redhat.com>
> Date: Wed, 28 Aug 2013 22:13:08 +0200
>
>> Daniel Borkmann (3):
>>    net: packet: add random fanout scheduler
>>    net: packet: use reciprocal_divide in fanout_demux_hash
>>    net: packet: document available fanout policies
>
> Please add the missing reciprocal_divide.h include to the second
> patch, as per Eric Dumazet's feedback, and resubmit this series.

That is already the case in the first patch of the series. It adds:

...
+#include <linux/reciprocal_div.h>
...

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 0/3] pf_packet updates
  2013-08-29  5:39 ` [PATCH net-next 0/3] pf_packet updates David Miller
  2013-08-29  6:20   ` Daniel Borkmann
@ 2013-08-29 10:25   ` Eric Dumazet
  2013-08-29 16:53     ` David Miller
  1 sibling, 1 reply; 10+ messages in thread
From: Eric Dumazet @ 2013-08-29 10:25 UTC (permalink / raw)
  To: David Miller; +Cc: dborkman, netdev

On Thu, 2013-08-29 at 01:39 -0400, David Miller wrote:
> From: Daniel Borkmann <dborkman@redhat.com>
> Date: Wed, 28 Aug 2013 22:13:08 +0200
> 
> > Daniel Borkmann (3):
> >   net: packet: add random fanout scheduler
> >   net: packet: use reciprocal_divide in fanout_demux_hash
> >   net: packet: document available fanout policies
> 
> Please add the missing reciprocal_divide.h include to the second
> patch, as per Eric Dumazet's feedback, and resubmit this series.

(It was Cong Wang feedback ;) )

Thanks

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 0/3] pf_packet updates
  2013-08-29 10:25   ` Eric Dumazet
@ 2013-08-29 16:53     ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2013-08-29 16:53 UTC (permalink / raw)
  To: eric.dumazet; +Cc: dborkman, netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 29 Aug 2013 03:25:45 -0700

> On Thu, 2013-08-29 at 01:39 -0400, David Miller wrote:
>> From: Daniel Borkmann <dborkman@redhat.com>
>> Date: Wed, 28 Aug 2013 22:13:08 +0200
>> 
>> > Daniel Borkmann (3):
>> >   net: packet: add random fanout scheduler
>> >   net: packet: use reciprocal_divide in fanout_demux_hash
>> >   net: packet: document available fanout policies
>> 
>> Please add the missing reciprocal_divide.h include to the second
>> patch, as per Eric Dumazet's feedback, and resubmit this series.
> 
> (It was Cong Wang feedback ;) )

Sorry Eric, I am just too anxious to give you credit everywhere that I
can. :-)

Anyways, thanks for explaining Daniel, I've put these patches back into
the to-apply queue.

Thanks!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH net-next 0/3] pf_packet updates
  2013-08-29  6:20   ` Daniel Borkmann
@ 2013-08-29 20:43     ` David Miller
  0 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2013-08-29 20:43 UTC (permalink / raw)
  To: dborkman; +Cc: netdev, amwang

From: Daniel Borkmann <dborkman@redhat.com>
Date: Thu, 29 Aug 2013 08:20:14 +0200

> On 08/29/2013 07:39 AM, David Miller wrote:
>> From: Daniel Borkmann <dborkman@redhat.com>
>> Date: Wed, 28 Aug 2013 22:13:08 +0200
>>
>>> Daniel Borkmann (3):
>>>    net: packet: add random fanout scheduler
>>>    net: packet: use reciprocal_divide in fanout_demux_hash
>>>    net: packet: document available fanout policies
>>
>> Please add the missing reciprocal_divide.h include to the second
>> patch, as per Eric Dumazet's feedback, and resubmit this series.
> 
> That is already the case in the first patch of the series. It adds:
> 
> ...
> +#include <linux/reciprocal_div.h>

Series applied, thanks Daniel.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-08-29 20:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-28 20:13 [PATCH net-next 0/3] pf_packet updates Daniel Borkmann
2013-08-28 20:13 ` [PATCH net-next 1/3] net: packet: add randomized fanout scheduler Daniel Borkmann
2013-08-28 20:13 ` [PATCH net-next 2/3] net: packet: use reciprocal_divide in fanout_demux_hash Daniel Borkmann
2013-08-29  1:47   ` Cong Wang
2013-08-28 20:13 ` [PATCH net-next 3/3] net: packet: document available fanout policies Daniel Borkmann
2013-08-29  5:39 ` [PATCH net-next 0/3] pf_packet updates David Miller
2013-08-29  6:20   ` Daniel Borkmann
2013-08-29 20:43     ` David Miller
2013-08-29 10:25   ` Eric Dumazet
2013-08-29 16:53     ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).