* Average instruction length in x86-built kernel?
@ 2005-07-29 21:32 Karim Yaghmour
2005-07-30 13:49 ` Ingo Oeser
0 siblings, 1 reply; 6+ messages in thread
From: Karim Yaghmour @ 2005-07-29 21:32 UTC (permalink / raw)
To: linux-kernel
I'm wondering if anyone's ever done an analysis on the average length
of instructions in an x86-built kernel.
Googling around, I can find references claiming that the average
instruction length on x86 is anywhere from 2.7 to 3.5 bytes, but I
can't find anything studying Linux specifically.
Just curious,
Karim
--
Author, Speaker, Developer, Consultant
Pushing Embedded and Real-Time Linux Systems Beyond the Limits
http://www.opersys.com || karim@opersys.com || 1-866-677-4546
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Average instruction length in x86-built kernel?
2005-07-29 21:32 Average instruction length in x86-built kernel? Karim Yaghmour
@ 2005-07-30 13:49 ` Ingo Oeser
2005-07-30 19:57 ` Karim Yaghmour
0 siblings, 1 reply; 6+ messages in thread
From: Ingo Oeser @ 2005-07-30 13:49 UTC (permalink / raw)
To: karim; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 785 bytes --]
Hi Karim,
On Friday 29 July 2005 23:32, Karim Yaghmour wrote:
> Googling around, I can find references claiming that the average
> instruction length on x86 is anywhere from 2.7 to 3.5 bytes, but I
> can't find anything studying Linux specifically.
This is not that hard to find out yourself:
Just study the output od objdump -d and average the differences
of the first hex number in a line printed, which are followed by a ":"
e.g.
scripts/kconfig/mconf.o: file format elf32-i386
Disassembly of section .text:
00000000 <init_wsize>:
0: 83 ec 1c sub $0x1c,%esp
3: 8d 44 24 10 lea 0x10(%esp),%eax
7: 89 44 24 08 mov %eax,0x8(%esp)
so avg(3-7, 3-0) = 2.5
and so on...
Happy analyzing!
Regards
Ingo Oeser
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Average instruction length in x86-built kernel?
2005-07-30 13:49 ` Ingo Oeser
@ 2005-07-30 19:57 ` Karim Yaghmour
2005-08-01 7:35 ` David Weinehall
0 siblings, 1 reply; 6+ messages in thread
From: Karim Yaghmour @ 2005-07-30 19:57 UTC (permalink / raw)
To: Ingo Oeser; +Cc: linux-kernel
Hello Ingo,
Ingo Oeser wrote:
> Just study the output od objdump -d and average the differences
> of the first hex number in a line printed, which are followed by a ":"
Here's a script that does what I was looking for:
#!/bin/bash
# Dissassemble
objdump -d $1 -j .text > $2-dissassembled-kernel
# Remove non-instruction lines:
sed /^[^c].*/d $2-dissassembled-kernel > $2-stage-1
# Remove empty lines:
sed /^'\t'*$/d $2-stage-1 > $2-stage-2
# Remove function names:
sed /^c[0-9,a-f]*' '\<.*\>:$/d $2-stage-2 > $2-stage-3
# Remove addresses:
sed s/^c[0-9,a-f]*:'\t'// $2-stage-3 > $2-stage-4
# Remove instruction text:
sed s/'\t'.*// $2-stage-4 > $2-stage-5
# Remove trailing whitespace:
sed s/'\s'*$// $2-stage-5 > $2-stage-6
# Separate instructions depending on size:
egrep "([0-9a-f]{2}[' ']*){5}" $2-stage-6 > $2-more-or-eq-5
egrep "^([0-9a-f]{2}[' ']*){0,4}$" $2-stage-6 > $2-less-or-eq-4
# Find out how much of each we've got:
wc -l $2-stage-6
wc -l $2-more-or-eq-5
wc -l $2-less-or-eq-4
The last part can easily be changed to iterate through and separate
those that are 1 byte, 2 bytes, etc. and automatically come up with
stats, but this was fine for what I was looking for.
I ran it on a 2.4.x and a 2.6.x kernel and about 3/4 of instructions
are 4 bytes or less.
Karim
--
Author, Speaker, Developer, Consultant
Pushing Embedded and Real-Time Linux Systems Beyond the Limits
http://www.opersys.com || karim@opersys.com || 1-866-677-4546
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Average instruction length in x86-built kernel?
[not found] ` <4w5OQ-6Z9-25@gated-at.bofh.it>
@ 2005-07-31 2:19 ` Bodo Eggert
2005-08-01 6:25 ` Jan Engelhardt
0 siblings, 1 reply; 6+ messages in thread
From: Bodo Eggert @ 2005-07-31 2:19 UTC (permalink / raw)
To: karim, Ingo Oeser, linux-kernel
Karim Yaghmour <karim@opersys.com> wrote:
> Here's a script that does what I was looking for:
<snip>
#!/bin/bash
for a in "$@"
do
objdump -d "$a" -j .text
done | perl -ne'
BEGIN{%h=();$b=0};
END{if($b){$h{$b}++};print map("$_: $h{$_}\n", sort(keys(%h)))};
if(/\tnop $/){$h{nop}++}
elsif(/^[\s0-9a-f]{8}:\t([^\t]+) (\t?)/){
$b+=split(" ",$1);if($2){$h{$b}++;$b=0}}'
--
Ich danke GMX dafür, die Verwendung meiner Adressen mittels per SPF
verbreiteten Lügen zu sabotieren.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Average instruction length in x86-built kernel?
2005-07-31 2:19 ` Bodo Eggert
@ 2005-08-01 6:25 ` Jan Engelhardt
0 siblings, 0 replies; 6+ messages in thread
From: Jan Engelhardt @ 2005-08-01 6:25 UTC (permalink / raw)
To: 7eggert; +Cc: karim, Ingo Oeser, linux-kernel
>> Here's a script that does what I was looking for:
><snip>
Mmmmh, perlgolf?
>#!/bin/bash
>for a in "$@"
>do
> objdump -d "$a" -j .text
>done | perl -ne'
>BEGIN{%h=();$b=0};
>END{if($b){$h{$b}++};print map("$_: $h{$_}\n", sort(keys(%h)))};
>if(/\tnop $/){$h{nop}++}
>elsif(/^[\s0-9a-f]{8}:\t([^\t]+) (\t?)/){
> $b+=split(" ",$1);if($2){$h{$b}++;$b=0}}'
objdump -j .text -d "$@" | perl -ne '
END{$h{$b}++if$b;print map"$_: $h{$_}\n",sort keys%h};
if(/\tnop\s*$/){$h{nop}++}
elsif(/^.*?:\t([^\t]+) (\t?)/){
$b+=split/ /,$1;if($2){$h{$b}++;$b=0}}'
Jan Engelhardt
--
| Alphagate Systems, http://alphagate.hopto.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Average instruction length in x86-built kernel?
2005-07-30 19:57 ` Karim Yaghmour
@ 2005-08-01 7:35 ` David Weinehall
0 siblings, 0 replies; 6+ messages in thread
From: David Weinehall @ 2005-08-01 7:35 UTC (permalink / raw)
To: Karim Yaghmour; +Cc: Ingo Oeser, linux-kernel
On Sat, Jul 30, 2005 at 03:57:25PM -0400, Karim Yaghmour wrote:
[snip]
> # Remove non-instruction lines:
> sed /^[^c].*/d $2-dissassembled-kernel > $2-stage-1
>
> # Remove empty lines:
> sed /^'\t'*$/d $2-stage-1 > $2-stage-2
>
> # Remove function names:
> sed /^c[0-9,a-f]*' '\<.*\>:$/d $2-stage-2 > $2-stage-3
>
> # Remove addresses:
> sed s/^c[0-9,a-f]*:'\t'// $2-stage-3 > $2-stage-4
>
> # Remove instruction text:
> sed s/'\t'.*// $2-stage-4 > $2-stage-5
>
> # Remove trailing whitespace:
> sed s/'\s'*$// $2-stage-5 > $2-stage-6
Uhm, you do know that sed allows you to execute several commands after
eachother, right?
sed -e 's/foo/bar/;s/baz/omph/'
That way you should be able to save a few stages.
Also, your script is, as far as I could see, a clean sh-script;
no need for /bin/bash; use /bin/sh instead.
Regards: David Weinehall
--
/) David Weinehall <tao@acc.umu.se> /) Northern lights wander (\
// Maintainer of the v2.0 kernel // Dance across the winter sky //
\) http://www.acc.umu.se/~tao/ (/ Full colour fire (/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-08-01 7:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-29 21:32 Average instruction length in x86-built kernel? Karim Yaghmour
2005-07-30 13:49 ` Ingo Oeser
2005-07-30 19:57 ` Karim Yaghmour
2005-08-01 7:35 ` David Weinehall
[not found] <4vKU4-3sU-21@gated-at.bofh.it>
[not found] ` <4w02Q-7e6-21@gated-at.bofh.it>
[not found] ` <4w5OQ-6Z9-25@gated-at.bofh.it>
2005-07-31 2:19 ` Bodo Eggert
2005-08-01 6:25 ` Jan Engelhardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox