Skip to content

Instantly share code, notes, and snippets.

@alessandroleite
Created December 7, 2012 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alessandroleite/4233584 to your computer and use it in GitHub Desktop.
Save alessandroleite/4233584 to your computer and use it in GitHub Desktop.
Counting the CPU cycles of a function/procedure
/////////////////////////////////////////////////////////////////////////
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
@tusifpk
Copy link

tusifpk commented Feb 22, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment