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