All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] const / static (against current CVS)
@ 2005-08-23 17:40 Andreas Mohr
  2005-08-24  3:24 ` Mulyadi Santosa
  2005-08-24 12:54 ` Doctor Bill
  0 siblings, 2 replies; 8+ messages in thread
From: Andreas Mohr @ 2005-08-23 17:40 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1582 bytes --]

Hello all,

Introduction part:
----------
I'm doing a performance tuning effort all over the place in
frequently-used Linux programs:
I'm trying to mark as many data areas as possible const (and static)
in various programs (at those places where it's actually feasible,
that is).

This should have the following benefits:
a) more .rodata (read-only) pages in programs, which means that
pages (since they're read-only and can thus be restored from the binary any
time) can simply be discarded instead of having to be paged out when
free memory is getting low
b) more page sharing between program instances due to less
modified / read-write (and thus unique instance *per-program*!) memory pages
c) various const compiler optimizations kicking in
d) less linker work to be done (static)
e) we detect previously silent memory corruption (random data area trashing)
better

(use "objdump -x" to analyze what can be improved)

In smaller programs marking variables as const won't be enough to get
several whole pages (4K size) back to read-only, but it goes into the
right direction after all, since we don't intend to actually increase
the number of read-write pages...
----------

This patch against current CVS adds const and/or static to numerous structs
that obviously could be made so. It compiles without any warnings,
and qemu even still runs! ;-)

Patch had been posted to "Patches Repository" on User Forum about a month
ago, but of course that wasn't enough... (silly me)

Thank you,

Andreas Mohr
(patch attached)

-- 
GNU/Linux. It's not the software that's free, it's you.

[-- Attachment #2: qemu_const.diff --]
[-- Type: text/plain, Size: 38800 bytes --]

Index: cpu-all.h
===================================================================
RCS file: /cvsroot/qemu/qemu/cpu-all.h,v
retrieving revision 1.45
diff -u -r1.45 cpu-all.h
--- cpu-all.h	21 Aug 2005 09:24:50 -0000	1.45
+++ cpu-all.h	23 Aug 2005 17:24:26 -0000
@@ -674,7 +674,7 @@
     const char *help;
 } CPULogItem;
 
-extern CPULogItem cpu_log_items[];
+extern const CPULogItem cpu_log_items[];
 
 void cpu_set_log(int log_flags);
 void cpu_set_log_filename(const char *filename);
Index: exec.c
===================================================================
RCS file: /cvsroot/qemu/qemu/exec.c,v
retrieving revision 1.64
diff -u -r1.64 exec.c
--- exec.c	21 Aug 2005 19:12:28 -0000	1.64
+++ exec.c	23 Aug 2005 17:24:27 -0000
@@ -141,7 +141,7 @@
 static int io_mem_nb;
 
 /* log support */
-char *logfilename = "/tmp/qemu.log";
+static const char *logfilename = "/tmp/qemu.log";
 FILE *logfile;
 int loglevel;
 
@@ -1289,7 +1289,7 @@
     env->interrupt_request &= ~mask;
 }
 
-CPULogItem cpu_log_items[] = {
+const CPULogItem cpu_log_items[] = {
     { CPU_LOG_TB_OUT_ASM, "out_asm", 
       "show generated host assembly code for each compiled TB" },
     { CPU_LOG_TB_IN_ASM, "in_asm",
@@ -1327,7 +1327,7 @@
 /* takes a comma separated list of log masks. Return 0 if error. */
 int cpu_str_to_log_mask(const char *str)
 {
-    CPULogItem *item;
+    const CPULogItem *item;
     int mask;
     const char *p, *p1;
 
Index: i386-dis.c
===================================================================
RCS file: /cvsroot/qemu/qemu/i386-dis.c,v
retrieving revision 1.5
diff -u -r1.5 i386-dis.c
--- i386-dis.c	12 Oct 2004 21:52:40 -0000	1.5
+++ i386-dis.c	23 Aug 2005 17:24:28 -0000
@@ -1129,63 +1129,63 @@
    need to update onebyte_has_modrm or twobyte_has_modrm.  */
 #define MODRM_CHECK  if (!need_modrm) abort ()
 
-static const char **names64;
-static const char **names32;
-static const char **names16;
-static const char **names8;
-static const char **names8rex;
-static const char **names_seg;
-static const char **index16;
+static const char * const *names64;
+static const char * const *names32;
+static const char * const *names16;
+static const char * const *names8;
+static const char * const *names8rex;
+static const char * const *names_seg;
+static const char * const *index16;
 
-static const char *intel_names64[] = {
+static const char * const intel_names64[] = {
   "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
   "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
 };
-static const char *intel_names32[] = {
+static const char * const intel_names32[] = {
   "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
   "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d"
 };
-static const char *intel_names16[] = {
+static const char * const intel_names16[] = {
   "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
   "r8w", "r9w", "r10w", "r11w", "r12w", "r13w", "r14w", "r15w"
 };
-static const char *intel_names8[] = {
+static const char * const intel_names8[] = {
   "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh",
 };
-static const char *intel_names8rex[] = {
+static const char * const intel_names8rex[] = {
   "al", "cl", "dl", "bl", "spl", "bpl", "sil", "dil",
   "r8b", "r9b", "r10b", "r11b", "r12b", "r13b", "r14b", "r15b"
 };
-static const char *intel_names_seg[] = {
+static const char * const intel_names_seg[] = {
   "es", "cs", "ss", "ds", "fs", "gs", "?", "?",
 };
-static const char *intel_index16[] = {
+static const char * const intel_index16[] = {
   "bx+si", "bx+di", "bp+si", "bp+di", "si", "di", "bp", "bx"
 };
 
-static const char *att_names64[] = {
+static const char * const att_names64[] = {
   "%rax", "%rcx", "%rdx", "%rbx", "%rsp", "%rbp", "%rsi", "%rdi",
   "%r8", "%r9", "%r10", "%r11", "%r12", "%r13", "%r14", "%r15"
 };
-static const char *att_names32[] = {
+static const char * const att_names32[] = {
   "%eax", "%ecx", "%edx", "%ebx", "%esp", "%ebp", "%esi", "%edi",
   "%r8d", "%r9d", "%r10d", "%r11d", "%r12d", "%r13d", "%r14d", "%r15d"
 };
-static const char *att_names16[] = {
+static const char * const att_names16[] = {
   "%ax", "%cx", "%dx", "%bx", "%sp", "%bp", "%si", "%di",
   "%r8w", "%r9w", "%r10w", "%r11w", "%r12w", "%r13w", "%r14w", "%r15w"
 };
-static const char *att_names8[] = {
+static const char * const att_names8[] = {
   "%al", "%cl", "%dl", "%bl", "%ah", "%ch", "%dh", "%bh",
 };
-static const char *att_names8rex[] = {
+static const char * const att_names8rex[] = {
   "%al", "%cl", "%dl", "%bl", "%spl", "%bpl", "%sil", "%dil",
   "%r8b", "%r9b", "%r10b", "%r11b", "%r12b", "%r13b", "%r14b", "%r15b"
 };
-static const char *att_names_seg[] = {
+static const char * const att_names_seg[] = {
   "%es", "%cs", "%ss", "%ds", "%fs", "%gs", "%?", "%?",
 };
-static const char *att_index16[] = {
+static const char * const att_index16[] = {
   "%bx,%si", "%bx,%di", "%bp,%si", "%bp,%di", "%si", "%di", "%bp", "%bx"
 };
 
@@ -2262,7 +2262,7 @@
   return codep - priv.the_buffer;
 }
 
-static const char *float_mem[] = {
+static const char * const float_mem[] = {
   /* d8 */
   "fadd{s||s|}",
   "fmul{s||s|}",
@@ -2455,7 +2455,7 @@
   },
 };
 
-static char *fgrps[][8] = {
+static char * const fgrps[][8] = {
   /* d9_2  0 */
   {
     "fnop","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)","(bad)",
@@ -4063,7 +4063,7 @@
     }
 }
 
-static const char *simd_cmp_op[] = {
+static const char * const simd_cmp_op[] = {
   "eq",
   "lt",
   "le",
Index: keymaps.c
===================================================================
RCS file: /cvsroot/qemu/qemu/keymaps.c,v
retrieving revision 1.1
diff -u -r1.1 keymaps.c
--- keymaps.c	12 Dec 2004 16:56:30 -0000	1.1
+++ keymaps.c	23 Aug 2005 17:24:28 -0000
@@ -24,7 +24,7 @@
 
 static int get_keysym(const char *name)
 {
-    name2keysym_t *p;
+    const name2keysym_t *p;
     for(p = name2keysym; p->name != NULL; p++) {
         if (!strcmp(p->name, name))
             return p->keysym;
Index: monitor.c
===================================================================
RCS file: /cvsroot/qemu/qemu/monitor.c,v
retrieving revision 1.37
diff -u -r1.37 monitor.c
--- monitor.c	21 Aug 2005 09:30:40 -0000	1.37
+++ monitor.c	23 Aug 2005 17:24:28 -0000
@@ -148,7 +148,7 @@
     } else {
         help_cmd1(term_cmds, "", name);
         if (name && !strcmp(name, "log")) {
-            CPULogItem *item;
+            const CPULogItem *item;
             term_printf("Log items (comma separated):\n");
             term_printf("%-10s %s\n", "none", "remove all logs");
             for(item = cpu_log_items; item->mask != 0; item++) {
@@ -992,19 +992,19 @@
 typedef struct MonitorDef {
     const char *name;
     int offset;
-    target_long (*get_value)(struct MonitorDef *md, int val);
+    target_long (*get_value)(const struct MonitorDef *md, int val);
     int type;
 } MonitorDef;
 
 #if defined(TARGET_I386)
-static target_long monitor_get_pc (struct MonitorDef *md, int val)
+static target_long monitor_get_pc (const struct MonitorDef *md, int val)
 {
     return cpu_single_env->eip + cpu_single_env->segs[R_CS].base;
 }
 #endif
 
 #if defined(TARGET_PPC)
-static target_long monitor_get_ccr (struct MonitorDef *md, int val)
+static target_long monitor_get_ccr (const struct MonitorDef *md, int val)
 {
     unsigned int u;
     int i;
@@ -1016,7 +1016,7 @@
     return u;
 }
 
-static target_long monitor_get_msr (struct MonitorDef *md, int val)
+static target_long monitor_get_msr (const struct MonitorDef *md, int val)
 {
     return (cpu_single_env->msr[MSR_POW] << MSR_POW) |
         (cpu_single_env->msr[MSR_ILE] << MSR_ILE) |
@@ -1035,7 +1035,7 @@
         (cpu_single_env->msr[MSR_LE] << MSR_LE);
 }
 
-static target_long monitor_get_xer (struct MonitorDef *md, int val)
+static target_long monitor_get_xer (const struct MonitorDef *md, int val)
 {
     return (cpu_single_env->xer[XER_SO] << XER_SO) |
         (cpu_single_env->xer[XER_OV] << XER_OV) |
@@ -1043,35 +1043,35 @@
         (cpu_single_env->xer[XER_BC] << XER_BC);
 }
 
-static target_long monitor_get_decr (struct MonitorDef *md, int val)
+static target_long monitor_get_decr (const struct MonitorDef *md, int val)
 {
     return cpu_ppc_load_decr(cpu_single_env);
 }
 
-static target_long monitor_get_tbu (struct MonitorDef *md, int val)
+static target_long monitor_get_tbu (const struct MonitorDef *md, int val)
 {
     return cpu_ppc_load_tbu(cpu_single_env);
 }
 
-static target_long monitor_get_tbl (struct MonitorDef *md, int val)
+static target_long monitor_get_tbl (const struct MonitorDef *md, int val)
 {
     return cpu_ppc_load_tbl(cpu_single_env);
 }
 #endif
 
 #if defined(TARGET_SPARC)
-static target_long monitor_get_psr (struct MonitorDef *md, int val)
+static target_long monitor_get_psr (const struct MonitorDef *md, int val)
 {
     return GET_PSR(cpu_single_env);
 }
 
-static target_long monitor_get_reg(struct MonitorDef *md, int val)
+static target_long monitor_get_reg(const struct MonitorDef *md, int val)
 {
     return cpu_single_env->regwptr[val];
 }
 #endif
 
-static MonitorDef monitor_defs[] = {
+static const MonitorDef monitor_defs[] = {
 #ifdef TARGET_I386
 
 #define SEG(name, seg) \
@@ -1251,7 +1251,7 @@
 
 static int get_monitor_def(target_long *pval, const char *name)
 {
-    MonitorDef *md;
+    const MonitorDef *md;
     void *ptr;
 
     for(md = monitor_defs; md->name != NULL; md++) {
Index: sdl_keysym.h
===================================================================
RCS file: /cvsroot/qemu/qemu/sdl_keysym.h,v
retrieving revision 1.3
diff -u -r1.3 sdl_keysym.h
--- sdl_keysym.h	1 Mar 2005 21:43:41 -0000	1.3
+++ sdl_keysym.h	23 Aug 2005 17:24:28 -0000
@@ -2,7 +2,7 @@
 	const char* name;
 	int keysym;
 } name2keysym_t;
-static name2keysym_t name2keysym[]={
+static const name2keysym_t name2keysym[]={
 /* ascii */
     { "space",                0x020},
     { "exclam",               0x021},
Index: translate-all.c
===================================================================
RCS file: /cvsroot/qemu/qemu/translate-all.c,v
retrieving revision 1.13
diff -u -r1.13 translate-all.c
--- translate-all.c	2 Jul 2005 14:56:31 -0000	1.13
+++ translate-all.c	23 Aug 2005 17:24:29 -0000
@@ -58,13 +58,13 @@
 int code_copy_enabled = 1;
 
 #ifdef DEBUG_DISAS
-static const char *op_str[] = {
+static const char * const op_str[] = {
 #define DEF(s, n, copy_size) #s,
 #include "opc.h"
 #undef DEF
 };
 
-static uint8_t op_nb_args[] = {
+static const uint8_t op_nb_args[] = {
 #define DEF(s, n, copy_size) n,
 #include "opc.h"
 #undef DEF
Index: vgafont.h
===================================================================
RCS file: /cvsroot/qemu/qemu/vgafont.h,v
retrieving revision 1.1
diff -u -r1.1 vgafont.h
--- vgafont.h	14 Jul 2004 17:39:50 -0000	1.1
+++ vgafont.h	23 Aug 2005 17:24:29 -0000
@@ -1,4 +1,4 @@
-static uint8_t vgafont16[256 * 16] = {
+static const uint8_t vgafont16[256 * 16] = {
 
 	/* 0 0x00 '^@' */
 	0x00, /* 00000000 */
Index: vl.c
===================================================================
RCS file: /cvsroot/qemu/qemu/vl.c,v
retrieving revision 1.133
diff -u -r1.133 vl.c
--- vl.c	24 Jul 2005 18:44:55 -0000	1.133
+++ vl.c	23 Aug 2005 17:24:29 -0000
@@ -3393,7 +3393,7 @@
             case QEMU_OPTION_d:
                 {
                     int mask;
-                    CPULogItem *item;
+                    const CPULogItem *item;
                     
                     mask = cpu_str_to_log_mask(optarg);
                     if (!mask) {
Index: audio/audio.c
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/audio.c,v
retrieving revision 1.5
diff -u -r1.5 audio.c
--- audio/audio.c	6 Dec 2004 23:14:48 -0000	1.5
+++ audio/audio.c	23 Aug 2005 17:24:31 -0000
@@ -775,7 +775,7 @@
     }
 }
 
-static struct audio_output_driver *drvtab[] = {
+static struct audio_output_driver * const drvtab[] = {
 #ifdef CONFIG_OSS
     &oss_output_driver,
 #endif
Index: audio/fmodaudio.c
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/fmodaudio.c,v
retrieving revision 1.3
diff -u -r1.3 fmodaudio.c
--- audio/fmodaudio.c	11 Nov 2004 16:55:09 -0000	1.3
+++ audio/fmodaudio.c	23 Aug 2005 17:24:31 -0000
@@ -354,7 +354,7 @@
     return 0;
 }
 
-static struct {
+static const struct {
     const char *name;
     int type;
 } drvtab[] = {
Index: audio/mixeng.c
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/mixeng.c,v
retrieving revision 1.1
diff -u -r1.1 mixeng.c
--- audio/mixeng.c	7 Nov 2004 18:04:02 -0000	1.1
+++ audio/mixeng.c	23 Aug 2005 17:24:31 -0000
@@ -62,7 +62,7 @@
 #undef IN_MIN
 #undef IN_T
 
-t_sample *mixeng_conv[2][2][2] = {
+t_sample * const mixeng_conv[2][2][2] = {
     {
         {
             conv_uint8_t_to_mono,
@@ -85,7 +85,7 @@
     }
 };
 
-f_sample *mixeng_clip[2][2][2] = {
+f_sample * const mixeng_clip[2][2][2] = {
     {
         {
             clip_uint8_t_from_mono,
Index: audio/mixeng.h
===================================================================
RCS file: /cvsroot/qemu/qemu/audio/mixeng.h,v
retrieving revision 1.1
diff -u -r1.1 mixeng.h
--- audio/mixeng.h	7 Nov 2004 18:04:02 -0000	1.1
+++ audio/mixeng.h	23 Aug 2005 17:24:31 -0000
@@ -28,8 +28,8 @@
 typedef void (f_sample) (void *dst, const void *src, int samples);
 typedef struct { int64_t l; int64_t r; } st_sample_t;
 
-extern t_sample *mixeng_conv[2][2][2];
-extern f_sample *mixeng_clip[2][2][2];
+extern t_sample * const mixeng_conv[2][2][2];
+extern f_sample * const mixeng_clip[2][2][2];
 
 void *st_rate_start (int inrate, int outrate);
 void st_rate_flow (void *opaque, st_sample_t *ibuf, st_sample_t *obuf,
Index: hw/adlib.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/adlib.c,v
retrieving revision 1.2
diff -u -r1.2 adlib.c
--- hw/adlib.c	9 Nov 2004 23:08:30 -0000	1.2
+++ hw/adlib.c	23 Aug 2005 17:24:31 -0000
@@ -52,7 +52,7 @@
 #define IO_WRITE_PROTO(name) \
     void name (void *opaque, uint32_t nport, uint32_t val)
 
-static struct {
+static const struct {
     int port;
     int freq;
 } conf = {0x220, 44100};
Index: hw/dma.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/dma.c,v
retrieving revision 1.13
diff -u -r1.13 dma.c
--- hw/dma.c	14 Nov 2004 17:30:35 -0000	1.13
+++ hw/dma.c	23 Aug 2005 17:24:31 -0000
@@ -77,7 +77,7 @@
 
 };
 
-static int channels[8] = {-1, 2, 3, 1, -1, -1, -1, 0};
+static const int channels[8] = {-1, 2, 3, 1, -1, -1, -1, 0};
 
 static void write_page (void *opaque, uint32_t nport, uint32_t data)
 {
Index: hw/fdc.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/fdc.c,v
retrieving revision 1.18
diff -u -r1.18 fdc.c
--- hw/fdc.c	13 Mar 2005 09:43:36 -0000	1.18
+++ hw/fdc.c	23 Aug 2005 17:24:31 -0000
@@ -180,7 +180,7 @@
     const unsigned char *str;
 } fd_format_t;
 
-static fd_format_t fd_formats[] = {
+static const fd_format_t fd_formats[] = {
     /* First entry is default format */
     /* 1.44 MB 3"1/2 floppy disks */
     { FDRIVE_DRV_144, FDRIVE_DISK_144, 18, 80, 1, "1.44 MB 3\"1/2", },
@@ -230,7 +230,7 @@
 /* Revalidate a disk drive after a disk change */
 static void fd_revalidate (fdrive_t *drv)
 {
-    fd_format_t *parse;
+    const fd_format_t *parse;
     int64_t nb_sectors, size;
     int i, first_match, match;
     int nb_heads, max_track, last_sect, ro;
Index: hw/pc.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/pc.c,v
retrieving revision 1.39
diff -u -r1.39 pc.c
--- hw/pc.c	23 Jul 2005 19:05:37 -0000	1.39
+++ hw/pc.c	23 Aug 2005 17:24:31 -0000
@@ -396,14 +396,14 @@
 
 #define NE2000_NB_MAX 6
 
-static int ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 };
-static int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 };
+static const int ne2000_io[NE2000_NB_MAX] = { 0x300, 0x320, 0x340, 0x360, 0x280, 0x380 };
+static const int ne2000_irq[NE2000_NB_MAX] = { 9, 10, 11, 3, 4, 5 };
 
-static int serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
-static int serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
+static const int serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
+static const int serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
 
-static int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
-static int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 };
+static const int parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
+static const int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 };
 
 /* PC hardware initialisation */
 static void pc_init1(int ram_size, int vga_ram_size, int boot_device,
Index: hw/sb16.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/sb16.c,v
retrieving revision 1.15
diff -u -r1.15 sb16.c
--- hw/sb16.c	21 Aug 2005 09:30:54 -0000	1.15
+++ hw/sb16.c	23 Aug 2005 17:24:31 -0000
@@ -43,7 +43,7 @@
 
 static const char e3[] = "COPYRIGHT (C) CREATIVE TECHNOLOGY LTD, 1992.";
 
-static struct {
+static const struct {
     int ver_lo;
     int ver_hi;
     int irq;
Index: hw/vga.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/vga.c,v
retrieving revision 1.41
diff -u -r1.41 vga.c
--- hw/vga.c	3 Jul 2005 14:00:51 -0000	1.41
+++ hw/vga.c	23 Aug 2005 17:24:32 -0000
@@ -961,21 +961,21 @@
     }
 }
 
-static vga_draw_glyph8_func *vga_draw_glyph8_table[4] = {
+static vga_draw_glyph8_func * const vga_draw_glyph8_table[4] = {
     vga_draw_glyph8_8,
     vga_draw_glyph8_16,
     vga_draw_glyph8_16,
     vga_draw_glyph8_32,
 };
 
-static vga_draw_glyph8_func *vga_draw_glyph16_table[4] = {
+static vga_draw_glyph8_func * const vga_draw_glyph16_table[4] = {
     vga_draw_glyph16_8,
     vga_draw_glyph16_16,
     vga_draw_glyph16_16,
     vga_draw_glyph16_32,
 };
 
-static vga_draw_glyph9_func *vga_draw_glyph9_table[4] = {
+static vga_draw_glyph9_func * const vga_draw_glyph9_table[4] = {
     vga_draw_glyph9_8,
     vga_draw_glyph9_16,
     vga_draw_glyph9_16,
@@ -1194,7 +1194,7 @@
     VGA_DRAW_LINE_NB,
 };
 
-static vga_draw_line_func *vga_draw_line_table[4 * VGA_DRAW_LINE_NB] = {
+static vga_draw_line_func * const vga_draw_line_table[4 * VGA_DRAW_LINE_NB] = {
     vga_draw_line2_8,
     vga_draw_line2_16,
     vga_draw_line2_16,
Index: linux-user/main.c
===================================================================
RCS file: /cvsroot/qemu/qemu/linux-user/main.c,v
retrieving revision 1.70
diff -u -r1.70 main.c
--- linux-user/main.c	24 Jul 2005 18:44:56 -0000	1.70
+++ linux-user/main.c	23 Aug 2005 17:24:32 -0000
@@ -1034,7 +1034,7 @@
             break;
         } else if (!strcmp(r, "d")) {
             int mask;
-            CPULogItem *item;
+            const CPULogItem *item;
 
 	    if (optind >= argc)
 		break;
Index: slirp/ip_icmp.c
===================================================================
RCS file: /cvsroot/qemu/qemu/slirp/ip_icmp.c,v
retrieving revision 1.1
diff -u -r1.1 ip_icmp.c
--- slirp/ip_icmp.c	22 Apr 2004 00:10:47 -0000	1.1
+++ slirp/ip_icmp.c	23 Aug 2005 17:24:33 -0000
@@ -40,11 +40,11 @@
 struct icmpstat icmpstat;
 
 /* The message sent when emulating PING */
-/* Be nice and tell them it's just a psuedo-ping packet */
-char icmp_ping_msg[] = "This is a psuedo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n";
+/* Be nice and tell them it's just a pseudo-ping packet */
+static const char icmp_ping_msg[] = "This is a pseudo-PING packet used by Slirp to emulate ICMP ECHO-REQUEST packets.\n";
 
 /* list of actions for icmp_error() on RX of an icmp message */
-static int icmp_flush[19] = {
+static const int icmp_flush[19] = {
 /*  ECHO REPLY (0)  */   0,
 		         1,
 		         1,
Index: slirp/mbuf.c
===================================================================
RCS file: /cvsroot/qemu/qemu/slirp/mbuf.c,v
retrieving revision 1.1
diff -u -r1.1 mbuf.c
--- slirp/mbuf.c	22 Apr 2004 00:10:47 -0000	1.1
+++ slirp/mbuf.c	23 Aug 2005 17:24:33 -0000
@@ -21,9 +21,9 @@
 char	*mclrefcnt;
 int mbuf_alloced = 0;
 struct mbuf m_freelist, m_usedlist;
-int mbuf_thresh = 30;
+static const int mbuf_thresh = 30;
 int mbuf_max = 0;
-int msize;
+static int msize;
 
 void
 m_init()
Index: slirp/tcp.h
===================================================================
RCS file: /cvsroot/qemu/qemu/slirp/tcp.h,v
retrieving revision 1.1
diff -u -r1.1 tcp.h
--- slirp/tcp.h	22 Apr 2004 00:10:47 -0000	1.1
+++ slirp/tcp.h	23 Aug 2005 17:24:33 -0000
@@ -164,6 +164,6 @@
 
 extern tcp_seq tcp_iss;                /* tcp initial send seq # */
 
-extern char *tcpstates[];
+extern const char * const tcpstates[];
 
 #endif
Index: slirp/tcp_input.c
===================================================================
RCS file: /cvsroot/qemu/qemu/slirp/tcp_input.c,v
retrieving revision 1.4
diff -u -r1.4 tcp_input.c
--- slirp/tcp_input.c	7 Oct 2004 23:27:35 -0000	1.4
+++ slirp/tcp_input.c	23 Aug 2005 17:24:33 -0000
@@ -47,7 +47,7 @@
 
 struct socket tcb;
 
-int	tcprexmtthresh = 3;
+static int	tcprexmtthresh = 3;
 struct	socket *tcp_last_so = &tcb;
 
 tcp_seq tcp_iss;                /* tcp initial send seq # */
Index: slirp/tcp_output.c
===================================================================
RCS file: /cvsroot/qemu/qemu/slirp/tcp_output.c,v
retrieving revision 1.2
diff -u -r1.2 tcp_output.c
--- slirp/tcp_output.c	12 Jul 2004 22:33:06 -0000	1.2
+++ slirp/tcp_output.c	23 Aug 2005 17:24:33 -0000
@@ -45,17 +45,17 @@
 #include <slirp.h>
 
 /*
- * Since this is only used in "stats socket", we give meaning
+ * Since this is only used in "stats socket", we give meaningful
  * names instead of the REAL names
  */
-char *tcpstates[] = {
+const char * const tcpstates[] = {
 /*	"CLOSED",       "LISTEN",       "SYN_SENT",     "SYN_RCVD", */
 	"REDIRECT",	"LISTEN",	"SYN_SENT",     "SYN_RCVD",
 	"ESTABLISHED",  "CLOSE_WAIT",   "FIN_WAIT_1",   "CLOSING",
 	"LAST_ACK",     "FIN_WAIT_2",   "TIME_WAIT",
 };
 
-u_char  tcp_outflags[TCP_NSTATES] = {
+static const u_char  tcp_outflags[TCP_NSTATES] = {
 	TH_RST|TH_ACK, 0,      TH_SYN,        TH_SYN|TH_ACK,
 	TH_ACK,        TH_ACK, TH_FIN|TH_ACK, TH_FIN|TH_ACK, 
 	TH_FIN|TH_ACK, TH_ACK, TH_ACK,
Index: slirp/tcp_subr.c
===================================================================
RCS file: /cvsroot/qemu/qemu/slirp/tcp_subr.c,v
retrieving revision 1.5
diff -u -r1.5 tcp_subr.c
--- slirp/tcp_subr.c	18 Sep 2004 19:33:56 -0000	1.5
+++ slirp/tcp_subr.c	23 Aug 2005 17:24:35 -0000
@@ -46,9 +46,9 @@
 #include <slirp.h>
 
 /* patchable/settable parameters for tcp */
-int 	tcp_mssdflt = TCP_MSS;
-int 	tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ;
-int	tcp_do_rfc1323 = 0;	/* Don't do rfc1323 performance enhancements */
+static const int 	tcp_mssdflt = TCP_MSS;
+static const int 	tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ;
+static const int	tcp_do_rfc1323 = 0;	/* Don't do rfc1323 performance enhancements */
 int	tcp_rcvspace;	/* You may want to change this */
 int	tcp_sndspace;	/* Keep small if you have an error prone link */
 
@@ -554,7 +554,7 @@
 /*
  * Set the socket's type of service field
  */
-struct tos_t tcptos[] = {
+static const struct tos_t tcptos[] = {
 	  {0, 20, IPTOS_THROUGHPUT, 0},	/* ftp data */
 	  {21, 21, IPTOS_LOWDELAY,  EMU_FTP},	/* ftp control */
 	  {0, 23, IPTOS_LOWDELAY, 0},	/* telnet */
Index: slirp/tcp_timer.c
===================================================================
RCS file: /cvsroot/qemu/qemu/slirp/tcp_timer.c,v
retrieving revision 1.2
diff -u -r1.2 tcp_timer.c
--- slirp/tcp_timer.c	12 Jul 2004 22:33:07 -0000	1.2
+++ slirp/tcp_timer.c	23 Aug 2005 17:24:35 -0000
@@ -127,7 +127,7 @@
 		tp->t_timer[i] = 0;
 }
 
-int	tcp_backoff[TCP_MAXRXTSHIFT + 1] =
+const int	tcp_backoff[TCP_MAXRXTSHIFT + 1] =
    { 1, 2, 4, 8, 16, 32, 64, 64, 64, 64, 64, 64, 64 };
 
 /*
Index: slirp/tcp_timer.h
===================================================================
RCS file: /cvsroot/qemu/qemu/slirp/tcp_timer.h,v
retrieving revision 1.1
diff -u -r1.1 tcp_timer.h
--- slirp/tcp_timer.h	22 Apr 2004 00:10:47 -0000	1.1
+++ slirp/tcp_timer.h	23 Aug 2005 17:24:35 -0000
@@ -130,7 +130,7 @@
 extern int tcp_keepintvl;		/* time between keepalive probes */
 extern int tcp_maxidle;			/* time to drop after starting probes */
 extern int tcp_ttl;			/* time to live for TCP segs */
-extern int tcp_backoff[];
+extern const int tcp_backoff[];
 
 struct tcpcb;
 
Index: slirp/udp.c
===================================================================
RCS file: /cvsroot/qemu/qemu/slirp/udp.c,v
retrieving revision 1.6
diff -u -r1.6 udp.c
--- slirp/udp.c	3 Jul 2005 17:08:43 -0000	1.6
+++ slirp/udp.c	23 Aug 2005 17:24:35 -0000
@@ -54,9 +54,9 @@
  * Per RFC 768, August, 1980.
  */
 #ifndef	COMPAT_42
-int	udpcksum = 1;
+static const int	udpcksum = 1;
 #else
-int	udpcksum = 0;		/* XXX */
+static const int	udpcksum = 0;		/* XXX */
 #endif
 
 struct	socket *udp_last_so = &udb;
@@ -363,7 +363,7 @@
 	sofree(so);
 }
 
-struct tos_t udptos[] = {
+static const struct tos_t udptos[] = {
 	{0, 53, IPTOS_LOWDELAY, 0},			/* DNS */
 	{517, 517, IPTOS_LOWDELAY, EMU_TALK},	/* talk */
 	{518, 518, IPTOS_LOWDELAY, EMU_NTALK},	/* ntalk */
Index: target-i386/helper2.c
===================================================================
RCS file: /cvsroot/qemu/qemu/target-i386/helper2.c,v
retrieving revision 1.35
diff -u -r1.35 helper2.c
--- target-i386/helper2.c	23 Jul 2005 17:41:26 -0000	1.35
+++ target-i386/helper2.c	23 Aug 2005 17:24:35 -0000
@@ -257,7 +257,7 @@
 {
     int eflags, i, nb;
     char cc_op_name[32];
-    static const char *seg_name[6] = { "ES", "CS", "SS", "DS", "FS", "GS" };
+    static const char * const seg_name[6] = { "ES", "CS", "SS", "DS", "FS", "GS" };
 
     eflags = env->eflags;
 #ifdef TARGET_X86_64
Index: target-i386/translate.c
===================================================================
RCS file: /cvsroot/qemu/qemu/target-i386/translate.c,v
retrieving revision 1.51
diff -u -r1.51 translate.c
--- target-i386/translate.c	21 Aug 2005 10:28:44 -0000	1.51
+++ target-i386/translate.c	23 Aug 2005 17:24:35 -0000
@@ -240,7 +240,7 @@
 
 #endif /* !TARGET_X86_64 */
 
-static GenOpFunc *gen_op_mov_reg_T0[NB_OP_SIZES][CPU_NB_REGS] = {
+static GenOpFunc * const gen_op_mov_reg_T0[NB_OP_SIZES][CPU_NB_REGS] = {
     [OT_BYTE] = {
         gen_op_movb_EAX_T0,
         gen_op_movb_ECX_T0,
@@ -279,7 +279,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_mov_reg_T1[NB_OP_SIZES][CPU_NB_REGS] = {
+static GenOpFunc * const gen_op_mov_reg_T1[NB_OP_SIZES][CPU_NB_REGS] = {
     [OT_BYTE] = {
         gen_op_movb_EAX_T1,
         gen_op_movb_ECX_T1,
@@ -318,7 +318,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_mov_reg_A0[NB_OP_SIZES - 1][CPU_NB_REGS] = {
+static GenOpFunc * const gen_op_mov_reg_A0[NB_OP_SIZES - 1][CPU_NB_REGS] = {
     [0] = {
         DEF_REGS(gen_op_movw_, _A0)
     },
@@ -332,7 +332,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_mov_TN_reg[NB_OP_SIZES][2][CPU_NB_REGS] = 
+static GenOpFunc * const gen_op_mov_TN_reg[NB_OP_SIZES][2][CPU_NB_REGS] = 
 {
     [OT_BYTE] = {
         {
@@ -414,11 +414,11 @@
 #endif
 };
 
-static GenOpFunc *gen_op_movl_A0_reg[CPU_NB_REGS] = {
+static GenOpFunc * const gen_op_movl_A0_reg[CPU_NB_REGS] = {
     DEF_REGS(gen_op_movl_A0_, )
 };
 
-static GenOpFunc *gen_op_addl_A0_reg_sN[4][CPU_NB_REGS] = {
+static GenOpFunc * const gen_op_addl_A0_reg_sN[4][CPU_NB_REGS] = {
     [0] = {
         DEF_REGS(gen_op_addl_A0_, )
     },
@@ -434,11 +434,11 @@
 };
 
 #ifdef TARGET_X86_64
-static GenOpFunc *gen_op_movq_A0_reg[CPU_NB_REGS] = {
+static GenOpFunc * const gen_op_movq_A0_reg[CPU_NB_REGS] = {
     DEF_REGS(gen_op_movq_A0_, )
 };
 
-static GenOpFunc *gen_op_addq_A0_reg_sN[4][CPU_NB_REGS] = {
+static GenOpFunc * const gen_op_addq_A0_reg_sN[4][CPU_NB_REGS] = {
     [0] = {
         DEF_REGS(gen_op_addq_A0_, )
     },
@@ -454,7 +454,7 @@
 };
 #endif
 
-static GenOpFunc *gen_op_cmov_reg_T1_T0[NB_OP_SIZES - 1][CPU_NB_REGS] = {
+static GenOpFunc * const gen_op_cmov_reg_T1_T0[NB_OP_SIZES - 1][CPU_NB_REGS] = {
     [0] = {
         DEF_REGS(gen_op_cmovw_, _T1_T0)
     },
@@ -468,7 +468,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_arith_T0_T1_cc[8] = {
+static GenOpFunc * const gen_op_arith_T0_T1_cc[8] = {
     NULL,
     gen_op_orl_T0_T1,
     NULL,
@@ -497,11 +497,11 @@
         X86_64_ONLY(gen_op_sbbq ## SUFFIX ## _T0_T1_cc),\
     },
 
-static GenOpFunc *gen_op_arithc_T0_T1_cc[4][2] = {
+static GenOpFunc * const gen_op_arithc_T0_T1_cc[4][2] = {
     DEF_ARITHC( )
 };
 
-static GenOpFunc *gen_op_arithc_mem_T0_T1_cc[3 * 4][2] = {
+static GenOpFunc * const gen_op_arithc_mem_T0_T1_cc[3 * 4][2] = {
     DEF_ARITHC(_raw)
 #ifndef CONFIG_USER_ONLY
     DEF_ARITHC(_kernel)
@@ -526,11 +526,11 @@
     gen_op_cmpxchgl ## SUFFIX ## _T0_T1_EAX_cc,\
     X86_64_ONLY(gen_op_cmpxchgq ## SUFFIX ## _T0_T1_EAX_cc),
 
-static GenOpFunc *gen_op_cmpxchg_T0_T1_EAX_cc[4] = {
+static GenOpFunc * const gen_op_cmpxchg_T0_T1_EAX_cc[4] = {
     DEF_CMPXCHG( )
 };
 
-static GenOpFunc *gen_op_cmpxchg_mem_T0_T1_EAX_cc[3 * 4] = {
+static GenOpFunc * const gen_op_cmpxchg_mem_T0_T1_EAX_cc[3 * 4] = {
     DEF_CMPXCHG(_raw)
 #ifndef CONFIG_USER_ONLY
     DEF_CMPXCHG(_kernel)
@@ -580,11 +580,11 @@
         X86_64_ONLY(gen_op_sarq ## SUFFIX ## _T0_T1_cc),\
     },
 
-static GenOpFunc *gen_op_shift_T0_T1_cc[4][8] = {
+static GenOpFunc * const gen_op_shift_T0_T1_cc[4][8] = {
     DEF_SHIFT( )
 };
 
-static GenOpFunc *gen_op_shift_mem_T0_T1_cc[3 * 4][8] = {
+static GenOpFunc * const gen_op_shift_mem_T0_T1_cc[3 * 4][8] = {
     DEF_SHIFT(_raw)
 #ifndef CONFIG_USER_ONLY
     DEF_SHIFT(_kernel)
@@ -610,15 +610,15 @@
            gen_op_shrdq ## SUFFIX ## _T0_T1_ ## op ## _cc,)\
     },
 
-static GenOpFunc1 *gen_op_shiftd_T0_T1_im_cc[4][2] = {
+static GenOpFunc1 * const gen_op_shiftd_T0_T1_im_cc[4][2] = {
     DEF_SHIFTD(, im)
 };
 
-static GenOpFunc *gen_op_shiftd_T0_T1_ECX_cc[4][2] = {
+static GenOpFunc * const gen_op_shiftd_T0_T1_ECX_cc[4][2] = {
     DEF_SHIFTD(, ECX)
 };
 
-static GenOpFunc1 *gen_op_shiftd_mem_T0_T1_im_cc[3 * 4][2] = {
+static GenOpFunc1 * const gen_op_shiftd_mem_T0_T1_im_cc[3 * 4][2] = {
     DEF_SHIFTD(_raw, im)
 #ifndef CONFIG_USER_ONLY
     DEF_SHIFTD(_kernel, im)
@@ -626,7 +626,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_shiftd_mem_T0_T1_ECX_cc[3 * 4][2] = {
+static GenOpFunc * const gen_op_shiftd_mem_T0_T1_ECX_cc[3 * 4][2] = {
     DEF_SHIFTD(_raw, ECX)
 #ifndef CONFIG_USER_ONLY
     DEF_SHIFTD(_kernel, ECX)
@@ -634,7 +634,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_btx_T0_T1_cc[3][4] = {
+static GenOpFunc * const gen_op_btx_T0_T1_cc[3][4] = {
     [0] = {
         gen_op_btw_T0_T1_cc,
         gen_op_btsw_T0_T1_cc,
@@ -657,13 +657,13 @@
 #endif
 };
 
-static GenOpFunc *gen_op_add_bit_A0_T1[3] = {
+static GenOpFunc * const gen_op_add_bit_A0_T1[3] = {
     gen_op_add_bitw_A0_T1,
     gen_op_add_bitl_A0_T1,
     X86_64_ONLY(gen_op_add_bitq_A0_T1),
 };
 
-static GenOpFunc *gen_op_bsx_T0_cc[3][2] = {
+static GenOpFunc * const gen_op_bsx_T0_cc[3][2] = {
     [0] = {
         gen_op_bsfw_T0_cc,
         gen_op_bsrw_T0_cc,
@@ -680,7 +680,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_lds_T0_A0[3 * 4] = {
+static GenOpFunc * const gen_op_lds_T0_A0[3 * 4] = {
     gen_op_ldsb_raw_T0_A0,
     gen_op_ldsw_raw_T0_A0,
     X86_64_ONLY(gen_op_ldsl_raw_T0_A0),
@@ -698,7 +698,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_ldu_T0_A0[3 * 4] = {
+static GenOpFunc * const gen_op_ldu_T0_A0[3 * 4] = {
     gen_op_ldub_raw_T0_A0,
     gen_op_lduw_raw_T0_A0,
     NULL,
@@ -718,7 +718,7 @@
 };
 
 /* sign does not matter, except for lidt/lgdt call (TODO: fix it) */
-static GenOpFunc *gen_op_ld_T0_A0[3 * 4] = {
+static GenOpFunc * const gen_op_ld_T0_A0[3 * 4] = {
     gen_op_ldub_raw_T0_A0,
     gen_op_lduw_raw_T0_A0,
     gen_op_ldl_raw_T0_A0,
@@ -737,7 +737,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_ld_T1_A0[3 * 4] = {
+static GenOpFunc * const gen_op_ld_T1_A0[3 * 4] = {
     gen_op_ldub_raw_T1_A0,
     gen_op_lduw_raw_T1_A0,
     gen_op_ldl_raw_T1_A0,
@@ -756,7 +756,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_st_T0_A0[3 * 4] = {
+static GenOpFunc * const gen_op_st_T0_A0[3 * 4] = {
     gen_op_stb_raw_T0_A0,
     gen_op_stw_raw_T0_A0,
     gen_op_stl_raw_T0_A0,
@@ -775,7 +775,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_st_T1_A0[3 * 4] = {
+static GenOpFunc * const gen_op_st_T1_A0[3 * 4] = {
     NULL,
     gen_op_stw_raw_T1_A0,
     gen_op_stl_raw_T1_A0,
@@ -865,32 +865,32 @@
     }
 }
 
-static GenOpFunc *gen_op_movl_T0_Dshift[4] = {
+static GenOpFunc * const gen_op_movl_T0_Dshift[4] = {
     gen_op_movl_T0_Dshiftb,
     gen_op_movl_T0_Dshiftw,
     gen_op_movl_T0_Dshiftl,
     X86_64_ONLY(gen_op_movl_T0_Dshiftq),
 };
 
-static GenOpFunc1 *gen_op_jnz_ecx[3] = {
+static GenOpFunc1 * const gen_op_jnz_ecx[3] = {
     gen_op_jnz_ecxw,
     gen_op_jnz_ecxl,
     X86_64_ONLY(gen_op_jnz_ecxq),
 };
     
-static GenOpFunc1 *gen_op_jz_ecx[3] = {
+static GenOpFunc1 * const gen_op_jz_ecx[3] = {
     gen_op_jz_ecxw,
     gen_op_jz_ecxl,
     X86_64_ONLY(gen_op_jz_ecxq),
 };
 
-static GenOpFunc *gen_op_dec_ECX[3] = {
+static GenOpFunc * const gen_op_dec_ECX[3] = {
     gen_op_decw_ECX,
     gen_op_decl_ECX,
     X86_64_ONLY(gen_op_decq_ECX),
 };
 
-static GenOpFunc1 *gen_op_string_jnz_sub[2][4] = {
+static GenOpFunc1 * const gen_op_string_jnz_sub[2][4] = {
     {
         gen_op_jnz_subb,
         gen_op_jnz_subw,
@@ -905,37 +905,37 @@
     },
 };
 
-static GenOpFunc *gen_op_in_DX_T0[3] = {
+static GenOpFunc * const gen_op_in_DX_T0[3] = {
     gen_op_inb_DX_T0,
     gen_op_inw_DX_T0,
     gen_op_inl_DX_T0,
 };
 
-static GenOpFunc *gen_op_out_DX_T0[3] = {
+static GenOpFunc * const gen_op_out_DX_T0[3] = {
     gen_op_outb_DX_T0,
     gen_op_outw_DX_T0,
     gen_op_outl_DX_T0,
 };
 
-static GenOpFunc *gen_op_in[3] = {
+static GenOpFunc * const gen_op_in[3] = {
     gen_op_inb_T0_T1,
     gen_op_inw_T0_T1,
     gen_op_inl_T0_T1,
 };
 
-static GenOpFunc *gen_op_out[3] = {
+static GenOpFunc * const gen_op_out[3] = {
     gen_op_outb_T0_T1,
     gen_op_outw_T0_T1,
     gen_op_outl_T0_T1,
 };
 
-static GenOpFunc *gen_check_io_T0[3] = {
+static GenOpFunc * const gen_check_io_T0[3] = {
     gen_op_check_iob_T0,
     gen_op_check_iow_T0,
     gen_op_check_iol_T0,
 };
 
-static GenOpFunc *gen_check_io_DX[3] = {
+static GenOpFunc * const gen_check_io_DX[3] = {
     gen_op_check_iob_DX,
     gen_op_check_iow_DX,
     gen_op_check_iol_DX,
@@ -1170,7 +1170,7 @@
     JCC_LE,
 };
 
-static GenOpFunc1 *gen_jcc_sub[4][8] = {
+static GenOpFunc1 * const gen_jcc_sub[4][8] = {
     [OT_BYTE] = {
         NULL,
         gen_op_jb_subb,
@@ -1214,7 +1214,7 @@
     },
 #endif
 };
-static GenOpFunc1 *gen_op_loop[3][4] = {
+static GenOpFunc1 * const gen_op_loop[3][4] = {
     [0] = {
         gen_op_loopnzw,
         gen_op_loopzw,
@@ -1234,7 +1234,7 @@
 #endif
 };
 
-static GenOpFunc *gen_setcc_slow[8] = {
+static GenOpFunc * const gen_setcc_slow[8] = {
     gen_op_seto_T0_cc,
     gen_op_setb_T0_cc,
     gen_op_setz_T0_cc,
@@ -1245,7 +1245,7 @@
     gen_op_setle_T0_cc,
 };
 
-static GenOpFunc *gen_setcc_sub[4][8] = {
+static GenOpFunc * const gen_setcc_sub[4][8] = {
     [OT_BYTE] = {
         NULL,
         gen_op_setb_T0_subb,
@@ -1290,7 +1290,7 @@
 #endif
 };
 
-static GenOpFunc *gen_op_fp_arith_ST0_FT0[8] = {
+static GenOpFunc * const gen_op_fp_arith_ST0_FT0[8] = {
     gen_op_fadd_ST0_FT0,
     gen_op_fmul_ST0_FT0,
     gen_op_fcom_ST0_FT0,
@@ -1302,7 +1302,7 @@
 };
 
 /* NOTE the exception in "r" op ordering */
-static GenOpFunc1 *gen_op_fp_arith_STN_ST0[8] = {
+static GenOpFunc1 * const gen_op_fp_arith_STN_ST0[8] = {
     gen_op_fadd_STN_ST0,
     gen_op_fmul_STN_ST0,
     NULL,
@@ -2277,7 +2277,7 @@
         gen_op_addl_A0_im(val);
 }
 
-static GenOpFunc1 *gen_ldq_env_A0[3] = {
+static GenOpFunc1 * const gen_ldq_env_A0[3] = {
     gen_op_ldq_raw_env_A0,
 #ifndef CONFIG_USER_ONLY
     gen_op_ldq_kernel_env_A0,
@@ -2285,7 +2285,7 @@
 #endif
 };
 
-static GenOpFunc1 *gen_stq_env_A0[3] = {
+static GenOpFunc1 * const gen_stq_env_A0[3] = {
     gen_op_stq_raw_env_A0,
 #ifndef CONFIG_USER_ONLY
     gen_op_stq_kernel_env_A0,
@@ -2293,7 +2293,7 @@
 #endif
 };
 
-static GenOpFunc1 *gen_ldo_env_A0[3] = {
+static GenOpFunc1 * const gen_ldo_env_A0[3] = {
     gen_op_ldo_raw_env_A0,
 #ifndef CONFIG_USER_ONLY
     gen_op_ldo_kernel_env_A0,
@@ -2301,7 +2301,7 @@
 #endif
 };
 
-static GenOpFunc1 *gen_sto_env_A0[3] = {
+static GenOpFunc1 * const gen_sto_env_A0[3] = {
     gen_op_sto_raw_env_A0,
 #ifndef CONFIG_USER_ONLY
     gen_op_sto_kernel_env_A0,
@@ -2315,7 +2315,7 @@
 #define SSE_FOP(x) { gen_op_ ## x ## ps, gen_op_ ## x ## pd, \
                      gen_op_ ## x ## ss, gen_op_ ## x ## sd, }
 
-static GenOpFunc2 *sse_op_table1[256][4] = {
+static GenOpFunc2 * const sse_op_table1[256][4] = {
     /* pure SSE operations */
     [0x10] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movups, movupd, movss, movsd */
     [0x11] = { SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL, SSE_SPECIAL }, /* movups, movupd, movss, movsd */
@@ -2438,7 +2438,7 @@
     [0xfe] = MMX_OP2(paddl),
 };
 
-static GenOpFunc2 *sse_op_table2[3 * 8][2] = {
+static GenOpFunc2 * const sse_op_table2[3 * 8][2] = {
     [0 + 2] = MMX_OP2(psrlw),
     [0 + 4] = MMX_OP2(psraw),
     [0 + 6] = MMX_OP2(psllw),
@@ -2451,7 +2451,7 @@
     [16 + 7] = { NULL, gen_op_pslldq_xmm },
 };
 
-static GenOpFunc1 *sse_op_table3[4 * 3] = {
+static GenOpFunc1 * const sse_op_table3[4 * 3] = {
     gen_op_cvtsi2ss,
     gen_op_cvtsi2sd,
     X86_64_ONLY(gen_op_cvtsq2ss),
@@ -2468,7 +2468,7 @@
     X86_64_ONLY(gen_op_cvtsd2sq),
 };
     
-static GenOpFunc2 *sse_op_table4[8][4] = {
+static GenOpFunc2 * const sse_op_table4[8][4] = {
     SSE_FOP(cmpeq),
     SSE_FOP(cmplt),
     SSE_FOP(cmple),
@@ -4637,7 +4637,7 @@
             case 0x18 ... 0x1b:
                 {
                     int op1;
-                    const static uint8_t fcmov_cc[8] = {
+                    static const uint8_t fcmov_cc[8] = {
                         (JCC_B << 1),
                         (JCC_Z << 1),
                         (JCC_BE << 1),
@@ -5871,7 +5871,7 @@
 #define CC_OSZAP (CC_O | CC_S | CC_Z | CC_A | CC_P)
 
 /* flags read by an operation */
-static uint16_t opc_read_flags[NB_OPS] = { 
+static const uint16_t opc_read_flags[NB_OPS] = { 
     [INDEX_op_aas] = CC_A,
     [INDEX_op_aaa] = CC_A,
     [INDEX_op_das] = CC_A | CC_C,
@@ -6004,7 +6004,7 @@
 };
 
 /* flags written by an operation */
-static uint16_t opc_write_flags[NB_OPS] = { 
+static const uint16_t opc_write_flags[NB_OPS] = { 
     [INDEX_op_update2_cc] = CC_OSZAPC,
     [INDEX_op_update1_cc] = CC_OSZAPC,
     [INDEX_op_cmpl_T0_T1_cc] = CC_OSZAPC,

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] const / static (against current CVS)
  2005-08-23 17:40 [Qemu-devel] [PATCH] const / static (against current CVS) Andreas Mohr
@ 2005-08-24  3:24 ` Mulyadi Santosa
  2005-08-24 12:54 ` Doctor Bill
  1 sibling, 0 replies; 8+ messages in thread
From: Mulyadi Santosa @ 2005-08-24  3:24 UTC (permalink / raw)
  To: qemu-devel, Andreas Mohr

Hello Andreas!

> Introduction part:
> ----------
> I'm doing a performance tuning effort all over the place in
> frequently-used Linux programs:
> I'm trying to mark as many data areas as possible const (and static)
> in various programs (at those places where it's actually feasible,
> that is).

Great! Damn, never think to do something like this before. Anyway, do 
you get any speed improvement when using this patch? or smaller memory 
consumption?

regards

Mulyadi

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] const / static (against current CVS)
  2005-08-23 17:40 [Qemu-devel] [PATCH] const / static (against current CVS) Andreas Mohr
  2005-08-24  3:24 ` Mulyadi Santosa
@ 2005-08-24 12:54 ` Doctor Bill
  2005-08-24 13:41   ` Paul Brook
  1 sibling, 1 reply; 8+ messages in thread
From: Doctor Bill @ 2005-08-24 12:54 UTC (permalink / raw)
  To: qemu-devel

My own experience is the effect of these types of optimizations is
usually negligible, although it is still the first thing I do when
optimizing a program.  The main improvement I find is reducing the
time required to initialize variables and improved code readability. 
If you know values are constant, you do not need to reference how
there values are changing in a debugger...

Probably more important is to make sure none constant data structures
are done on the stack.  There is no good reason why any code page
should be read-write.

Bill

On 8/23/05, Andreas Mohr <andi@rhlx01.fht-esslingen.de> wrote:
> Hello all,
> 
> Introduction part:
> ----------
> I'm doing a performance tuning effort all over the place in
> frequently-used Linux programs:
> I'm trying to mark as many data areas as possible const (and static)
> in various programs (at those places where it's actually feasible,
> that is).
> 
> This should have the following benefits:
> a) more .rodata (read-only) pages in programs, which means that
> pages (since they're read-only and can thus be restored from the binary any
> time) can simply be discarded instead of having to be paged out when
> free memory is getting low
> b) more page sharing between program instances due to less
> modified / read-write (and thus unique instance *per-program*!) memory pages
> c) various const compiler optimizations kicking in
> d) less linker work to be done (static)
> e) we detect previously silent memory corruption (random data area trashing)
> better
> 
> (use "objdump -x" to analyze what can be improved)
> 
> In smaller programs marking variables as const won't be enough to get
> several whole pages (4K size) back to read-only, but it goes into the
> right direction after all, since we don't intend to actually increase
> the number of read-write pages...
> ----------
> 
> This patch against current CVS adds const and/or static to numerous structs
> that obviously could be made so. It compiles without any warnings,
> and qemu even still runs! ;-)
> 
> Patch had been posted to "Patches Repository" on User Forum about a month
> ago, but of course that wasn't enough... (silly me)
> 
> Thank you,
> 
> Andreas Mohr
> (patch attached)
> 
> --
> GNU/Linux. It's not the software that's free, it's you.
> 
> 
> _______________________________________________
> Qemu-devel mailing list
> Qemu-devel@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/qemu-devel
> 
> 
> 
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] const / static (against current CVS)
  2005-08-24 12:54 ` Doctor Bill
@ 2005-08-24 13:41   ` Paul Brook
  2005-08-24 14:38     ` Andreas Mohr
  2005-08-24 20:35     ` Jamie Lokier
  0 siblings, 2 replies; 8+ messages in thread
From: Paul Brook @ 2005-08-24 13:41 UTC (permalink / raw)
  To: qemu-devel

> Probably more important is to make sure none constant data structures
> are done on the stack.  There is no good reason why any code page
> should be read-write.

Huh? this is nonsense.

You have three segements in an application (ignoring dynamic heap allocated 
memory):

The RO segment that contains code and readonly data. This is typically 
implemented as a readonly file mapping shared by multiple applications.

The RW segment contains read/write data, some of which may be initialized by 
data stored in the executable file, the rest is zero-initialized at startup.

The Stack is readwrite, unititialized, and typically allocated dynamically at 
runtime.

The compiler never puts readwrite objects in th RO segment. If it does you've 
got a buggy toolchain or build system.

Making global data readonly is a small win because it means it can be shared 
by multiple instances of the same application.

Moving global RW data onto the stack isn't neccly a win. Most systems have a 
relatively small limit on stack size, so putting large objects on the stack 
is a bad idea.

Contrary to popular belief the "const" qualifier on pointers has absolutely no 
effect on optimization. It's simply a debugging aid so the compiler will 
generate an error if you accidentally assign to it. It's perfectly legal to 
cast a (const char *) to a (char *) then dereference and write to it, 
provided the object the object it points to is modifiable.

Paul

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] const / static (against current CVS)
  2005-08-24 13:41   ` Paul Brook
@ 2005-08-24 14:38     ` Andreas Mohr
  2005-08-24 14:49       ` Paul Brook
  2005-08-24 20:35     ` Jamie Lokier
  1 sibling, 1 reply; 8+ messages in thread
From: Andreas Mohr @ 2005-08-24 14:38 UTC (permalink / raw)
  To: qemu-devel

Hi,

On Wed, Aug 24, 2005 at 02:41:44PM +0100, Paul Brook wrote:
> > Probably more important is to make sure none constant data structures
> > are done on the stack.  There is no good reason why any code page
> > should be read-write.
> 
> Huh? this is nonsense.

Uhoh, I seem to have managed to stir up a veritable hornet's net with my
patch...

> Making global data readonly is a small win because it means it can be shared 
> by multiple instances of the same application.

Yup.

> Moving global RW data onto the stack isn't neccly a win. Most systems have a 
> relatively small limit on stack size, so putting large objects on the stack 
> is a bad idea.

Indeed. Witness e.g. Linux's optional kernel stack reduction to 4k
and the problems that ensued.

> Contrary to popular belief the "const" qualifier on pointers has absolutely no 
> effect on optimization. It's simply a debugging aid so the compiler will 
> generate an error if you accidentally assign to it. It's perfectly legal to 
> cast a (const char *) to a (char *) then dereference and write to it, 
> provided the object the object it points to is modifiable.

I was thinking just that: that constifying stuff at most gives a very small
compiler gain, but most probably just nothing (some people reported some
rather weak 1.4% performance gain somewhere!? Statistical noise...).
Since you say it's nothing I'm strongly inclined to believe it...

Well, it's not only a compiler debugging aid, but also a runtime debugging
aid, since random (attempted) .rodata page corruption should SEGV in that case.

Andreas Mohr

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] const / static (against current CVS)
  2005-08-24 14:38     ` Andreas Mohr
@ 2005-08-24 14:49       ` Paul Brook
  2005-08-24 16:49         ` Doctor Bill
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Brook @ 2005-08-24 14:49 UTC (permalink / raw)
  To: qemu-devel

On Wednesday 24 August 2005 15:38, Andreas Mohr wrote:
> Hi,
>
> On Wed, Aug 24, 2005 at 02:41:44PM +0100, Paul Brook wrote:
> > > Probably more important is to make sure none constant data structures
> > > are done on the stack.  There is no good reason why any code page
> > > should be read-write.
> >
> > Huh? this is nonsense.
>
> Uhoh, I seem to have managed to stir up a veritable hornet's net with my
> patch...

For the record this wasn't intended as a criticism of your patch. I think 
adding const/static is a good idea for debugging/maintainability, even if it 
doesn't give any actual performance benefits.

Paul

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] const / static (against current CVS)
  2005-08-24 14:49       ` Paul Brook
@ 2005-08-24 16:49         ` Doctor Bill
  0 siblings, 0 replies; 8+ messages in thread
From: Doctor Bill @ 2005-08-24 16:49 UTC (permalink / raw)
  To: qemu-devel

 On Wed, Aug 24, 2005 at 02:41:44PM +0100, Paul Brook wrote:
 > > Probably more important is to make sure none constant data structures
 > > are done on the stack.  There is no good reason why any code page
 > > should be read-write.
 >
> Huh? this is nonsense.


I stand corrected, I ment to say on the stack or in the heap.  ie. I
was only refering within the scope of the original post.  The point is
you don't want self modifing code.  In rare circumstances you need
self modifing code, but it is very rare.  While it possible to mark
allocated pages as read only, this usually only done for runtime error
detection and sometimes thread saftey.  Pretty much all modern
operating systems do copy on write.  However, this is completely
beyond the scope of our discussion.

Bill

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH] const / static (against current CVS)
  2005-08-24 13:41   ` Paul Brook
  2005-08-24 14:38     ` Andreas Mohr
@ 2005-08-24 20:35     ` Jamie Lokier
  1 sibling, 0 replies; 8+ messages in thread
From: Jamie Lokier @ 2005-08-24 20:35 UTC (permalink / raw)
  To: qemu-devel

Paul Brook wrote:
> Contrary to popular belief the "const" qualifier on pointers has
> absolutely no effect on optimization. It's simply a debugging aid so
> the compiler will generate an error if you accidentally assign to
> it.

That's only true when the "const" applies to pointer targets, as in:

   const char * ptr = "foo";

It does not apply when the "const" applies to the pointer itself.
This puts the pointer "ptr" into RO storage:

   const char * const ptr = "foo";

Hence the large number of times that pattern occurs in the patch.

> It's perfectly legal to cast a (const char *) to a (char *) then
> dereference and write to it, provided the object the object it
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> points to is modifiable.
  ^^^^^^^^^^^^^^^^^^^^^^^

Precisely.  Global and static variables that are declared "const" are
not "modifiable", and are put in RO storage, so they cannot be written
to.  Taking their address creates a "const" pointer which must not be
derefenced and written to.

-- Jamie

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2005-08-24 20:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-23 17:40 [Qemu-devel] [PATCH] const / static (against current CVS) Andreas Mohr
2005-08-24  3:24 ` Mulyadi Santosa
2005-08-24 12:54 ` Doctor Bill
2005-08-24 13:41   ` Paul Brook
2005-08-24 14:38     ` Andreas Mohr
2005-08-24 14:49       ` Paul Brook
2005-08-24 16:49         ` Doctor Bill
2005-08-24 20:35     ` Jamie Lokier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.