Skip to content

Commit b26bbda

Browse files
Paolo Abenidavem330
authored andcommitted
udp: move scratch area helpers into the include file
So that they can be later used by the IPv6 code, too. Also lift the comments a bit. Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d97af30 commit b26bbda

File tree

2 files changed

+61
-60
lines changed

2 files changed

+61
-60
lines changed

include/net/udp.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,67 @@ struct sock *__udp6_lib_lookup(struct net *net,
302302
struct sock *udp6_lib_lookup_skb(struct sk_buff *skb,
303303
__be16 sport, __be16 dport);
304304

305+
/* UDP uses skb->dev_scratch to cache as much information as possible and avoid
306+
* possibly multiple cache miss on dequeue()
307+
*/
308+
#if BITS_PER_LONG == 64
309+
310+
/* truesize, len and the bit needed to compute skb_csum_unnecessary will be on
311+
* cold cache lines at recvmsg time.
312+
* skb->len can be stored on 16 bits since the udp header has been already
313+
* validated and pulled.
314+
*/
315+
struct udp_dev_scratch {
316+
u32 truesize;
317+
u16 len;
318+
bool is_linear;
319+
bool csum_unnecessary;
320+
};
321+
322+
static inline unsigned int udp_skb_len(struct sk_buff *skb)
323+
{
324+
return ((struct udp_dev_scratch *)&skb->dev_scratch)->len;
325+
}
326+
327+
static inline bool udp_skb_csum_unnecessary(struct sk_buff *skb)
328+
{
329+
return ((struct udp_dev_scratch *)&skb->dev_scratch)->csum_unnecessary;
330+
}
331+
332+
static inline bool udp_skb_is_linear(struct sk_buff *skb)
333+
{
334+
return ((struct udp_dev_scratch *)&skb->dev_scratch)->is_linear;
335+
}
336+
337+
#else
338+
static inline unsigned int udp_skb_len(struct sk_buff *skb)
339+
{
340+
return skb->len;
341+
}
342+
343+
static inline bool udp_skb_csum_unnecessary(struct sk_buff *skb)
344+
{
345+
return skb_csum_unnecessary(skb);
346+
}
347+
348+
static inline bool udp_skb_is_linear(struct sk_buff *skb)
349+
{
350+
return !skb_is_nonlinear(skb);
351+
}
352+
#endif
353+
354+
static inline int copy_linear_skb(struct sk_buff *skb, int len, int off,
355+
struct iov_iter *to)
356+
{
357+
int n, copy = len - off;
358+
359+
n = copy_to_iter(skb->data + off, copy, to);
360+
if (n == copy)
361+
return 0;
362+
363+
return -EFAULT;
364+
}
365+
305366
/*
306367
* SNMP statistics for UDP and UDP-Lite
307368
*/

net/ipv4/udp.c

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,24 +1163,7 @@ int udp_sendpage(struct sock *sk, struct page *page, int offset,
11631163
return ret;
11641164
}
11651165

1166-
/* Copy as much information as possible into skb->dev_scratch to avoid
1167-
* possibly multiple cache miss on dequeue();
1168-
*/
11691166
#if BITS_PER_LONG == 64
1170-
1171-
/* we can store multiple info here: truesize, len and the bit needed to
1172-
* compute skb_csum_unnecessary will be on cold cache lines at recvmsg
1173-
* time.
1174-
* skb->len can be stored on 16 bits since the udp header has been already
1175-
* validated and pulled.
1176-
*/
1177-
struct udp_dev_scratch {
1178-
u32 truesize;
1179-
u16 len;
1180-
bool is_linear;
1181-
bool csum_unnecessary;
1182-
};
1183-
11841167
static void udp_set_dev_scratch(struct sk_buff *skb)
11851168
{
11861169
struct udp_dev_scratch *scratch;
@@ -1197,22 +1180,6 @@ static int udp_skb_truesize(struct sk_buff *skb)
11971180
{
11981181
return ((struct udp_dev_scratch *)&skb->dev_scratch)->truesize;
11991182
}
1200-
1201-
static unsigned int udp_skb_len(struct sk_buff *skb)
1202-
{
1203-
return ((struct udp_dev_scratch *)&skb->dev_scratch)->len;
1204-
}
1205-
1206-
static bool udp_skb_csum_unnecessary(struct sk_buff *skb)
1207-
{
1208-
return ((struct udp_dev_scratch *)&skb->dev_scratch)->csum_unnecessary;
1209-
}
1210-
1211-
static bool udp_skb_is_linear(struct sk_buff *skb)
1212-
{
1213-
return ((struct udp_dev_scratch *)&skb->dev_scratch)->is_linear;
1214-
}
1215-
12161183
#else
12171184
static void udp_set_dev_scratch(struct sk_buff *skb)
12181185
{
@@ -1223,21 +1190,6 @@ static int udp_skb_truesize(struct sk_buff *skb)
12231190
{
12241191
return skb->dev_scratch;
12251192
}
1226-
1227-
static unsigned int udp_skb_len(struct sk_buff *skb)
1228-
{
1229-
return skb->len;
1230-
}
1231-
1232-
static bool udp_skb_csum_unnecessary(struct sk_buff *skb)
1233-
{
1234-
return skb_csum_unnecessary(skb);
1235-
}
1236-
1237-
static bool udp_skb_is_linear(struct sk_buff *skb)
1238-
{
1239-
return !skb_is_nonlinear(skb);
1240-
}
12411193
#endif
12421194

12431195
/* fully reclaim rmem/fwd memory allocated for skb */
@@ -1598,18 +1550,6 @@ struct sk_buff *__skb_recv_udp(struct sock *sk, unsigned int flags,
15981550
}
15991551
EXPORT_SYMBOL_GPL(__skb_recv_udp);
16001552

1601-
static int copy_linear_skb(struct sk_buff *skb, int len, int off,
1602-
struct iov_iter *to)
1603-
{
1604-
int n, copy = len - off;
1605-
1606-
n = copy_to_iter(skb->data + off, copy, to);
1607-
if (n == copy)
1608-
return 0;
1609-
1610-
return -EFAULT;
1611-
}
1612-
16131553
/*
16141554
* This should be easy, if there is something there we
16151555
* return it, otherwise we block.

0 commit comments

Comments
 (0)