# uname -a Linux dcm 2.6.10-mV01-00-13 #1 Wed Dec 20 01:43:38 CET 2006 ppc GNU/Linux Source code: # cat /home/test/clockcycles/clockcycles.cpp #include <cassert> #include <iostream> #include <stdint.h> uint64_t GetCPU_ClockCyclesSinceStartup(void) { #if defined(__i386__) || defined(__x86_64) uint32_t uTimerValueHigh; uint32_t uTimerValueLow; __asm__ __volatile__("rdtsc;" "movl %%edx, %0;" "movl %%eax, %1" : "=r" (uTimerValueHigh), "=r" (uTimerValueLow) : : "%edx", "%eax" ); return (((uint64_t)(uTimerValueHigh) << 32) | uTimerValueLow); #elif defined(__PPC__) uint32_t uTimeBaseLow; uint32_t uTimeBaseHigh; uint32_t uCheck; __asm__ __volatile__("1: mftbu %0;" " mftb %1;" " mftbu %2;" " cmpw %2, %0;" " bne 1b" : "=r" (uTimeBaseHigh), "=r" (uTimeBaseLow), "=r" (uCheck)); return (((uint64_t)(uTimeBaseHigh) << 32) | uTimeBaseLow); #else assert(0); return 0; #endif } int main(int /*argc*/, char** /*argv*/) { std::cout << "Clock cycles since boot: " << GetCPU_ClockCyclesSinceStartup() << std::endl; return 0; } // Local variables: // compile-command: "for c in ppc_440-g++ g++; do echo $c ...; $c -Wall -W -g clockcycles.cpp -o ${c%g++}clockcycles; done" // End: Full output: # vg -v /home/test/clockcycles/ppc_440-clockcycles ==16359== Memcheck, a memory error detector. ==16359== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al. ==16359== Using LibVEX rev 1658, a library for dynamic binary translation. ==16359== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP. ==16359== Using valgrind-3.2.1, a dynamic binary instrumentation framework. ==16359== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al. ==16359== --16359-- Command line --16359-- /home/test/clockcycles/ppc_440-clockcycles --16359-- Startup, with flags: --16359-- --num-callers=32 --16359-- --error-limit=no --16359-- --suppressions=/app/bin/dcm-suppressions.txt --16359-- -v --16359-- Contents of /proc/version: --16359-- Linux version 2.6.10-mV01-00-13 (build@sabekorlnx03) (gcc version 3.4.3 (MontaVista 3.4.3-25.0.107.0601076 2006-07-21)) #1 Wed Dec 20 01:43:38 CET 2006 --16359-- Arch and hwcaps: PPC32, ppc32-int --16359-- Valgrind library directory: /mnt/usr/lib/valgrind --16359-- Reading syms from /lib/ld-2.3.3.so (0x4000000) --16359-- Reading syms from /home/test/clockcycles/ppc_440-clockcycles (0x10000000) --16359-- Reading syms from /mnt/usr/lib/valgrind/ppc32-linux/memcheck (0x38000000) --16359-- object doesn't have a dynamic symbol table --16359-- Reading suppressions file: /app/bin/dcm-suppressions.txt --16359-- Reading suppressions file: /mnt/usr/lib/valgrind/default.supp --16359-- REDIR: 0x4012A20 (strlen) redirected to 0x3802F8C0 (vgPlain_ppc32_linux_REDIR_FOR_strlen) --16359-- REDIR: 0x4012850 (strcmp) redirected to 0x3802F8E8 (vgPlain_ppc32_linux_REDIR_FOR_strcmp) --16359-- REDIR: 0x4012778 (index) redirected to 0x3802F95C (vgPlain_ppc32_linux_REDIR_FOR_strchr) --16359-- Reading syms from /mnt/usr/lib/valgrind/ppc32-linux/vgpreload_core.so (0xFFDF000) --16359-- Reading syms from /mnt/usr/lib/valgrind/ppc32-linux/vgpreload_memcheck.so (0xFFB9000) --16359-- REDIR: 0x40137A0 (memcpy) redirected to 0xFFBD6C4 (memcpy) --16359-- Reading syms from /usr/lib/libstdc++.so.6.0.3 (0xFEB3000) --16359-- object doesn't have a symbol table --16359-- Reading syms from /lib/libm-2.3.3.so (0xFDE7000) --16359-- object doesn't have a symbol table --16359-- Reading syms from /lib/libgcc_s.so.1 (0xFDBA000) --16359-- object doesn't have a symbol table --16359-- Reading syms from /lib/libc-2.3.3.so (0xFC6E000) --16359-- object doesn't have a symbol table --16359-- REDIR: 0xFCE2B08 (rindex) redirected to 0xFFBC9E0 (rindex) --16359-- REDIR: 0xFCE2664 (strlen) redirected to 0xFFBCF58 (strlen) --16359-- REDIR: 0xFCE28E0 (strncmp) redirected to 0xFFBD2AC (strncmp) --16359-- REDIR: 0xFCE2040 (strcpy) redirected to 0xFFBD00C (strcpy) --16359-- REDIR: 0xFCE38A4 (memset) redirected to 0xFFBDD24 (memset) --16359-- REDIR: 0xFCE33E4 (bcmp) redirected to 0xFFBD908 (bcmp) dis_proc_ctl(ppc)(mfspr,SPR)(0x10D) disInstr(ppc): unhandled instruction: 0x7C0D42A6 primary 31(0x1F), secondary 678(0x2A6) ==16359== valgrind: Unrecognised instruction at address 0x100008F4. ==16359== Your program just tried to execute an instruction that Valgrind ==16359== did not recognise. There are two possible reasons for this. ==16359== 1. Your program has a bug and erroneously jumped to a non-code ==16359== location. If you are running Memcheck and you just saw a ==16359== warning about a bad jump, it's probably your program's fault. ==16359== 2. The instruction is legitimate but Valgrind doesn't handle it, ==16359== i.e. it's Valgrind's fault. If you think this is the case or ==16359== you are not sure, please let us know and we'll try to fix it. ==16359== Either way, Valgrind will now raise a SIGILL signal which will ==16359== probably kill your program. ==16359== ==16359== Process terminating with default action of signal 4 (SIGILL) ==16359== Illegal opcode at address 0x100008F4 ==16359== at 0x100008F4: GetCPU_ClockCyclesSinceStartup() (clockcycles.cpp:30) ==16359== by 0x100009CC: main (clockcycles.cpp:40) Clock cycles since boot: --16359-- REDIR: 0xFCDEB54 (free) redirected to 0xFFBB634 (free) ==16359== ==16359== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 7 from 3) --16359-- --16359-- supp: 2 Ubuntu-stripped-ld.so --16359-- supp: 1 glibc-2.3.x-on-SuSE-10.1-(PPC)-1 --16359-- supp: 4 glibc-2.3.x-on-SuSE-10.0-(PPC)-1 ==16359== malloc/free: in use at exit: 0 bytes in 0 blocks. ==16359== malloc/free: 0 allocs, 0 frees, 0 bytes allocated. ==16359== ==16359== All heap blocks were freed -- no leaks are possible. --16359-- memcheck: sanity checks: 4 cheap, 1 expensive --16359-- memcheck: auxmaps: 0 auxmap entries (0k, 0M) in use --16359-- memcheck: auxmaps: 0 searches, 0 comparisons --16359-- memcheck: SMs: n_issued = 17 (272k, 0M) --16359-- memcheck: SMs: n_deissued = 0 (0k, 0M) --16359-- memcheck: SMs: max_noaccess = 65535 (1048560k, 1023M) --16359-- memcheck: SMs: max_undefined = 0 (0k, 0M) --16359-- memcheck: SMs: max_defined = 47 (752k, 0M) --16359-- memcheck: SMs: max_non_DSM = 17 (272k, 0M) --16359-- memcheck: max sec V bit nodes: 0 (0k, 0M) --16359-- memcheck: set_sec_vbits8 calls: 0 (new: 0, updates: 0) --16359-- memcheck: max shadow mem size: 576k, 0M --16359-- translate: fast SP updates identified: 466 ( 72.1%) --16359-- translate: generic_known SP updates identified: 141 ( 21.8%) --16359-- translate: generic_unknown SP updates identified: 39 ( 6.0%) --16359-- tt/tc: 9,242 tt lookups requiring 9,311 probes --16359-- tt/tc: 9,242 fast-cache updates, 63 flushes --16359-- transtab: new 2,078 (65,564 -> 1,023,084; ratio 156:10) [0 scs] --16359-- transtab: dumped 0 (0 -> ??) --16359-- transtab: discarded 82 (3,884 -> ??) --16359-- scheduler: 494,548 jumps (bb entries). --16359-- scheduler: 4/7,504 major/minor sched events. --16359-- sanity: 5 cheap, 1 expensive checks. --16359-- exectx: 30,011 lists, 5 contexts (avg 0 per list) --16359-- exectx: 7 searches, 2 full compares (285 per 1000) --16359-- exectx: 0 cmp2, 14 cmp4, 0 cmpAll /usr/sbin/vg: line 20: 16359 Illegal instruction GLIBCPP_FORCE_NEW=1 GLIBCXX_FORCE_NEW=1 DISABLE_PLAYOUT=1 $EXE --num-callers=32 --error-limit=no $SUPPRESS "${@:-/app/bin/$APP}"
Fixed. vex r1705 (trunk), r1706 (3_2_BRANCH).