Commit 039a299b authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-12534 Use atomic operations whenever available

Define UNIV_WORD_SIZE as a simple alias to SIZEOF_SIZE_T.
In MariaDB 10.0 and 10.1, it was incorrectly defined as 4 on
64-bit Windows.

MONITOR_OS_PENDING_READS, MONITOR_OS_PENDING_WRITES: Enable by default.

os_n_pending_reads, os_n_pending_writes: Remove.
Use the monitor counters instead.
parent 8bbeac01
...@@ -52,11 +52,6 @@ struct fil_space_t; ...@@ -52,11 +52,6 @@ struct fil_space_t;
extern bool os_has_said_disk_full; extern bool os_has_said_disk_full;
extern my_bool srv_use_trim; extern my_bool srv_use_trim;
/** Number of pending read operations */
extern ulint os_n_pending_reads;
/** Number of pending write operations */
extern ulint os_n_pending_writes;
/** File offset in bytes */ /** File offset in bytes */
typedef ib_uint64_t os_offset_t; typedef ib_uint64_t os_offset_t;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Copyright (c) 2010, 2015, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2010, 2015, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc. Copyright (c) 2012, Facebook Inc.
Copyright (c) 2013, 2016, MariaDB Corporation. Copyright (c) 2013, 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the under the terms of the GNU General Public License as published by the
...@@ -603,9 +603,10 @@ on the counters */ ...@@ -603,9 +603,10 @@ on the counters */
/** Atomically increment a monitor counter. /** Atomically increment a monitor counter.
Use MONITOR_INC if appropriate mutex protection exists. Use MONITOR_INC if appropriate mutex protection exists.
@param monitor monitor to be incremented by 1 */ @param monitor monitor to be incremented by 1
# define MONITOR_ATOMIC_INC(monitor) \ @param enabled whether the monitor is enabled */
if (MONITOR_IS_ON(monitor)) { \ #define MONITOR_ATOMIC_INC_LOW(monitor, enabled) \
if (enabled) { \
ib_uint64_t value; \ ib_uint64_t value; \
value = my_atomic_add64( \ value = my_atomic_add64( \
(int64*) &MONITOR_VALUE(monitor), 1) + 1; \ (int64*) &MONITOR_VALUE(monitor), 1) + 1; \
...@@ -618,9 +619,10 @@ Use MONITOR_INC if appropriate mutex protection exists. ...@@ -618,9 +619,10 @@ Use MONITOR_INC if appropriate mutex protection exists.
/** Atomically decrement a monitor counter. /** Atomically decrement a monitor counter.
Use MONITOR_DEC if appropriate mutex protection exists. Use MONITOR_DEC if appropriate mutex protection exists.
@param monitor monitor to be decremented by 1 */ @param monitor monitor to be decremented by 1
# define MONITOR_ATOMIC_DEC(monitor) \ @param enabled whether the monitor is enabled */
if (MONITOR_IS_ON(monitor)) { \ #define MONITOR_ATOMIC_DEC_LOW(monitor, enabled) \
if (enabled) { \
ib_uint64_t value; \ ib_uint64_t value; \
value = my_atomic_add64( \ value = my_atomic_add64( \
(int64*) &MONITOR_VALUE(monitor), -1) - 1; \ (int64*) &MONITOR_VALUE(monitor), -1) - 1; \
...@@ -631,6 +633,17 @@ Use MONITOR_DEC if appropriate mutex protection exists. ...@@ -631,6 +633,17 @@ Use MONITOR_DEC if appropriate mutex protection exists.
} \ } \
} }
/** Atomically increment a monitor counter if it is enabled.
Use MONITOR_INC if appropriate mutex protection exists.
@param monitor monitor to be incremented by 1 */
#define MONITOR_ATOMIC_INC(monitor) \
MONITOR_ATOMIC_INC_LOW(monitor, MONITOR_IS_ON(monitor))
/** Atomically decrement a monitor counter if it is enabled.
Use MONITOR_DEC if appropriate mutex protection exists.
@param monitor monitor to be decremented by 1 */
#define MONITOR_ATOMIC_DEC(monitor) \
MONITOR_ATOMIC_DEC_LOW(monitor, MONITOR_IS_ON(monitor))
#define MONITOR_DEC(monitor) \ #define MONITOR_DEC(monitor) \
if (MONITOR_IS_ON(monitor)) { \ if (MONITOR_IS_ON(monitor)) { \
MONITOR_VALUE(monitor)--; \ MONITOR_VALUE(monitor)--; \
......
...@@ -282,16 +282,7 @@ rarely invoked function for size instead for speed. */ ...@@ -282,16 +282,7 @@ rarely invoked function for size instead for speed. */
#define UNIV_INLINE static inline #define UNIV_INLINE static inline
#ifdef _WIN32 #define UNIV_WORD_SIZE SIZEOF_SIZE_T
# ifdef _WIN64
# define UNIV_WORD_SIZE 8
# else
# define UNIV_WORD_SIZE 4
# endif
#else /* !_WIN32 */
/** MySQL config.h generated by CMake will define SIZEOF_LONG in Posix */
#define UNIV_WORD_SIZE SIZEOF_LONG
#endif /* _WIN32 */
/** The following alignment is used in memory allocations in memory heap /** The following alignment is used in memory allocations in memory heap
management to ensure correct alignment for doubles etc. */ management to ensure correct alignment for doubles etc. */
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 1995, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2009, Percona Inc. Copyright (c) 2009, Percona Inc.
Copyright (c) 2012, 2017, MariaDB Corporation. Copyright (c) 2013, 2017, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted Portions of this file contain modifications contributed and copyrighted
by Percona Inc.. Those modifications are by Percona Inc.. Those modifications are
...@@ -687,10 +687,6 @@ ulint os_n_fsyncs; ...@@ -687,10 +687,6 @@ ulint os_n_fsyncs;
static ulint os_n_file_reads_old; static ulint os_n_file_reads_old;
static ulint os_n_file_writes_old; static ulint os_n_file_writes_old;
static ulint os_n_fsyncs_old; static ulint os_n_fsyncs_old;
/** Number of pending write operations */
ulint os_n_pending_writes;
/** Number of pending read operations */
ulint os_n_pending_reads;
static time_t os_last_printout; static time_t os_last_printout;
bool os_has_said_disk_full; bool os_has_said_disk_full;
...@@ -4945,14 +4941,11 @@ os_file_pwrite( ...@@ -4945,14 +4941,11 @@ os_file_pwrite(
++os_n_file_writes; ++os_n_file_writes;
(void) my_atomic_addlint(&os_n_pending_writes, 1); const bool monitor = MONITOR_IS_ON(MONITOR_OS_PENDING_WRITES);
MONITOR_ATOMIC_INC(MONITOR_OS_PENDING_WRITES); MONITOR_ATOMIC_INC_LOW(MONITOR_OS_PENDING_WRITES, monitor);
ssize_t n_bytes = os_file_io(type, file, const_cast<byte*>(buf), ssize_t n_bytes = os_file_io(type, file, const_cast<byte*>(buf),
n, offset, err); n, offset, err);
MONITOR_ATOMIC_DEC_LOW(MONITOR_OS_PENDING_WRITES, monitor);
(void) my_atomic_addlint(&os_n_pending_writes, -1);
MONITOR_ATOMIC_DEC(MONITOR_OS_PENDING_WRITES);
return(n_bytes); return(n_bytes);
} }
...@@ -5032,13 +5025,10 @@ os_file_pread( ...@@ -5032,13 +5025,10 @@ os_file_pread(
{ {
++os_n_file_reads; ++os_n_file_reads;
(void) my_atomic_addlint(&os_n_pending_reads, 1); const bool monitor = MONITOR_IS_ON(MONITOR_OS_PENDING_READS);
MONITOR_ATOMIC_INC(MONITOR_OS_PENDING_READS); MONITOR_ATOMIC_INC_LOW(MONITOR_OS_PENDING_READS, monitor);
ssize_t n_bytes = os_file_io(type, file, buf, n, offset, err); ssize_t n_bytes = os_file_io(type, file, buf, n, offset, err);
MONITOR_ATOMIC_DEC_LOW(MONITOR_OS_PENDING_READS, monitor);
(void) my_atomic_addlint(&os_n_pending_reads, -1);
MONITOR_ATOMIC_DEC(MONITOR_OS_PENDING_READS);
return(n_bytes); return(n_bytes);
} }
...@@ -7467,19 +7457,24 @@ os_aio_print(FILE* file) ...@@ -7467,19 +7457,24 @@ os_aio_print(FILE* file)
time_elapsed = 0.001 + difftime(current_time, os_last_printout); time_elapsed = 0.001 + difftime(current_time, os_last_printout);
fprintf(file, fprintf(file,
"Pending flushes (fsync) log: %lu; buffer pool: %lu\n" "Pending flushes (fsync) log: " ULINTPF
"%lu OS file reads, %lu OS file writes, %lu OS fsyncs\n", "; buffer pool: " ULINTPF "\n"
(ulint) fil_n_pending_log_flushes, ULINTPF " OS file reads, "
(ulint) fil_n_pending_tablespace_flushes, ULINTPF " OS file writes, "
(ulint) os_n_file_reads, ULINTPF " OS fsyncs\n",
(ulint) os_n_file_writes, fil_n_pending_log_flushes,
(ulint) os_n_fsyncs); fil_n_pending_tablespace_flushes,
os_n_file_reads,
if (os_n_pending_writes != 0 || os_n_pending_reads != 0) { os_n_file_writes,
os_n_fsyncs);
const ulint n_reads = ulint(MONITOR_VALUE(MONITOR_OS_PENDING_READS));
const ulint n_writes = ulint(MONITOR_VALUE(MONITOR_OS_PENDING_WRITES));
if (n_reads != 0 || n_writes != 0) {
fprintf(file, fprintf(file,
"%lu pending preads, %lu pending pwrites\n", ULINTPF " pending reads, " ULINTPF " pending writes\n",
(ulint) os_n_pending_reads, n_reads, n_writes);
(ulint) os_n_pending_writes);
} }
if (os_n_file_reads == os_n_file_reads_old) { if (os_n_file_reads == os_n_file_reads_old) {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Copyright (c) 2010, 2016, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2010, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2012, Facebook Inc. Copyright (c) 2012, Facebook Inc.
Copyright (c) 2013, 2016, MariaDB Corporation Copyright (c) 2013, 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software the terms of the GNU General Public License as published by the Free Software
...@@ -739,11 +739,11 @@ static monitor_info_t innodb_counter_info[] = ...@@ -739,11 +739,11 @@ static monitor_info_t innodb_counter_info[] =
MONITOR_DEFAULT_START, MONITOR_OVLD_OS_FSYNC}, MONITOR_DEFAULT_START, MONITOR_OVLD_OS_FSYNC},
{"os_pending_reads", "os", "Number of reads pending", {"os_pending_reads", "os", "Number of reads pending",
MONITOR_NONE, MONITOR_DEFAULT_ON,
MONITOR_DEFAULT_START, MONITOR_OS_PENDING_READS}, MONITOR_DEFAULT_START, MONITOR_OS_PENDING_READS},
{"os_pending_writes", "os", "Number of writes pending", {"os_pending_writes", "os", "Number of writes pending",
MONITOR_NONE, MONITOR_DEFAULT_ON,
MONITOR_DEFAULT_START, MONITOR_OS_PENDING_WRITES}, MONITOR_DEFAULT_START, MONITOR_OS_PENDING_WRITES},
{"os_log_bytes_written", "os", {"os_log_bytes_written", "os",
......
...@@ -1482,10 +1482,10 @@ srv_export_innodb_status(void) ...@@ -1482,10 +1482,10 @@ srv_export_innodb_status(void)
mutex_enter(&srv_innodb_monitor_mutex); mutex_enter(&srv_innodb_monitor_mutex);
export_vars.innodb_data_pending_reads = export_vars.innodb_data_pending_reads =
os_n_pending_reads; ulint(MONITOR_VALUE(MONITOR_OS_PENDING_READS));
export_vars.innodb_data_pending_writes = export_vars.innodb_data_pending_writes =
os_n_pending_writes; ulint(MONITOR_VALUE(MONITOR_OS_PENDING_READS));
export_vars.innodb_data_pending_fsyncs = export_vars.innodb_data_pending_fsyncs =
fil_n_pending_log_flushes fil_n_pending_log_flushes
......
...@@ -1093,9 +1093,10 @@ sync_array_print_long_waits( ...@@ -1093,9 +1093,10 @@ sync_array_print_long_waits(
now the values of pending calls of these. */ now the values of pending calls of these. */
fprintf(stderr, fprintf(stderr,
"InnoDB: Pending preads %lu, pwrites %lu\n", "InnoDB: Pending reads " UINT64PF
(ulong) os_n_pending_reads, ", writes " UINT64PF "\n",
(ulong) os_n_pending_writes); MONITOR_VALUE(MONITOR_OS_PENDING_READS),
MONITOR_VALUE(MONITOR_OS_PENDING_WRITES));
srv_print_innodb_monitor = TRUE; srv_print_innodb_monitor = TRUE;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment