X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/527f99514973766e9c0382a4d8550dfb00f54939..a39ff7e25e19b3a8c3020042a3872ca9ec9659f1:/osfmk/arm64/platform_tests.c?ds=inline diff --git a/osfmk/arm64/platform_tests.c b/osfmk/arm64/platform_tests.c index d5391b327..61b627419 100644 --- a/osfmk/arm64/platform_tests.c +++ b/osfmk/arm64/platform_tests.c @@ -425,6 +425,7 @@ static kern_return_t lt_test_trylocks() { boolean_t success; + extern unsigned int real_ncpus; /* * First mtx try lock succeeds, second fails. @@ -512,9 +513,15 @@ lt_test_trylocks() lt_start_trylock_thread(lt_trylock_hw_lock_with_to); success = hw_lock_to(<_hw_lock, 100); T_ASSERT_NOTNULL(success, "First spin lock with timeout should succeed"); + if (real_ncpus == 1) { + mp_enable_preemption(); /* if we re-enable preemption, the other thread can timeout and exit */ + } OSIncrementAtomic((volatile SInt32*)<_thread_lock_grabbed); lt_wait_for_lock_test_threads(); T_ASSERT_NULL(lt_thread_lock_success, "Second spin lock with timeout should fail and timeout"); + if (real_ncpus == 1) { + mp_disable_preemption(); /* don't double-enable when we unlock */ + } hw_lock_unlock(<_hw_lock); lt_reset(); @@ -524,9 +531,15 @@ lt_test_trylocks() OSMemoryBarrier(); lt_start_trylock_thread(lt_trylock_hw_lock_with_to); hw_lock_lock(<_hw_lock); + if (real_ncpus == 1) { + mp_enable_preemption(); /* if we re-enable preemption, the other thread can timeout and exit */ + } OSIncrementAtomic((volatile SInt32*)<_thread_lock_grabbed); lt_wait_for_lock_test_threads(); T_ASSERT_NULL(lt_thread_lock_success, "after taking a spin lock, lock attempt with timeout should fail"); + if (real_ncpus == 1) { + mp_disable_preemption(); /* don't double-enable when we unlock */ + } hw_lock_unlock(<_hw_lock); success = lck_spin_try_lock(<_lck_spin_t); @@ -541,9 +554,15 @@ lt_test_trylocks() lt_target_done_threads = 1; lt_start_trylock_thread(lt_trylock_spin_try_lock); lck_spin_lock(<_lck_spin_t); + if (real_ncpus == 1) { + mp_enable_preemption(); /* if we re-enable preemption, the other thread can timeout and exit */ + } OSIncrementAtomic((volatile SInt32*)<_thread_lock_grabbed); lt_wait_for_lock_test_threads(); T_ASSERT_NULL(lt_thread_lock_success, "spin trylock attempt of previously held lock should fail"); + if (real_ncpus == 1) { + mp_disable_preemption(); /* don't double-enable when we unlock */ + } lck_spin_unlock(<_lck_spin_t); return KERN_SUCCESS;