Commit 98dc4142 authored by unknown's avatar unknown

InnoDB: Some low-level optimizations made based on OProfile results.


innobase/dict/dict0mem.c:
  dict_mem_table_create(): Add a debug assertion.
innobase/include/btr0btr.ic:
  btr_node_ptr_get_child_page_no(): Add a UNIV_UNLIKELY hint.
  Remove a buf_frame_align() call.
innobase/include/btr0cur.ic:
  btr_cur_get_page(): Add a debug assertion.
innobase/include/buf0buf.ic:
  buf_block_peek_if_too_old(): Replace if() with return().
  buf_block_align(), buf_frame_align(): Add UNIV_UNLIKELY hints.
innobase/include/data0type.ic:
  dtype_get_fixed_size(): Add UNIV_UNLIKELY hints.
innobase/include/mem0mem.ic:
  Remove signedness warning in debug assertion.
innobase/include/read0read.ic:
  read_view_sees_trx_id(): Eliminate a comparison inside loop.
innobase/include/row0sel.ic:
  open_step(): Add UNIV_EXPECT hint.
innobase/include/row0upd.ic:
  upd_field_set_field_no(): Add a UNIV_UNLIKELY hint.
innobase/include/sync0rw.ic:
  Add UNIV_LIKELY and UNIV_UNLIKELY hints.
  rw_lock_x_lock_func_nowait(): Eliminate a function call.
  Replace ut_a() assertions with ut_ad().
innobase/include/trx0rseg.ic:
  Add UNIV_UNLIKELY hints.
innobase/include/ut0rnd.ic:
  ut_fold_binary(): Eliminate a loop variable
  to avoid register spilling on x86.
parent f2c13c3f
...@@ -42,6 +42,7 @@ dict_mem_table_create( ...@@ -42,6 +42,7 @@ dict_mem_table_create(
mem_heap_t* heap; mem_heap_t* heap;
ut_ad(name); ut_ad(name);
ut_ad(comp == FALSE || comp == TRUE);
heap = mem_heap_create(DICT_HEAP_SIZE); heap = mem_heap_create(DICT_HEAP_SIZE);
......
...@@ -200,10 +200,10 @@ btr_node_ptr_get_child_page_no( ...@@ -200,10 +200,10 @@ btr_node_ptr_get_child_page_no(
page_no = mach_read_from_4(field); page_no = mach_read_from_4(field);
if (page_no == 0) { if (UNIV_UNLIKELY(page_no == 0)) {
fprintf(stderr, fprintf(stderr,
"InnoDB: a nonsensical page number 0 in a node ptr record at offset %lu\n", "InnoDB: a nonsensical page number 0 in a node ptr record at offset %lu\n",
(unsigned long)(rec - buf_frame_align(rec))); (ulong) ut_align_offset(rec, UNIV_PAGE_SIZE));
buf_page_print(buf_frame_align(rec)); buf_page_print(buf_frame_align(rec));
} }
......
...@@ -52,7 +52,9 @@ btr_cur_get_page( ...@@ -52,7 +52,9 @@ btr_cur_get_page(
/* out: pointer to page */ /* out: pointer to page */
btr_cur_t* cursor) /* in: tree cursor */ btr_cur_t* cursor) /* in: tree cursor */
{ {
return(buf_frame_align(page_cur_get_rec(&(cursor->page_cur)))); page_t* page = buf_frame_align(page_cur_get_rec(&(cursor->page_cur)));
ut_ad(!!page_is_comp(page) == cursor->index->table->comp);
return(page);
} }
/************************************************************* /*************************************************************
......
...@@ -26,12 +26,8 @@ buf_block_peek_if_too_old( ...@@ -26,12 +26,8 @@ buf_block_peek_if_too_old(
/* out: TRUE if should be made younger */ /* out: TRUE if should be made younger */
buf_block_t* block) /* in: block to make younger */ buf_block_t* block) /* in: block to make younger */
{ {
if (buf_pool->freed_page_clock >= block->freed_page_clock return(buf_pool->freed_page_clock >= block->freed_page_clock
+ 1 + (buf_pool->curr_size / 1024)) { + 1 + (buf_pool->curr_size / 1024));
return(TRUE);
}
return(FALSE);
} }
/************************************************************************* /*************************************************************************
...@@ -210,8 +206,8 @@ buf_block_align( ...@@ -210,8 +206,8 @@ buf_block_align(
frame_zero = buf_pool->frame_zero; frame_zero = buf_pool->frame_zero;
if ((ulint)ptr < (ulint)frame_zero if (UNIV_UNLIKELY((ulint)ptr < (ulint)frame_zero)
|| (ulint)ptr > (ulint)(buf_pool->high_end)) { || UNIV_UNLIKELY((ulint)ptr > (ulint)(buf_pool->high_end))) {
ut_print_timestamp(stderr); ut_print_timestamp(stderr);
fprintf(stderr, fprintf(stderr,
...@@ -246,8 +242,8 @@ buf_frame_align( ...@@ -246,8 +242,8 @@ buf_frame_align(
frame = ut_align_down(ptr, UNIV_PAGE_SIZE); frame = ut_align_down(ptr, UNIV_PAGE_SIZE);
if (((ulint)frame < (ulint)(buf_pool->frame_zero)) if (UNIV_UNLIKELY((ulint)frame < (ulint)(buf_pool->frame_zero))
|| (ulint)frame >= (ulint)(buf_pool->high_end)) { || UNIV_UNLIKELY((ulint)frame >= (ulint)(buf_pool->high_end))) {
ut_print_timestamp(stderr); ut_print_timestamp(stderr);
fprintf(stderr, fprintf(stderr,
......
...@@ -388,8 +388,8 @@ dtype_get_fixed_size( ...@@ -388,8 +388,8 @@ dtype_get_fixed_size(
dtype_get_charset_coll(type->prtype), dtype_get_charset_coll(type->prtype),
&mbminlen, &mbmaxlen); &mbminlen, &mbmaxlen);
if (type->mbminlen != mbminlen if (UNIV_UNLIKELY(type->mbminlen != mbminlen)
|| type->mbmaxlen != mbmaxlen) { || UNIV_UNLIKELY(type->mbmaxlen != mbmaxlen)) {
ut_print_timestamp(stderr); ut_print_timestamp(stderr);
fprintf(stderr, " InnoDB: " fprintf(stderr, " InnoDB: "
......
...@@ -623,7 +623,7 @@ mem_strdupq( ...@@ -623,7 +623,7 @@ mem_strdupq(
} }
*d++ = q; *d++ = q;
*d++ = '\0'; *d++ = '\0';
ut_ad(len == d - dst); ut_ad((ssize_t) len == d - dst);
return(dst); return(dst);
} }
......
...@@ -71,13 +71,8 @@ read_view_sees_trx_id( ...@@ -71,13 +71,8 @@ read_view_sees_trx_id(
cmp = ut_dulint_cmp(trx_id, cmp = ut_dulint_cmp(trx_id,
read_view_get_nth_trx_id(view, n_ids - i - 1)); read_view_get_nth_trx_id(view, n_ids - i - 1));
if (0 == cmp) { if (cmp <= 0) {
return(cmp < 0);
return(FALSE);
} else if (cmp < 0) {
return(TRUE);
} }
} }
......
...@@ -75,7 +75,7 @@ open_step( ...@@ -75,7 +75,7 @@ open_step(
} }
} }
if (err != DB_SUCCESS) { if (UNIV_EXPECT(err, DB_SUCCESS) != DB_SUCCESS) {
/* SQL error detected */ /* SQL error detected */
fprintf(stderr, "SQL error %lu\n", (ulong) err); fprintf(stderr, "SQL error %lu\n", (ulong) err);
......
...@@ -83,7 +83,7 @@ upd_field_set_field_no( ...@@ -83,7 +83,7 @@ upd_field_set_field_no(
{ {
upd_field->field_no = field_no; upd_field->field_no = field_no;
if (field_no >= dict_index_get_n_fields(index)) { if (UNIV_UNLIKELY(field_no >= dict_index_get_n_fields(index))) {
fprintf(stderr, fprintf(stderr,
"InnoDB: Error: trying to access field %lu in ", "InnoDB: Error: trying to access field %lu in ",
(ulong) field_no); (ulong) field_no);
......
...@@ -138,7 +138,7 @@ rw_lock_s_lock_low( ...@@ -138,7 +138,7 @@ rw_lock_s_lock_low(
#endif /* UNIV_SYNC_DEBUG */ #endif /* UNIV_SYNC_DEBUG */
/* Check if the writer field is free */ /* Check if the writer field is free */
if (lock->writer == RW_LOCK_NOT_LOCKED) { if (UNIV_LIKELY(lock->writer == RW_LOCK_NOT_LOCKED)) {
/* Set the shared lock by incrementing the reader count */ /* Set the shared lock by incrementing the reader count */
lock->reader_count++; lock->reader_count++;
...@@ -243,7 +243,7 @@ rw_lock_s_lock_func( ...@@ -243,7 +243,7 @@ rw_lock_s_lock_func(
mutex_enter(rw_lock_get_mutex(lock)); mutex_enter(rw_lock_get_mutex(lock));
if (TRUE == rw_lock_s_lock_low(lock, pass, file_name, line)) { if (UNIV_LIKELY(rw_lock_s_lock_low(lock, pass, file_name, line))) {
mutex_exit(rw_lock_get_mutex(lock)); mutex_exit(rw_lock_get_mutex(lock));
return; /* Success */ return; /* Success */
...@@ -308,20 +308,17 @@ rw_lock_x_lock_func_nowait( ...@@ -308,20 +308,17 @@ rw_lock_x_lock_func_nowait(
ulint line) /* in: line where requested */ ulint line) /* in: line where requested */
{ {
ibool success = FALSE; ibool success = FALSE;
os_thread_id_t curr_thread = os_thread_get_curr_id();
mutex_enter(rw_lock_get_mutex(lock)); mutex_enter(rw_lock_get_mutex(lock));
if ((rw_lock_get_reader_count(lock) == 0) if (UNIV_UNLIKELY(rw_lock_get_reader_count(lock) != 0)) {
&& ((rw_lock_get_writer(lock) == RW_LOCK_NOT_LOCKED) } else if (UNIV_LIKELY(rw_lock_get_writer(lock)
|| ((rw_lock_get_writer(lock) == RW_LOCK_EX) == RW_LOCK_NOT_LOCKED)) {
&& (lock->pass == 0)
&& os_thread_eq(lock->writer_thread,
os_thread_get_curr_id())))) {
rw_lock_set_writer(lock, RW_LOCK_EX); rw_lock_set_writer(lock, RW_LOCK_EX);
lock->writer_thread = os_thread_get_curr_id(); lock->writer_thread = curr_thread;
lock->writer_count++;
lock->pass = 0; lock->pass = 0;
relock:
lock->writer_count++;
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
rw_lock_add_debug_info(lock, 0, RW_LOCK_EX, file_name, line); rw_lock_add_debug_info(lock, 0, RW_LOCK_EX, file_name, line);
...@@ -331,6 +328,10 @@ rw_lock_x_lock_func_nowait( ...@@ -331,6 +328,10 @@ rw_lock_x_lock_func_nowait(
lock->last_x_line = line; lock->last_x_line = line;
success = TRUE; success = TRUE;
} else if (rw_lock_get_writer(lock) == RW_LOCK_EX
&& lock->pass == 0
&& os_thread_eq(lock->writer_thread, curr_thread)) {
goto relock;
} }
mutex_exit(rw_lock_get_mutex(lock)); mutex_exit(rw_lock_get_mutex(lock));
...@@ -361,7 +362,7 @@ rw_lock_s_unlock_func( ...@@ -361,7 +362,7 @@ rw_lock_s_unlock_func(
/* Reset the shared lock by decrementing the reader count */ /* Reset the shared lock by decrementing the reader count */
ut_a(lock->reader_count > 0); ut_ad(lock->reader_count > 0);
lock->reader_count--; lock->reader_count--;
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
...@@ -371,7 +372,8 @@ rw_lock_s_unlock_func( ...@@ -371,7 +372,8 @@ rw_lock_s_unlock_func(
/* If there may be waiters and this was the last s-lock, /* If there may be waiters and this was the last s-lock,
signal the object */ signal the object */
if (lock->waiters && (lock->reader_count == 0)) { if (UNIV_UNLIKELY(lock->waiters)
&& lock->reader_count == 0) {
sg = TRUE; sg = TRUE;
rw_lock_set_waiters(lock, 0); rw_lock_set_waiters(lock, 0);
...@@ -379,7 +381,7 @@ rw_lock_s_unlock_func( ...@@ -379,7 +381,7 @@ rw_lock_s_unlock_func(
mutex_exit(mutex); mutex_exit(mutex);
if (sg == TRUE) { if (UNIV_UNLIKELY(sg)) {
sync_array_signal_object(sync_primary_wait_array, lock); sync_array_signal_object(sync_primary_wait_array, lock);
} }
...@@ -450,7 +452,8 @@ rw_lock_x_unlock_func( ...@@ -450,7 +452,8 @@ rw_lock_x_unlock_func(
#endif #endif
/* If there may be waiters, signal the lock */ /* If there may be waiters, signal the lock */
if (lock->waiters && (lock->writer_count == 0)) { if (UNIV_UNLIKELY(lock->waiters)
&& lock->writer_count == 0) {
sg = TRUE; sg = TRUE;
rw_lock_set_waiters(lock, 0); rw_lock_set_waiters(lock, 0);
...@@ -458,7 +461,7 @@ rw_lock_x_unlock_func( ...@@ -458,7 +461,7 @@ rw_lock_x_unlock_func(
mutex_exit(&(lock->mutex)); mutex_exit(&(lock->mutex));
if (sg == TRUE) { if (UNIV_UNLIKELY(sg)) {
sync_array_signal_object(sync_primary_wait_array, lock); sync_array_signal_object(sync_primary_wait_array, lock);
} }
......
...@@ -65,7 +65,7 @@ trx_rsegf_get_nth_undo( ...@@ -65,7 +65,7 @@ trx_rsegf_get_nth_undo(
ulint n, /* in: index of slot */ ulint n, /* in: index of slot */
mtr_t* mtr) /* in: mtr */ mtr_t* mtr) /* in: mtr */
{ {
if (n >= TRX_RSEG_N_SLOTS) { if (UNIV_UNLIKELY(n >= TRX_RSEG_N_SLOTS)) {
fprintf(stderr, fprintf(stderr,
"InnoDB: Error: trying to get slot %lu of rseg\n", (unsigned long) n); "InnoDB: Error: trying to get slot %lu of rseg\n", (unsigned long) n);
ut_error; ut_error;
...@@ -86,7 +86,7 @@ trx_rsegf_set_nth_undo( ...@@ -86,7 +86,7 @@ trx_rsegf_set_nth_undo(
ulint page_no,/* in: page number of the undo log segment */ ulint page_no,/* in: page number of the undo log segment */
mtr_t* mtr) /* in: mtr */ mtr_t* mtr) /* in: mtr */
{ {
if (n >= TRX_RSEG_N_SLOTS) { if (UNIV_UNLIKELY(n >= TRX_RSEG_N_SLOTS)) {
fprintf(stderr, fprintf(stderr,
"InnoDB: Error: trying to set slot %lu of rseg\n", (unsigned long) n); "InnoDB: Error: trying to set slot %lu of rseg\n", (unsigned long) n);
ut_error; ut_error;
......
...@@ -207,12 +207,12 @@ ut_fold_binary( ...@@ -207,12 +207,12 @@ ut_fold_binary(
const byte* str, /* in: string of bytes */ const byte* str, /* in: string of bytes */
ulint len) /* in: length */ ulint len) /* in: length */
{ {
ulint i; const byte* str_end = str + len;
ulint fold = 0; ulint fold = 0;
ut_ad(str); ut_ad(str);
for (i = 0; i < len; i++) { while (str < str_end) {
fold = ut_fold_ulint_pair(fold, (ulint)(*str)); fold = ut_fold_ulint_pair(fold, (ulint)(*str));
str++; str++;
......
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