linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] removal of "static foo = 0"
  2000-11-27  5:56 ` Adam J. Richter
@ 2000-11-27  8:41 Werner Almesberger
  2000-11-27  5:56 ` Adam J. Richter
  2000-11-27 18:01 ` Michael Meissner
  0 siblings, 2 replies; 69+ messages in thread
From: Werner Almesberger @ 2000-11-27  8:41 UTC (permalink / raw)
  To: Adam J. Richter; +Cc: linux-kernel

Adam J. Richter wrote:
> 	At the moment, I have started daydreaming about instead
> writing an "elf squeezer" to do this and other space optimizations
> by modifying objdump.

Hmm, this would require that gcc never calculates the location of an
explicitly initialized static variable based on the address of another
one. E.g. in

static int a = 0, b = 0, c = 0, d = 0;

...
    ... a+b+c+d ...
...

egcs-2.91.66 indeed doesn't seem to make this optimization on i386.
(Maybe the pointer increment or pointer offset solution would
actually be slower - didn't check.) But I'm not sure if this is also
true for other versions/architectures, or other code constructs.

- Werner

-- 
  _________________________________________________________________________
 / Werner Almesberger, ICA, EPFL, CH           Werner.Almesberger@epfl.ch /
/_IN_N_032__Tel_+41_21_693_6621__Fax_+41_21_693_6610_____________________/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 69+ messages in thread
* Re: [PATCH] removal of "static foo = 0"
@ 2000-11-26 17:53 Elmer Joandi
  2000-11-26 18:36 ` Alexander Viro
  2000-11-26 22:49 ` Rogier Wolff
  0 siblings, 2 replies; 69+ messages in thread
From: Elmer Joandi @ 2000-11-26 17:53 UTC (permalink / raw)
  To: linux-kernel


Nice to see again a two cutting-edge-killing opinions.

Every time I really wonder, how such brilliant hackers can be that stupid
that they can not have cake and eat it the same time, and have to scratch
each-others eyes every time.

Use macros.

Kernel has become so big that it really needs universal  debugging macros
instead of comments. Comments are waste of brain&fingerpower, if the same
can be explained by long variable names and debug macros.

static Subsystem_module_LocalVariableForThisPurpose;

int Subsytem_module_function_this_and_that(){
	DEBUG_ASSERT( Subsystem_module_LocalVariableForThisPurpose  == 0 );
	DEBUG_ASSERT(MOST_OF_TIME,FS_AREA,MYFS_MODULE, somethingaboutIndodes->node != NULL )
}


Those macros would be acceptable if they are unified and taken to
kernel configuration level, so it would be easy to switch them in/out 
not only as boolean option but systematically for different levels,
subsystems and modules.

elmer.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 69+ messages in thread
* Re: [PATCH] removal of "static foo = 0"
@ 2000-11-26 15:15 Adam J. Richter
  0 siblings, 0 replies; 69+ messages in thread
From: Adam J. Richter @ 2000-11-26 15:15 UTC (permalink / raw)
  To: linux-kernel

	Is there some reason why gcc does not put static data that
is explicitly initialized to zero in .bss?  If not, then fixing
gcc would provide more space savings than these patches, and
improve more software than just the Linux kernel.

Adam J. Richter     __     ______________   4880 Stevens Creek Blvd, Suite 104
adam@yggdrasil.com     \ /                  San Jose, California 95129-1034
+1 408 261-6630         | g g d r a s i l   United States of America
fax +1 408 261-6631      "Free Software For The Rest Of Us."
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 69+ messages in thread
* Re: [PATCH] removal of "static foo = 0"
@ 2000-11-25 20:19 Andries Brouwer
  2000-11-25 21:07 ` Russell King
                   ` (2 more replies)
  0 siblings, 3 replies; 69+ messages in thread
From: Andries Brouwer @ 2000-11-25 20:19 UTC (permalink / raw)
  To: rmk, rusty; +Cc: tigran, linux-kernel, Andries.Brouwer

On Sat, Nov 25, 2000 at 11:50:20AM +0000, Russell King wrote:
> Rusty Russell writes:
> > What irritates about these monkey-see-monkey-do patches is that if I
> > initialize a variable to NULL, it's because my code actually relies on
> > it; I don't want that information eliminated.
> 
> What information is lost?  Unless you're working on a really strange
> machine which does not zero bss, the following means the same from the
> codes point of view:
> 
> static int foo = 0;
> static int foo;
> 
> Both are initialised to zero by the time the code sees them for the
> first time.  Therefore there is no difference to the code in its reliance
> on whether foo is zero.  foo will be zero in both cases.
> 
> Also, any good programmer worth their skin should know this, and should
> realise it.  Therefore, there is no information loss

What a strange reaction. If I write

 static int foo;

this means that foo is a variable, local to the present compilation unit,
whose initial value is irrelevant because it will be assigned to before use.
If I write

 static int foo = 0;

this means that the code depends on the initialization.
Indeed, it is customary to write

 int foo = 0;  /* just for gcc */

when the initialization in fact is not necessary.


It is a bad programming habit to depend on this zero initialization.
Indeed, very often, when you have a program that does something
you need to change it so that it does that thing a number of times.
Well, put a for- or while-loop around it. But wait! The second time
through the loop certain variables need to be reinitialized. Which ones?
The ones that were initialized explicitly in your first program.
Make the program into a function in a larger one. Same story.


Saving a byte in the binary image is not very interesting.
Preserving information about the program is important.

I see that this message is cc'ed to Tigran, so let me address him as well.
Tigran, you like to destabilize Linux. I like to stabilize Linux.

If it is your intention to destabilize then you need not read the following.
But let us assume that you try to make a perfect system.

There is the issue of local and global correctness.
A piece of code is locally correct when its correctness can be seen
by just looking at those lines, or that function, or that source file.
A piece of code is globally correct when you need to read the entire kernel
source to convince yourself that all is well.

Often local correctness is obtained by local tests. After reading the entire
kernel source you conclude that these tests are superfluous because they
are satisfied in all cases. And you think it is an improvement to remove
the test. It almost never is. On a fast path, where every cycle counts, yes.
But it is not a good idea to sacrifice local correctness and save five
kernel image bytes, or speed up the mount system call by 0.001%.
Why not? Because you read the entire kernel source of today.
But not that of next week. Somewhere someone changes some code.
The test is gone and the kernel crashes instead of returning an error.

You even like to destabilize when there is no gain in size or speed at all.
It is bad coding practice to use casts. They tell the compiler not to check.
With functions returning (void *) the opposite is true. The compiler cannot
check now, but given a cast, it can. Thus, I wrote a few months ago

> If one just writes
>       foo = kmalloc(n * sizeof(some_type), GFP_x);
> then neither the compiler nor the human eye can check
> easily that things are right, i.e. that foo really is
> a (some_type *). Therefore it is better to write
>       foo = (some_type *) kmalloc(n * sizeof(some_type), GFP_x);

To my surprise you answered

: It is a small thing, Andries, but I still think otherwise than you.
: It is better for code to be smaller than to be slightly more fool-proof.

Please change your mind.

Andries

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

end of thread, other threads:[~2000-11-29 10:17 UTC | newest]

Thread overview: 69+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-27  8:41 [PATCH] removal of "static foo = 0" Werner Almesberger
2000-11-27  5:56 ` Adam J. Richter
2000-11-27  8:39   ` David S. Miller
2000-11-27  9:08     ` Werner Almesberger
2000-11-27 17:21     ` Andrea Arcangeli
2000-11-27 17:36       ` Michael Meissner
2000-11-27 19:06         ` Andrea Arcangeli
2000-11-27 19:34           ` Richard B. Johnson
2000-11-28  0:28             ` Andrea Arcangeli
2000-11-28 11:25               ` Horst von Brand
2000-11-27 21:27         ` Marcus Sundberg
2000-11-28  0:49           ` real_root_dev Andries Brouwer
2000-11-28  3:10         ` [PATCH] removal of "static foo = 0" kumon
2000-11-28  3:28           ` Andrea Arcangeli
2000-11-28  3:35             ` Alexander Viro
2000-11-28  4:15               ` Michael Meissner
2000-11-28  9:55               ` Andreas Schwab
2000-11-28 15:16                 ` Andrea Arcangeli
2000-11-28 16:09                   ` Andreas Schwab
2000-11-28 19:29                     ` Andrea Arcangeli
2000-11-28 16:44                   ` Michael Meissner
2000-11-27 18:11       ` Richard B. Johnson
2000-11-27 18:01 ` Michael Meissner
  -- strict thread matches above, loose matches on Subject: below --
2000-11-26 17:53 Elmer Joandi
2000-11-26 18:36 ` Alexander Viro
2000-11-26 19:11   ` Elmer Joandi
2000-11-26 22:49 ` Rogier Wolff
2000-11-26 15:15 Adam J. Richter
2000-11-25 20:19 Andries Brouwer
2000-11-25 21:07 ` Russell King
2000-11-25 21:29   ` Andries Brouwer
2000-11-26  1:19     ` Russell King
2000-11-25 22:11 ` Herbert Xu
2000-11-25 22:46   ` Andries Brouwer
2000-11-25 22:53     ` James A Sutherland
2000-11-25 23:55       ` Tim Waugh
2000-11-26  3:10         ` James A Sutherland
2000-11-26 10:37         ` Tigran Aivazian
2000-11-26 14:52           ` Philipp Rumpf
2000-11-28  0:01           ` Peter Samuelson
2000-11-27  4:00         ` Michael Meissner
2000-11-25 23:02     ` Jeff Garzik
2000-11-26  2:08       ` Andries Brouwer
2000-11-26  9:22         ` Martin Mares
2000-11-25 23:33     ` Herbert Xu
2000-11-27 10:03     ` Helge Hafting
2000-11-27 20:33     ` Albert D. Cahalan
2000-11-27 22:57       ` Russell King
2000-11-29  1:46         ` Albert D. Cahalan
2000-11-29  3:21           ` Peter Samuelson
2000-11-29  7:25           ` Russell King
2000-11-25 22:27 ` Tigran Aivazian
2000-11-26  1:32   ` Andries Brouwer
2000-11-26  6:21     ` Werner Almesberger
2000-11-26  2:11   ` Georg Nikodym
2000-11-26  4:25     ` Alan Cox
2000-11-26  5:01       ` John Alvord
2000-11-26  5:10         ` Andre Hedrick
2000-11-26  6:22           ` Keith Owens
2000-11-26  6:28             ` Andre Hedrick
2000-11-26 10:43         ` Tigran Aivazian
2000-11-26 10:52         ` Tigran Aivazian
2000-11-24  7:47           ` Pavel Machek
2000-11-26 14:32           ` bert hubert
2000-11-26 10:52         ` Rogier Wolff
2000-11-26 14:13       ` Philipp Rumpf
2000-11-26 20:47       ` H. Peter Anvin
2000-11-27 21:12         ` Kai Henningsen
2000-11-26 15:19     ` Georg Nikodym

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).