PAPI  5.0.1.0
nmi_watchdog.c
Go to the documentation of this file.
00001 /* If the NMI watchdog is enabled it will steal a performance counter.   */
00002 /* There is a bug that if you try to use the maximum number of counters  */
00003 /*   (not counting the stolen one) with a group leader, sys_perf_open()  */
00004 /* will indicate success, as will starting the count, but you will fail  */
00005 /* at read time.                                                         */
00006 
00007 /* This bug still exists in 3.x */
00008 /* The perf NMI watchdog was not introduced until 2.6.34        */
00009 
00010 /* This also triggers in the case of the schedulability bug      */
00011 /* but since that was fixed in 2.6.34 then in theory there is    */
00012 /* no overlap in the tests.                                      */
00013 
00014 #include "papi_test.h"
00015 
00016 
00017 int detect_nmi_watchdog(void) {
00018 
00019   int watchdog_detected=0,watchdog_value=0;
00020   FILE *fff;
00021 
00022   fff=fopen("/proc/sys/kernel/nmi_watchdog","r");
00023   if (fff!=NULL) {
00024     if (fscanf(fff,"%d",&watchdog_value)==1) {
00025        if (watchdog_value>0) watchdog_detected=1;
00026     }
00027     fclose(fff);
00028   }
00029   else {
00030     watchdog_detected=-1;
00031   }
00032 
00033   return watchdog_detected;
00034 }
00035 
00036 int main( int argc, char **argv ) {
00037 
00038   int retval,watchdog_active=0;
00039   
00040   /* Set TESTS_QUIET variable */
00041   tests_quiet( argc, argv );    
00042 
00043   /* Init the PAPI library */
00044   retval = PAPI_library_init( PAPI_VER_CURRENT );
00045   if ( retval != PAPI_VER_CURRENT ) {
00046      test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00047   }
00048 
00049   watchdog_active=detect_nmi_watchdog();
00050 
00051   if (watchdog_active<0) {
00052     test_skip( __FILE__, __LINE__, "nmi_watchdog file does not exist\n", 0);
00053   }
00054 
00055   if (watchdog_active) {
00056     if (!TESTS_QUIET) {
00057       printf("\nOn perf_event kernels with the nmi_watchdog enabled\n");
00058       printf("the watchdog steals an event, but the scheduability code\n");
00059       printf("is not notified.  Thus adding a full complement of events\n");
00060       printf("seems to pass, but then fails at read time.\n");
00061       printf("Because of this, PAPI has to do some slow workarounds.\n");
00062       printf("For best PAPI performance, you may wish to disable\n");
00063       printf("the watchdog by running (as root)\n");
00064       printf("\techo \"0\" > /proc/sys/kernel/nmi_watchdog\n\n");
00065     }
00066 
00067      test_warn( __FILE__, __LINE__, "NMI Watchdog Active, enabling slow workarounds", 0 );
00068   }
00069     
00070   test_pass( __FILE__, NULL, 0 );
00071     
00072   return 0;
00073 }
00074 
00075 
00076 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines