Skip to content

Commit 06442e3

Browse files
kevgsdr-m
authored andcommitted
MDEV-19399 do not call slow my_timer_init() several times
No functional change. Call my_timer_init() only once and then reuse it from InnoDB and perfschema storage engines. This patch speeds up empty test for me like this: ./mtr -mem innodb.kevg,xtradb 1.21s user 0.84s system 34% cpu 5.999 total ./mtr -mem innodb.kevg,xtradb 1.12s user 0.60s system 31% cpu 5.385 total
1 parent d0ee3b5 commit 06442e3

File tree

8 files changed

+54
-56
lines changed

8 files changed

+54
-56
lines changed

sql/mysqld.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef Bitmap<((MAX_INDEXES+7)/8*8)> key_map; /* Used for finding keys */
6464
#define OPT_SESSION SHOW_OPT_SESSION
6565
#define OPT_GLOBAL SHOW_OPT_GLOBAL
6666

67-
extern MY_TIMER_INFO sys_timer_info;
67+
extern MYSQL_PLUGIN_IMPORT MY_TIMER_INFO sys_timer_info;
6868

6969
/*
7070
Values for --slave-parallel-mode

storage/innobase/ut/ut0timer.cc

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Function pointer to point selected timer function.
4646
ulonglong (*ut_timer_now)(void) = &ut_timer_none;
4747

4848
struct my_timer_unit_info ut_timer;
49+
extern MYSQL_PLUGIN_IMPORT MY_TIMER_INFO sys_timer_info;
4950

5051
/**************************************************************//**
5152
Sets up the data required for use of my_timer_* functions.
@@ -57,30 +58,27 @@ void
5758
ut_init_timer(void)
5859
/*===============*/
5960
{
60-
MY_TIMER_INFO all_timer_info;
61-
my_timer_init(&all_timer_info);
62-
63-
if (all_timer_info.cycles.frequency > 1000000 &&
64-
all_timer_info.cycles.resolution == 1) {
65-
ut_timer = all_timer_info.cycles;
61+
if (sys_timer_info.cycles.frequency > 1000000 &&
62+
sys_timer_info.cycles.resolution == 1) {
63+
ut_timer = sys_timer_info.cycles;
6664
ut_timer_now = &my_timer_cycles;
67-
} else if (all_timer_info.nanoseconds.frequency > 1000000 &&
68-
all_timer_info.nanoseconds.resolution == 1) {
69-
ut_timer = all_timer_info.nanoseconds;
65+
} else if (sys_timer_info.nanoseconds.frequency > 1000000 &&
66+
sys_timer_info.nanoseconds.resolution == 1) {
67+
ut_timer = sys_timer_info.nanoseconds;
7068
ut_timer_now = &my_timer_nanoseconds;
71-
} else if (all_timer_info.microseconds.frequency >= 1000000 &&
72-
all_timer_info.microseconds.resolution == 1) {
73-
ut_timer = all_timer_info.microseconds;
69+
} else if (sys_timer_info.microseconds.frequency >= 1000000 &&
70+
sys_timer_info.microseconds.resolution == 1) {
71+
ut_timer = sys_timer_info.microseconds;
7472
ut_timer_now = &my_timer_microseconds;
7573

76-
} else if (all_timer_info.milliseconds.frequency >= 1000 &&
77-
all_timer_info.milliseconds.resolution == 1) {
78-
ut_timer = all_timer_info.milliseconds;
74+
} else if (sys_timer_info.milliseconds.frequency >= 1000 &&
75+
sys_timer_info.milliseconds.resolution == 1) {
76+
ut_timer = sys_timer_info.milliseconds;
7977
ut_timer_now = &my_timer_milliseconds;
80-
} else if (all_timer_info.ticks.frequency >= 1000 &&
78+
} else if (sys_timer_info.ticks.frequency >= 1000 &&
8179
/* Will probably be false */
82-
all_timer_info.ticks.resolution == 1) {
83-
ut_timer = all_timer_info.ticks;
80+
sys_timer_info.ticks.resolution == 1) {
81+
ut_timer = sys_timer_info.ticks;
8482
ut_timer_now = &my_timer_ticks;
8583
} else {
8684
/* None are acceptable, so leave it as "None", and fill in struct */

storage/perfschema/pfs_timer.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ enum_timer_name idle_timer= TIMER_NAME_MICROSEC;
2626
enum_timer_name wait_timer= TIMER_NAME_CYCLE;
2727
enum_timer_name stage_timer= TIMER_NAME_NANOSEC;
2828
enum_timer_name statement_timer= TIMER_NAME_NANOSEC;
29-
MY_TIMER_INFO pfs_timer_info;
3029

3130
static ulonglong cycle_v0;
3231
static ulonglong nanosec_v0;
@@ -65,41 +64,39 @@ void init_timers(void)
6564
{
6665
double pico_frequency= 1.0e12;
6766

68-
my_timer_init(&pfs_timer_info);
69-
7067
cycle_v0= my_timer_cycles();
7168
nanosec_v0= my_timer_nanoseconds();
7269
microsec_v0= my_timer_microseconds();
7370
millisec_v0= my_timer_milliseconds();
7471
tick_v0= my_timer_ticks();
7572

76-
if (pfs_timer_info.cycles.frequency > 0)
73+
if (sys_timer_info.cycles.frequency > 0)
7774
cycle_to_pico= round_to_ulong(pico_frequency/
78-
(double)pfs_timer_info.cycles.frequency);
75+
(double)sys_timer_info.cycles.frequency);
7976
else
8077
cycle_to_pico= 0;
8178

82-
if (pfs_timer_info.nanoseconds.frequency > 0)
79+
if (sys_timer_info.nanoseconds.frequency > 0)
8380
nanosec_to_pico= round_to_ulong(pico_frequency/
84-
(double)pfs_timer_info.nanoseconds.frequency);
81+
(double)sys_timer_info.nanoseconds.frequency);
8582
else
8683
nanosec_to_pico= 0;
8784

88-
if (pfs_timer_info.microseconds.frequency > 0)
85+
if (sys_timer_info.microseconds.frequency > 0)
8986
microsec_to_pico= round_to_ulong(pico_frequency/
90-
(double)pfs_timer_info.microseconds.frequency);
87+
(double)sys_timer_info.microseconds.frequency);
9188
else
9289
microsec_to_pico= 0;
9390

94-
if (pfs_timer_info.milliseconds.frequency > 0)
91+
if (sys_timer_info.milliseconds.frequency > 0)
9592
millisec_to_pico= round_to_ulong(pico_frequency/
96-
(double)pfs_timer_info.milliseconds.frequency);
93+
(double)sys_timer_info.milliseconds.frequency);
9794
else
9895
millisec_to_pico= 0;
9996

100-
if (pfs_timer_info.ticks.frequency > 0)
97+
if (sys_timer_info.ticks.frequency > 0)
10198
tick_to_pico= round_to_ulonglong(pico_frequency/
102-
(double)pfs_timer_info.ticks.frequency);
99+
(double)sys_timer_info.ticks.frequency);
103100
else
104101
tick_to_pico= 0;
105102

storage/perfschema/pfs_timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ extern enum_timer_name statement_timer;
102102
Timer information data.
103103
Characteristics about each suported timer.
104104
*/
105-
extern MY_TIMER_INFO pfs_timer_info;
105+
extern MYSQL_PLUGIN_IMPORT MY_TIMER_INFO sys_timer_info;
106106

107107
/** Initialize the timer component. */
108108
void init_timers();

storage/perfschema/table_performance_timers.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,23 @@ table_performance_timers::table_performance_timers()
5858

5959
index= (int)TIMER_NAME_CYCLE - FIRST_TIMER_NAME;
6060
m_data[index].m_timer_name= TIMER_NAME_CYCLE;
61-
m_data[index].m_info= pfs_timer_info.cycles;
61+
m_data[index].m_info= sys_timer_info.cycles;
6262

6363
index= (int)TIMER_NAME_NANOSEC - FIRST_TIMER_NAME;
6464
m_data[index].m_timer_name= TIMER_NAME_NANOSEC;
65-
m_data[index].m_info= pfs_timer_info.nanoseconds;
65+
m_data[index].m_info= sys_timer_info.nanoseconds;
6666

6767
index= (int)TIMER_NAME_MICROSEC - FIRST_TIMER_NAME;
6868
m_data[index].m_timer_name= TIMER_NAME_MICROSEC;
69-
m_data[index].m_info= pfs_timer_info.microseconds;
69+
m_data[index].m_info= sys_timer_info.microseconds;
7070

7171
index= (int)TIMER_NAME_MILLISEC - FIRST_TIMER_NAME;
7272
m_data[index].m_timer_name= TIMER_NAME_MILLISEC;
73-
m_data[index].m_info= pfs_timer_info.milliseconds;
73+
m_data[index].m_info= sys_timer_info.milliseconds;
7474

7575
index= (int)TIMER_NAME_TICK - FIRST_TIMER_NAME;
7676
m_data[index].m_timer_name= TIMER_NAME_TICK;
77-
m_data[index].m_info= pfs_timer_info.ticks;
77+
m_data[index].m_info= sys_timer_info.ticks;
7878
}
7979

8080
void table_performance_timers::reset_position(void)

storage/perfschema/unittest/pfs_server_stubs.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ enum sys_var::where get_sys_var_value_origin(void *ptr)
4343
{
4444
return sys_var::AUTO;
4545
}
46+
47+
MY_TIMER_INFO sys_timer_info;

storage/perfschema/unittest/pfs_timer-t.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ void test_timers()
3333
ulonglong t4_b;
3434
ulonglong t5_b;
3535

36+
my_timer_init(&sys_timer_info);
37+
3638
init_timers();
3739

3840
t1_a= get_timer_pico_value(TIMER_NAME_CYCLE);

storage/xtradb/ut/ut0timer.cc

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ ulonglong (*ut_timer_now)(void) = &ut_timer_none;
4747

4848
struct my_timer_unit_info ut_timer;
4949

50+
extern MYSQL_PLUGIN_IMPORT MY_TIMER_INFO sys_timer_info;
51+
5052
/**************************************************************//**
5153
Sets up the data required for use of my_timer_* functions.
5254
Selects the best timer by high frequency, and tight resolution.
@@ -57,30 +59,27 @@ void
5759
ut_init_timer(void)
5860
/*===============*/
5961
{
60-
MY_TIMER_INFO all_timer_info;
61-
my_timer_init(&all_timer_info);
62-
63-
if (all_timer_info.cycles.frequency > 1000000 &&
64-
all_timer_info.cycles.resolution == 1) {
65-
ut_timer = all_timer_info.cycles;
62+
if (sys_timer_info.cycles.frequency > 1000000 &&
63+
sys_timer_info.cycles.resolution == 1) {
64+
ut_timer = sys_timer_info.cycles;
6665
ut_timer_now = &my_timer_cycles;
67-
} else if (all_timer_info.nanoseconds.frequency > 1000000 &&
68-
all_timer_info.nanoseconds.resolution == 1) {
69-
ut_timer = all_timer_info.nanoseconds;
66+
} else if (sys_timer_info.nanoseconds.frequency > 1000000 &&
67+
sys_timer_info.nanoseconds.resolution == 1) {
68+
ut_timer = sys_timer_info.nanoseconds;
7069
ut_timer_now = &my_timer_nanoseconds;
71-
} else if (all_timer_info.microseconds.frequency >= 1000000 &&
72-
all_timer_info.microseconds.resolution == 1) {
73-
ut_timer = all_timer_info.microseconds;
70+
} else if (sys_timer_info.microseconds.frequency >= 1000000 &&
71+
sys_timer_info.microseconds.resolution == 1) {
72+
ut_timer = sys_timer_info.microseconds;
7473
ut_timer_now = &my_timer_microseconds;
7574

76-
} else if (all_timer_info.milliseconds.frequency >= 1000 &&
77-
all_timer_info.milliseconds.resolution == 1) {
78-
ut_timer = all_timer_info.milliseconds;
75+
} else if (sys_timer_info.milliseconds.frequency >= 1000 &&
76+
sys_timer_info.milliseconds.resolution == 1) {
77+
ut_timer = sys_timer_info.milliseconds;
7978
ut_timer_now = &my_timer_milliseconds;
80-
} else if (all_timer_info.ticks.frequency >= 1000 &&
79+
} else if (sys_timer_info.ticks.frequency >= 1000 &&
8180
/* Will probably be false */
82-
all_timer_info.ticks.resolution == 1) {
83-
ut_timer = all_timer_info.ticks;
81+
sys_timer_info.ticks.resolution == 1) {
82+
ut_timer = sys_timer_info.ticks;
8483
ut_timer_now = &my_timer_ticks;
8584
} else {
8685
/* None are acceptable, so leave it as "None", and fill in struct */

0 commit comments

Comments
 (0)