From: Eric Dumazet <dada1@cosmosbay.com>
To: Russell Leighton <russ@elegant-software.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: OT: Does Linux have any "Perfect Code"
Date: Thu, 15 Nov 2007 07:29:47 +0100 [thread overview]
Message-ID: <473BE75B.9070701@cosmosbay.com> (raw)
In-Reply-To: <c9d133bdb3481fbc01a572d948049f5e@elegant-software.com>
Russell Leighton a écrit :
>
> Bryan Cantrill of Sun (ala DTrace) has a notion of perfect code:
>
> http://blogs.sun.com/bmc/entry/on_i_dreaming_in_code
>
> He also has some examples (from bottom comment section of above):
>
>>
>>
>> Can you list a small number of examples of "software perfection"?
>>
>> Posted by Russell Leighton on November 14, 2007 at 04:02 AM PST #
>>
>> Russell,
>>
>> My canonical small example of perfection in Solaris would be Jeff
>> Bonwick's mod-by-a-billion code in hrt2ts():
>>
>> http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/os/timers.c#875
>>
>>
>> Solaris of course has lots of bigger, more complicated examples. Now
>> on the one hand, one wants to refrain from pointing to thousands of
>> lines of code and saying that there are no bugs therein, but on the
>> other, there are many subsystems that have been in place and in heavy
>> use for years without defect or modification. At the risk of being
>> egocentric, the cyclic subsystem (which is executed at least 100 times
>> per second on every Solaris system) had its last substantial fix over
>> six years ago, and its last fix of any flavor over three years ago:
>>
>> http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/os/cyclic.c
>>
>>
>> Modesty (and the lack, of course, of a proof of its correctness)
>> prevents me from calling the cyclic subsystem perfect -- but such as
>> unknown defects remain, there are damn few of them, and we can say
>> that they must be a result of highly usual (or at least, heretofore
>> unseen) circumstances.
>>
>> A non-Solaris example -- and one that I've been known to use as the
>> canonical example of the persistence of software -- is Super Mario
>> Kart. This is a game that was developed (to its completion) fifteen
>> years ago for the Super Nintendo console. Source code, to the best of
>> my knowledge, is not publicly available and may indeed be lost -- but
>> the binaries persist and (if my coworkers are any indication) remain
>> in active use. Given the longevity of, say, Homer's Odyssey, there is
>> reason to believe that Super Mario Kart will survive in perpetuity --
>> that thousands of years from now, twenty-somethings somewhere will be
>> using the software exactly as it is used today. Is this perfection?
>> Perhaps not -- but it also might not be discernible from perfection...
>>
>> Posted by Bryan Cantrill on November 14, 2007 at 07:51 AM PST #
>
> Does Linux have any such examples true software perfection?
>
I dont know, (what a strange idea is it anyway ?) but reading two Solaris
functions just gave me the example of non true software perfection.
http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/os/timers.c#1106
I would say this code was OK 10 years ago.
Now that a processor (say an Opteron in 64 bits mode, used on SUN hardware),
can perform a multiply in few cycles, ts2hrt() could use a normal multiply and
an addition.
Processors are improving, compilers are improving, memory sizes are
increasing, source code (and algorithms) should be changed accordingly.
(gcc for example already knows the reciprocal division trick and so can
compile this :
hrt2ts_div(hrtime_t hrt, timestruc_t *tsp)
{
tsp->tv_nsec = do_div(hrt, NANOSEC);
tsp->tv_sec = hrt;
}
to :
movq %rdi, %rdx
movabsq $19342813113834067, %rax
shrq $9, %rdx
mulq %rdx
shrq $11, %rdx
imulq $1000000000, %rdx, %rax
movq %rdx, (%rsi)
subq %rax, %rdi
movl %edi, 8(%rsi)
while
hrtime_t
ts2hrt(const timestruc_t *tsp)
{
return tsp->tv_sec * NANOSEC + tsp->tv_nsec;
}
can be inlined as it is trivial (and much faster than Solaris version)
movq (%rdi), %rdx
mov 8(%rdi), %eax
imulq $1000000000, %rdx, %rdx
addq %rdx, %rax
next prev parent reply other threads:[~2007-11-15 6:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-15 1:21 OT: Does Linux have any "Perfect Code" Russell Leighton
2007-11-15 1:33 ` David Miller
2007-11-15 6:29 ` Eric Dumazet [this message]
2007-11-15 7:11 ` David Miller
2007-11-15 7:43 ` Andi Kleen
2007-11-15 8:27 ` Philippe Elie
2007-11-15 13:16 ` Michael Gerdau
2007-11-15 15:10 ` Daniel Barkalow
2007-11-17 8:44 ` Geert Uytterhoeven
2007-11-15 17:05 ` Chris Friesen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=473BE75B.9070701@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=linux-kernel@vger.kernel.org \
--cc=russ@elegant-software.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox