Created
December 7, 2012 14:28
Counting the CPU cycles of a function/procedure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////////////////////// | |
static u_int64_t start = 0; | |
void access_counter(unsigned* hi, unsigned* low); | |
void start_counter() | |
{ | |
unsigned hi, lo; | |
access_counter(&hi, &lo); | |
start = ((u_int64_t)hi << 32) | lo; | |
} | |
u_int64_t get_counter() | |
{ | |
unsigned ncyc_hi, ncyc_lo; | |
access_counter(&ncyc_hi, &ncyc_lo); | |
return | |
(((u_int64_t)ncyc_hi << 32) | ncyc_lo) - start; | |
} | |
void access_counter(unsigned *hi, unsigned *lo) | |
{ | |
asm volatile | |
("rdtsc; movl %%edx, %0; movl %%eax, %1" /* Format string */ | |
: "=r" (*hi), "=r" (*lo) /* Output list */ | |
: /* No input */ | |
: "%edx", "%eax"); /* Clobber list */ | |
} | |
///////////////////////////////////////////////////////////////////////// | |
So, the sequence is | |
start_counter() ; | |
// call your function or procedure | |
get_counter(); // to get the number of cycles consumed by pour code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi i want to implement an algorithm in cloudsim which works like this
Scenerio : Three VMs with different specs
Tasks/Cloudlets : 10 task/cloudlets
step 1: algorithm first check for available/independent tasks/cloudelts in a DAG (Directed Acyclic Graph)
step 2: algorithm does a computation on given size of cloudlets and decides which task is to be run on which VM
step 3: algorithm run the selected cloudlet on selecte vm
step 4: checks if any new independent cloudlet is available are not
if available it adds it to the list of independent task and does required computation for it
step 5: step 2 till all the cloudlets are executed
Kindly guide me how to do that