Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* LX164 and rpcc
@ 1998-12-17 10:45 Hannu Mallat
  1998-12-17 11:36 ` Thorsten Koch
  0 siblings, 1 reply; 8+ messages in thread
From: Hannu Mallat @ 1998-12-17 10:45 UTC (permalink / raw)
  To: axp-list


Hi all,

I'm working on a executable instrumentation toolkit for my thesis, and
ran on the following problem: I'm trying to measure execution times
using the procedure cycle counter, obtaining the 64-bit counter value
by rpcc and adding the high 32 bits to the low 32 bits, as mentioned
in David Mosberger's Linux Expo '97 paper. For the most part, I'm
getting reasonable values; however, sometimes the pcc is _smaller_
after the routine than before (and no, it did not have time to wrap
around). 

I'm doing my measurements on a 533 MHz LX164, with 2.0.35 kernel and
the latest MILO. Below is a small program that illustrates the problem.
I've run it on the equipment mentioned above and on another Alpha with
v4.0 of OSF/1 on it (I believe it's a DEC AlphaServer 2100 5/300), where
the problem does not reproduce. 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

static inline unsigned long cc64 (void) {
  unsigned long cc;
  asm volatile("rpcc %0" : "=r"(cc) : : "memory");
  return cc;
}

int main(int argc, char* argv[]) {
  char *buf = NULL;
  int i;
  unsigned long c1, c2;
  unsigned int i1, i2;
  unsigned int buf_len = 0;

  buf_len = atoi(argv[1]);
  buf = malloc(buf_len);
  if(!buf)
    abort();

  for(i = 0; i < buf_len; i++)
    buf[i] = i % 256;

  for(i = 0; i < 10; i++) {
    FILE* f = fopen("foo.bar", "w+");
    if(!f) {
      fprintf(stderr, "Argh! %s\n", strerror(errno));
      exit(1);
    }
    fwrite(buf, buf_len, 1, f);
    c1 = cc64();
    fclose(f);
    c2 = cc64();

    i1 = ((c1 >> 32ULL) & 0xffffffff) + (c1 & 0xffffffff); 
    i2 = ((c2 >> 32ULL) & 0xffffffff) + (c2 & 0xffffffff); 

    fprintf(stdout, 
            "%08x %08x ... %08x %08x : %08x ... %08x : %08x\n",
            (unsigned int)(c1 >> 32), 
            (unsigned int)(c1 & 0xffffffff), 
            (unsigned int)(c2 >> 32), 
            (unsigned int)(c2 & 0xffffffff), 
            i1, i2, i2 - i1);
  }

  exit(0);
}

Here's the interesting part: if I write < 1024 bytes, the results are OK,
if more, things fail. Sample logs:

[peak9:src] ./rpcc 1024
14606d55 11f0bc9f ... 145fe353 11f13abe : 265129f4 ... 26511e11 : fffff41d
144f0f79 12054dc5 ... 144ed043 1205788d : 26545d3e ... 265448d0 : ffffeb92
1442d48e 1213addc ... 1442980f 1213d920 : 2656826a ... 2656712f : ffffeec5
1436ac67 1221d69a ... 14366da5 122200c1 : 26588301 ... 26586e66 : ffffeb65
142a75c8 12301401 ... 142a36e8 12304089 : 265a89c9 ... 265a7771 : ffffeda8
141dc20c 123ec09d ... 141d8569 123eead3 : 265c82a9 ... 265c703c : ffffed93
14118ad9 124cf05f ... 14114f92 124d1ab8 : 265e7b38 ... 265e6a4a : ffffef12
140264a2 125e4fa1 ... 140225bf 125e79f0 : 2660b443 ... 26609faf : ffffeb6c
1374a167 12ee12f3 ... 1374625f 12ee3e1d : 2662b45a ... 2662a07c : ffffec22
136735d4 12fd79c2 ... 1366f850 12fda411 : 2664af96 ... 26649c61 : ffffeccb
[peak9:src] ./rpcc 1023
cd9c9425 58b55ec6 ... cd97179a 58bb9575 : 2651f2eb ... 2652ad0f : 0000ba24
cd8fc1c5 58c5ae29 ... cd8a9120 58cb4b35 : 26556fee ... 2655dc55 : 00006c67
cd836c28 58d43aee ... cd7e49b1 58d9c72f : 2657a716 ... 265810e0 : 000069ca
cd772481 58e2af2b ... cd720390 58e83b6e : 2659d3ac ... 265a3efe : 00006b52
cd6ac300 58f14ef5 ... cd659865 58f6e2f2 : 265c11f5 ... 265c7b57 : 00006962
cd5e7eb7 58ffbbf2 ... cd595c9a 59054386 : 265e3aa9 ... 265ea020 : 00006577
cd523212 590e33a4 ... cd4d0dd9 5913bf1a : 266065b6 ... 2660ccf3 : 0000673d
cd42f040 591fc57e ... cd3d7171 5925b348 : 2662b5be ... 266324b9 : 00006efb
ccb4c72b 59b01d70 ... ccaf770b 59b5da3d : 2664e49b ... 26655148 : 00006cad
cca74054 59bfea07 ... cca218bf 59c57d0d : 26672a5b ... 266795cc : 00006b71

Perhaps I'm just blind to some obviousity, but I really don't know what
at the moment. I haven't had the energy to look properly inside the lx164
palcode yet (afaik the palcode is responsible for the high 32 bits, right?)
but I'd be surprised if the bug was there and no one found it yet.

Hannu




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: LX164 and rpcc
  1998-12-17 10:45 Hannu Mallat
@ 1998-12-17 11:36 ` Thorsten Koch
  1998-12-17 14:58   ` Hannu Mallat
  1998-12-18 13:02   ` Hannu Mallat
  0 siblings, 2 replies; 8+ messages in thread
From: Thorsten Koch @ 1998-12-17 11:36 UTC (permalink / raw)
  To: axp-list

Hello Hannu,

On my 21164A/533-UX/2 with RH 5.1 I get 
 
[/tmp]$ cc -O6 -mcpu=21164 -g xx.c
[/tmp]$ ./a.out 1
ba2bd5dc 087e7a40 ... ba12b532 087f89f7 : c2aa501c ... c2923f29 : ffe7ef0d
ba076f90 088d7a66 ... ba05eed5 088ded8c : c294e9f6 ... c293dc61 : fffef26b
b9f6e939 089e9848 ... b9f5af05 089f0ed1 : c2958181 ... c294bdd6 : ffff3c55
b9ebb977 08aab406 ... b9ea7a1e 08ab2926 : c2966d7d ... c295a344 : ffff35c7
b9e0b08b 08b69955 ... b9df709a 08b71287 : c29749e0 ... c2968321 : ffff3941
b9d5b612 08c29f17 ... b9d44e1e 08c31848 : c2985529 ... c2976666 : ffff113d
b9ca8ae0 08ce9d91 ... b9c9389c 08cf1828 : c2992871 ... c29850c4 : ffff2853
b9bf76ca 08da81dc ... b9be363b 08dafbfc : c299f8a6 ... c2993237 : ffff3991
b9b47a08 08e65a36 ... b9b33e54 08e6d4d5 : c29ad43e ... c29a1329 : ffff3eeb
b9a99cef 08f21b7f ... b9a85f49 08f29404 : c29bb86e ... c29af34d : ffff3adf

           ^                      ^
           |                      |
          this is allways smaller than
          as it should be.

This doesn't change much with the argument. it's allways ffxxxxxx in the
last column.
The question is if the correction value works correct with
system calls.

Regards,
Thorsten
-- 
"They that can give up essential liberty to obtain a little temporary
saftey deserve neither liberty not saftey."
-- Benjamin Franklin, 1759


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: LX164 and rpcc
  1998-12-17 11:36 ` Thorsten Koch
@ 1998-12-17 14:58   ` Hannu Mallat
  1998-12-18 13:02   ` Hannu Mallat
  1 sibling, 0 replies; 8+ messages in thread
From: Hannu Mallat @ 1998-12-17 14:58 UTC (permalink / raw)
  To: axp-list


On Thu, 17 Dec 1998, Thorsten Koch wrote:

> On my 21164A/533-UX/2 with RH 5.1 I get 
>  
> [/tmp]$ cc -O6 -mcpu=21164 -g xx.c
> [/tmp]$ ./a.out 1
	[ ... snip snip ... ]
> b9a99cef 08f21b7f ... b9a85f49 08f29404 : c29bb86e ... c29af34d : ffff3adf
> 
> This doesn't change much with the argument. it's allways ffxxxxxx in the
> last column.

After posting, I realized that if the file is on an NFS mount, the  
'1k effect' takes place, otherwise not, and I get ff...... counts, too,
with any argument when on a device directly hooked to the machine. 

> The question is if the correction value works correct with
> system calls.

I've instrumented about every libc I/O routine used by cpp, cc1, as and ld
in my test runs; fclose is the only routine that gives me a headache.
e.g. doing a write() and a close() instead of fwrite() and fclose() works  
nicely and produces decent numbers. I haven't yet looked into libc sources 
to see if some particular syscall fclose uses causes the odd behaviour. 

Hannu



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: LX164 and rpcc
  1998-12-17 11:36 ` Thorsten Koch
  1998-12-17 14:58   ` Hannu Mallat
@ 1998-12-18 13:02   ` Hannu Mallat
  1998-12-18 16:53     ` Richard Henderson
  1 sibling, 1 reply; 8+ messages in thread
From: Hannu Mallat @ 1998-12-18 13:02 UTC (permalink / raw)
  To: axp-list


Sorry for the continued C source spam on the list ;-), but I've managed
to track my problem down a bit further. I was stracing the little example
program I posted earlier and found out that a munmap() call done by the
stdio lib freaks out the process cycle counter. Here's another sample
program that demonstrates what happens:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>

static inline unsigned long cc64 (void) {
  unsigned long cc;
  asm volatile("rpcc %0" : "=r"(cc) : : "memory");
  return cc;
}

int main(int argc, char* argv[]) {
  int i;
  unsigned long c1, c2;
  unsigned int i1, i2;

  for(i = 0; i < 10; i++) {
    char* stuff;
    struct stat buf;
    int mfd;

    mfd = open("/vmlinux.gz" /* or something ... */, O_RDONLY);
    fstat(mfd, &buf);
    stuff = mmap(0, buf.st_size, 
		 PROT_READ,
		 MAP_PRIVATE, mfd, 0);
    c1 = cc64();
    munmap(stuff, buf.st_size);
    c2 = cc64();
    close(mfd);

    i1 = ((c1 >> 32ULL) & 0xffffffff) + (c1 & 0xffffffff); 
    i2 = ((c2 >> 32ULL) & 0xffffffff) + (c2 & 0xffffffff); 

    fprintf(stdout, 
            "%08x %08x ... %08x %08x : %08x\n",
            (unsigned int)(c1 >> 32), 
            (unsigned int)(c1 & 0xffffffff), 
            (unsigned int)(c2 >> 32), 
            (unsigned int)(c2 & 0xffffffff), 
            i2 - i1);
  }

  exit(0);
}

Any kernel hackers out there? What's going on? Again, the sample program
works fine on the OSF/1 machine I have access to. 

Hannu



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: LX164 and rpcc
  1998-12-18 13:02   ` Hannu Mallat
@ 1998-12-18 16:53     ` Richard Henderson
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 1998-12-18 16:53 UTC (permalink / raw)
  To: axp-list

On Fri, Dec 18, 1998 at 03:02:05PM +0200, Hannu Mallat wrote:
> Any kernel hackers out there? What's going on? Again, the sample program
> works fine on the OSF/1 machine I have access to. 

I think there's a bug in the PALcode, in that it doesn't 
properly handle the CC when swapping to the same context,
which we do when we need to change page table mappings.

If you're adventurous, you might try something like this:

        stq_p   t10, PCB_Q_USP(v0)      // Store user stack pointer
        addl    p5, p7, p7              // Set new time

+	cmpeq	v0, a0, t10		// Are old and new contexts equal?
+	cmoveq	t10, p7, p5		// If not, set new time.

-       stl_p   p7, PCB_L_PCC(v0)       // Store new time
+       stl_p   p5, PCB_L_PCC(v0)       // Store new time
        bis     zero, 1, t10            // Get a '1'

        sll     t10, ICSR_V_FPE, t10    // Shift '1' into ICSR<FPE> position
        mfpr    p7, icsr                // Get current ICSR value


Grr, actually, that won't work as-is cause we've run out of room
in the SwpCtx block.  More code would have to go out of line.
But that's the problem. 

Alternately, you could try

Index: mmu_context.h
===================================================================
RCS file: /home/rth/CVSROOT/linux/include/asm-alpha/mmu_context.h,v
retrieving revision 1.7
diff -u -p -r1.7 mmu_context.h
--- mmu_context.h       1998/09/06 06:45:25     1.7
+++ mmu_context.h       1998/12/18 16:51:25
@@ -169,7 +169,9 @@ __reload_tss(struct thread_struct *tss)
 __EXTERN_INLINE void
 reload_context(struct task_struct *task)
 {
+       int pcc = task->tss.pcc;
        __reload_tss(&task->tss);
+       task->tss.pcc = pcc;
 }
 
 /*




r~


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: LX164 and rpcc
@ 1998-12-24 17:53 Hannu Mallat
  1998-12-26 18:50 ` Jay.Estabrook
  0 siblings, 1 reply; 8+ messages in thread
From: Hannu Mallat @ 1998-12-24 17:53 UTC (permalink / raw)
  To: axp-list


Richard Henderson wrote:

> If you're adventurous, you might try something like this:
> 
>         stq_p   t10, PCB_Q_USP(v0)      // Store user stack pointer
>         addl    p5, p7, p7              // Set new time

Unfortunately, I'm having loads of trouble getting a decent, working MILO
compiled, with or without the patched palcode. The furthest I got was to
produce an image that hung up on boot. Is there any special wizardry that
needs to be invoked? (requirements for a specific egcs version, etc? I'm
running RH 5.2, the 2.0.35-0.2 kernel from gatekeeper and trying to
compile the corresponding milo sources)

In any case, happy holidays!

Hannu



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: LX164 and rpcc
  1998-12-24 17:53 LX164 and rpcc Hannu Mallat
@ 1998-12-26 18:50 ` Jay.Estabrook
  1998-12-29 14:03   ` Hannu Mallat
  0 siblings, 1 reply; 8+ messages in thread
From: Jay.Estabrook @ 1998-12-26 18:50 UTC (permalink / raw)
  To: axp-list


>>> Hannu Mallat said:
> 
> Unfortunately, I'm having loads of trouble getting a decent, working MILO
> compiled, with or without the patched palcode. The furthest I got was to
> produce an image that hung up on boot. Is there any special wizardry that
> needs to be invoked? (requirements for a specific egcs version, etc? I'm
> running RH 5.2, the 2.0.35-0.2 kernel from gatekeeper and trying to
> compile the corresponding milo sources)

One can successfully build/link MILO *ONLY* under RH 4.2, unless you want
to use the free x86 BIOS emulator (not recommended for most VGA cards).

The DEC BIOS emulator is written in C++ and is the cause of this limitation.
The current binary of it was compiled under RH 4.2, and it seems to have some
problem when linked under any later release. When compiled under a RH 5.2
beta, it built and linked fine, but when executed caused my monitor to shut
itself off, indicating (to me) that the emulation was flawed in some way.
I haven't (yet) had the time to revisit this.

Sorry.

--Jay++

-------------------------------------------------------------------------------
  American Non Sequitur Society: we don't make sense, but we do like pizza...

Jay A Estabrook                            Alpha Motherboards - LINUX Project
Compaq Computer Corporation                (508) 841-3241 or (DTN) 237-3241
334 South Street, Shrewsbury, MA 01545     Jay.Estabrook@digital.com
-------------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: LX164 and rpcc
  1998-12-26 18:50 ` Jay.Estabrook
@ 1998-12-29 14:03   ` Hannu Mallat
  0 siblings, 0 replies; 8+ messages in thread
From: Hannu Mallat @ 1998-12-29 14:03 UTC (permalink / raw)
  To: axp-list


On Sat, 26 Dec 1998 Jay.Estabrook@digital.com wrote:

> One can successfully build/link MILO *ONLY* under RH 4.2, unless you want
> to use the free x86 BIOS emulator (not recommended for most VGA cards).

Ok, I threw in RH 4.2 on another partition and got a working milo. I
managed to get reasonable-looking PCC values even after a munmap() by
modifying palcode/lx164/osfpal.S as follows:

[root@peak9 lx164]# diff -c osfpal.S.old osfpal.S
*** osfpal.S.old        Wed Dec 28 17:46:35 2078
--- osfpal.S    Tue Dec 29 14:09:18 1998
***************
*** 2042,2048 ****
        mfpr    v0, ptPcbb              // Get current PCBB
  
        ldq_p   t8, PCB_Q_FEN(a0)       // Get new FEN
-       ldq_p   t9, PCB_L_PCC(a0)       // Get new ASN 
  
        srl     p5, 32, p7              // Move CC<OFFSET> to low longword
        mfpr    t10, ptUsp              // Get the user stack pointer
--- 2042,2047 ----
***************
*** 2064,2069 ****
--- 2063,2069 ----
        mfpr    p7, icsr                // Get current ICSR value
  
        and     t8, 1, t8               // Clean new FEN value to single bit
+       sll     t8, ICSR_V_FPE, t8      // Shift new FEN into position
        br      zero, CallPal_SwpCtxCont
  

  /*
***************
*** 3402,3410 ****
        ALIGN_BLOCK
  
  CallPal_SwpCtxCont:
-       sll     t8, ICSR_V_FPE, t8      // Shift new FEN into position
        bic     p7, t10, p7             // Clean ISR<FPE> 
  
        srl     t9, 32, t10             // Move ASN to low longword
        ldq_p   p6, PCB_Q_PTBR(a0)      // Get the new page table base
  
--- 3402,3410 ----
        ALIGN_BLOCK
  
  CallPal_SwpCtxCont:
        bic     p7, t10, p7             // Clean ISR<FPE> 
  
+       ldq_p   t9, PCB_L_PCC(a0)       // Get new ASN 
        srl     t9, 32, t10             // Move ASN to low longword
        ldq_p   p6, PCB_Q_PTBR(a0)      // Get the new page table base
  
I suppose there were some instruction scheduling issues that decided
the original placing of ldq_p t9, but I wouldn't know anything about 
that, so I just placed it near the point of use.

I haven't yet properly validated the PCC values after my patch: they seem 
to be in the right order of magnitude ;-)

Hannu



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~1998-12-29 14:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-12-24 17:53 LX164 and rpcc Hannu Mallat
1998-12-26 18:50 ` Jay.Estabrook
1998-12-29 14:03   ` Hannu Mallat
  -- strict thread matches above, loose matches on Subject: below --
1998-12-17 10:45 Hannu Mallat
1998-12-17 11:36 ` Thorsten Koch
1998-12-17 14:58   ` Hannu Mallat
1998-12-18 13:02   ` Hannu Mallat
1998-12-18 16:53     ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox