2007-08-30 13:00:41

by Mohamed Bamakhrama

[permalink] [raw]
Subject: Average number of instructions per line of kernel code

Hi all,
I have a question regarding the average number of assembly
instructions per line of kernel code. I know that this is a difficult
question since it depends on many factors such as the instruction set
architecture, compiler used, optimizations used, type of code, coding
style, etc...
I would like to know a rough estimate for such a quantity for the
kernel 2.4/2.6 code running on MIPS32 architecture.
My estimate is between 5-10 instructions. I googled for such a thing
but couldn't find any useful papers/resources.

Many thanks in advance.

Best regards

--
Mohamed A. Bamakhrama


2007-08-30 13:31:22

by Jesper Juhl

[permalink] [raw]
Subject: Re: Average number of instructions per line of kernel code

On 30/08/2007, Mohamed Bamakhrama <[email protected]> wrote:
> Hi all,
> I have a question regarding the average number of assembly
> instructions per line of kernel code. I know that this is a difficult
> question since it depends on many factors such as the instruction set
> architecture, compiler used, optimizations used, type of code, coding
> style, etc...
> I would like to know a rough estimate for such a quantity for the
> kernel 2.4/2.6 code running on MIPS32 architecture.
> My estimate is between 5-10 instructions. I googled for such a thing
> but couldn't find any useful papers/resources.
>

Why don't you simply count the number of non-blank non-comment lines
in the source files that you are building, build the kernel and then
count the number of instructions in the resulting binary ?

--
Jesper Juhl <[email protected]>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html

2007-08-30 13:48:45

by Mohamed Bamakhrama

[permalink] [raw]
Subject: Re: Average number of instructions per line of kernel code

On 8/30/07, Jesper Juhl <[email protected]> wrote:
> On 30/08/2007, Mohamed Bamakhrama <[email protected]> wrote:
> > Hi all,
> > I have a question regarding the average number of assembly
> > instructions per line of kernel code. I know that this is a difficult
> > question since it depends on many factors such as the instruction set
> > architecture, compiler used, optimizations used, type of code, coding
> > style, etc...
> > I would like to know a rough estimate for such a quantity for the
> > kernel 2.4/2.6 code running on MIPS32 architecture.
> > My estimate is between 5-10 instructions. I googled for such a thing
> > but couldn't find any useful papers/resources.
> >
>
> Why don't you simply count the number of non-blank non-comment lines
> in the source files that you are building, build the kernel and then
> count the number of instructions in the resulting binary ?

Hi,
I agree with you but is there any way to include ALL the drivers in
the kernel tree in building the image? Otherwise, I will be counting
un-used lines.

--
Mohamed

2007-08-30 13:55:22

by Jesper Juhl

[permalink] [raw]
Subject: Re: Average number of instructions per line of kernel code

On 30/08/2007, Mohamed Bamakhrama <[email protected]> wrote:
> On 8/30/07, Jesper Juhl <[email protected]> wrote:
> > On 30/08/2007, Mohamed Bamakhrama <[email protected]> wrote:
> > > Hi all,
> > > I have a question regarding the average number of assembly
> > > instructions per line of kernel code. I know that this is a difficult
> > > question since it depends on many factors such as the instruction set
> > > architecture, compiler used, optimizations used, type of code, coding
> > > style, etc...
> > > I would like to know a rough estimate for such a quantity for the
> > > kernel 2.4/2.6 code running on MIPS32 architecture.
> > > My estimate is between 5-10 instructions. I googled for such a thing
> > > but couldn't find any useful papers/resources.
> > >
> >
> > Why don't you simply count the number of non-blank non-comment lines
> > in the source files that you are building, build the kernel and then
> > count the number of instructions in the resulting binary ?
>
> Hi,
> I agree with you but is there any way to include ALL the drivers in
> the kernel tree in building the image? Otherwise, I will be counting
> un-used lines.
>
make allyesconfig
make


--
Jesper Juhl <[email protected]>
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please http://www.expita.com/nomime.html

2007-08-30 16:37:39

by J. Scott Kasten

[permalink] [raw]
Subject: Re: Average number of instructions per line of kernel code


On Thu, 30 Aug 2007, Mohamed Bamakhrama wrote:
>>> Hi all,
>>> I have a question regarding the average number of assembly
>>> instructions per line of kernel code. I know that this is a difficult
>>> question since it depends on many factors such as the instruction set

Here's a quick answer, not the best, but quick.

I took a user space flash memory driver I'm doing at work and compiled it
on my R5000 at home using gcc 4.1 and the MIPS3 abi, stopping with a .o
file. I also ran the source through cpp and a couple of grep passes to
strip out junk that wasn't really code. This driver may be somewhat
typical of what you would run into as it has quite a few inline functions
and such.

The driver.o was about 23000 bytes. Forgetting about the symboltables and
just dividing by 4 to estimate instructions and dividing by about 1650
net lines of code, I got about 3.5 instructions per line of C code.

I'm guessing that ball park, you're looking at 3-5 average - 10 seems high
except in sections with lots and lots of inlines.

Regards,

-S-

2007-08-30 19:49:23

by Jan Engelhardt

[permalink] [raw]
Subject: Re: Average number of instructions per line of kernel code


On Aug 30 2007 12:29, J. Scott Kasten wrote:
> On Thu, 30 Aug 2007, Mohamed Bamakhrama wrote:
>> > > Hi all,
>> > > I have a question regarding the average number of assembly
>> > > instructions per line of kernel code. I know that this is a difficult
>> > > question since it depends on many factors such as the instruction set
>
> Here's a quick answer, not the best, but quick.
>
> I took a user space flash memory driver I'm doing at work and compiled it on my
> R5000 at home using gcc 4.1 and the MIPS3 abi, stopping with a .o file. I also
> ran the source through cpp and a couple of grep passes to strip out junk that
> wasn't really code. This driver may be somewhat typical of what you would run
> into as it has quite a few inline functions and such.
>
> The driver.o was about 23000 bytes. Forgetting about the symboltables and just
> dividing by 4 to estimate instructions and dividing by about 1650 net lines of
> code, I got about 3.5 instructions per line of C code.

objcopy -j .text input.o output.o
objcopy -O binary output.o output2.o

Then you can objdump -S output.o and count. output2.o has the ELF header
stripped, so provides the raw size, but at the cost of not being able to run
objdump. If you know that every instruction is fixed size, then of course
output2.o is easy.


Jan
--

2007-08-30 20:03:51

by Freddy Spierenburg

[permalink] [raw]
Subject: Re: Average number of instructions per line of kernel code

Hi all,

On Thu, 30 Aug 2007, Mohamed Bamakhrama wrote:
> I have a question regarding the average number of assembly
> instructions per line of kernel code.

I may completely miss out on this one, but what's the point in
knowing?


--
$ cat ~/.signature
Freddy Spierenburg <[email protected]> http://freddy.snarl.nl/
GnuPG: 0x7941D1E1=C948 5851 26D2 FA5C 39F1 E588 6F17 FD5D 7941 D1E1
$ # Please read http://www.ietf.org/rfc/rfc2015.txt before complain!


Attachments:
(No filename) (462.00 B)
signature.asc (189.00 B)
Digital signature
Download all attachments