Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Hannu Mallat <hmallat@peak3.cs.hut.fi>
To: axp-list@redhat.com
Subject: Re: LX164 and rpcc
Date: Fri, 18 Dec 1998 15:02:05 +0200 (EET)	[thread overview]
Message-ID: <Pine.LNX.3.96.981218145230.21851A-100000@peak3.cs.hut.fi> (raw)
In-Reply-To: <19981217123625.G2290@zib.de>


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



  parent reply	other threads:[~1998-12-18 13:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-17 10:45 LX164 and rpcc Hannu Mallat
1998-12-17 11:36 ` Thorsten Koch
1998-12-17 14:58   ` Hannu Mallat
1998-12-18 13:02   ` Hannu Mallat [this message]
1998-12-18 16:53     ` Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
1998-12-24 17:53 Hannu Mallat
1998-12-26 18:50 ` Jay.Estabrook
1998-12-29 14:03   ` Hannu Mallat
read-only archive

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