//------------------------------------------------------------------- // howfast.cpp // // This program shows how you can measure the rate at which the // kernel's 'jiffies' variable increments. It makes use of the // standard UNIX 'sleep()' function to create a 1-second delay, // and assumes our compiled 'jiffies.ko' module can be found in // the current directory. // // programmer: ALLAN CRUSE // written on: 27 JAN 2005 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for system(), exit(), stroul() #include // for read(), sleep(), lseek(), close() #define BUFSZ 80 char filename[] = "/proc/jiffies"; char buffer[ BUFSZ ]; int main( int argc, char **argv ) { // install module that creates our pseudo-file system( "/sbin/insmod jiffies.ko" ); // open the pseudo-file for reading int fd = open( filename, O_RDONLY ); if ( fd < 0 ) { perror( filename ); exit(1); } // read the current value of jiffies if ( read( fd, buffer, BUFSZ ) < 0 ) { perror( "read 1" ); exit(1); } unsigned long first = strtoul( buffer+10, NULL, 10 ); // delay for one second sleep( 1 ); // now read the value of jiffies again lseek( fd, 0, SEEK_SET ); if ( read( fd, buffer, BUFSZ ) < 0 ) { perror( "read 2" ); exit(1); } unsigned long final = strtoul( buffer+10, NULL, 10 ); // calculate and display the number of jiffies-per-second printf( "%lu\n", first ); printf( "%lu\n", final ); printf( "difference = %lu \n", final - first ); // close the pseudo-file and remove our kernel module close( fd ); system( "/sbin/rmmod jiffies " ); }