From: Matt Mackall <mpm@selenic.com>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: netdev@oss.sgi.com, Jeff Moyer <jmoyer@redhat.com>
Subject: [PATCH 5/7] netpoll: add optional dropping and queueing support
Date: Thu, 03 Mar 2005 14:46:32 -0600 [thread overview]
Message-ID: <6.454130102@selenic.com> (raw)
In-Reply-To: <5.454130102@selenic.com>
This adds a callback for packets we can't deliver immediately and a
helper function for clients to queue such packets to the device
post-interrupt.
Netconsole is modified to use the queueing function for best-effort
delivery.
Signed-off-by: Matt Mackall <mpm@selenic.com>
Index: rc4/drivers/net/netconsole.c
===================================================================
--- rc4.orig/drivers/net/netconsole.c 2005-02-17 22:39:29.000000000 -0600
+++ rc4/drivers/net/netconsole.c 2005-02-17 22:40:05.000000000 -0600
@@ -60,6 +60,7 @@
.local_port = 6665,
.remote_port = 6666,
.remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
+ .drop = netpoll_queue,
};
static int configured = 0;
Index: rc4/net/core/netpoll.c
===================================================================
--- rc4.orig/net/core/netpoll.c 2005-02-17 22:40:02.000000000 -0600
+++ rc4/net/core/netpoll.c 2005-02-17 22:40:05.000000000 -0600
@@ -19,6 +19,7 @@
#include <linux/netpoll.h>
#include <linux/sched.h>
#include <linux/rcupdate.h>
+#include <linux/workqueue.h>
#include <net/tcp.h>
#include <net/udp.h>
#include <asm/unaligned.h>
@@ -28,13 +29,18 @@
* message gets out even in extreme OOM situations.
*/
-#define MAX_SKBS 32
#define MAX_UDP_CHUNK 1460
+#define MAX_SKBS 32
+#define MAX_QUEUE_DEPTH (MAX_SKBS / 2)
static DEFINE_SPINLOCK(skb_list_lock);
static int nr_skbs;
static struct sk_buff *skbs;
+static DEFINE_SPINLOCK(queue_lock);
+static int queue_depth;
+static struct sk_buff *queue_head, *queue_tail;
+
static atomic_t trapped;
#define NETPOLL_RX_ENABLED 1
@@ -46,6 +52,50 @@
static void zap_completion_queue(void);
+static void queue_process(void *p)
+{
+ unsigned long flags;
+ struct sk_buff *skb;
+
+ while (queue_head) {
+ spin_lock_irqsave(&queue_lock, flags);
+
+ skb = queue_head;
+ queue_head = skb->next;
+ if (skb == queue_tail)
+ queue_head = NULL;
+
+ queue_depth--;
+
+ spin_unlock_irqrestore(&queue_lock, flags);
+
+ dev_queue_xmit(skb);
+ }
+}
+
+static DECLARE_WORK(send_queue, queue_process, NULL);
+
+void netpoll_queue(struct sk_buff *skb)
+{
+ unsigned long flags;
+
+ if (queue_depth == MAX_QUEUE_DEPTH) {
+ __kfree_skb(skb);
+ return;
+ }
+
+ spin_lock_irqsave(&queue_lock, flags);
+ if (!queue_head)
+ queue_head = skb;
+ else
+ queue_tail->next = skb;
+ queue_tail = skb;
+ queue_depth++;
+ spin_unlock_irqrestore(&queue_lock, flags);
+
+ schedule_work(&send_queue);
+}
+
static int checksum_udp(struct sk_buff *skb, struct udphdr *uh,
unsigned short ulen, u32 saddr, u32 daddr)
{
@@ -199,7 +249,10 @@
/* avoid ->poll recursion */
if(np->poll_owner == __smp_processor_id()) {
- __kfree_skb(skb);
+ if (np->drop)
+ np->drop(skb);
+ else
+ __kfree_skb(skb);
return;
}
@@ -275,6 +328,8 @@
memcpy(eth->h_source, np->local_mac, 6);
memcpy(eth->h_dest, np->remote_mac, 6);
+ skb->dev = np->dev;
+
netpoll_send_skb(np, skb);
}
Index: rc4/include/linux/netpoll.h
===================================================================
--- rc4.orig/include/linux/netpoll.h 2005-02-17 22:40:02.000000000 -0600
+++ rc4/include/linux/netpoll.h 2005-02-17 22:40:05.000000000 -0600
@@ -18,6 +18,7 @@
char dev_name[16], *name;
int rx_flags;
void (*rx_hook)(struct netpoll *, int, char *, int);
+ void (*drop)(struct sk_buff *skb);
u32 local_ip, remote_ip;
u16 local_port, remote_port;
unsigned char local_mac[6], remote_mac[6];
@@ -33,6 +34,7 @@
void netpoll_set_trap(int trap);
void netpoll_cleanup(struct netpoll *np);
int __netpoll_rx(struct sk_buff *skb);
+void netpoll_queue(struct sk_buff *skb);
#ifdef CONFIG_NETPOLL
static inline int netpoll_rx(struct sk_buff *skb)
next prev parent reply other threads:[~2005-03-03 20:46 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-03-03 20:46 [PATCH 0/7] netpoll: recursion fixes, queueing, and cleanups Matt Mackall
2005-03-03 20:46 ` [PATCH 1/7] netpoll: shorten carrier detect timeout Matt Mackall
2005-03-03 20:46 ` [PATCH 2/7] netpoll: filter inlines Matt Mackall
2005-03-03 20:46 ` [PATCH 3/7] netpoll: add netpoll point to net_device Matt Mackall
2005-03-03 20:46 ` [PATCH 4/7] netpoll: fix ->poll() locking Matt Mackall
2005-03-03 20:46 ` Matt Mackall [this message]
2005-03-03 20:46 ` [PATCH 6/7] netpoll: handle xmit_lock recursion similarly Matt Mackall
2005-03-03 20:46 ` [PATCH 7/7] netpoll: avoid kfree_skb on packets with destructo Matt Mackall
2005-03-03 21:00 ` David S. Miller
2005-03-03 21:17 ` Jeff Garzik
2005-03-03 21:29 ` David S. Miller
2005-03-03 21:33 ` Jeff Garzik
2005-03-03 21:39 ` Matt Mackall
2005-03-03 21:41 ` David S. Miller
2005-03-03 21:32 ` Matt Mackall
2005-03-23 2:35 ` David S. Miller
2005-04-22 22:24 ` [PATCH 4/7] netpoll: fix ->poll() locking Jeff Moyer
2005-04-22 22:52 ` David S. Miller
2005-04-22 23:02 ` Jeff Moyer
2005-04-22 22:59 ` David S. Miller
2005-04-23 2:14 ` Matt Mackall
2005-04-23 5:12 ` David S. Miller
2005-03-06 0:09 ` [PATCH 1/7] netpoll: shorten carrier detect timeout Patrick McHardy
2005-03-06 0:20 ` Matt Mackall
2005-03-06 1:01 ` Patrick McHardy
2005-03-10 23:01 ` Matt Mackall
2005-03-11 4:35 ` Patrick McHardy
2005-03-11 4:42 ` Matt Mackall
2005-03-11 4:53 ` Patrick McHardy
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=6.454130102@selenic.com \
--to=mpm@selenic.com \
--cc=jgarzik@pobox.com \
--cc=jmoyer@redhat.com \
--cc=netdev@oss.sgi.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;
as well as URLs for NNTP newsgroup(s).