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