How to rdtsc ? [SOLVED]

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
SpiceGuid
Posts: 20
Joined: Thu 20 Mar 2008, 15:45

How to rdtsc ? [SOLVED]

#1 Post by SpiceGuid »

:arrow: Racy Puppy Linux 5.3 is such a great programming eco-system that i am instantly converted from Windows XP-pro SP3 8)

:arrow: Among other things i love with computers is HPC (High Performance Computing)

:arrow: One achievement i am proud of (found saturday 5 november 2005) :

Image

These are 11 levels Absolute Difference triangles 8)

:arrow: For HPC purpose high precision benchmark is a must have. On windows i have always used printtsc so my benchmarks have cpu-clock accuracy. Because at this performance level almost no cpu-cycle can be wasted.

:arrow: So one thing i miss is TSC :(

:arrow: However i am sure this lack can be eliminated because you will cool guys at murga-linux 8)

:idea: Of course if you provide me a TSC console command then i will reward you with more amazing Absolute Difference triangles.
Last edited by SpiceGuid on Mon 18 Feb 2013, 02:15, edited 2 times in total.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#2 Post by amigo »

You can time the execution of commands very easily using the program called (what else?) 'time'.
From the command line simply type:
time command-here

User avatar
SpiceGuid
Posts: 20
Joined: Thu 20 Mar 2008, 15:45

#3 Post by SpiceGuid »

Ok, thanks to you.

Unfortunately the story is not over :
:arrow: It seems to me you overlook the HPC problems.
:arrow: The time is a MHz-dependant information. Moreover cpu frequency can scale up or down. So time is just an inaccurate performance measurement.
:arrow: The TSC is a MHz-independant information.
:arrow: More importantly, i have a need to access clock information while the program is progressing, not only when it is terminated. The motivation is the program is so loooooooong hence it displays certain progress information. The time when a certain computation step occurs really matters.
:arrow: I need to know if the program will terminate after the sun explodes or before i turn 50 :wink: It makes a huge difference, isn't it ? The time command will not tell me that information. Or it will tell it long after i am died :roll:

Conclusion : i still have a need to display the cpu TSC.

Edit: i finally wrote the code myself, just have to test it

Code: Select all

// gcc -o rdtsc rdtsc.c 
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

static __inline__ uint64_t rdtsc(void)
{
   uint32_t a, d;
   asm("cpuid");
   asm volatile("rdtsc" : "=a" (a), "=d" (d));
   return (((uint64_t)a) | (((uint64_t)d) << 32));
}

int main()
{
   uint64_t clock;
   clock = rdtsc();
   printf("%llu\n",clock);
   return 0;
}

Post Reply