From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111c93,bac49ba29fd725c8 X-Google-Attributes: gid111c93,public From: Robert Harley Subject: Re: high resolution timer? Date: 1999/07/21 Message-ID: #1/1 X-Deja-AN: 503478919 Content-Transfer-Encoding: 8bit References: <37956EC0.F6ABC09B@ife.ee.ethz.ch> Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: usenet@inria.fr X-Trace: ites.inria.fr 932552266 23983 128.93.11.84 (21 Jul 1999 10:17:46 GMT) Organization: I.N.R.I.A Rocquencourt Mime-Version: 1.0 NNTP-Posting-Date: 21 Jul 1999 10:17:46 GMT Newsgroups: comp.os.linux.alpha Alex Rhomberg writes: > I'm looking for a way to profile my programs in detail. for this, I need > a register with at least microsecond resolution. A register that just > counts the cycles would be fine. There is a cycle-counter that you can read with the 'rpcc' instruction. The result is a 64-bit number. The low 32 bits count the actual cycles executed. The high 32 bits are an offset that is supposed to allow you to determine the cycles used by the current process. Unfortunately the offset seems to be bogus. Presumably the PAL code or kernel (or whatever is supposed to set it) doesn't do it right. To measure very short times, you can use the real cycle count and filter out the garbage from context switches: for instance measure five times and take the median. For longer times, use getrusage() and friends. NB: Beware that 32-bit cycle counters wrap around in a few seconds! Bye, Rob. #if defined(__GNUC__) && defined(__alpha) /* Cool! */ typedef unsigned u32; typedef unsigned long u64; /* Return the 64-bit process cycle counter. */ static inline u64 rpcc(void) { u64 cyc; asm volatile("rpcc %0" : "=r"(cyc) :: "memory"); return cyc; } /* end rpcc */ /* Return the real cycle count. */ static inline u32 realcc(void) { u64 cyc; asm volatile("rpcc %0" : "=r"(cyc) :: "memory"); return (u32)cyc; } /* end realcc */ /* Return the virtual cycle count, using the process offset. */ static inline u32 virtcc(void) { u64 cyc; asm volatile("rpcc %0" : "=r"(cyc) :: "memory"); return (u32)(cyc+(cyc>>32)); } /* end virtcc */ #else #error Too bad, dude. #end