lkml.org 
[lkml]   [1999]   [Sep]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject#include cleanup (was linux/malloc.h)
Date
Ok,

For those of you who missed my previous mailing on this subject, I have
suggested modifing the include files to remove some of the inter-dependencies
between them. As the situation stands with 2.3.16, you probably only need
to include in each .c file a single Linux header file - malloc.h.

Why? Well, malloc.h only includes slab.h. slab.h unfortunately includes
mm.h. Big deal. Oh, and about 160 other #include statements which
pull in sched.h, tty.h, fs.h and all their dependents. Did someone mention
the whole set in include/linux? Not quite, but it's getting on for 50%.
This makes a farse of makefiles and dependencies.

So, what can be done about it? Well, one way is to look at why there are
all these dependencies between them. What can we get rid of?

1. Needless #includes. There are some in there. Have a look through
capability.h, and you will come to realise very quickly that fs.h
is not actually required. Don't remove it though! Although
capability.h doesn't need it, there's going to be other files
which are relying on that being there.

2. #includes to get structure prototypes. This could be a contravercial
point, but my reasoning behind this is as follows.

The reason you dependency files is to work out what needs to be
recompiled after changing a make file. The dependency file is
generated by scanning all the files for #include statements.
The reason that you #include header files is to get some useful
and beneficial information from it.

Now, take two header files, thus:

a.h:

struct foo {
int a;
int b;
};

b.h:

#include "a.h"

struct bar {
int c;
struct foo *d;
};

With dependencies generated from #include statements, you are saying
that something in 'b.h' relies on the definition in 'a.h'. This is
obviously not true in this case, since you are only relying on the
compiler knowing that 'struct foo' is valid, not what size, what it
contains, or anything like that. If you like, that is 'private' to
a.h.

Now, for the purposes of this example, say a.h is actually linux/fs.h,
and struct foo is struct file, b.h is linux/sched.h, and struct bar
is struct task_struct.

Is it really worth including fs.h and about 70 unique (103 #include
statements seen by the compiler) just to tell the compiler that
'struct file' exists?

Similar situations occur through out the header files. In an attempt to
get something started, you can try out the following patch. Oh, you may
want to try an experiment on a lightly loaded machine. Firstly, make
your 2.3.16 kernel source clean and dep, and then use 'time' to measure
how long it takes to compilation. Then, make clean, apply this patch,
make dep and time the recompile. Use 'make linuxsubdirs' for this.

Looking at just the linux/kernel directory, I can get knock off 30% of the
compile time just by getting rid of the sched.h's fs.h and tty.h dependency.

::: Note: I expect that things may get broken by this patch
::: I would prefer to receive patches to fix these breakages,
::: but I may be pursuaded to fix some of them, provided I
::: receive all relevent info on it.

Anyway, enough talk, here's part 1 of the patch (removes sched.h's dependency
on tty.h):

diff -ur -x .* -x *.[oas] linux/drivers/char/consolemap.c linux-ebsa285/drivers/char/consolemap.c
--- linux/drivers/char/consolemap.c Fri Jul 9 22:45:05 1999
+++ linux-ebsa285/drivers/char/consolemap.c Mon Sep 6 23:17:55 1999
@@ -16,10 +16,12 @@
#include <linux/mm.h>
#include <linux/malloc.h>
#include <linux/init.h>
-#include <asm/uaccess.h>
+#include <linux/tty.h>
#include <linux/consolemap.h>
#include <linux/console_struct.h>
#include <linux/vt_kern.h>
+
+#include <asm/uaccess.h>

static unsigned short translations[][256] = {
/* 8-bit Latin-1 mapped to Unicode -- trivial mapping */
diff -ur -x .* -x *.[oas] linux/drivers/char/mem.c linux-ebsa285/drivers/char/mem.c
--- linux/drivers/char/mem.c Sat Aug 21 22:56:38 1999
+++ linux-ebsa285/drivers/char/mem.c Tue Sep 7 07:43:34 1999
@@ -18,6 +18,7 @@
#include <linux/i2c.h>
#include <linux/raw.h>
#include <linux/capability.h>
+#include <linux/major.h>

#include <asm/uaccess.h>
#include <asm/io.h>
@@ -56,6 +57,7 @@
#ifdef CONFIG_USB
extern void usb_init(void);
#endif
+extern int tty_init(void);

static ssize_t do_write_mem(struct file * file, void *p, unsigned long realp,
const char * buf, size_t count, loff_t *ppos)
diff -ur -x .* -x *.[oas] linux/drivers/char/random.c linux-ebsa285/drivers/char/random.c
--- linux/drivers/char/random.c Sat Sep 4 19:05:20 1999
+++ linux-ebsa285/drivers/char/random.c Tue Sep 7 19:58:45 1999
@@ -241,6 +241,7 @@
#include <linux/fcntl.h>
#include <linux/malloc.h>
#include <linux/random.h>
+#include <linux/tqueue.h>
#include <linux/poll.h>
#include <linux/init.h>

diff -ur -x .* -x *.[oas] linux/fs/ext2/truncate.c linux-ebsa285/fs/ext2/truncate.c
--- linux/fs/ext2/truncate.c Thu Jul 1 00:01:29 1999
+++ linux-ebsa285/fs/ext2/truncate.c Tue Sep 7 20:18:25 1999
@@ -31,6 +31,7 @@
#include <linux/stat.h>
#include <linux/locks.h>
#include <linux/string.h>
+#include <linux/tqueue.h>

#if 0

diff -ur -x .* -x *.[oas] linux/fs/iobuf.c linux-ebsa285/fs/iobuf.c
--- linux/fs/iobuf.c Sat Sep 4 19:13:49 1999
+++ linux-ebsa285/fs/iobuf.c Tue Sep 7 20:40:38 1999
@@ -9,6 +9,7 @@
#include <linux/iobuf.h>
#include <linux/malloc.h>
#include <linux/slab.h>
+#include <linux/tqueue.h>

static kmem_cache_t *kiobuf_cachep;

diff -ur -x .* -x *.[oas] linux/fs/ioctl.c linux-ebsa285/fs/ioctl.c
--- linux/fs/ioctl.c Fri Aug 27 22:26:05 1999
+++ linux-ebsa285/fs/ioctl.c Tue Sep 7 20:37:18 1999
@@ -8,6 +8,7 @@
#include <linux/smp_lock.h>
#include <linux/file.h>

+#include <asm/ioctls.h>
#include <asm/uaccess.h>

static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
diff -ur -x .* -x *.[oas] linux/fs/open.c linux-ebsa285/fs/open.c
--- linux/fs/open.c Fri Aug 27 22:26:06 1999
+++ linux-ebsa285/fs/open.c Mon Sep 6 22:25:29 1999
@@ -9,6 +9,7 @@
#include <linux/file.h>
#include <linux/smp_lock.h>
#include <linux/quotaops.h>
+#include <linux/tty.h> /* for sys_vhangup - should it be in tty.c? */

#include <asm/uaccess.h>

diff -ur -x .* -x *.[oas] linux/fs/pipe.c linux-ebsa285/fs/pipe.c
--- linux/fs/pipe.c Fri Aug 27 22:26:06 1999
+++ linux-ebsa285/fs/pipe.c Tue Sep 7 20:33:41 1999
@@ -10,6 +10,7 @@
#include <linux/malloc.h>
#include <linux/smp_lock.h>

+#include <asm/ioctls.h>
#include <asm/uaccess.h>

/*
diff -ur -x .* -x *.[oas] linux/fs/super.c linux-ebsa285/fs/super.c
--- linux/fs/super.c Sat Sep 4 19:13:50 1999
+++ linux-ebsa285/fs/super.c Tue Sep 7 20:31:19 1999
@@ -25,6 +25,7 @@
#include <linux/init.h>
#include <linux/quotaops.h>
#include <linux/acct.h>
+#include <linux/major.h>

#include <asm/uaccess.h>

diff -ur -x .* -x *.[oas] linux/include/linux/kbd_kern.h linux-ebsa285/include/linux/kbd_kern.h
--- linux/include/linux/kbd_kern.h Sun May 2 17:28:10 1999
+++ linux-ebsa285/include/linux/kbd_kern.h Tue Sep 7 00:07:04 1999
@@ -3,6 +3,7 @@

#include <linux/interrupt.h>
#include <linux/keyboard.h>
+#include <linux/tty.h>

extern int shift_state;

diff -ur -x .* -x *.[oas] linux/include/linux/proc_fs.h linux-ebsa285/include/linux/proc_fs.h
--- linux/include/linux/proc_fs.h Fri Aug 27 22:26:45 1999
+++ linux-ebsa285/include/linux/proc_fs.h Tue Sep 7 00:09:50 1999
@@ -5,6 +5,11 @@
#include <linux/malloc.h>

/*
+ * forward declare this
+ */
+struct tty_driver;
+
+/*
* The proc filesystem constants/structures
*/

diff -ur -x .* -x *.[oas] linux/include/linux/sched.h linux-ebsa285/include/linux/sched.h
--- linux/include/linux/sched.h Tue Sep 7 21:46:33 1999
+++ linux-ebsa285/include/linux/sched.h Tue Sep 7 21:46:43 1999
@@ -128,6 +128,15 @@
#include <asm/spinlock.h>

/*
+ * forward declare these to cut down on the include dependencies
+ * and therefore the amount of rebuiling we do. Really, for the
+ * purposes of this header file, we don't care what's in these,
+ * but we do care that they exist.
+ * -- rmk
+ */
+struct tty_struct;
+
+/*
* This serializes "schedule()" and also protects
* the run-queue from deletions/modifications (but
* _adding_ to the beginning of the run-queue has
diff -ur -x .* -x *.[oas] linux/include/linux/tty.h linux-ebsa285/include/linux/tty.h
--- linux/include/linux/tty.h Fri Jul 9 22:45:43 1999
+++ linux-ebsa285/include/linux/tty.h Tue Sep 7 00:07:04 1999
@@ -344,7 +344,6 @@
extern int rs_init(void);
extern int lp_init(void);
extern int pty_init(void);
-extern int tty_init(void);
extern int pcxe_init(void);
extern int pc_init(void);
extern int vcs_init(void);
diff -ur -x .* -x *.[oas] linux/kernel/exit.c linux-ebsa285/kernel/exit.c
--- linux/kernel/exit.c Fri Sep 3 23:55:50 1999
+++ linux-ebsa285/kernel/exit.c Mon Sep 6 22:17:40 1999
@@ -6,6 +6,7 @@

#include <linux/config.h>
#include <linux/malloc.h>
+#include <linux/tty.h>
#include <linux/interrupt.h>
#include <linux/smp_lock.h>
#include <linux/module.h>
diff -ur -x .* -x *.[oas] linux/kernel/printk.c linux-ebsa285/kernel/printk.c
--- linux/kernel/printk.c Fri Aug 27 22:27:00 1999
+++ linux-ebsa285/kernel/printk.c Sun Sep 5 23:55:51 1999
@@ -15,7 +15,7 @@
*/

#include <linux/mm.h>
-#include <linux/tty_driver.h>
+#include <linux/tty.h>
#include <linux/smp_lock.h>
#include <linux/console.h>
#include <linux/init.h>
diff -ur -x .* -x *.[oas] linux/kernel/sched.c linux-ebsa285/kernel/sched.c
--- linux/kernel/sched.c Fri Aug 27 22:27:00 1999
+++ linux-ebsa285/kernel/sched.c Tue Sep 7 00:11:12 1999
@@ -30,6 +30,7 @@
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/smp_lock.h>
+#include <linux/tqueue.h>
#include <linux/init.h>

#include <asm/io.h>
diff -ur -x .* -x *.[oas] linux/mm/vmscan.c linux-ebsa285/mm/vmscan.c
--- linux/mm/vmscan.c Sat Sep 4 19:24:50 1999
+++ linux-ebsa285/mm/vmscan.c Tue Sep 7 20:13:16 1999
@@ -16,6 +16,7 @@
#include <linux/swapctl.h>
#include <linux/smp_lock.h>
#include <linux/pagemap.h>
+#include <linux/tqueue.h>
#include <linux/init.h>
#include <linux/bigmem.h>

diff -ur -x .* -x *.[oas] linux/net/ipv4/tcp.c linux-ebsa285/net/ipv4/tcp.c
--- linux/net/ipv4/tcp.c Sat Sep 4 19:24:52 1999
+++ linux-ebsa285/net/ipv4/tcp.c Tue Sep 7 21:02:40 1999
@@ -422,6 +422,7 @@
#include <net/icmp.h>
#include <net/tcp.h>

+#include <asm/ioctls.h>
#include <asm/uaccess.h>

int sysctl_tcp_fin_timeout = TCP_FIN_TIMEOUT;
diff -ur -x .* -x *.[oas] linux/net/ipv4/udp.c linux-ebsa285/net/ipv4/udp.c
--- linux/net/ipv4/udp.c Fri Aug 27 22:28:49 1999
+++ linux-ebsa285/net/ipv4/udp.c Tue Sep 7 21:10:15 1999
@@ -116,6 +116,8 @@
#include <net/inet_common.h>
#include <net/checksum.h>

+#include <asm/ioctls.h>
+
/*
* Snmp MIB for the UDP layer
*/
diff -ur -x .* -x *.[oas] linux/net/netsyms.c linux-ebsa285/net/netsyms.c
--- linux/net/netsyms.c Sat Sep 4 19:25:06 1999
+++ linux-ebsa285/net/netsyms.c Sun Sep 5 18:46:34 1999
@@ -10,6 +10,7 @@

#include <linux/types.h>
#include <linux/net.h>
+#include <linux/tty.h>
#include <linux/in.h>
#include <linux/netdevice.h>
#include <linux/inetdevice.h>
diff -ur -x .* -x *.[oas] linux/net/sunrpc/svcsock.c linux-ebsa285/net/sunrpc/svcsock.c
--- linux/net/sunrpc/svcsock.c Fri Aug 27 22:28:55 1999
+++ linux-ebsa285/net/sunrpc/svcsock.c Tue Sep 7 21:19:40 1999
@@ -37,11 +37,12 @@
#include <asm/uaccess.h>
#endif

+#include <asm/ioctls.h>
+
#include <linux/sunrpc/types.h>
#include <linux/sunrpc/xdr.h>
#include <linux/sunrpc/svcsock.h>
#include <linux/sunrpc/stats.h>
-

#define RPCDBG_FACILITY RPCDBG_SVCSOCK

_____
|_____| ------------------------------------------------- ---+---+-
| | Russell King rmk@arm.linux.org.uk --- ---
| | | | http://www.arm.linux.org.uk/~rmk/aboutme.html / / |
| +-+-+ --- -+-
/ | THE developer of ARM Linux |+| /|\
/ | | | --- |
+-+-+ ------------------------------------------------- /\\\ |
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:53    [W:0.096 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site