Skip to content

Commit 5950c21

Browse files
committed
Bug #77577: setup_timers initialization assumes CYCLE timer is always available
Test if the CYCLE timer is actually implemented when using it as the default timer for wait events. If CYCLE is not available, fall back to the nanosecond timer (or even less resolution timers, if nanosecond is also unavailable), similar to how other event timing defaults are adjusted.
1 parent 961958f commit 5950c21

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

storage/perfschema/pfs_timer.cc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,41 @@ void init_timers(void)
186186
/* Robustness, no known cases. */
187187
idle_timer= TIMER_NAME_CYCLE;
188188
}
189+
190+
/*
191+
For WAIT, the cycle timer is used by default. However, it is not available
192+
on all architectures. Fall back to the nanosecond timer in this case. It is
193+
unlikely that neither cycle nor nanosecond are available, but we continue
194+
probing less resolution timers anyway for considency with other events.
195+
*/
196+
if (cycle_to_pico != 0)
197+
{
198+
/* Normal case. */
199+
wait_timer= TIMER_NAME_CYCLE;
200+
}
201+
else if (nanosec_to_pico != 0)
202+
{
203+
/* Robustness, no known cases. */
204+
wait_timer= TIMER_NAME_NANOSEC;
205+
}
206+
else if (microsec_to_pico != 0)
207+
{
208+
/* Robustness, no known cases. */
209+
wait_timer= TIMER_NAME_MICROSEC;
210+
}
211+
else if (millisec_to_pico != 0)
212+
{
213+
/* Robustness, no known cases. */
214+
wait_timer= TIMER_NAME_MILLISEC;
215+
}
216+
else
217+
{
218+
/*
219+
Will never be reached on any architecture, but must provide a default if
220+
no other timers are available.
221+
*/
222+
wait_timer= TIMER_NAME_TICK;
223+
}
189224
}
190225

191226
ulonglong get_timer_raw_value(enum_timer_name timer_name)

0 commit comments

Comments
 (0)