: net/ipv{4,6}: reduce code size by inlining
Subsystems (3)
PATCH v2 2/2 : net/ipv{4,6}: reduce code size by inlining
[UDP]: Reduce size of shared code
This patch reduces size of source code files by moving some of the smaller functions shared by UDP and UDP-Lite into the header file udp_impl.h, and in-lining these.
It is an optimisation and applies on top of the previous UDP-Lite patch.
------------------------------------------------------------------------------
net/ipv4/udp.c | 74 ++------------------------------------------------- net/ipv4/udp_impl.h | 75 +++++++++++++++++++++++++++++++++++++++++++++------- net/ipv6/udp.c | 70 ++---------------------------------------------- net/ipv6/udp_impl.h | 72 +++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 136 insertions(+), 155 deletions(-)
------------------------------------------------------------------------------
net/ipv4/udp_impl.h +65 -10
@@ -11,26 +11,81 @@ extern void __udp4_lib_err(struct sk_buextern int __udp_lib_get_port (struct sock *sk,unsigned short snum,struct hlist_head udptable[],int *port_rover,int (*)(const struct sock *,const struct sock *)); -extern int ipv4_rcv_saddr_equal (const struct sock *,const struct sock *); +static inline int ipv4_rcv_saddr_equal (const struct sock *sk1,const struct sock *sk2) +{ +struct inet_sock *inet1 =inet_sk (sk1), *inet2 =inet_sk (sk2); -extern int udp_setsockopt (struct sock *sk,int level,int optname, -char __user *optval,int optlen); -extern int udp_getsockopt (struct sock *sk,int level,int optname, -char __user *optval,int __user *optlen); +return ( !ipv6_only_sock (sk2) && + (!inet1->rcv_saddr || !inet2->rcv_saddr || + inet1->rcv_saddr == inet2->rcv_saddr )); +} + +extern int do_udp_setsockopt (struct sock *sk,int level,int optname, +char __user *optval,int optlen); +extern int do_udp_getsockopt (struct sock *sk,int level,int optname, +char __user *optval,int __user *optlen); + +static inline int udp_setsockopt (struct sock *sk,int level,int optname, +char __user *optval,int optlen) +{ +if (level ==SOL_UDP || level ==SOL_UDPLITE ) +return do_udp_setsockopt (sk, level, optname, optval, optlen); +return ip_setsockopt (sk, level, optname, optval, optlen); +} + +static inline int udp_getsockopt (struct sock *sk,int level,int optname, +char __user *optval,int __user *optlen) +{ +if (level ==SOL_UDP || level ==SOL_UDPLITE ) +return do_udp_getsockopt (sk, level, optname, optval, optlen); +return ip_getsockopt (sk, level, optname, optval, optlen); +}#ifdef CONFIG_COMPAT -extern int compat_udp_setsockopt (struct sock *sk,int level,int optname, -char __user *optval,int optlen); -extern int compat_udp_getsockopt (struct sock *sk,int level,int optname, -char __user *optval,int __user *optlen); +static inline int compat_udp_setsockopt (struct sock *sk,int level,int optname, +char __user *optval,int optlen) +{ +if (level ==SOL_UDP || level ==SOL_UDPLITE ) +return do_udp_setsockopt (sk, level, optname, optval, optlen); +return compat_ip_setsockopt (sk, level, optname, optval, optlen); +} +static inline int compat_udp_getsockopt (struct sock *sk,int level,int optname, +char __user *optval,int __user *optlen) +{ +if (level ==SOL_UDP || level ==SOL_UDPLITE ) +return do_udp_getsockopt (sk, level, optname, optval, optlen); +return compat_ip_getsockopt (sk, level, optname, optval, optlen); +}#endif +extern int udp_recvmsg (struct kiocb *iocb,struct sock *sk,struct msghdr *msg,size_t len,int noblock,int flags,int *addr_len);extern int udp_sendpage (struct sock *sk,struct page *page,int offset,size_t size,int flags);extern int udp_queue_rcv_skb (struct sock * sk,struct sk_buff *skb); -extern int udp_destroy_sock (struct sock *sk); + +/* +* Throw away all pending data and cancel the corking. Socket is locked. +*/ +static inline void udp_flush_pending_frames (struct sock *sk) +{ +struct udp_sock *up =udp_sk (sk); + +if (up->pending) { + up->len =0 ; + up->pending =0 ; +ip_flush_pending_frames (sk); + } +} + +static inline int udp_destroy_sock (struct sock *sk) +{ +lock_sock (sk); +udp_flush_pending_frames (sk); +release_sock (sk); +return 0 ; +}#ifdef CONFIG_PROC_FS extern int udp4_seq_show (struct seq_file *seq,void *v);
net/ipv4/udp.c +4 -70
107 lines not on this page · raw message
net/ipv6/udp_impl.h +63 -9
92 lines not on this page · raw message
net/ipv6/udp.c +4 -66
103 lines not on this page · raw message
Quoted 8 lines · Gerrit Renker
[UDP]: Reduce size of shared code
This patch reduces size of source code files by moving some of the smaller functions shared by UDP and UDP-Lite into the header file
udp_impl.h, and in-lining these.It is an optimisation and applies on top of the previous UDP-Lite patch.
Wouldn't it be better to just call them? They all don't particularly time critical.
-Andi
Quoting Andi Kleen:
| On Tuesday 14 November 2006 09:49, Gerrit Renker wrote: | > [UDP]: Reduce size of shared code | > | > This patch reduces size of source code files by moving | > some of the smaller functions shared by UDP and UDP-Lite | > into the header file udp_impl.h, and in-lining these. | > | > It is an optimisation and applies on top of the previous | > UDP-Lite patch. | | Wouldn't it be better to just call them? They all don't | particularly time critical.
This patch was sent as an optional add-on, it is not as important as the other one. You are probably right - I also noted that the gains (in terms of line numbers) are not as high as intended.
David Miller
maintainerFrom: Gerrit Renker <[email protected]>
Date: Tue, 14 Nov 2006 12:50:33 +0000
Quoted 13 lines
Quoting Andi Kleen:
| On Tuesday 14 November 2006 09:49, Gerrit Renker wrote: | > [UDP]: Reduce size of shared code | > | > This patch reduces size of source code files by moving | > some of the smaller functions shared by UDP and UDP-Lite | > into the header file udp_impl.h, and in-lining these. | > | > It is an optimisation and applies on top of the previous | > UDP-Lite patch. | | Wouldn't it be better to just call them? They all don't | particularly time critical.
Quoted 3 lines
This patch was sent as an optional add-on, it is not as important as the other one. You are probably right - I also noted that the gains (in terms of line numbers) are not as high as intended.
I'm not too sure on this one either, so I won't apply this one for now.