PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nmi_watchdog.c
Go to the documentation of this file.
1 /* If the NMI watchdog is enabled it will steal a performance counter. */
2 /* There is a bug that if you try to use the maximum number of counters */
3 /* (not counting the stolen one) with a group leader, sys_perf_open() */
4 /* will indicate success, as will starting the count, but you will fail */
5 /* at read time. */
6 
7 /* This bug still exists in 3.x */
8 /* The perf NMI watchdog was not introduced until 2.6.34 */
9 
10 /* This also triggers in the case of the schedulability bug */
11 /* but since that was fixed in 2.6.34 then in theory there is */
12 /* no overlap in the tests. */
13 
14 #include "papi_test.h"
15 
16 
18 
19  int watchdog_detected=0,watchdog_value=0;
20  FILE *fff;
21 
22  fff=fopen("/proc/sys/kernel/nmi_watchdog","r");
23  if (fff!=NULL) {
24  if (fscanf(fff,"%d",&watchdog_value)==1) {
25  if (watchdog_value>0) watchdog_detected=1;
26  }
27  fclose(fff);
28  }
29  else {
30  watchdog_detected=-1;
31  }
32 
33  return watchdog_detected;
34 }
35 
36 int main( int argc, char **argv ) {
37 
38  int retval,watchdog_active=0;
39 
40  /* Set TESTS_QUIET variable */
41  tests_quiet( argc, argv );
42 
43  /* Init the PAPI library */
45  if ( retval != PAPI_VER_CURRENT ) {
46  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
47  }
48 
49  watchdog_active=detect_nmi_watchdog();
50 
51  if (watchdog_active<0) {
52  test_skip( __FILE__, __LINE__, "nmi_watchdog file does not exist\n", 0);
53  }
54 
55  if (watchdog_active) {
56  if (!TESTS_QUIET) {
57  printf("\nOn perf_event kernels with the nmi_watchdog enabled\n");
58  printf("the watchdog steals an event, but the scheduability code\n");
59  printf("is not notified. Thus adding a full complement of events\n");
60  printf("seems to pass, but then fails at read time.\n");
61  printf("Because of this, PAPI has to do some slow workarounds.\n");
62  printf("For best PAPI performance, you may wish to disable\n");
63  printf("the watchdog by running (as root)\n");
64  printf("\techo \"0\" > /proc/sys/kernel/nmi_watchdog\n\n");
65  }
66 
67  test_warn( __FILE__, __LINE__, "NMI Watchdog Active, enabling slow workarounds", 0 );
68  }
69 
70  test_pass( __FILE__, NULL, 0 );
71 
72  return 0;
73 }
74 
75 
76 
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
tests_quiet(argc, argv)
fclose(thread_wqfd)
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
FILE * fff[MAX_EVENTS]
int TESTS_QUIET
Definition: test_utils.c:11
char ** argv
Definition: iozone.c:1610
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
void test_warn(char *file, int line, char *call, int retval)
Definition: test_utils.c:578
int detect_nmi_watchdog(void)
Definition: nmi_watchdog.c:17
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.