Skip to content

Commit fd1f739

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 fd1f739

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

mysql-test/suite/perfschema/r/query_cache.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ spins
3838
NULL
3939
select * from performance_schema.setup_timers where name='wait';
4040
NAME TIMER_NAME
41-
wait CYCLE
41+
wait {CYCLE_OR_NANOSECOND}
4242
show status like "Qcache_queries_in_cache";
4343
Variable_name Value
4444
Qcache_queries_in_cache 1
@@ -53,7 +53,7 @@ spins
5353
NULL
5454
select * from performance_schema.setup_timers where name='wait';
5555
NAME TIMER_NAME
56-
wait CYCLE
56+
wait {CYCLE_OR_NANOSECOND}
5757
show status like "Qcache_queries_in_cache";
5858
Variable_name Value
5959
Qcache_queries_in_cache 1

mysql-test/suite/perfschema/t/query_cache.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ show status like "Qcache_hits";
3434

3535
select spins from performance_schema.events_waits_current order by event_name limit 1;
3636

37+
--replace_result CYCLE {CYCLE_OR_NANOSECOND} NANOSECOND {CYCLE_OR_NANOSECOND}
3738
select * from performance_schema.setup_timers where name='wait';
3839

3940
show status like "Qcache_queries_in_cache";
@@ -42,6 +43,7 @@ show status like "Qcache_hits";
4243

4344
select spins from performance_schema.events_waits_current order by event_name limit 1;
4445

46+
--replace_result CYCLE {CYCLE_OR_NANOSECOND} NANOSECOND {CYCLE_OR_NANOSECOND}
4547
select * from performance_schema.setup_timers where name='wait';
4648

4749
show status like "Qcache_queries_in_cache";

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)