Subject: [PATCH-2.6.0-tiny] "uninline" {lock,release}_sock

From: Arnaldo Carvalho de Melo <[email-masked]>
Date: Sun, 28 Dec 2003 05:54:27 -0200

Hi Matt,

	Please apply on top of your 2.6.0-tiny1 tree, CC to netdev for
eventual comments.

	With this patch we save more 3.321 bytes. At a first compilation
on top of plain 2.6.0 I thought I had seen it save more, will perhaps check
this later... if you optimized some of the kernel primitives that are called
by the current lock_sock/release_sock... Nah, too sleepy now :)

	Will test too with lock_sock/release_sock as an inline (or not if
CONFIG_NET_SMALL is selected) and not as a macro as it is today, does anybody
knows why it isn't already inline? Dave? /me must be missing something here...

   text    data     bss     dec     hex filename  patch        savings
 858052  163460   65068 1086580  109474 vmlinux   2.6.0-tiny1
 854697  163494   65068 1083259  10877b vmlinux   lock_sock       3321

Best Regards,

- Arnaldo

diff -urp linux-2.6.0.tiny.orig/include/net/sock.h linux-2.6.0.tiny.acme/include/net/sock.h
--- linux-2.6.0.tiny.orig/include/net/sock.h	2003-12-18 00:59:15.000000000 -0200
+++ linux-2.6.0.tiny.acme/include/net/sock.h	2003-12-28 01:32:50.000000000 -0200
@@ -542,7 +542,7 @@ static inline struct inode *SOCK_INODE(s
 extern void __lock_sock(struct sock *sk);
 extern void __release_sock(struct sock *sk);
 #define sock_owned_by_user(sk)	((sk)->sk_lock.owner)
-#define lock_sock(__sk) \
+#define _lock_sock(__sk) \
 do {	might_sleep(); \
 	spin_lock_bh(&((__sk)->sk_lock.slock)); \
 	if ((__sk)->sk_lock.owner) \
@@ -551,7 +551,7 @@ do {	might_sleep(); \
 	spin_unlock_bh(&((__sk)->sk_lock.slock)); \
 } while(0)
 
-#define release_sock(__sk) \
+#define _release_sock(__sk) \
 do {	spin_lock_bh(&((__sk)->sk_lock.slock)); \
 	if ((__sk)->sk_backlog.tail) \
 		__release_sock(__sk); \
@@ -561,6 +561,14 @@ do {	spin_lock_bh(&((__sk)->sk_lock.sloc
 	spin_unlock_bh(&((__sk)->sk_lock.slock)); \
 } while(0)
 
+#ifdef CONFIG_NET_SMALL
+extern void lock_sock(struct sock *sk);
+extern void release_sock(struct sock *sk);
+#else
+#define lock_sock(__sk) _lock_sock(__sk)
+#define release_sock(__sk) _release_sock(__sk)
+#endif
+
 /* BH context may only use the following locking interface. */
 #define bh_lock_sock(__sk)	spin_lock(&((__sk)->sk_lock.slock))
 #define bh_unlock_sock(__sk)	spin_unlock(&((__sk)->sk_lock.slock))
diff -urp linux-2.6.0.tiny.orig/net/core/sock.c linux-2.6.0.tiny.acme/net/core/sock.c
--- linux-2.6.0.tiny.orig/net/core/sock.c	2003-12-18 00:59:15.000000000 -0200
+++ linux-2.6.0.tiny.acme/net/core/sock.c	2003-12-28 01:32:50.000000000 -0200
@@ -1119,6 +1119,22 @@ void sock_init_data(struct socket *sock,
 	atomic_set(&sk->sk_refcnt, 1);
 }
 
+#ifdef CONFIG_NET_SMALL
+void lock_sock(struct sock *sk)
+{
+	_lock_sock(sk);
+}
+
+EXPORT_SYMBOL(lock_sock);
+
+void release_sock(struct sock *sk)
+{
+	_release_sock(sk);
+}
+
+EXPORT_SYMBOL(release_sock);
+#endif
+
 EXPORT_SYMBOL(__lock_sock);
 EXPORT_SYMBOL(__release_sock);
 EXPORT_SYMBOL(sk_alloc);