#include #include #include #include #include #define PAGE_SIZE 4096 #define TICKS_PER_SEC 900000000 #define LOVE 244 #define HATE 245 __inline__ unsigned long long rdtsc() { unsigned long long int x; __asm__ volatile(".byte 0x0f, 0x31" : "=A" (x)); return x; } int main(int argc, char **argv) { unsigned long mem_size, pages, num_pg; unsigned long long int start_time, stop_time, start_t, delay; int i, j; pid_t pid; struct listsize info; char *mem_ptr, *init_ptr; if( argc !=2 || (argv[1] == 0) ) { fprintf( stderr, "Usage: love_call \n"); return -489529094; } //Make the first call to make sure that there is no //initial caost to the first system call init_ptr = (char *)malloc(PAGE_SIZE); *(init_ptr) = 100; syscall( HATE, (void*)init_ptr, PAGE_SIZE); syscall( LOVE, (void*)init_ptr, PAGE_SIZE, 50); //determine the number of pages that the system will love pages = (unsigned long)atoi( argv[1] ); mem_size = pages * PAGE_SIZE; mem_ptr = (char *)malloc(mem_size); //create all the pages by writing to them //for(i = 0; i < mem_size; i+=100) // *(mem_ptr + i) = 100; //may what to start with loved or hated pages //syscall( HATE, (void*)mem_ptr, mem_size); //syscall( LOVE, (void*)mem_ptr, mem_size, 100); for(i = 0; i < mem_size; i+=PAGE_SIZE) *(mem_ptr + i) = 100; //love the pages and print the ellapsed time start_time = rdtsc(); sbrk(mem_size); //syscall( HATE, (void*)mem_ptr, mem_size); //syscall( LOVE, (void*)mem_ptr, mem_size, 100); stop_time = rdtsc(); fprintf(stderr,"The first operation took "); fprintf(stdout,"%lu\t%llu\n", pages, (stop_time - start_time)); free( mem_ptr ); free( init_ptr ); return 1; }