Bug #107123 CPU usage incorrectly calculated。
Submitted: 26 Apr 2022 2:27 Modified: 26 Apr 2022 10:22
Reporter: Runchen Xu Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Information schema Severity:S3 (Non-critical)
Version:8.0.28 OS:Linux
Assigned to: CPU Architecture:Any

[26 Apr 2022 2:27] Runchen Xu
Description:
When the number of cores on a linux server is greater than 128, the CPU usage of innodb_metrics is incorrectly calculated.

How to repeat:
Mysqld is running on the linux server with more than 128 cores.

Run the following SQL statement:

mysql> set global innodb_monitor_disable = 'cpu%';
mysql> select name,subsystem,status,count,max_count,avg_count from information_schema.innodb_metrics where subsystem='cpu';

Then we get the wrong counts of these three metrics: cpu_utime_pct, cpu_stime_pct, and cpu_n.

Suggested fix:
In the source file storage\innobase\srv\srv0srv.cc:2154, MAX_CPU_N is defined as constant 128, which led to this bug. You can use std::thread::hardware_concurrency() to obtain the number of server cores.
[26 Apr 2022 2:52] Runchen Xu
The preceding SQL statements are modified as follows:

mysql> set global innodb_monitor_enable = 'cpu%';
mysql> select name,subsystem,status,count,max_count,avg_count from information_schema.innodb_metrics where subsystem='cpu';
[26 Apr 2022 10:22] MySQL Verification Team
Hello Runchen Xu,

Thank you for the report and feedback.
Verified as described.

regards,
Umesh
[26 Apr 2022 11:37] Runchen Xu
A patch for this bug.

Attachment: 8028_srv_cpu_usage.patch (application/octet-stream, text), 880 bytes.