Sponsored Content
Full Discussion: RDTSC use in C:
Top Forums Programming RDTSC use in C: Post 302237580 by GloriousDaisy on Thursday 18th of September 2008 12:58:16 AM
Old 09-18-2008
RDTSC use in C:

I have to use rdtsc on ubuntu for performance evaluation. But i am not getting the correct value. I am placing a sleep on 10 seconds, but value i get is some 1 sec... i dont know where im going wrong?

Code:
#include<sys/time.h>
#include<time.h>
#include<stdio.h>
typedef unsigned long long ticks;

static __inline__ ticks getticks(void)
{
     unsigned a, d;
     asm("cpuid");
     asm volatile("rdtsc" : "=a" (a), "=d" (d));

     return (((ticks)a) | (((ticks)d) << 32));
}
int main(){
     int r = 0;
     ticks tick,tick1,tickh;
     unsigned time =0;

     tick = getticks();
   
     sleep(10);
   
     tick1 = getticks();
   
     time = (unsigned)((tick1-tick)/1662543);
    printf("\ntime in MS%u\n",time);
return 0;
}

cat /proc/cpuinfo gives
Code:
pprocessor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 14
model name      : Genuine Intel(R) CPU           T2300  @ 1.66GHz
stepping        : 8
cpu MHz         : 1662.543
cache size      : 2048 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 10
wp              : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat clflush dts acpi mmx fxsr sse sse2 ss tm pbe constant_tsc up arch_perfmon bts pni monitor vmx est tm2 xtpr
bogomips        : 3328.87
clflush size    : 64


Last edited by vino; 09-18-2008 at 03:45 AM.. Reason: added code tags
 
drv_usectohz(9F)					   Kernel Functions for Drivers 					  drv_usectohz(9F)

NAME
drv_usectohz - convert microseconds to clock ticks SYNOPSIS
#include <sys/types.h> #include <sys/ddi.h> clock_t drv_usectohz(clock_t microsecs); INTERFACE LEVEL
Architecture independent level 1 (DDI/DKI). PARAMETERS
microsecs The number of microseconds to convert. DESCRIPTION
drv_usectohz() converts a length of time expressed in microseconds to a number of system clock ticks. The time arguments to timeout(9F) and delay(9F) are expressed in clock ticks. drv_usectohz() is a portable interface for drivers to make calls to timeout(9F) and delay(9F) and remain binary compatible should the driver object file be used on a system with a different clock speed (a different number of ticks in a second). RETURN VALUES
The value returned is the number of system clock ticks equivalent to the microsecs argument. No error value is returned. If the clock tick equivalent to microsecs is too large to be represented as a clock_t, then the maximum clock_t value will be returned. CONTEXT
drv_usectohz() can be called from user or interrupt context. SEE ALSO
delay(9F), drv_hztousec(9F), timeout(9F) Writing Device Drivers SunOS 5.10 12 Nov 1992 drv_usectohz(9F)
All times are GMT -4. The time now is 05:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy