Skip to content

Commit 7bbd8bc

Browse files
montywisvoj
authored andcommitted
Added VALGRIND_YIELD to be able to abort from busy loops
Valgrind is single threaded and only changes threads as part of system calls or waits. I found some busy loops where the server assumes that some other thread will change the state, which will not happen with valgrind. Added VALGRIND_YIELD to the loops, which calls pthread_yield() if HAVE_VALGRIND is defined. Added pthread_yield() to the loops in table_cache. We should consider changing some of the VALGRIND_YIELD calls to call pthread_yield() as busy loop without any sleep() is usually a bad thing. Reviewer: [email protected]
1 parent 05813f5 commit 7bbd8bc

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

include/my_valgrind.h

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
# else
4343
# define MSAN_STAT_WORKAROUND(st) ((void) 0)
4444
# endif
45+
# define VALGRIND_YIELD
4546
#elif defined(HAVE_VALGRIND_MEMCHECK_H) && defined(HAVE_valgrind)
4647
# include <valgrind/memcheck.h>
4748
# define HAVE_MEM_CHECK
@@ -55,6 +56,7 @@
5556
# define MEM_SET_VBITS(a,b,len) VALGRIND_SET_VBITS(a,b,len)
5657
# define REDZONE_SIZE 8
5758
# define MSAN_STAT_WORKAROUND(st) ((void) 0)
59+
# define VALGRIND_YIELD pthread_yield()
5860
#elif defined(__SANITIZE_ADDRESS__) && (!defined(_MSC_VER) || defined (__clang__))
5961
# include <sanitizer/asan_interface.h>
6062
/* How to do manual poisoning:
@@ -70,6 +72,7 @@
7072
# define MEM_SET_VBITS(a,b,len) ((void) 0)
7173
# define MSAN_STAT_WORKAROUND(st) ((void) 0)
7274
# define REDZONE_SIZE 8
75+
# define VALGRIND_YIELD
7376
#else
7477
# define MEM_UNDEFINED(a,len) ((void) 0)
7578
# define MEM_MAKE_ADDRESSABLE(a,len) ((void) 0)
@@ -81,6 +84,7 @@
8184
# define MEM_SET_VBITS(a,b,len) ((void) 0)
8285
# define REDZONE_SIZE 0
8386
# define MSAN_STAT_WORKAROUND(st) ((void) 0)
87+
# define VALGRIND_YIELD
8488
#endif /* __has_feature(memory_sanitizer) */
8589

8690
#ifdef TRASH_FREED_MEMORY

sql/sql_base.cc

+2
Original file line numberDiff line numberDiff line change
@@ -4690,6 +4690,7 @@ bool open_tables(THD *thd, const DDL_options_st &options,
46904690
goto error;
46914691

46924692
error= FALSE;
4693+
pthread_yield();
46934694
goto restart;
46944695
}
46954696
goto error;
@@ -4755,6 +4756,7 @@ bool open_tables(THD *thd, const DDL_options_st &options,
47554756

47564757
error= FALSE;
47574758
sroutine_to_open= &thd->lex->sroutines_list.first;
4759+
pthread_yield();
47584760
goto restart;
47594761
}
47604762
/*

sql/table_cache.cc

+1
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ TABLE_SHARE *tdc_acquire_share(THD *thd, TABLE_LIST *tl, uint flags,
901901
{
902902
mysql_mutex_unlock(&element->LOCK_table_share);
903903
lf_hash_search_unpin(thd->tdc_hash_pins);
904+
VALGRIND_YIELD;
904905
goto retry;
905906
}
906907
lf_hash_search_unpin(thd->tdc_hash_pins);

storage/innobase/trx/trx0purge.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ dict_table_t *purge_sys_t::close_and_reopen(table_id_t id, THD *thd,
11771177
MDL_context *mdl_context= static_cast<MDL_context*>(thd_mdl_context(thd));
11781178
ut_ad(mdl_context);
11791179
retry:
1180+
VALGRIND_YIELD;
11801181
ut_ad(m_active);
11811182

11821183
for (que_thr_t *thr= UT_LIST_GET_FIRST(purge_sys.query->thrs); thr;

0 commit comments

Comments
 (0)