Lines Matching +full:cycle +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Module-based API test facility for ww_mutexes
22 (a)->deadlock_inject_countdown = ~0U; \
36 #define TEST_MTX_TRY BIT(1)
44 complete(&mtx->ready);
45 wait_for_completion(&mtx->go);
47 if (mtx->flags & TEST_MTX_TRY) {
48 while (!ww_mutex_trylock(&mtx->mutex, NULL))
51 ww_mutex_lock(&mtx->mutex, NULL);
53 complete(&mtx->done);
54 ww_mutex_unlock(&mtx->mutex);
85 ret = -EINVAL;
100 ret = -EINVAL;
150 ret = -EINVAL;
157 ret = -EINVAL;
162 if (ret != -EALREADY) {
167 ret = -EINVAL;
195 if (!abba->trylock)
196 ww_mutex_lock(&abba->b_mutex, &ctx);
198 WARN_ON(!ww_mutex_trylock(&abba->b_mutex, &ctx));
200 WARN_ON(READ_ONCE(abba->b_mutex.ctx) != &ctx);
202 complete(&abba->b_ready);
203 wait_for_completion(&abba->a_ready);
205 err = ww_mutex_lock(&abba->a_mutex, &ctx);
206 if (abba->resolve && err == -EDEADLK) {
207 ww_mutex_unlock(&abba->b_mutex);
208 ww_mutex_lock_slow(&abba->a_mutex, &ctx);
209 err = ww_mutex_lock(&abba->b_mutex, &ctx);
213 ww_mutex_unlock(&abba->a_mutex);
214 ww_mutex_unlock(&abba->b_mutex);
217 abba->result = err;
248 if (resolve && err == -EDEADLK) {
267 ret = -EINVAL;
270 if (err != -EDEADLK && abba.result != -EDEADLK) {
273 ret = -EINVAL;
290 struct test_cycle *cycle = container_of(work, typeof(*cycle), work);
295 ww_mutex_lock(&cycle->a_mutex, &ctx);
297 complete(cycle->a_signal);
298 wait_for_completion(&cycle->b_signal);
300 err = ww_mutex_lock(cycle->b_mutex, &ctx);
301 if (err == -EDEADLK) {
303 ww_mutex_unlock(&cycle->a_mutex);
304 ww_mutex_lock_slow(cycle->b_mutex, &ctx);
305 erra = ww_mutex_lock(&cycle->a_mutex, &ctx);
309 ww_mutex_unlock(cycle->b_mutex);
311 ww_mutex_unlock(&cycle->a_mutex);
314 cycle->result = err ?: erra;
320 unsigned int n, last = nthreads - 1;
325 return -ENOMEM;
328 struct test_cycle *cycle = &cycles[n];
330 ww_mutex_init(&cycle->a_mutex, &ww_class);
332 cycle->b_mutex = &cycles[0].a_mutex;
334 cycle->b_mutex = &cycles[n + 1].a_mutex;
337 cycle->a_signal = &cycles[last].b_signal;
339 cycle->a_signal = &cycles[n - 1].b_signal;
340 init_completion(&cycle->b_signal);
342 INIT_WORK(&cycle->work, test_cycle_work);
343 cycle->result = 0;
353 struct test_cycle *cycle = &cycles[n];
355 if (!cycle->result)
359 n, nthreads, cycle->result);
360 ret = -EINVAL;
375 for (n = 2; n <= ncpus + 1; n++) {
416 for (n = count - 1; n > 1; n--) {
417 r = prandom_u32_below(n + 1);
433 const int nlocks = stress->nlocks;
434 struct ww_mutex *locks = stress->locks;
443 int contended = -1;
463 while (n--)
466 if (err == -EDEADLK) {
467 if (!time_after(jiffies, stress->timeout)) {
479 } while (!time_after(jiffies, stress->timeout));
498 order = get_random_order(stress->nlocks);
502 for (n = 0; n < stress->nlocks; n++) {
507 ll->lock = &stress->locks[order[n]];
508 list_add(&ll->link, &locks);
517 err = ww_mutex_lock(ll->lock, &ctx);
523 ww_mutex_unlock(ln->lock);
525 if (err != -EDEADLK) {
531 ww_mutex_lock_slow(ll->lock, &ctx);
532 list_move(&ll->link, &locks); /* restarts iteration */
537 ww_mutex_unlock(ll->lock);
540 } while (!time_after(jiffies, stress->timeout));
551 const int nlocks = stress->nlocks;
552 struct ww_mutex *lock = stress->locks + get_random_u32_below(nlocks);
565 } while (!time_after(jiffies, stress->timeout));
569 #define STRESS_REORDER BIT(1)
581 return -ENOMEM;
587 return -ENOMEM;
604 case 1:
619 INIT_WORK(&stress->work, fn);
620 stress->locks = locks;
621 stress->nlocks = nlocks;
622 stress->timeout = jiffies + 2*HZ;
624 queue_work(wq, &stress->work);
625 nthreads--;
647 wq = alloc_workqueue("test-ww_mutex", WQ_UNBOUND, 0);
649 return -ENOMEM;
664 ret = test_abba(i & 1, i & 2);