empty function optimizations

From: Geert Uytterhoeven (geert@linux-m68k.org)
Date: Sat Jul 08 2000 - 14:50:38 EST


        Hi,

I wrote a small Perl script to find empty functions and simple functions (i.e.
`return <some_value>') in C code. Here are the results for the complete
2.4.0-test3-pre6 tree:

    Number of empty functions: 492
    Number of empty functions with a debug statement: 375
    -------------------------------------------------------
    Total number of empty functions: 867

    Number of simple functions: 2593
    Number of simple functions with a debug statement: 261
    -------------------------------------------------------
    Total number of simple functions: 2854

Currently the debug statement is a printk(). I could add tests for other debug
variants in the future. I suppose most simple functions return either 0, -1 or
-EINVAL. I haven't analyzed these yet.

If empty or simple functions are static inline and no pointer points to them,
they will be optimized away by the compiler. But many of them are referenced
by a pointer in some struct *_ops so they do end up in the final kernel image.

My idea was to replace empty and most simple functions by predefined dummy(),
dummy_zeros(), dummy_ones() and dummy_einval() functions, so they appear only
once in a kernel image. But is it worth the effort? Note that you don't compile
all code into your favorite kernel image, only the parts you need for your
hardware, so you won't catch all empty functions at once.

Of course it depends on the architecture, too: if you can return from a
subroutine in 1 byte, elimating all copies of empty functions would save only a
few bytes.

Anyway, even if it's not worth the effort, we now have a guestimate for the
waste :-)

Gr{oetje,eeting}s,

                                                Geert

P.S. If you're interested in the Perl script, just ask me in personal mail.

--
Geert Uytterhoeven -- Linux/{m68k~Amiga,PPC~CHRP} -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds

- 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/



This archive was generated by hypermail 2b29 : Sat Jul 15 2000 - 21:00:11 EST