Novell Home

How to use RDTSC with Watcom C C-plus-plus and CodeWarrior PDK

From Developer Community

This tiny sample demonstrates how to use RDTSC processor instruction with Watcom C/C++ and CodeWarrior PDK for NetWare. It tells you how many processor ticks a single call to ThreadSwitch() spends on your system; you can use this approach to profile other system calls or parts of your application.

Sample Code

#include <nwthread.h>
#include <stdio.h>
#include <stdlib.h>

#ifdef __WATCOMC__
unsigned __int64 rdtsc( void);
#pragma aux rdtsc = 0x0F 0x31 value [edx eax] parm nomemory modify exact [edx eax] nomemory;
#else /* CW PDK */
static unsigned __int64 rdtsc( void) {
   __asm rdtsc;
}
#endif
int main( void) {
   unsigned __int64 start = rdtsc();
   ThreadSwitch();
   printf( "stop - start = %u\n", rdtsc() - start);
   return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.