Skip to content

Commit a87908a

Browse files
author
Tiago Alves
committed
BUG#32413458 FIXES ARITHMETIC EXCEPTION IN NDB_INIT
Fixes arithmetic exception when trying to calculate the amount of instructions to pause cpu using spinning (introduced in WL#12554). Under some situations, when trying to measure the time of a cpu pause, we might end up with an elapsed time of zero (e.g. non-monotonic clock). Also, if spinning is really fast (100 loops taking less than 100ns) we might compute an average of zero nanoseconds. In both cases, this will cause the algorithm to calibrate spinning to throw an arithmetic exception due to division by zero. Modifies the algorithm to ignore zero values when computing mean spinning time. Change-Id: I55166705e1a0d5fa453aa2a75831db8943321541
1 parent f2e217c commit a87908a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

storage/ndb/src/common/portlib/NdbSpin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ void NdbSpin_Init()
5050
NDB_TICKS now = NdbTick_getCurrentTicks();
5151
const Uint64 nanos_passed = NdbTick_Elapsed(start, now).nanoSec();
5252
const Uint64 nanos_per_call = nanos_passed / loop_count;
53-
if (nanos_per_call < min_nanos_per_call)
53+
if ((nanos_per_call > 0) && (nanos_per_call < min_nanos_per_call))
5454
{
5555
min_nanos_per_call = nanos_per_call;
5656
}
5757
}
58+
5859
loops = ((min_nanos_per_call - 1) + spin_nanos) / min_nanos_per_call;
5960
#endif
6061
if (loops == 0)

0 commit comments

Comments
 (0)