c3c0f2
commit 7a6ae407b62615d3ffa9b0d2ac17771b7fc63056
c3c0f2
Author: Vince Weaver <vince@deater.net>
c3c0f2
Date:   Thu Sep 27 23:47:58 2018 -0400
c3c0f2
c3c0f2
    perf_event: avoid floating point exception if running is 0
c3c0f2
    
c3c0f2
    The perf_event interface isn't supposed to return 0 for running, but
c3c0f2
    it happens occasionally.  So be sure not to divide by zero if this
c3c0f2
    happens.  This makes the rdpmc code match the generic perf code in this
c3c0f2
    case.
c3c0f2
    
c3c0f2
    This is in response to bitbucket issue #52
c3c0f2
c3c0f2
diff --git a/src/components/perf_event/perf_event.c b/src/components/perf_event/perf_event.c
c3c0f2
index 7fd753ed..82b7d398 100644
c3c0f2
--- a/src/components/perf_event/perf_event.c
c3c0f2
+++ b/src/components/perf_event/perf_event.c
c3c0f2
@@ -1099,14 +1099,23 @@ _pe_rdpmc_read( hwd_context_t *ctx, hwd_control_state_t *ctl,
c3c0f2
 		count = mmap_read_self(pe_ctl->events[i].mmap_buf,
c3c0f2
 						&enabled,&running);
c3c0f2
 
c3c0f2
-		/* TODO: error checking? */
c3c0f2
+		/* TODO: more error checking? */
c3c0f2
 
c3c0f2
 		/* Handle multiplexing case */
c3c0f2
-		if (enabled!=running) {
c3c0f2
+		if (enabled == running) {
c3c0f2
+			/* no adjustment needed */
c3c0f2
+		}
c3c0f2
+		else if (enabled && running) {
c3c0f2
 			adjusted = (enabled * 128LL) / running;
c3c0f2
 			adjusted = adjusted * count;
c3c0f2
 			adjusted = adjusted / 128LL;
c3c0f2
 			count = adjusted;
c3c0f2
+		} else {
c3c0f2
+			/* This should not happen, but we have had it reported */
c3c0f2
+			SUBDBG("perf_event kernel bug(?) count, enabled, "
c3c0f2
+				"running: %lld, %lld, %lld\n",
c3c0f2
+				papi_pe_buffer[0],enabled,running);
c3c0f2
+
c3c0f2
 		}
c3c0f2
 
c3c0f2
 		pe_ctl->counts[i] = count;