From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 15757 invoked from network); 17 Dec 1998 10:56:20 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 17 Dec 1998 10:56:20 -0000 Received: from peak3.cs.hut.fi (peak3.cs.hut.fi [130.233.192.128]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id FAA24007 for ; Thu, 17 Dec 1998 05:46:28 -0500 Received: from localhost (hmallat@localhost) by peak3.cs.hut.fi (8.8.7/8.8.5) with SMTP id MAA19430 for ; Thu, 17 Dec 1998 12:45:08 +0200 Date: Thu, 17 Dec 1998 12:45:07 +0200 (EET) From: Hannu Mallat To: axp-list@redhat.com Subject: LX164 and rpcc Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 #include #include #include 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