PAPI  5.6.0.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 <stdio.h>
15 
16 #include "papi.h"
17 #include "papi_test.h"
18 
19 
20 static int detect_nmi_watchdog(void) {
21 
22  int watchdog_detected=0,watchdog_value=0;
23  FILE *fff;
24 
25  fff=fopen("/proc/sys/kernel/nmi_watchdog","r");
26  if (fff!=NULL) {
27  if (fscanf(fff,"%d",&watchdog_value)==1) {
28  if (watchdog_value>0) watchdog_detected=1;
29  }
30  fclose(fff);
31  }
32  else {
33  watchdog_detected=-1;
34  }
35 
36  return watchdog_detected;
37 }
38 
39 int main( int argc, char **argv ) {
40 
41  int retval,watchdog_active=0;
42  int quiet;
43 
44  /* Set TESTS_QUIET variable */
45  quiet=tests_quiet( argc, argv );
46 
47  /* Init the PAPI library */
49  if ( retval != PAPI_VER_CURRENT ) {
50  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
51  }
52 
53  watchdog_active=detect_nmi_watchdog();
54 
55  if (watchdog_active<0) {
56  test_skip( __FILE__, __LINE__,
57  "nmi_watchdog file does not exist\n", 0);
58  }
59 
60  if (watchdog_active) {
61  if (!quiet) {
62  printf("\nOn perf_event kernels with the nmi_watchdog enabled\n");
63  printf("the watchdog steals an event, but the scheduability code\n");
64  printf("is not notified. Thus adding a full complement of events\n");
65  printf("seems to pass, but then fails at read time.\n");
66  printf("Because of this, PAPI has to do some slow workarounds.\n");
67  printf("For best PAPI performance, you may wish to disable\n");
68  printf("the watchdog by running (as root)\n");
69  printf("\techo \"0\" > /proc/sys/kernel/nmi_watchdog\n\n");
70  }
71 
72  test_warn( __FILE__, __LINE__,
73  "NMI Watchdog Active, enabling slow workarounds", 0 );
74  }
75 
76  test_pass( __FILE__ );
77 
78  return 0;
79 }
80 
81 
82 
void test_pass(const char *filename)
Definition: test_utils.c:432
fclose(thread_wqfd)
void test_warn(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:522
int int argc
Definition: iozone.c:1609
Return codes and api definitions.
FILE * fff[MAX_EVENTS]
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
printf("\tTry: -i 0 -i 1 \n\n")
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225
int main(int argc, char **argv)
List all appio events codes and names.
static int detect_nmi_watchdog(void)
Definition: nmi_watchdog.c:20