* [RFC] __initdata strings
@ 2004-10-10 15:28 Oleg Nesterov
2004-10-10 16:31 ` Matt Mackall
0 siblings, 1 reply; 6+ messages in thread
From: Oleg Nesterov @ 2004-10-10 15:28 UTC (permalink / raw)
To: linux-kernel; +Cc: Matt Mackall
Hello.
This patch is not intended for inclusion, just for illustration.
__init functions leaves strings (mainly printk's arguments) in
.data section. It make sense to move them in .init.data.
Is there anyone else who would consider this useful?
Oleg.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
diff -rup 2.6.9-rc3-clean/include/linux/init.h 2.6.9-rc3-i_str/include/linux/init.h
--- 2.6.9-rc3-clean/include/linux/init.h Sun Oct 10 11:48:46 2004
+++ 2.6.9-rc3-i_str/include/linux/init.h Sun Oct 10 11:55:07 2004
@@ -61,6 +61,31 @@
/*
* Used for initialization calls..
*/
+
+#define I_STRING(str) \
+({ \
+ static char data[] __initdata = (str); \
+ data; \
+})
+
+#if defined(__GNUC__) && (__GNUC__ >= 3)
+#define CK_FMTSTR(expr) do if (0) { expr; } while (0)
+#else
+#define CK_FMTSTR(expr) do ; while (0)
+#endif
+
+#define i_printk(fmt, args...) \
+({ \
+ CK_FMTSTR(printk(fmt , ##args)); \
+ printk(I_STRING(fmt) , ##args); \
+})
+
+#define i_panic(fmt, args...) \
+({ \
+ CK_FMTSTR(panic(fmt , ##args)); \
+ panic(I_STRING(fmt) , ##args); \
+})
+
typedef int (*initcall_t)(void);
typedef void (*exitcall_t)(void);
diff -rup 2.6.9-rc3-clean/init/do_mounts.c 2.6.9-rc3-i_str/init/do_mounts.c
--- 2.6.9-rc3-clean/init/do_mounts.c Sun Oct 10 11:48:57 2004
+++ 2.6.9-rc3-i_str/init/do_mounts.c Sat Oct 9 18:18:30 2004
@@ -265,10 +265,10 @@ static int __init do_mount_root(char *na
sys_chdir("/root");
ROOT_DEV = current->fs->pwdmnt->mnt_sb->s_dev;
- printk("VFS: Mounted root (%s filesystem)%s.\n",
+ i_printk("VFS: Mounted root (%s filesystem)%s.\n",
current->fs->pwdmnt->mnt_sb->s_type->name,
current->fs->pwdmnt->mnt_sb->s_flags & MS_RDONLY ?
- " readonly" : "");
+ I_STRING(" readonly") : "");
return 0;
}
@@ -296,13 +296,13 @@ retry:
* and bad superblock on root device.
*/
__bdevname(ROOT_DEV, b);
- printk("VFS: Cannot open root device \"%s\" or %s\n",
+ i_printk("VFS: Cannot open root device \"%s\" or %s\n",
root_device_name, b);
- printk("Please append a correct \"root=\" boot option\n");
+ i_printk("Please append a correct \"root=\" boot option\n");
- panic("VFS: Unable to mount root fs on %s", b);
+ i_panic("VFS: Unable to mount root fs on %s", b);
}
- panic("VFS: Unable to mount root fs on %s", __bdevname(ROOT_DEV, b));
+ i_panic("VFS: Unable to mount root fs on %s", __bdevname(ROOT_DEV, b));
out:
putname(fs_names);
}
@@ -336,7 +336,7 @@ void __init change_floppy(char *fmt, ...
sys_ioctl(fd, FDEJECT, 0);
sys_close(fd);
}
- printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
+ i_printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
fd = sys_open("/dev/console", O_RDWR, 0);
if (fd >= 0) {
sys_ioctl(fd, TCGETS, (long)&termios);
@@ -357,7 +357,7 @@ void __init mount_root(void)
if (mount_nfs_root())
return;
- printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n");
+ i_printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n");
ROOT_DEV = Root_FD0;
}
#endif
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [RFC] __initdata strings
2004-10-10 15:28 [RFC] __initdata strings Oleg Nesterov
@ 2004-10-10 16:31 ` Matt Mackall
2004-10-10 16:40 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 6+ messages in thread
From: Matt Mackall @ 2004-10-10 16:31 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: linux-kernel
On Sun, Oct 10, 2004 at 07:28:29PM +0400, Oleg Nesterov wrote:
> Hello.
>
> This patch is not intended for inclusion, just for illustration.
>
> __init functions leaves strings (mainly printk's arguments) in
> .data section. It make sense to move them in .init.data.
Probably better to do this with something like objcopy?
--
Mathematics is the supreme nostalgia of our time.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC] __initdata strings
2004-10-10 16:31 ` Matt Mackall
@ 2004-10-10 16:40 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2004-10-10 16:40 UTC (permalink / raw)
To: Matt Mackall; +Cc: Oleg Nesterov, linux-kernel
Matt Mackall wrote:
> On Sun, Oct 10, 2004 at 07:28:29PM +0400, Oleg Nesterov wrote:
>
>>Hello.
>>
>>This patch is not intended for inclusion, just for illustration.
>>
>>__init functions leaves strings (mainly printk's arguments) in
>>.data section. It make sense to move them in .init.data.
>
>
> Probably better to do this with something like objcopy?
>
Yes, this is another way of doing that, but the kernel has to be
prepared to get such treatment, think about register functions
that only save a pointer to strings passed from __init functions...
Ah, nothing related to this specific way of doing what is intended,
any scheme that moves strings in __init functions to .data.init has
to deal with this.
- Arnaldo
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <2NNXM-1fZ-5@gated-at.bofh.it>]
* Re: [RFC] __initdata strings
[not found] <2NNXM-1fZ-5@gated-at.bofh.it>
@ 2004-10-10 15:45 ` Andi Kleen
2004-10-10 16:12 ` Oleg Nesterov
0 siblings, 1 reply; 6+ messages in thread
From: Andi Kleen @ 2004-10-10 15:45 UTC (permalink / raw)
To: Oleg Nesterov; +Cc: linux-kernel
Oleg Nesterov <oleg@tv-sign.ru> writes:
> Hello.
>
> This patch is not intended for inclusion, just for illustration.
>
> __init functions leaves strings (mainly printk's arguments) in
> .data section. It make sense to move them in .init.data.
>
> Is there anyone else who would consider this useful?
There is a more generic way to do this with gcc extensions. Something like
(uncompiled/untested)
#define __i(x) ({ static char __str[] __initdata = x; __str; })
But I'm not sure the few bytes saved are worth the code uglification.
Probably not. likely/unlikely is already bad enough.
-Andi
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [RFC] __initdata strings
2004-10-10 15:45 ` Andi Kleen
@ 2004-10-10 16:12 ` Oleg Nesterov
2004-10-10 16:36 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 6+ messages in thread
From: Oleg Nesterov @ 2004-10-10 16:12 UTC (permalink / raw)
To: Andi Kleen; +Cc: linux-kernel
Andi Kleen wrote:
>
> There is a more generic way to do this with gcc extensions. Something like
>
> #define __i(x) ({ static char __str[] __initdata = x; __str; })
I can't see any difference with:
#define I_STRING(str) \
({ \
static char data[] __initdata = (str); \
data; \
})
> But I'm not sure the few bytes saved are worth the code uglification.
Probably you are right, but i think it would be few kilobytes,
there are so many __init functions.
Oleg.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-10-10 16:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-10 15:28 [RFC] __initdata strings Oleg Nesterov
2004-10-10 16:31 ` Matt Mackall
2004-10-10 16:40 ` Arnaldo Carvalho de Melo
[not found] <2NNXM-1fZ-5@gated-at.bofh.it>
2004-10-10 15:45 ` Andi Kleen
2004-10-10 16:12 ` Oleg Nesterov
2004-10-10 16:36 ` Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox