Bug #77577 setup_timers initialization assumes CYCLE timer is always available
Submitted: 1 Jul 2015 10:51 Modified: 14 Jul 2015 14:00
Reporter: Alexey Kopytov Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Performance Schema Severity:S3 (Non-critical)
Version:5.5, 5.6, 5.7 OS:Any
Assigned to: CPU Architecture:Any

[1 Jul 2015 10:51] Alexey Kopytov
Description:
Performance Schema uses the CYCLE timer for 'wait' events by default:

mysql> select * from setup_timers;
+-----------+-------------+
| NAME      | TIMER_NAME  |
+-----------+-------------+
| idle      | MICROSECOND |
| wait      | CYCLE       |
| stage     | NANOSECOND  |
| statement | NANOSECOND  |
+-----------+-------------+
4 rows in set (0.00 sec)

The initial value may be adjusted if the corresponding timer is unavailable, which is documented at https://dev.mysql.com/doc/refman/5.6/en/performance-schema-timing.html

"By default, the Performance Schema uses the best timer available for each instrument type, but you can select a different one. "

The above is true for stage, statement, idle and (in 5.7) transaction events, see code in init_timers() from pfs_timer.cc after the following comment:

  /*
    Depending on the platform and build options,
    some timers may not be available.
    Pick best replacements.
  */

However, wait events have been left behind for some reason: they use the CYCLE timer by default, and that default is not adjusted if the cycle timer is unavailable.

This is what I get on a platform where the cycle timer is not implemented (which will be reported separately):

mysql> select * from performance_timers;
+-------------+-----------------+------------------+----------------+
| TIMER_NAME  | TIMER_FREQUENCY | TIMER_RESOLUTION | TIMER_OVERHEAD |
+-------------+-----------------+------------------+----------------+
| CYCLE       |            NULL |             NULL |           NULL |
| NANOSECOND  |      1000000000 |                1 |             60 |
| MICROSECOND |         1000000 |                1 |             80 |
| MILLISECOND |            1000 |                1 |            130 |
| TICK        |             100 |                1 |            940 |
+-------------+-----------------+------------------+----------------+
5 rows in set (0.00 sec)

As a result, the wait events timing is broken with default settings.

How to repeat:
Examine code in init_timers() from pfs_timer.cc. Note that wait_timer is initialized to TIMER_NAME_CYCLE and unlike other events is not adjusted if that timer is not available. Note that code in my_timer_init() called from init_timers() does assume that the cycle timer may not be available, in which case the nanosecond timer is used instead.

Suggested fix:
Auto-adjust the default timer for wait events if the CYCLE timer is not available, similar to other events.
[2 Jul 2015 15:03] OCA Admin
Contribution submitted via Github - Bug #77577: setup_timers initialization assumes CYCLE timer is always available 
(*) Contribution by Alexey Kopytov (Github akopytov, mysql-server/pull/20#issuecomment-117642002): I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: git_patch_38972448.txt (text/plain), 3.71 KiB.

[6 Jul 2015 6:18] Umesh Shastry
Hello Alexey Kopytov,
 
Thank you for the report and contribution.

Thanks,
Umesh
[14 Jul 2015 14:00] Paul Dubois
Noted in 5.5.46, 5.6.27, 5.7.9, 5.8.0 changelogs.

For wait events, the Performance Schema uses the CYCLE timer by
default, but failed to fall back to a different timer if CYCLE was
unavailable.