1 Index: linux-2.4.21/include/linux/skbuff.h
2 ===================================================================
3 --- linux-2.4.21.orig/include/linux/skbuff.h 2004-04-24 02:38:40.000000000 -0400
4 +++ linux-2.4.21/include/linux/skbuff.h 2004-04-24 02:47:46.000000000 -0400
9 +/* Support for callback when skb data has been released */
10 +typedef struct zccd /* Zero Copy Callback Descriptor */
11 +{ /* (embed as first member of custom struct) */
12 + atomic_t zccd_count; /* reference count */
13 + void (*zccd_destructor)(struct zccd *); /* callback when refcount reaches zero */
16 +static inline void zccd_init (zccd_t *d, void (*callback)(zccd_t *))
18 + atomic_set (&d->zccd_count, 1);
19 + d->zccd_destructor = callback;
22 +static inline void zccd_get (zccd_t *d) /* take a reference */
24 + atomic_inc (&d->zccd_count);
27 +static inline void zccd_put (zccd_t *d) /* release a reference */
29 + if (atomic_dec_and_test (&d->zccd_count))
30 + (d->zccd_destructor)(d);
33 /* This data is invariant across clones and lives at
34 * the end of the header data, ie. at skb->end.
38 unsigned int nr_frags;
39 struct sk_buff *frag_list;
40 + zccd_t *zccd; /* zero copy descriptor */
41 + zccd_t *zccd2; /* 2nd zero copy descriptor */
42 + /* NB we expect zero-copy data to be at least 1 packet, so
43 + * having 2 zccds means we don't unneccessarily split the packet
44 + * where consecutive zero-copy sends abutt.
46 skb_frag_t frags[MAX_SKB_FRAGS];
49 Index: linux-2.4.21/include/net/tcp.h
50 ===================================================================
51 --- linux-2.4.21.orig/include/net/tcp.h 2004-04-24 02:39:20.000000000 -0400
52 +++ linux-2.4.21/include/net/tcp.h 2004-04-24 02:48:27.000000000 -0400
55 extern int tcp_sendmsg(struct sock *sk, struct msghdr *msg, int size);
56 extern ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset, size_t size, int flags);
57 +extern ssize_t tcp_sendpage_zccd(struct socket *sock, struct page *page, int offset, size_t size,
58 + int flags, zccd_t *zccd);
60 extern int tcp_ioctl(struct sock *sk,
64 int len, int nonblock,
65 int flags, int *addr_len);
66 +extern int tcp_recvpackets(struct sock *sk,
67 + struct sk_buff_head *packets,
68 + int len, int nonblock);
71 extern int tcp_listen_start(struct sock *sk);
73 Index: linux-2.4.21/net/netsyms.c
74 ===================================================================
75 --- linux-2.4.21.orig/net/netsyms.c 2004-04-24 02:39:13.000000000 -0400
76 +++ linux-2.4.21/net/netsyms.c 2004-04-24 02:47:46.000000000 -0400
81 +EXPORT_SYMBOL(tcp_sendpage_zccd);
82 +EXPORT_SYMBOL(tcp_recvpackets);
83 EXPORT_SYMBOL(tcp_read_sock);
85 EXPORT_SYMBOL(netlink_set_err);
86 Index: linux-2.4.21/net/core/skbuff.c
87 ===================================================================
88 --- linux-2.4.21.orig/net/core/skbuff.c 2004-04-24 02:38:40.000000000 -0400
89 +++ linux-2.4.21/net/core/skbuff.c 2004-04-24 02:47:46.000000000 -0400
91 atomic_set(&(skb_shinfo(skb)->dataref), 1);
92 skb_shinfo(skb)->nr_frags = 0;
93 skb_shinfo(skb)->frag_list = NULL;
94 + skb_shinfo(skb)->zccd = NULL; /* skbuffs kick off with NO user zero copy descriptors */
95 + skb_shinfo(skb)->zccd2 = NULL;
102 atomic_dec_and_test(&(skb_shinfo(skb)->dataref))) {
103 + if (skb_shinfo(skb)->zccd != NULL) /* zero copy callback descriptor? */
104 + zccd_put (skb_shinfo(skb)->zccd); /* release hold */
105 + if (skb_shinfo(skb)->zccd2 != NULL) /* 2nd zero copy callback descriptor? */
106 + zccd_put (skb_shinfo(skb)->zccd2); /* release hold */
107 if (skb_shinfo(skb)->nr_frags) {
109 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
111 atomic_set(&(skb_shinfo(skb)->dataref), 1);
112 skb_shinfo(skb)->nr_frags = 0;
113 skb_shinfo(skb)->frag_list = NULL;
114 + skb_shinfo(skb)->zccd = NULL; /* copied data => no user zero copy descriptor */
115 + skb_shinfo(skb)->zccd2 = NULL;
117 /* We are no longer a clone, even if we were. */
120 n->data_len = skb->data_len;
123 + if (skb_shinfo(skb)->zccd != NULL) /* user zero copy descriptor? */
124 + zccd_get (skb_shinfo(skb)->zccd); /* 1 more ref (pages are shared) */
125 + skb_shinfo(n)->zccd = skb_shinfo(skb)->zccd;
127 + if (skb_shinfo(skb)->zccd2 != NULL) /* 2nd user zero copy descriptor? */
128 + zccd_get (skb_shinfo(skb)->zccd2); /* 1 more ref (pages are shared) */
129 + skb_shinfo(n)->zccd2 = skb_shinfo(skb)->zccd2;
131 if (skb_shinfo(skb)->nr_frags) {
136 int size = nhead + (skb->end - skb->head) + ntail;
138 + zccd_t *zccd = skb_shinfo(skb)->zccd; /* stash user zero copy descriptor */
139 + zccd_t *zccd2 = skb_shinfo(skb)->zccd2; /* stash 2nd user zero copy descriptor */
144 if (skb_shinfo(skb)->frag_list)
145 skb_clone_fraglist(skb);
147 + if (zccd != NULL) /* user zero copy descriptor? */
148 + zccd_get (zccd); /* extra ref (pages are shared) */
149 + if (zccd2 != NULL) /* 2nd user zero copy descriptor? */
150 + zccd_get (zccd2); /* extra ref (pages are shared) */
152 skb_release_data(skb);
154 off = (data+nhead) - skb->head;
158 atomic_set(&skb_shinfo(skb)->dataref, 1);
159 + skb_shinfo(skb)->zccd = zccd;
160 + skb_shinfo(skb)->zccd2 = zccd2;
164 Index: linux-2.4.21/net/ipv4/tcp.c
165 ===================================================================
166 --- linux-2.4.21.orig/net/ipv4/tcp.c 2004-04-24 02:39:21.000000000 -0400
167 +++ linux-2.4.21/net/ipv4/tcp.c 2004-04-24 02:50:40.000000000 -0400
172 -ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size_t psize, int flags);
173 +ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size_t psize, int flags, zccd_t *zccd);
176 can_coalesce(struct sk_buff *skb, int i, struct page *page, int off)
181 -ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size_t psize, int flags)
182 +ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffset, size_t psize, int flags, zccd_t *zccd)
184 struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
189 i = skb_shinfo(skb)->nr_frags;
191 + if (zccd != NULL && /* this is a zcc I/O */
192 + skb_shinfo(skb)->zccd != NULL && /* skb is part of a zcc I/O */
193 + skb_shinfo(skb)->zccd2 != NULL &&
194 + skb_shinfo(skb)->zccd != zccd && /* not the same one */
195 + skb_shinfo(skb)->zccd2 != zccd)
197 + tcp_mark_push (tp, skb);
201 if (can_coalesce(skb, i, page, offset)) {
202 skb_shinfo(skb)->frags[i-1].size += copy;
203 } else if (i < MAX_SKB_FRAGS) {
208 + if (zccd != NULL && /* this is a zcc I/O */
209 + skb_shinfo(skb)->zccd != zccd && /* not already referencing this zccd */
210 + skb_shinfo(skb)->zccd2 != zccd)
212 + zccd_get (zccd); /* bump ref count */
214 + BUG_TRAP (skb_shinfo(skb)->zccd2 == NULL);
216 + if (skb_shinfo(skb)->zccd == NULL) /* reference this zccd */
217 + skb_shinfo(skb)->zccd = zccd;
219 + skb_shinfo(skb)->zccd2 = zccd;
223 skb->data_len += copy;
224 skb->ip_summed = CHECKSUM_HW;
229 - res = do_tcp_sendpages(sk, &page, offset, size, flags);
230 + res = do_tcp_sendpages(sk, &page, offset, size, flags, NULL);
231 + TCP_CHECK_TIMER(sk);
236 +ssize_t tcp_sendpage_zccd(struct socket *sock, struct page *page, int offset, size_t size,
237 + int flags, zccd_t *zccd)
240 + struct sock *sk = sock->sk;
242 +#define TCP_ZC_CSUM_FLAGS (NETIF_F_IP_CSUM|NETIF_F_NO_CSUM|NETIF_F_HW_CSUM)
244 + if (!(sk->route_caps & NETIF_F_SG) || /* caller shouldn't waste her time */
245 + !(sk->route_caps & TCP_ZC_CSUM_FLAGS)) /* on double mapping */
249 + TCP_CHECK_TIMER(sk);
251 + res = do_tcp_sendpages(sk, &page, 0, size, flags, zccd);
256 @@ -1772,6 +1819,202 @@
260 +int tcp_recvpackets (struct sock *sk, struct sk_buff_head *packets,
261 + int len, int nonblock)
263 + struct tcp_opt *tp = &(sk->tp_pinfo.af_tcp);
267 + BUG_TRAP (len > 0);
268 + /*BUG_TRAP ((flags & (MSG_OOB | MSG_PEEK | MSG_TRUNC)) == 0);*/
272 + TCP_CHECK_TIMER(sk);
274 + copied = -ENOTCONN;
275 + if (sk->state == TCP_LISTEN)
279 + timeo = sock_rcvtimeo(sk, nonblock);
282 + struct sk_buff * skb;
284 + unsigned long used;
288 + /* Are we at urgent data? Stop if we have read anything. */
289 + if (copied && tp->urg_data && tp->urg_seq == tp->copied_seq)
292 + /* We need to check signals first, to get correct SIGURG
293 + * handling. FIXME: Need to check this doesnt impact 1003.1g
294 + * and move it down to the bottom of the loop
296 + if (signal_pending(current)) {
299 + copied = timeo ? sock_intr_errno(timeo) : -EAGAIN;
303 + /* Next get a buffer. */
305 + skb = skb_peek(&sk->receive_queue);
307 + if (skb == NULL) /* nothing ready */
311 + sk->state == TCP_CLOSE ||
312 + (sk->shutdown & RCV_SHUTDOWN) ||
321 + copied = sock_error(sk);
325 + if (sk->shutdown & RCV_SHUTDOWN)
328 + if (sk->state == TCP_CLOSE) {
330 + /* This occurs when user tries to read
331 + * from never connected socket.
333 + copied = -ENOTCONN;
345 + cleanup_rbuf(sk, copied);
346 + timeo = tcp_data_wait(sk, timeo);
350 + BUG_TRAP (atomic_read (&skb->users) == 1);
352 + exhausted = eaten = 0;
354 + offset = tp->copied_seq - TCP_SKB_CB(skb)->seq;
355 + if (skb->h.th->syn)
358 + used = skb->len - offset;
360 + if (tp->urg_data) {
361 + u32 urg_offset = tp->urg_seq - tp->copied_seq;
362 + if (urg_offset < used) {
363 + if (!urg_offset) { /* at urgent date */
364 + if (!sk->urginline) {
365 + tp->copied_seq++; /* discard the single byte of urgent data */
369 + } else /* truncate read */
374 + BUG_TRAP (used >= 0);
382 + if (skb_is_nonlinear (skb))
384 + int rc = skb_linearize (skb, GFP_KERNEL);
386 + printk ("tcp_recvpackets(): linearising: %d\n", rc);
396 + if ((offset + used) == skb->len) /* consuming the whole packet */
398 + __skb_unlink (skb, &sk->receive_queue);
399 + dst_release (skb->dst);
401 + __skb_pull (skb, offset);
402 + __skb_queue_tail (packets, skb);
403 + exhausted = eaten = 1;
405 + else /* consuming only part of the packet */
407 + struct sk_buff *skb2 = skb_clone (skb, GFP_KERNEL);
416 + dst_release (skb2->dst);
417 + __skb_pull (skb2, offset);
418 + __skb_trim (skb2, used);
419 + __skb_queue_tail (packets, skb2);
422 + tp->copied_seq += used;
427 + if (tp->urg_data && after(tp->copied_seq,tp->urg_seq)) {
429 + tcp_fast_path_check(sk, tp);
435 + if (skb->h.th->fin)
439 + tcp_eat_skb (sk, skb);
444 + tcp_eat_skb (sk, skb);
449 + /* Clean up data we have read: This will do ACK frames. */
450 + cleanup_rbuf(sk, copied);
451 + TCP_CHECK_TIMER(sk);
457 * State processing on a close. This implements the state shift for
458 * sending our FIN frame. Note that we only send a FIN for some