Skip to content

Commit a8eeffb

Browse files
committed
MDEV-18030 waiting_threads-t is disabled
enabled. updated to use mysql_* pthread wrappers. reduced the number of iterations to finish in mtr-appropriate time
1 parent aedc65f commit a8eeffb

File tree

4 files changed

+48
-51
lines changed

4 files changed

+48
-51
lines changed

unittest/mysys/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
# along with this program; if not, write to the Free Software
1414
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
1515

16-
MY_ADD_TESTS(bitmap base64 my_atomic my_rdtsc lf my_malloc my_getopt dynstring
17-
byte_order
18-
queues stacktrace stack_allocation crc32 LINK_LIBRARIES mysys)
16+
MY_ADD_TESTS(base64 bitmap byte_order crc32 dynstring lf my_atomic my_getopt
17+
my_malloc my_rdtsc queues stack_allocation stacktrace waiting_threads
18+
LINK_LIBRARIES mysys)
1919
MY_ADD_TESTS(my_vsnprintf LINK_LIBRARIES strings mysys)
20-
MY_ADD_TESTS(aes LINK_LIBRARIES mysys mysys_ssl)
2120
ADD_DEFINITIONS(${SSL_DEFINES})
21+
MY_ADD_TESTS(aes LINK_LIBRARIES mysys mysys_ssl)
2222
INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS})
2323
MY_ADD_TESTS(ma_dyncol LINK_LIBRARIES mysys)
2424

unittest/mysys/lf-t.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pthread_handler_t test_lf_alloc(void *arg)
9191
lf_alloc_free(pins, node2);
9292
}
9393
lf_alloc_put_pins(pins);
94-
pthread_mutex_lock(&mutex);
94+
mysql_mutex_lock(&mutex);
9595
bad+= y;
9696

9797
if (--N == 0)
@@ -102,7 +102,7 @@ pthread_handler_t test_lf_alloc(void *arg)
102102
bad|= lf_allocator.mallocs - lf_alloc_pool_count(&lf_allocator);
103103
#endif
104104
}
105-
pthread_mutex_unlock(&mutex);
105+
mysql_mutex_unlock(&mutex);
106106

107107
if (with_my_thread_init)
108108
my_thread_end();
@@ -157,7 +157,7 @@ pthread_handler_t test_lf_hash(void *arg)
157157
}
158158
}
159159
lf_hash_put_pins(pins);
160-
pthread_mutex_lock(&mutex);
160+
mysql_mutex_lock(&mutex);
161161
bad+= sum;
162162
inserts+= ins;
163163

@@ -168,7 +168,7 @@ pthread_handler_t test_lf_hash(void *arg)
168168
lf_hash.size, inserts, scans);
169169
bad|= lf_hash.count;
170170
}
171-
pthread_mutex_unlock(&mutex);
171+
mysql_mutex_unlock(&mutex);
172172
if (with_my_thread_init)
173173
my_thread_end();
174174
return 0;

unittest/mysys/thr_template.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <tap.h>
2020

2121
volatile uint32 bad;
22-
pthread_mutex_t mutex;
22+
mysql_mutex_t mutex;
2323

2424
void do_tests();
2525

@@ -57,7 +57,7 @@ int main(int argc __attribute__((unused)), char **argv)
5757
if (argv[1] && *argv[1])
5858
DBUG_SET_INITIAL(argv[1]);
5959

60-
pthread_mutex_init(&mutex, 0);
60+
mysql_mutex_init(PSI_NOT_INSTRUMENTED, &mutex, 0);
6161

6262
#define CYCLES 30000
6363
#define THREADS 30
@@ -66,7 +66,7 @@ int main(int argc __attribute__((unused)), char **argv)
6666

6767
do_tests();
6868

69-
pthread_mutex_destroy(&mutex);
69+
mysql_mutex_destroy(&mutex);
7070
my_end(0);
7171
return exit_status();
7272
}

unittest/mysys/waiting_threads-t.c

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
#include "thr_template.c"
1717
#include <waiting_threads.h>
1818
#include <m_string.h>
19+
#include <my_rnd.h>
1920

2021
struct test_wt_thd {
2122
WT_THD thd;
22-
pthread_mutex_t lock;
23+
mysql_mutex_t lock;
2324
} thds[THREADS];
2425

2526
uint i, cnt;
26-
pthread_mutex_t lock;
27-
pthread_cond_t thread_sync;
27+
mysql_mutex_t lock;
28+
mysql_cond_t thread_sync;
2829

2930
ulong wt_timeout_short=100, wt_deadlock_search_depth_short=4;
3031
ulong wt_timeout_long=10000, wt_deadlock_search_depth_long=15;
@@ -49,19 +50,19 @@ pthread_handler_t test_wt(void *arg)
4950

5051
my_thread_init();
5152

52-
pthread_mutex_lock(&mutex);
53+
mysql_mutex_lock(&mutex);
5354
id= cnt++;
5455
wt_thd_lazy_init(& thds[id].thd,
5556
& wt_deadlock_search_depth_short, & wt_timeout_short,
5657
& wt_deadlock_search_depth_long, & wt_timeout_long);
5758

5859
/* now, wait for everybody to be ready to run */
5960
if (cnt >= THREADS)
60-
pthread_cond_broadcast(&thread_sync);
61+
mysql_cond_broadcast(&thread_sync);
6162
else
6263
while (cnt < THREADS)
63-
pthread_cond_wait(&thread_sync, &mutex);
64-
pthread_mutex_unlock(&mutex);
64+
mysql_cond_wait(&thread_sync, &mutex);
65+
mysql_mutex_unlock(&mutex);
6566

6667
my_rnd_init(&rand, (ulong)(intptr)&m, id);
6768
if (kill_strategy == YOUNGEST)
@@ -72,7 +73,7 @@ pthread_handler_t test_wt(void *arg)
7273
for (m= *(int *)arg; m ; m--)
7374
{
7475
WT_RESOURCE_ID resid;
75-
int blockers[THREADS/10], j, k;
76+
int blockers[THREADS/10]={0}, j, k;
7677

7778
resid.value= id;
7879
resid.type= &restype;
@@ -94,25 +95,25 @@ pthread_handler_t test_wt(void *arg)
9495
if (kill_strategy == RANDOM)
9596
thds[id].thd.weight= rnd();
9697

97-
pthread_mutex_lock(& thds[i].lock);
98+
mysql_mutex_lock(& thds[i].lock);
9899
res= wt_thd_will_wait_for(& thds[id].thd, & thds[i].thd, &resid);
99-
pthread_mutex_unlock(& thds[i].lock);
100+
mysql_mutex_unlock(& thds[i].lock);
100101
}
101102

102103
if (!res)
103104
{
104-
pthread_mutex_lock(&lock);
105+
mysql_mutex_lock(&lock);
105106
res= wt_thd_cond_timedwait(& thds[id].thd, &lock);
106-
pthread_mutex_unlock(&lock);
107+
mysql_mutex_unlock(&lock);
107108
}
108109

109110
if (res)
110111
{
111-
pthread_mutex_lock(& thds[id].lock);
112-
pthread_mutex_lock(&lock);
112+
mysql_mutex_lock(& thds[id].lock);
113+
mysql_mutex_lock(&lock);
113114
wt_thd_release_all(& thds[id].thd);
114-
pthread_mutex_unlock(&lock);
115-
pthread_mutex_unlock(& thds[id].lock);
115+
mysql_mutex_unlock(&lock);
116+
mysql_mutex_unlock(& thds[id].lock);
116117
if (kill_strategy == LOCKS)
117118
thds[id].thd.weight= 0;
118119
if (kill_strategy == YOUNGEST)
@@ -122,21 +123,21 @@ pthread_handler_t test_wt(void *arg)
122123
thds[id].thd.weight++;
123124
}
124125

125-
pthread_mutex_lock(&mutex);
126+
mysql_mutex_lock(&mutex);
126127
/* wait for everybody to finish */
127128
if (!--cnt)
128-
pthread_cond_broadcast(&thread_sync);
129+
mysql_cond_broadcast(&thread_sync);
129130
else
130131
while (cnt)
131-
pthread_cond_wait(&thread_sync, &mutex);
132+
mysql_cond_wait(&thread_sync, &mutex);
132133

133-
pthread_mutex_lock(& thds[id].lock);
134-
pthread_mutex_lock(&lock);
134+
mysql_mutex_lock(& thds[id].lock);
135+
mysql_mutex_lock(&lock);
135136
wt_thd_release_all(& thds[id].thd);
136-
pthread_mutex_unlock(&lock);
137-
pthread_mutex_unlock(& thds[id].lock);
137+
mysql_mutex_unlock(&lock);
138+
mysql_mutex_unlock(& thds[id].lock);
138139
wt_thd_destroy(& thds[id].thd);
139-
pthread_mutex_unlock(&mutex);
140+
mysql_mutex_unlock(&mutex);
140141

141142
DBUG_PRINT("wt", ("exiting"));
142143
my_thread_end();
@@ -152,7 +153,8 @@ void do_one_test()
152153
reset(wt_wait_stats);
153154
wt_success_stats=0;
154155
cnt=0;
155-
test_concurrently("waiting_threads", test_wt, THREADS, CYCLES);
156+
test_concurrently("waiting_threads", test_wt, THREADS,
157+
CYCLES/(skip_big_tests?500:10));
156158

157159
sum=sum0=0;
158160
for (cnt=0; cnt < WT_CYCLE_STATS; cnt++)
@@ -179,21 +181,16 @@ void do_one_test()
179181
void do_tests()
180182
{
181183
DBUG_ENTER("do_tests");
182-
if (skip_big_tests)
183-
{
184-
skip(1, "Big test skipped");
185-
return;
186-
}
187184
plan(13);
188185
compile_time_assert(THREADS >= 4);
189186

190187
DBUG_PRINT("wt", ("================= initialization ==================="));
191188

192-
pthread_cond_init(&thread_sync, 0);
193-
pthread_mutex_init(&lock, 0);
189+
mysql_cond_init(PSI_NOT_INSTRUMENTED, &thread_sync, 0);
190+
mysql_mutex_init(PSI_NOT_INSTRUMENTED, &lock, 0);
194191
wt_init();
195192
for (cnt=0; cnt < THREADS; cnt++)
196-
pthread_mutex_init(& thds[cnt].lock, 0);
193+
mysql_mutex_init(PSI_NOT_INSTRUMENTED, & thds[cnt].lock, 0);
197194
{
198195
WT_RESOURCE_ID resid[4];
199196
for (i=0; i < array_elements(resid); i++)
@@ -218,16 +215,16 @@ void do_tests()
218215
ok_wait(0,2,0);
219216
ok_wait(0,3,0);
220217

221-
pthread_mutex_lock(&lock);
218+
mysql_mutex_lock(&lock);
222219
bad= wt_thd_cond_timedwait(& thds[0].thd, &lock);
223-
pthread_mutex_unlock(&lock);
220+
mysql_mutex_unlock(&lock);
224221
ok(bad == WT_TIMEOUT, "timeout test returned %d", bad);
225222

226223
ok_wait(0,1,0);
227224
ok_wait(1,2,1);
228225
ok_deadlock(2,0,2);
229226

230-
pthread_mutex_lock(&lock);
227+
mysql_mutex_lock(&lock);
231228
ok(wt_thd_cond_timedwait(& thds[0].thd, &lock) == WT_TIMEOUT, "as always");
232229
ok(wt_thd_cond_timedwait(& thds[1].thd, &lock) == WT_TIMEOUT, "as always");
233230
wt_thd_release_all(& thds[0].thd);
@@ -240,7 +237,7 @@ void do_tests()
240237
wt_thd_release_all(& thds[i].thd);
241238
wt_thd_destroy(& thds[i].thd);
242239
}
243-
pthread_mutex_unlock(&lock);
240+
mysql_mutex_unlock(&lock);
244241
}
245242

246243
wt_deadlock_search_depth_short=6;
@@ -277,10 +274,10 @@ void do_tests()
277274

278275
DBUG_PRINT("wt", ("================= cleanup ==================="));
279276
for (cnt=0; cnt < THREADS; cnt++)
280-
pthread_mutex_destroy(& thds[cnt].lock);
277+
mysql_mutex_destroy(& thds[cnt].lock);
281278
wt_end();
282-
pthread_mutex_destroy(&lock);
283-
pthread_cond_destroy(&thread_sync);
279+
mysql_mutex_destroy(&lock);
280+
mysql_cond_destroy(&thread_sync);
284281
DBUG_VOID_RETURN;
285282
}
286283

0 commit comments

Comments
 (0)