From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Maksim Radziwill" <7c00@wp.pl> To: <9fans@cse.psu.edu> Message-ID: <000601c2daa7$17972450$270363d9@makr4j0ty5i9an> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0007_01C2DAAF.795B8C50" Subject: [9fans] A quite amusing thing... Date: Sat, 22 Feb 2003 20:17:50 +0100 Topicbox-Message-UUID: 6e231de6-eacb-11e9-9e20-41e7f4b1d025 This is a multi-part message in MIME format. ------=_NextPart_000_0007_01C2DAAF.795B8C50 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi everyone, I recently have found an amusing thing between (FSD-)Amoeba and Plan9 : The code for cpu speed identification is the same ;) Here I paste it. If you don't believe youre eyes check out /sys/src/9/pc/i8253.c in the plan9 system /profile/module/amoeba/src/machdep/dev/ibm_at/timer/pit.c in the FSD-Amoeba system (the sys source must be installed of course) You can get FSD-Amoeba at fsd-amoeba.sourceforge.net it is the continuation of the original Amoeba project (www.cs.vu.nl/pub/amoeba) who has been terminated in 1996. ++++++ i8253.c the guesscpuhz function void guesscpuhz(int aalcycles) { int cpufreq, loops, incr, x, y; uvlong a, b; /* find biggest loop that doesn't wrap */ incr = 16000000/(aalcycles*HZ*2); x = 2000; for(loops = incr; loops < 64*1024; loops += incr) { /* * measure time for the loop * * MOVL loops,CX * aaml1: AAM * LOOP aaml1 * * the time for the loop should be independent of external * cache and memory system since it fits in the execution * prefetch buffer. * */ outb(Tmode, Latch0); if(m->havetsc) rdtsc(&a); x = inb(T0cntr); x |= inb(T0cntr)<<8; aamloop(loops); outb(Tmode, Latch0); if(m->havetsc) rdtsc(&b); y = inb(T0cntr); y |= inb(T0cntr)<<8; x -= y; if(x < 0) x += Freq/HZ; if(x > Freq/(3*HZ)) break; } /* * figure out clock frequency and a loop multiplier for delay(). * n.b. counter goes up by 2*Freq */ cpufreq = loops*((aalcycles*2*Freq)/x); m->loopconst = (cpufreq/1000)/aalcycles; /* AAM+LOOP's for 1 ms */ if(m->havetsc){ /* counter goes up by 2*Freq */ b = (b-a)<<1; b *= Freq; b /= x; /* * round to the nearest megahz */ m->cpumhz = (b+500000)/1000000L; m->cpuhz = b; } else { /* * add in possible 0.5% error and convert to MHz */ m->cpumhz = (cpufreq + cpufreq/200)/1000000; m->cpuhz = cpufreq; } i8253.hz = Freq< PIT_FREQ/(3*PIT_HZ)) break; } /* * figure out clock frequency and a loop multiplier for delay(). * n.b. counter goes up by 2*PIT_FREQ */ cpufreq = loops*((aalcycles*PIT_FREQ)/x); cpu.loopconst = (cpufreq/1000)/aalcycles; /* AAM+LOOP's for 1ms */ /* check aalcycle value */ if(kernel_option("cud") == 1) printf("cpuspeed: aalcycle MHz=%d\n", (cpufreq + cpufreq/200)/1000000); if(havecycleclock){ if(dx2 == dx1) b = (ax2-ax1); else /* counter wrap */ b = (ax2+0xffffffff-ax1); b /= x; b *= PIT_FREQ; /* * round to the nearest megahz */ cpu.cpumhz = (b+500000)/1000000L; cpu.cpuhz = b; } else { /* * add in possible 0.5% error and convert to MHz */ cpu.cpumhz = (cpufreq + cpufreq/200)/1000000; cpu.cpuhz = cpufreq; } } The thing is even more amusing since I heard someone saying plan9 is written from the ground up... ;) Hmm... It is possible too that Amoeba developer's have copied this code but I doubt it. Or maybe I'm missing something and the code comes from an other external source... (Don't forget these all are only hypotheses) If someone could explain this it would be great, since I would like to know the only real true (story) ;) Maks, ------=_NextPart_000_0007_01C2DAAF.795B8C50 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi everyone,

I recently have found an amusing thing between (FSD-)Amoeba and Plan9 :

The code for cpu = speed identification is the same ;)

 

Here I paste it. If you don't believe youre eyes = check out

/sys/src/9/pc/i8253.c in the plan9 system

/profile/module/amoeba/src/machdep/dev/ibm_at/timer/pit.c in the = FSD-Amoeba system

(the sys source must be installed of = course)

 

You can get FSD-Amoeba at fsd-amoeba.sourceforge.net it is the continuation = of

the original Amoeba project (www.cs.vu.nl/pub/amoeba) who has been = terminated

in 1996.

 

++++++ i8253.c the guesscpuhz function

void

guesscpuhz(int aalcycles)

{

      int cpufreq, loops, incr, x, y;

      uvlong a, b;

 

      /* find = biggest loop that doesn't wrap */

      incr =3D 16000000/(aalcycles*HZ*2);

      x =3D = 2000;

      for(loops =3D incr; loops < 64*1024; loops +=3D incr) {

      =

        = ;    /*

        = ;     *  measure time for the = loop

        = ;     *

        = ;     *        = ;        MOVL  loops,CX

        = ;     *    aaml1:           = AAM

        = ;     *        = ;        = LOOP  = aaml1

        = ;     *

        = ;     *  the time for the loop = should be independent of external

        = ;     *  cache and memory system = since it fits in the execution

        = ;     *  prefetch buffer.

        = ;     *

        = ;     */

        = ;    outb(Tmode, Latch0);

        = ;    if(m->havetsc)

        = ;          rdtsc(&a);

        = ;    x =3D inb(T0cntr);

        = ;    x |=3D inb(T0cntr)<<8;

        = ;    aamloop(loops);

        = ;    outb(Tmode, Latch0);

        = ;    if(m->havetsc)

        = ;          rdtsc(&b);

        = ;    y =3D inb(T0cntr);

        = ;    y |=3D inb(T0cntr)<<8;

        = ;    x -=3D y;

      =

        = ;    if(x < 0)

        = ;          x +=3D = Freq/HZ;

 

        = ;    if(x > Freq/(3*HZ))

        = ;          break;

      = }

 

      = /*

       *  figure out clock = frequency and a loop multiplier for delay().

       *  n.b. counter goes up by 2*Freq

       */

      cpufreq =3D loops*((aalcycles*2*Freq)/x);

      m->loopconst =3D (cpufreq/1000)/aalcycles;  /* AAM+LOOP's for 1 ms */

 

      if(m->havetsc){

 

        = ;    /* counter goes up by 2*Freq = */

        = ;    b =3D (b-a)<<1;

        = ;    b *=3D = Freq;

        = ;    b /=3D = x;

 

        = ;    /*

        = ;     *  round to the nearest = megahz

        = ;     */

        = ;    m->cpumhz =3D = (b+500000)/1000000L;

        = ;    m->cpuhz =3D b;

      } else = {

        = ;    /*

        = ;     *  add in possible 0.5% = error and convert to MHz

        = ;     */

        = ;    m->cpumhz =3D (cpufreq + cpufreq/200)/1000000;

        = ;    m->cpuhz =3D cpufreq;

      = }

 

      i8253.hz = =3D Freq<<Tickshift;

}

 

+++++ Amoeba's pit.c cpuspeed function

 

/* For cpu speed = measurement. We need timer access. */

 

void

cpuspeed(int aalcycles, int = havecycleclock)

{

        = int cpufreq, loops, incr, x, y;

        = unsigned long ax1,dx1,ax2,dx2,a,b;

 

        = pit_init();

 

        = /* find biggest loop that doesn't wrap */

        = incr =3D 16000000/(aalcycles*HZ*2);

        = x =3D 2000;

        = for(loops =3D incr; loops < 64*1024; loops +=3D incr) {

        =

       &nbs= p;        = /*

       &nbs= p;         *  measure time for the = loop

       &nbs= p;         *

       &nbs= p;         *       &nbs= p;            = ;    MOVL        = loops,CX

       &nbs= p;         *        = aaml1:       &nbs= p;         = AAM

       &nbs= p;         *       &nbs= p;            = ;    LOOP        = aaml1

       &nbs= p;         = *

       &nbs= p;         *  the time for the loop = should be independent of external

       &nbs= p;         *  cache and memory system = since it fits in the execution

       &nbs= p;         *  prefetch buffer.

       &nbs= p;         = *

       &nbs= p;         = */

 

       &nbs= p;        /* Beware of counter reset's (wraps)... = */

 

       &nbs= p;        /* Read the cpu internal clock if available = */

       &nbs= p;        if(havecycleclock)

       &nbs= p;            = ;    rdmsr(0x10, &ax1,&dx1);

       &nbs= p;        x =3D (int)pit_channel0();

 

       &nbs= p;        aamloop(loops);

 

       &nbs= p;        if(havecycleclock)

       &nbs= p;            = ;    rdmsr(0x10, &ax2,&dx2);

 

       &nbs= p;        y =3D (int)pit_channel0();

 

       &nbs= p;        x -=3D = y;

 

       &nbs= p;        if(x < 0)

       &nbs= p;            = ;    x +=3D = PIT_FREQ/PIT_HZ;

 

       &nbs= p;        if(x > PIT_FREQ/(3*PIT_HZ))

       &nbs= p;            = ;    break;

        = }

 

        = /*

       &nbs= p; *  figure out clock = frequency and a loop multiplier for delay().

       &nbs= p; *  n.b. counter goes up by 2*PIT_FREQ

       &nbs= p; */

        = cpufreq =3D loops*((aalcycles*PIT_FREQ)/x);

        = cpu.loopconst =3D (cpufreq/1000)/aalcycles; /* AAM+LOOP's for 1ms */

 

        = /* check aalcycle value */

        = if(kernel_option("cud") =3D=3D = 1)

       &nbs= p;        printf("cpuspeed: aalcycle MHz=3D%d\n",

       &nbs= p;            = ;    (cpufreq + = cpufreq/200)/1000000);

 

        = if(havecycleclock){

 

 

       &nbs= p;        if(dx2 =3D=3D dx1)

       &nbs= p;            = ;    b =3D (ax2-ax1);

       &nbs= p;        else        = /* counter wrap */

       &nbs= p;            = ;    b =3D (ax2+0xffffffff-ax1);

 

       &nbs= p;        b /=3D x;

       &nbs= p;        b *=3D PIT_FREQ;

 

 

       &nbs= p;        = /*

       &nbs= p;         *  round to the nearest = megahz

       &nbs= p;         = */

       &nbs= p;        cpu.cpumhz =3D (b+500000)/1000000L;

       &nbs= p;        cpu.cpuhz =3D b;

        = } else {

       &nbs= p;        = /*

       &nbs= p;         *  add in possible 0.5% = error and convert to MHz

       &nbs= p;         = */

       &nbs= p;        cpu.cpumhz =3D (cpufreq + = cpufreq/200)/1000000;

       &nbs= p;        cpu.cpuhz =3D cpufreq;

        = }

 

}

 

 

The thing is even more amusing since I heard someone saying plan9 is =

written from the ground up... ;)

 

Hmm... It is possible too that Amoeba developer's have copied this code but I = doubt it.

Or maybe I'm missing something and the code comes from an other external source...

(Don't forget these all are only hypotheses)

 

If someone could explain this it would be great, since I would like to know = the

only real true (story) ;)

 

Maks,

 

------=_NextPart_000_0007_01C2DAAF.795B8C50--