On Linux, you'll probably also need a 

    static {
        System.loadLibrary("nameofsofilethathascyclecounterdoto");
    }

in CycleCounter.java.

        - Godmar

> 
> > 
> > I've had similar problems measuring bandwidth. The greatest difficulty was the
> > limited resoution of the available timers. It's a darn shame that a high
> > resolution counter isn't available given all these fancy hardware. Milliseconds!
> > Pah! You can do an awful lot in a millisecond. Ever since the Pentium was
> > release there have been high resolution counters available - anyone written some
> > code to access them ? - back then it was all restricted access only! Does Intel
> > give a damn now ?
> > 
> 
>  Here you go.
> 
>       - Godmar
> 
> // ------------------------------------------------------------------------
> // CycleCounter.java
> package kaffeos.sys;
> 
> /**
>  * Give Java programs access to the cycle counter on Pentium PCs.
>  */
> public class CycleCounter
> {
>     /**
>      * read the current cycle counter
>      */
>     public static native long read();
> }
> 
> /* ------------------------------------------------------------------------
>   CycleCounter.c
>  */
> /*
>  * Read the 64-bit timestamp counter (TSC) register.
>  * Works only on Pentium and higher processors,
>  * and in user mode only if the TSD bit in CR4 is not set.
>  */
> #if defined(i386)
> #if HAVE_RDTSC
> #define get_tsc() \
>     ({ \
>         unsigned long low, high; \
>         asm volatile("rdtsc" : "=d" (high), "=a" (low)); \
>         ((unsigned long long)high << 32) | low; \
>     })
> #else
> #define get_tsc() \
>     ({ \
>         unsigned long low, high; \
>         asm volatile( \
>         ".byte 0x0f; .byte 0x31" \
>         : "=d" (high), "=a" (low)); \
>         ((unsigned long long)high << 32) | low; \
>     })
> #endif
> #else
> #define get_tsc() 0
> #endif
> 
> #include <jni.h>
> 
> jlong
> Java_kaffeos_sys_CycleCounter_read(JNIEnv *env, jclass counterclass)
> {
>     return (jlong)get_tsc();
> }
> ~
> 
> 
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
> 


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to