2012-08-13 13:49:39 +08:00
|
|
|
#ifndef __PACKET_INTERNAL_H__
|
|
|
|
#define __PACKET_INTERNAL_H__
|
|
|
|
|
|
|
|
struct packet_mclist {
|
|
|
|
struct packet_mclist *next;
|
|
|
|
int ifindex;
|
|
|
|
int count;
|
|
|
|
unsigned short type;
|
|
|
|
unsigned short alen;
|
|
|
|
unsigned char addr[MAX_ADDR_LEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
/* kbdq - kernel block descriptor queue */
|
|
|
|
struct tpacket_kbdq_core {
|
|
|
|
struct pgv *pkbdq;
|
|
|
|
unsigned int feature_req_word;
|
|
|
|
unsigned int hdrlen;
|
|
|
|
unsigned char reset_pending_on_curr_blk;
|
|
|
|
unsigned char delete_blk_timer;
|
|
|
|
unsigned short kactive_blk_num;
|
|
|
|
unsigned short blk_sizeof_priv;
|
|
|
|
|
|
|
|
/* last_kactive_blk_num:
|
|
|
|
* trick to see if user-space has caught up
|
|
|
|
* in order to avoid refreshing timer when every single pkt arrives.
|
|
|
|
*/
|
|
|
|
unsigned short last_kactive_blk_num;
|
|
|
|
|
|
|
|
char *pkblk_start;
|
|
|
|
char *pkblk_end;
|
|
|
|
int kblk_size;
|
|
|
|
unsigned int knum_blocks;
|
|
|
|
uint64_t knxt_seq_num;
|
|
|
|
char *prev;
|
|
|
|
char *nxt_offset;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
|
|
|
|
atomic_t blk_fill_in_prog;
|
|
|
|
|
|
|
|
/* Default is set to 8ms */
|
|
|
|
#define DEFAULT_PRB_RETIRE_TOV (8)
|
|
|
|
|
|
|
|
unsigned short retire_blk_tov;
|
|
|
|
unsigned short version;
|
|
|
|
unsigned long tov_in_jiffies;
|
|
|
|
|
|
|
|
/* timer to retire an outstanding block */
|
|
|
|
struct timer_list retire_blk_timer;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pgv {
|
|
|
|
char *buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct packet_ring_buffer {
|
|
|
|
struct pgv *pg_vec;
|
2013-04-19 14:12:28 +08:00
|
|
|
|
2012-08-13 13:49:39 +08:00
|
|
|
unsigned int head;
|
|
|
|
unsigned int frames_per_block;
|
|
|
|
unsigned int frame_size;
|
|
|
|
unsigned int frame_max;
|
|
|
|
|
|
|
|
unsigned int pg_vec_order;
|
|
|
|
unsigned int pg_vec_pages;
|
|
|
|
unsigned int pg_vec_len;
|
|
|
|
|
|
|
|
atomic_t pending;
|
2013-04-19 14:12:28 +08:00
|
|
|
|
|
|
|
struct tpacket_kbdq_core prb_bdqc;
|
2012-08-13 13:49:39 +08:00
|
|
|
};
|
|
|
|
|
2012-08-16 13:36:48 +08:00
|
|
|
extern struct mutex fanout_mutex;
|
|
|
|
#define PACKET_FANOUT_MAX 256
|
|
|
|
|
|
|
|
struct packet_fanout {
|
|
|
|
#ifdef CONFIG_NET_NS
|
|
|
|
struct net *net;
|
|
|
|
#endif
|
|
|
|
unsigned int num_members;
|
|
|
|
u16 id;
|
|
|
|
u8 type;
|
packet: packet fanout rollover during socket overload
Changes:
v3->v2: rebase (no other changes)
passes selftest
v2->v1: read f->num_members only once
fix bug: test rollover mode + flag
Minimize packet drop in a fanout group. If one socket is full,
roll over packets to another from the group. Maintain flow
affinity during normal load using an rxhash fanout policy, while
dispersing unexpected traffic storms that hit a single cpu, such
as spoofed-source DoS flows. Rollover breaks affinity for flows
arriving at saturated sockets during those conditions.
The patch adds a fanout policy ROLLOVER that rotates between sockets,
filling each socket before moving to the next. It also adds a fanout
flag ROLLOVER. If passed along with any other fanout policy, the
primary policy is applied until the chosen socket is full. Then,
rollover selects another socket, to delay packet drop until the
entire system is saturated.
Probing sockets is not free. Selecting the last used socket, as
rollover does, is a greedy approach that maximizes chance of
success, at the cost of extreme load imbalance. In practice, with
sufficiently long queues to absorb bursts, sockets are drained in
parallel and load balance looks uniform in `top`.
To avoid contention, scales counters with number of sockets and
accesses them lockfree. Values are bounds checked to ensure
correctness.
Tested using an application with 9 threads pinned to CPUs, one socket
per thread and sufficient busywork per packet operation to limits each
thread to handling 32 Kpps. When sent 500 Kpps single UDP stream
packets, a FANOUT_CPU setup processes 32 Kpps in total without this
patch, 270 Kpps with the patch. Tested with read() and with a packet
ring (V1).
Also, passes psock_fanout.c unit test added to selftests.
Signed-off-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-03-19 18:18:11 +08:00
|
|
|
u8 flags;
|
2012-08-16 13:36:48 +08:00
|
|
|
atomic_t rr_cur;
|
|
|
|
struct list_head list;
|
|
|
|
struct sock *arr[PACKET_FANOUT_MAX];
|
packet: packet fanout rollover during socket overload
Changes:
v3->v2: rebase (no other changes)
passes selftest
v2->v1: read f->num_members only once
fix bug: test rollover mode + flag
Minimize packet drop in a fanout group. If one socket is full,
roll over packets to another from the group. Maintain flow
affinity during normal load using an rxhash fanout policy, while
dispersing unexpected traffic storms that hit a single cpu, such
as spoofed-source DoS flows. Rollover breaks affinity for flows
arriving at saturated sockets during those conditions.
The patch adds a fanout policy ROLLOVER that rotates between sockets,
filling each socket before moving to the next. It also adds a fanout
flag ROLLOVER. If passed along with any other fanout policy, the
primary policy is applied until the chosen socket is full. Then,
rollover selects another socket, to delay packet drop until the
entire system is saturated.
Probing sockets is not free. Selecting the last used socket, as
rollover does, is a greedy approach that maximizes chance of
success, at the cost of extreme load imbalance. In practice, with
sufficiently long queues to absorb bursts, sockets are drained in
parallel and load balance looks uniform in `top`.
To avoid contention, scales counters with number of sockets and
accesses them lockfree. Values are bounds checked to ensure
correctness.
Tested using an application with 9 threads pinned to CPUs, one socket
per thread and sufficient busywork per packet operation to limits each
thread to handling 32 Kpps. When sent 500 Kpps single UDP stream
packets, a FANOUT_CPU setup processes 32 Kpps in total without this
patch, 270 Kpps with the patch. Tested with read() and with a packet
ring (V1).
Also, passes psock_fanout.c unit test added to selftests.
Signed-off-by: Willem de Bruijn <willemb@google.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-03-19 18:18:11 +08:00
|
|
|
int next[PACKET_FANOUT_MAX];
|
2012-08-16 13:36:48 +08:00
|
|
|
spinlock_t lock;
|
|
|
|
atomic_t sk_ref;
|
|
|
|
struct packet_type prot_hook ____cacheline_aligned_in_smp;
|
|
|
|
};
|
|
|
|
|
2012-08-13 13:49:39 +08:00
|
|
|
struct packet_sock {
|
|
|
|
/* struct sock has to be the first member of packet_sock */
|
|
|
|
struct sock sk;
|
|
|
|
struct packet_fanout *fanout;
|
2013-04-19 14:12:29 +08:00
|
|
|
union tpacket_stats_u stats;
|
2012-08-13 13:49:39 +08:00
|
|
|
struct packet_ring_buffer rx_ring;
|
|
|
|
struct packet_ring_buffer tx_ring;
|
|
|
|
int copy_thresh;
|
|
|
|
spinlock_t bind_lock;
|
|
|
|
struct mutex pg_vec_lock;
|
|
|
|
unsigned int running:1, /* prot_hook is attached*/
|
|
|
|
auxdata:1,
|
|
|
|
origdev:1,
|
|
|
|
has_vnet_hdr:1;
|
|
|
|
int ifindex; /* bound device */
|
|
|
|
__be16 num;
|
|
|
|
struct packet_mclist *mclist;
|
|
|
|
atomic_t mapped;
|
|
|
|
enum tpacket_versions tp_version;
|
|
|
|
unsigned int tp_hdrlen;
|
|
|
|
unsigned int tp_reserve;
|
|
|
|
unsigned int tp_loss:1;
|
2012-11-07 07:10:47 +08:00
|
|
|
unsigned int tp_tx_has_off:1;
|
2012-08-13 13:49:39 +08:00
|
|
|
unsigned int tp_tstamp;
|
2013-11-21 23:50:58 +08:00
|
|
|
struct net_device __rcu *cached_dev;
|
packet: introduce PACKET_QDISC_BYPASS socket option
This patch introduces a PACKET_QDISC_BYPASS socket option, that
allows for using a similar xmit() function as in pktgen instead
of taking the dev_queue_xmit() path. This can be very useful when
PF_PACKET applications are required to be used in a similar
scenario as pktgen, but with full, flexible packet payload that
needs to be provided, for example.
On default, nothing changes in behaviour for normal PF_PACKET
TX users, so everything stays as is for applications. New users,
however, can now set PACKET_QDISC_BYPASS if needed to prevent
own packets from i) reentering packet_rcv() and ii) to directly
push the frame to the driver.
In doing so we can increase pps (here 64 byte packets) for
PF_PACKET a bit:
# CPUs -- QDISC_BYPASS -- qdisc path -- qdisc path[**]
1 CPU == 1,509,628 pps -- 1,208,708 -- 1,247,436
2 CPUs == 3,198,659 pps -- 2,536,012 -- 1,605,779
3 CPUs == 4,787,992 pps -- 3,788,740 -- 1,735,610
4 CPUs == 6,173,956 pps -- 4,907,799 -- 1,909,114
5 CPUs == 7,495,676 pps -- 5,956,499 -- 2,014,422
6 CPUs == 9,001,496 pps -- 7,145,064 -- 2,155,261
7 CPUs == 10,229,776 pps -- 8,190,596 -- 2,220,619
8 CPUs == 11,040,732 pps -- 9,188,544 -- 2,241,879
9 CPUs == 12,009,076 pps -- 10,275,936 -- 2,068,447
10 CPUs == 11,380,052 pps -- 11,265,337 -- 1,578,689
11 CPUs == 11,672,676 pps -- 11,845,344 -- 1,297,412
[...]
20 CPUs == 11,363,192 pps -- 11,014,933 -- 1,245,081
[**]: qdisc path with packet_rcv(), how probably most people
seem to use it (hopefully not anymore if not needed)
The test was done using a modified trafgen, sending a simple
static 64 bytes packet, on all CPUs. The trick in the fast
"qdisc path" case, is to avoid reentering packet_rcv() by
setting the RAW socket protocol to zero, like:
socket(PF_PACKET, SOCK_RAW, 0);
Tradeoffs are documented as well in this patch, clearly, if
queues are busy, we will drop more packets, tc disciplines are
ignored, and these packets are not visible to taps anymore. For
a pktgen like scenario, we argue that this is acceptable.
The pointer to the xmit function has been placed in packet
socket structure hole between cached_dev and prot_hook that
is hot anyway as we're working on cached_dev in each send path.
Done in joint work together with Jesper Dangaard Brouer.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-12-06 18:36:17 +08:00
|
|
|
int (*xmit)(struct sk_buff *skb);
|
2012-08-13 13:49:39 +08:00
|
|
|
struct packet_type prot_hook ____cacheline_aligned_in_smp;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct packet_sock *pkt_sk(struct sock *sk)
|
|
|
|
{
|
|
|
|
return (struct packet_sock *)sk;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|