├── .clang-format ├── .cmake-format ├── .github └── workflows │ └── actions.yml ├── .gitignore ├── CHANGELOG.md ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake ├── check.cmake ├── config.cmake.in ├── export.cmake ├── lotto_test.cmake └── v_add_test.cmake ├── doc ├── api │ └── vsync │ │ ├── GROUP_linearizable.md │ │ ├── GROUP_lock_free.md │ │ ├── GROUP_requires_smr.md │ │ ├── README.md │ │ ├── atomic.h.md │ │ ├── atomic │ │ ├── README.md │ │ ├── atomicptr_markable.h.md │ │ ├── atomicptr_stamped.h.md │ │ ├── await.h.md │ │ ├── await_ptr.h.md │ │ ├── await_u32.h.md │ │ ├── await_u64.h.md │ │ ├── compat.h.md │ │ ├── config.h.md │ │ ├── core.h.md │ │ ├── core_ptr.h.md │ │ ├── core_sz.h.md │ │ ├── core_u16.h.md │ │ ├── core_u32.h.md │ │ ├── core_u64.h.md │ │ ├── core_u8.h.md │ │ └── dispatch.h.md │ │ ├── bitmap │ │ ├── README.md │ │ └── bitmap.h.md │ │ ├── map │ │ ├── README.md │ │ ├── hashtable_standard.h.md │ │ ├── listset_coarse.h.md │ │ ├── listset_fine.h.md │ │ ├── listset_lazy.h.md │ │ ├── listset_lf.h.md │ │ ├── listset_opt.h.md │ │ ├── simpleht.h.md │ │ ├── skiplist_lf.h.md │ │ ├── treeset_bst_coarse.h.md │ │ ├── treeset_bst_fine.h.md │ │ ├── treeset_rb_coarse.h.md │ │ └── treeset_rb_fine.h.md │ │ ├── pool │ │ ├── README.md │ │ └── cached_pool.h.md │ │ ├── queue │ │ ├── GROUP_unbounded_queue.md │ │ ├── README.md │ │ ├── bounded_locked.h.md │ │ ├── bounded_mpmc.h.md │ │ ├── bounded_spsc.h.md │ │ ├── cachedq.h.md │ │ ├── chaselev.h.md │ │ ├── unbounded_queue_lf.h.md │ │ ├── unbounded_queue_lf_recycle.h.md │ │ ├── unbounded_queue_total.h.md │ │ ├── vqueue_prio_heap_based.h.md │ │ ├── vqueue_prio_skiplist_based.h.md │ │ ├── vqueue_prio_stack_array_based.h.md │ │ └── vqueue_prio_stack_tree_based.h.md │ │ ├── smr │ │ ├── README.md │ │ └── ebr.h.md │ │ ├── spinlock │ │ ├── GROUP_numa_aware.md │ │ ├── README.md │ │ ├── arraylock.h.md │ │ ├── caslock.h.md │ │ ├── clhlock.h.md │ │ ├── cnalock.h.md │ │ ├── hclhlock.h.md │ │ ├── hemlock.h.md │ │ ├── hmcslock.h.md │ │ ├── mcslock.h.md │ │ ├── rec_mcslock.h.md │ │ ├── rec_seqlock.h.md │ │ ├── rec_spinlock.h.md │ │ ├── rec_ticketlock.h.md │ │ ├── rwlock.h.md │ │ ├── semaphore.h.md │ │ ├── seqcount.h.md │ │ ├── seqlock.h.md │ │ ├── ticketlock.h.md │ │ ├── ttaslock.h.md │ │ └── twalock.h.md │ │ ├── stack │ │ ├── README.md │ │ ├── elimination_stack.h.md │ │ ├── quack.h.md │ │ └── xbo_stack.h.md │ │ └── thread │ │ ├── README.md │ │ ├── cond.h.md │ │ ├── mutex.h.md │ │ ├── mutex │ │ ├── README.md │ │ ├── musl.h.md │ │ ├── slim.h.md │ │ └── tristate.h.md │ │ └── once.h.md └── developer_guide.md ├── include └── vsync │ ├── atomic │ ├── atomicptr_markable.h │ └── atomicptr_stamped.h │ ├── bitmap │ └── bitmap.h │ ├── common │ ├── assert.h │ ├── cache.h │ ├── compiler.h │ └── dbg.h │ ├── map │ ├── hashtable_standard.h │ ├── internal │ │ ├── hashtable │ │ │ └── hashtable_config.h │ │ ├── listset │ │ │ └── listset_common.h │ │ ├── skiplist │ │ │ ├── skiplist_helper.h │ │ │ ├── skiplist_internal_fun.h │ │ │ └── skiplist_types.h │ │ └── treeset │ │ │ ├── treeset_alloc.h │ │ │ ├── treeset_common.h │ │ │ ├── treeset_lock.h │ │ │ ├── treeset_lock_fake.h │ │ │ ├── treeset_lock_pthread.h │ │ │ ├── treeset_lock_rw.h │ │ │ └── treeset_lock_ttas.h │ ├── listset_coarse.h │ ├── listset_fine.h │ ├── listset_lazy.h │ ├── listset_lf.h │ ├── listset_opt.h │ ├── simpleht.h │ ├── skiplist_lf.h │ ├── treeset_bst_coarse.h │ ├── treeset_bst_fine.h │ ├── treeset_rb_coarse.h │ └── treeset_rb_fine.h │ ├── pool │ └── cached_pool.h │ ├── queue │ ├── bounded_locked.h │ ├── bounded_mpmc.h │ ├── bounded_spsc.h │ ├── cachedq.h │ ├── chaselev.h │ ├── internal │ │ ├── bounded_ret.h │ │ ├── ub │ │ │ └── vqueue_ub_common.h │ │ └── vqueue_prio_lock.h │ ├── unbounded_queue_lf.h │ ├── unbounded_queue_lf_recycle.h │ ├── unbounded_queue_total.h │ ├── vqueue_prio_heap_based.h │ ├── vqueue_prio_skiplist_based.h │ ├── vqueue_prio_stack_array_based.h │ └── vqueue_prio_stack_tree_based.h │ ├── smr │ ├── ebr.h │ └── internal │ │ ├── dbl_list.h │ │ ├── smr_lock.h │ │ ├── smr_node.h │ │ └── smr_nodes_list.h │ ├── spinlock │ ├── arraylock.h │ ├── caslock.h │ ├── clhlock.h │ ├── cnalock.h │ ├── hclhlock.h │ ├── hemlock.h │ ├── hmcslock.h │ ├── mcslock.h │ ├── rec_mcslock.h │ ├── rec_seqlock.h │ ├── rec_spinlock.h │ ├── rec_ticketlock.h │ ├── rwlock.h │ ├── semaphore.h │ ├── seqcount.h │ ├── seqlock.h │ ├── ticketlock.h │ ├── ttaslock.h │ └── twalock.h │ ├── stack │ ├── elimination_stack.h │ ├── internal │ │ ├── range_policy.h │ │ └── stack_core.h │ ├── quack.h │ └── xbo_stack.h │ ├── thread │ ├── cond.h │ ├── internal │ │ ├── futex.h │ │ ├── futex_mock_liveness.h │ │ ├── futex_mock_liveness_simple.h │ │ └── futex_mock_safety.h │ ├── mutex.h │ ├── mutex │ │ ├── musl.h │ │ ├── slim.h │ │ └── tristate.h │ └── once.h │ └── utils │ ├── abstract_lock.h │ ├── alloc.h │ ├── backoff.h │ ├── exchanger.h │ ├── internal │ └── math.h │ ├── math.h │ ├── recursive_lock.h │ ├── string.h │ ├── string_helpers.h │ └── xbo.h ├── scripts ├── clang-format.sh ├── cmake-format.sh └── sanitize.sh ├── template ├── CMakeLists.txt └── include │ ├── CMakeLists.txt │ └── vsync │ ├── CMakeLists.txt │ └── atomic │ ├── CMakeLists.txt │ ├── atomicptr_markable.h.in │ ├── atomicptr_stamped.h.in │ ├── tmplr.h │ └── vatomic.rules ├── test ├── CMakeLists.txt ├── atomics │ ├── CMakeLists.txt │ ├── atomicptr_markable_test.c │ └── atomicptr_stamped_test.c ├── bitmap │ ├── CMakeLists.txt │ ├── test_mt_bitmap.c │ ├── test_mt_ranges_bitmap.c │ └── test_ut_bitmap.c ├── cachedq │ ├── CMakeLists.txt │ └── cachedq_stress.c ├── chaselev │ ├── CMakeLists.txt │ ├── chaselev_stress_test.c │ ├── test_enq_deq.c │ ├── test_enq_steal.c │ ├── test_multithreaded.c │ ├── test_singlethreaded.c │ └── test_unit.c ├── hashtable │ ├── CMakeLists.txt │ ├── test_stress.c │ └── test_unit.c ├── include │ └── test │ │ ├── boilerplate │ │ ├── lock.h │ │ ├── reader_writer.h │ │ └── test_case.h │ │ ├── hashtable │ │ ├── hashtable.h │ │ ├── hashtable_stats.h │ │ ├── iref_hashtable.h │ │ ├── map.h │ │ ├── ref_hashtable.h │ │ └── user_key.h │ │ ├── listset │ │ ├── ilistset.h │ │ └── listset_test_interface.h │ │ ├── locked_trace.h │ │ ├── map │ │ ├── isimple.h │ │ ├── itreeset.h │ │ ├── treeset_test_interface.h │ │ └── treeset_test_interface_traces.h │ │ ├── prio │ │ ├── pqueue_interface.h │ │ └── queue_prio.h │ │ ├── queue │ │ └── ub │ │ │ ├── aligned_alloc.h │ │ │ ├── queue_interface.h │ │ │ └── queue_recycle_pool.h │ │ ├── rand.h │ │ ├── skiplist │ │ └── skiplist_interface.h │ │ ├── smr │ │ ├── ismr.h │ │ ├── ismr_ebr.h │ │ ├── ismr_none.h │ │ ├── mock_node.h │ │ ├── thread_lock.h │ │ └── thread_storage.h │ │ ├── stack │ │ ├── stack_baseline.h │ │ └── stack_interface.h │ │ ├── thread_barrier.h │ │ ├── thread_launcher.h │ │ ├── time.h │ │ ├── trace_manager.h │ │ ├── vmem_stdlib.h │ │ └── vtid.h ├── listset │ ├── CMakeLists.txt │ ├── include │ │ └── test │ │ │ └── listset │ │ │ ├── ilistset.h │ │ │ └── listset_test_interface.h │ ├── test_listset.c │ └── test_listset_sanity.c ├── pool │ ├── CMakeLists.txt │ ├── pool_capacity.c │ ├── pool_single_thread.c │ └── pool_stress.c ├── priority_queue │ ├── CMakeLists.txt │ ├── include │ │ └── test │ │ │ └── prio │ │ │ ├── pqueue_interface.h │ │ │ └── queue_prio.h │ ├── test_same_priority.c │ ├── test_sanity.c │ └── test_stress.c ├── quack │ ├── CMakeLists.txt │ ├── quack.c │ └── quack_reverse.c ├── queue │ ├── CMakeLists.txt │ ├── bounded_locked.c │ ├── bounded_mpmc_check_empty.c │ ├── bounded_mpmc_check_full.c │ └── bounded_spsc.c ├── simpleht │ ├── CMakeLists.txt │ ├── include │ │ └── test │ │ │ └── map │ │ │ └── isimple.h │ ├── mt_test.c │ ├── mt_test_no_rem.c │ └── ut_test.c ├── skiplist │ ├── CMakeLists.txt │ ├── include │ │ └── test │ │ │ └── skiplist │ │ │ └── skiplist_interface.h │ ├── test_sanity.c │ ├── test_sanity_ext.c │ ├── test_stress.c │ └── test_stress_success.c ├── smr │ ├── CMakeLists.txt │ ├── test_sanity.c │ ├── test_stress.c │ └── test_stress_sync.c ├── spinlock │ ├── CMakeLists.txt │ ├── arraylock.c │ ├── caslock.c │ ├── clhlock.c │ ├── cnalock.c │ ├── hclhlock.c │ ├── hemlock.c │ ├── hmcslock.c │ ├── mcslock.c │ ├── rec_mcslock.c │ ├── rec_seqlock.c │ ├── rec_spinlock.c │ ├── rec_ticketlock.c │ ├── rwlock.c │ ├── semaphore.c │ ├── seqcount.c │ ├── seqlock.c │ ├── ticketlock.c │ ├── ttaslock.c │ └── twalock.c ├── stack │ ├── CMakeLists.txt │ ├── include │ │ └── test │ │ │ └── stack │ │ │ ├── stack_baseline.h │ │ │ └── stack_interface.h │ ├── test_sanity.c │ └── test_stress.c ├── treeset │ ├── CMakeLists.txt │ ├── include │ │ └── test │ │ │ └── map │ │ │ ├── itreeset.h │ │ │ ├── treeset_test_interface.h │ │ │ └── treeset_test_interface_traces.h │ ├── test_treeset_sanity.c │ ├── test_treeset_sanity_interface.c │ ├── test_treeset_sanity_visit.c │ ├── test_treeset_stress.c │ └── test_treeset_traces.c └── unbounded_queue │ ├── CMakeLists.txt │ ├── unbounded_queue_sanity.c │ └── unbounded_queue_stress.c ├── vatomic ├── .clang-format ├── .cmake-format ├── .github │ ├── Dockerfile.boogie │ ├── Dockerfile.qemu │ ├── docker-context │ │ └── placeholder │ ├── toolchains │ │ ├── arm64.cmake │ │ ├── arm64_lse.cmake │ │ ├── armeb.cmake │ │ ├── armeb8.cmake │ │ ├── armel.cmake │ │ ├── armel8.cmake │ │ ├── riscv.cmake │ │ └── x86_64.cmake │ └── workflows │ │ └── actions.yml ├── .gitignore ├── CHANGELOG.md ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake │ ├── config.cmake.in │ ├── export.cmake │ └── v_add_test.cmake ├── include │ └── vsync │ │ ├── atomic.h │ │ ├── atomic │ │ ├── await.h │ │ ├── await_ptr.h │ │ ├── await_u32.h │ │ ├── await_u64.h │ │ ├── compat.h │ │ ├── config.h │ │ ├── core.h │ │ ├── core_ptr.h │ │ ├── core_sz.h │ │ ├── core_u16.h │ │ ├── core_u32.h │ │ ├── core_u64.h │ │ ├── core_u8.h │ │ ├── dispatch.h │ │ ├── doc.h │ │ └── internal │ │ │ ├── arm32_v7.h │ │ │ ├── arm32_v8.h │ │ │ ├── arm64.h │ │ │ ├── arm64_llsc.h │ │ │ ├── arm64_lse.h │ │ │ ├── arm64_lxe.h │ │ │ ├── atomic_rlx.h │ │ │ ├── builtins.h │ │ │ ├── config │ │ │ ├── fnc_rlx.h │ │ │ ├── fnc_sc.h │ │ │ ├── ptr_rlx.h │ │ │ ├── ptr_sc.h │ │ │ ├── sz_rlx.h │ │ │ ├── sz_sc.h │ │ │ ├── u16_rlx.h │ │ │ ├── u16_sc.h │ │ │ ├── u32_rlx.h │ │ │ ├── u32_sc.h │ │ │ ├── u64_rlx.h │ │ │ ├── u64_sc.h │ │ │ ├── u8_rlx.h │ │ │ └── u8_sc.h │ │ │ ├── dispatch.h │ │ │ ├── fallback.h │ │ │ ├── macros.h │ │ │ ├── types.h │ │ │ ├── undef.h │ │ │ └── x86.h │ │ ├── common │ │ ├── await_while.h │ │ ├── internal │ │ │ └── await_while.h │ │ ├── macros.h │ │ └── verify.h │ │ ├── doc.h │ │ └── vtypes.h ├── scripts │ ├── clang-format.sh │ ├── cmake-format.sh │ ├── license-check.sh │ └── sanitize.sh ├── template │ ├── CMakeLists.txt │ ├── empty.c │ └── include │ │ ├── CMakeLists.txt │ │ └── vsync │ │ ├── CMakeLists.txt │ │ └── atomic │ │ ├── CMakeLists.txt │ │ ├── await.h.in │ │ ├── await_TY.h.in │ │ ├── core.h.in │ │ ├── core_TY.h.in │ │ ├── dispatch.h.in │ │ ├── internal │ │ ├── CMakeLists.txt │ │ ├── arm32_v7.h.in │ │ ├── arm32_v8.h.in │ │ ├── arm64.h.in │ │ ├── arm64_llsc.h.in │ │ ├── arm64_lse.h.in │ │ ├── arm64_lxe.h.in │ │ ├── builtins.h.in │ │ ├── config │ │ │ ├── CMakeLists.txt │ │ │ ├── TY_rlx.h.in │ │ │ └── TY_sc.h.in │ │ └── fallback.h.in │ │ ├── tmplr.h │ │ └── vatomic.rules ├── test │ ├── CMakeLists.txt │ ├── atomics │ │ ├── CMakeLists.txt │ │ ├── dispatcher_test.c │ │ ├── freestanding_test.c │ │ ├── include │ │ │ └── vfreestanding.h.tpl │ │ ├── leftover_patterns.txt │ │ ├── pause_test.c │ │ ├── unit.sh │ │ └── vatomic_empty.c │ ├── atomics_basic │ │ ├── CMakeLists.txt │ │ └── vatomic_basic.c.in │ ├── atomics_cxx │ │ ├── CMakeLists.txt │ │ └── vatomic_empty.cpp │ ├── atomics_gen │ │ ├── CMakeLists.txt │ │ ├── call_tests │ │ │ ├── call_add.c │ │ │ ├── call_add_get.c │ │ │ ├── call_and.c │ │ │ ├── call_and_get.c │ │ │ ├── call_await_eq.c │ │ │ ├── call_await_eq_add.c │ │ │ ├── call_await_eq_set.c │ │ │ ├── call_await_eq_sub.c │ │ │ ├── call_await_ge.c │ │ │ ├── call_await_ge_add.c │ │ │ ├── call_await_ge_set.c │ │ │ ├── call_await_ge_sub.c │ │ │ ├── call_await_gt.c │ │ │ ├── call_await_gt_add.c │ │ │ ├── call_await_gt_set.c │ │ │ ├── call_await_gt_sub.c │ │ │ ├── call_await_le.c │ │ │ ├── call_await_le_add.c │ │ │ ├── call_await_le_set.c │ │ │ ├── call_await_le_sub.c │ │ │ ├── call_await_lt.c │ │ │ ├── call_await_lt_add.c │ │ │ ├── call_await_lt_set.c │ │ │ ├── call_await_lt_sub.c │ │ │ ├── call_await_neq.c │ │ │ ├── call_await_neq_add.c │ │ │ ├── call_await_neq_set.c │ │ │ ├── call_await_neq_sub.c │ │ │ ├── call_cmpxchg.c │ │ │ ├── call_dec.c │ │ │ ├── call_dec_get.c │ │ │ ├── call_fence.c │ │ │ ├── call_get_add.c │ │ │ ├── call_get_and.c │ │ │ ├── call_get_dec.c │ │ │ ├── call_get_inc.c │ │ │ ├── call_get_max.c │ │ │ ├── call_get_or.c │ │ │ ├── call_get_sub.c │ │ │ ├── call_get_xor.c │ │ │ ├── call_inc.c │ │ │ ├── call_inc_get.c │ │ │ ├── call_max.c │ │ │ ├── call_max_get.c │ │ │ ├── call_or.c │ │ │ ├── call_or_get.c │ │ │ ├── call_read.c │ │ │ ├── call_sub.c │ │ │ ├── call_sub_get.c │ │ │ ├── call_write.c │ │ │ ├── call_xchg.c │ │ │ ├── call_xor.c │ │ │ ├── call_xor_get.c │ │ │ └── compare.sh │ │ ├── mt_test_await_ptr.c │ │ ├── mt_test_await_u32.c │ │ ├── mt_test_await_u64.c │ │ ├── mt_test_rmw_ptr.c │ │ ├── mt_test_rmw_sz.c │ │ ├── mt_test_rmw_u32.c │ │ ├── mt_test_rmw_u64.c │ │ ├── templates │ │ │ ├── CMakeLists.txt │ │ │ ├── call_FUNC.c.in │ │ │ ├── mt_test_await_TY.c.in │ │ │ ├── mt_test_rmw_TY.c.in │ │ │ ├── ut_test_TY.c.in │ │ │ └── ut_test_await_TY.c.in │ │ ├── ut_test_await_ptr.c │ │ ├── ut_test_await_u32.c │ │ ├── ut_test_await_u64.c │ │ ├── ut_test_ptr.c │ │ ├── ut_test_sz.c │ │ ├── ut_test_u16.c │ │ ├── ut_test_u32.c │ │ ├── ut_test_u64.c │ │ └── ut_test_u8.c │ └── project │ │ ├── CMakeLists.txt │ │ └── test.c ├── tmplr │ ├── CMakeLists.txt │ ├── include │ │ └── tmplr │ │ │ └── macros.h │ ├── test │ │ ├── test-drop.in │ │ ├── test-skip.in │ │ ├── test1.in │ │ ├── test2.in │ │ ├── test3.in │ │ ├── test4.in │ │ ├── test5.in │ │ ├── test6.in │ │ └── test7.in │ └── tmplr.c ├── verify │ ├── ASMModel.hs │ ├── ASMParsers.hs │ ├── BoogieTranslator.hs │ ├── CMakeLists.txt │ ├── Main.hs │ ├── atomics_list.txt │ ├── await.bpl │ ├── library.bpl │ ├── read.bpl │ ├── rmw.bpl │ ├── write.bpl │ └── xchg.bpl └── vmm.cat ├── verify ├── CMakeLists.txt ├── bitmap │ ├── CMakeLists.txt │ ├── test_case_clr_interset.h │ ├── test_case_intact.h │ ├── test_case_iter.h │ ├── test_case_range.h │ ├── test_case_set_intersect.h │ └── verify.c ├── cachedq │ ├── CMakeLists.txt │ └── cachedq_verify.c ├── chaselev │ ├── CMakeLists.txt │ ├── verify_basic.c │ ├── verify_basic_variation.c │ ├── verify_empty.c │ └── verify_mutual_exclusion.c ├── include │ └── verify │ │ └── rwlock.h ├── listset │ ├── CMakeLists.txt │ ├── test_case_1.h │ ├── test_case_2.h │ ├── test_case_3.h │ ├── test_case_4.h │ ├── test_case_5.h │ ├── test_case_6.h │ ├── test_case_7.h │ ├── test_case_8.h │ └── verify.c ├── pool │ ├── CMakeLists.txt │ └── pool_2thread.c ├── priority_queue │ ├── CMakeLists.txt │ ├── test_case_add_vs_add_diff_prio.h │ ├── test_case_add_vs_add_same_prio.h │ ├── test_case_add_vs_rem.h │ ├── test_case_add_vs_rem_rem_same_prio.h │ ├── test_case_boudary.h │ ├── test_case_rem_vs_add_add_same_prio.h │ ├── test_case_rem_vs_rem_diff_prio.h │ ├── test_case_rem_vs_rem_same_prio.h │ └── verify.c ├── simpleht │ ├── CMakeLists.txt │ ├── test_case_add.h │ ├── test_case_add_get.h │ ├── test_case_add_get_rem.h │ ├── test_case_same_bucket.h │ └── verify.c ├── skiplist │ ├── CMakeLists.txt │ ├── test_case_add_add_rem.h │ ├── test_case_add_rem_lku_msg_passing.h │ ├── test_case_add_rem_succ.h │ ├── test_case_extensions.h │ ├── test_case_rem_node.h │ └── verify.c ├── smr │ ├── CMakeLists.txt │ ├── test_case_arr.h │ ├── test_case_arr2.h │ ├── test_case_free_after_sync.h │ ├── test_case_list.h │ ├── test_case_spec.h │ └── verify.c ├── stack │ ├── CMakeLists.txt │ ├── test_case_2push_2pop.h │ ├── test_case_2push_msg_passing.h │ ├── test_case_lifo.h │ ├── test_case_only_pop.h │ ├── test_case_only_push.h │ ├── test_case_pop_twice_push_pop.h │ ├── test_case_popped_once.h │ └── verify_stack.c ├── thread │ ├── CMakeLists.txt │ ├── cond_test1.c │ ├── cond_test2.c │ ├── mock_mutex.h │ ├── mutex_musl.c │ ├── mutex_slim.c │ ├── mutex_slim_liveness.c │ ├── mutex_slim_liveness_simple.c │ ├── mutex_tristate.c │ └── once.c ├── treeset │ ├── CMakeLists.txt │ ├── testcase_add_1.h │ ├── testcase_add_2.h │ ├── testcase_add_3.h │ ├── testcase_add_4.h │ ├── testcase_add_5.h │ ├── testcase_add_rem_1.h │ ├── testcase_add_rem_2.h │ ├── testcase_add_rem_3.h │ ├── testcase_add_rem_4.h │ ├── testcase_add_rem_5.h │ ├── testcase_add_rem_6.h │ ├── testcase_rem_1.h │ ├── testcase_rem_2.h │ ├── testcase_rem_3.h │ ├── testcase_rem_4.h │ ├── testcase_rem_5.h │ └── verify.c └── unbounded_queue │ ├── CMakeLists.txt │ ├── test_case_1.h │ ├── test_case_2.h │ ├── test_case_3.h │ ├── test_case_4.h │ ├── test_case_5.h │ ├── test_case_6.h │ └── verify.c └── vmm └── vmm.cat /.gitignore: -------------------------------------------------------------------------------- 1 | doc.h 2 | build/ 3 | *.ll 4 | .kakrc 5 | .vscode 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (C) 2023 Huawei Technologies Co., Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cmake/config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") 4 | check_required_components("@PROJECT_NAME@") 5 | -------------------------------------------------------------------------------- /cmake/export.cmake: -------------------------------------------------------------------------------- 1 | set(CONFIG_IN_FILE "cmake/config.cmake.in") 2 | 3 | if(NOT DEFINED PROJECT_TARGETS) 4 | set(PROJECT_TARGETS "${PROJECT_NAME}Targets") 5 | endif() 6 | 7 | set(PROJECT_CMAKE_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake") 8 | set(PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake") 9 | set(PROJECT_VERSION_FILE 10 | "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") 11 | 12 | include(CMakePackageConfigHelpers) 13 | configure_package_config_file(${CONFIG_IN_FILE} ${PROJECT_CONFIG_FILE} 14 | INSTALL_DESTINATION ${PROJECT_CMAKE_DIR}) 15 | 16 | write_basic_package_version_file( 17 | ${PROJECT_VERSION_FILE} 18 | VERSION ${PROJECT_VERSION} 19 | COMPATIBILITY SameMajorVersion) 20 | 21 | install( 22 | EXPORT ${PROJECT_TARGETS} 23 | FILE ${PROJECT_TARGETS}.cmake 24 | NAMESPACE ${PROJECT_NAME}:: 25 | DESTINATION ${PROJECT_CMAKE_DIR}) 26 | install(FILES ${PROJECT_CONFIG_FILE} ${PROJECT_VERSION_FILE} 27 | DESTINATION ${PROJECT_CMAKE_DIR}) 28 | -------------------------------------------------------------------------------- /doc/api/vsync/README.md: -------------------------------------------------------------------------------- 1 | # vsync 2 | _libvsync is library of robust atomics, synchronization primitives, concurrent data structures and safe memory reclamation schemes._ 3 | 4 | --- 5 | ## File Index 6 | 7 | 8 | | File|Description| 9 | | --- | --- | 10 | | [vsync/atomic.h](atomic.h.md)|Rich interface of atomic operations and fences. | 11 | 12 | --- 13 | ## Directory Index 14 | 15 | 16 | | Directory|Description| 17 | | --- | --- | 18 | | [vsync/atomic](atomic/README.md)|Rich interface of atomic operations and fences. | 19 | | [vsync/bitmap](bitmap/README.md)|Bitmap implementations. | 20 | | [vsync/map](map/README.md)|This is a collection of algos that implement map interface. | 21 | | [vsync/pool](pool/README.md)|Memory pools. | 22 | | [vsync/queue](queue/README.md)|Queues, priority queues and ringbuffers. | 23 | | [vsync/smr](smr/README.md)|Safe Memory Reclamation Schemes. | 24 | | [vsync/spinlock](spinlock/README.md)|Spinlocks for kernel and userspace. | 25 | | [vsync/stack](stack/README.md)|Concurrent stacks. | 26 | | [vsync/thread](thread/README.md)|Userspace synchronization primitives. | 27 | 28 | 29 | --- 30 | -------------------------------------------------------------------------------- /doc/api/vsync/atomic.h.md: -------------------------------------------------------------------------------- 1 | # [vsync](README.md) / atomic.h 2 | _Rich interface of atomic operations and fences._ 3 | 4 | Atomics are implemented in custom assembly or compiler builtins. 5 | 6 | 7 | - check [core.h](atomic/core.h.md) for the documentation of the core interface. 8 | - check [await.h](atomic/await.h.md) for the documentation of the await interface. 9 | - check [config.h](atomic/config.h.md) to learn about libvsync available configurations. 10 | - check [atomic/dispatch.h](atomic/dispatch.h.md) an additional dispatch layer allows for a more flexible use of the interface. 11 | 12 | 13 | 14 | --- 15 | -------------------------------------------------------------------------------- /doc/api/vsync/bitmap/README.md: -------------------------------------------------------------------------------- 1 | # [vsync](../README.md) / bitmap 2 | _Bitmap implementations._ 3 | 4 | --- 5 | ## File Index 6 | 7 | 8 | | File|Description| 9 | | --- | --- | 10 | | [vsync/bitmap/bitmap.h](bitmap.h.md)|A bitmap implementation. | 11 | 12 | 13 | --- 14 | -------------------------------------------------------------------------------- /doc/api/vsync/pool/README.md: -------------------------------------------------------------------------------- 1 | # [vsync](../README.md) / pool 2 | _Memory pools._ 3 | 4 | --- 5 | ## File Index 6 | 7 | 8 | | File|Description| 9 | | --- | --- | 10 | | [vsync/pool/cached_pool.h](cached_pool.h.md)|Multi-threaded, fixed size, and fixed capacity memory pool. | 11 | 12 | 13 | --- 14 | -------------------------------------------------------------------------------- /doc/api/vsync/queue/GROUP_unbounded_queue.md: -------------------------------------------------------------------------------- 1 | # Unbounded-Queue 2 | _Group of Unbounded Queues._ 3 | 4 | These queues have no capacity limit and thus enqueue operations shall always succeed. 5 | 6 | --- 7 | ## File Index 8 | 9 | 10 | | File|Description|Linearizable|Lock-free|SMR-required|Unbounded-Queue| 11 | | --- | --- | --- | --- | --- | --- | 12 | | [vsync/queue/unbounded_queue_lf.h](unbounded_queue_lf.h.md)|Lock-free unbounded queue. | ✔ | ✔ | ✔ | ✔ | 13 | | [vsync/queue/unbounded_queue_lf_recycle.h](unbounded_queue_lf_recycle.h.md)|Lock-free recycle unbounded queue. | ✔ | ✔ | ❌ | ✔ | 14 | | [vsync/queue/unbounded_queue_total.h](unbounded_queue_total.h.md)|Unbounded blocking total queue. | ✔ | ❌ | ❌ | ✔ | 15 | | [vsync/queue/vqueue_prio_skiplist_based.h](vqueue_prio_skiplist_based.h.md)|Skiplist-based priority queue implementation. | ✔ | ✔ | ✔ | ✔ | 16 | | [vsync/queue/vqueue_prio_stack_array_based.h](vqueue_prio_stack_array_based.h.md)|Array-based bounded priority queue. | ✔ | ✔ | ✔ | ✔ | 17 | 18 | 19 | --- 20 | -------------------------------------------------------------------------------- /doc/api/vsync/smr/README.md: -------------------------------------------------------------------------------- 1 | # [vsync](../README.md) / smr 2 | _Safe Memory Reclamation Schemes._ 3 | 4 | --- 5 | ## File Index 6 | 7 | 8 | | File|Description| 9 | | --- | --- | 10 | | [vsync/smr/ebr.h](ebr.h.md)|Epoch Based Reclamation (EBR) SMR scheme. | 11 | 12 | 13 | --- 14 | -------------------------------------------------------------------------------- /doc/api/vsync/spinlock/GROUP_numa_aware.md: -------------------------------------------------------------------------------- 1 | # Numa-aware 2 | _Group of numa-aware algorithms._ 3 | 4 | --- 5 | ## File Index 6 | 7 | 8 | | File|Description|Numa-aware| 9 | | --- | --- | --- | 10 | | [vsync/spinlock/cnalock.h](cnalock.h.md)|Compact NUMA-aware Lock. | ✔ | 11 | | [vsync/spinlock/hclhlock.h](hclhlock.h.md)|Hierarchical CLH Queue Lock. | ✔ | 12 | | [vsync/spinlock/hmcslock.h](hmcslock.h.md)|Hierarchical MCS lock for systems with NUMA Hierarchies. | ✔ | 13 | 14 | 15 | --- 16 | -------------------------------------------------------------------------------- /doc/api/vsync/stack/README.md: -------------------------------------------------------------------------------- 1 | # [vsync](../README.md) / stack 2 | _Concurrent stacks._ 3 | 4 | --- 5 | ## File Index 6 | 7 | 8 | | File|Description|Linearizable|Lock-free|SMR-required| 9 | | --- | --- | --- | --- | --- | 10 | | [vsync/stack/elimination_stack.h](elimination_stack.h.md)|Unbounded lock-free stack with elimination backoff. | ✔ | ✔ | ✔ | 11 | | [vsync/stack/quack.h](quack.h.md)|Lockfree concurrent stack/queue (Treiber stack) | ✔ | ✔ | ❌ | 12 | | [vsync/stack/xbo_stack.h](xbo_stack.h.md)|Unbounded lock-free stack with exponential backoff. | ✔ | ✔ | ✔ | 13 | 14 | 15 | --- 16 | -------------------------------------------------------------------------------- /doc/api/vsync/thread/README.md: -------------------------------------------------------------------------------- 1 | # [vsync](../README.md) / thread 2 | _Userspace synchronization primitives._ 3 | 4 | --- 5 | ## File Index 6 | 7 | 8 | | File|Description| 9 | | --- | --- | 10 | | [vsync/thread/cond.h](cond.h.md)|Condition variable. | 11 | | [vsync/thread/mutex.h](mutex.h.md)|Futex-based mutex. | 12 | | [vsync/thread/once.h](once.h.md)|One-time initializer. | 13 | 14 | --- 15 | ## Directory Index 16 | 17 | 18 | | Directory|Description| 19 | | --- | --- | 20 | | [vsync/thread/mutex](mutex/README.md)|Different implementations of user-space mutex. | 21 | 22 | 23 | --- 24 | -------------------------------------------------------------------------------- /doc/api/vsync/thread/mutex.h.md: -------------------------------------------------------------------------------- 1 | # [vsync](../README.md) / [thread](README.md) / mutex.h 2 | _Futex-based mutex._ 3 | 4 | This file includes the default mutex implementation. See [mutex/slim.h](mutex/slim.h.md) for details. 5 | 6 | 7 | ### Example: 8 | 9 | 10 | 11 | ```c 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define N 12 19 | #define EXPECTED_VAL N 20 | 21 | vmutex_t g_mutex; 22 | vuint32_t g_x = 0; 23 | vuint32_t g_y = 0; 24 | 25 | void * 26 | run(void *args) 27 | { 28 | vmutex_acquire(&g_mutex); 29 | g_x++; 30 | g_y++; 31 | vmutex_release(&g_mutex); 32 | 33 | (void)args; 34 | return NULL; 35 | } 36 | 37 | int 38 | main(void) 39 | { 40 | pthread_t threads[N]; 41 | 42 | vmutex_init(&g_mutex); 43 | 44 | for (vsize_t i = 0; i < N; i++) { 45 | pthread_create(&threads[i], NULL, run, (void *)i); 46 | } 47 | 48 | for (vsize_t i = 0; i < N; i++) { 49 | pthread_join(threads[i], NULL); 50 | } 51 | 52 | ASSERT(g_x == EXPECTED_VAL); 53 | ASSERT(g_x == g_y); 54 | printf("Final value %u\n", g_x); 55 | return 0; 56 | } 57 | ``` 58 | 59 | 60 | 61 | 62 | --- 63 | -------------------------------------------------------------------------------- /doc/api/vsync/thread/mutex/README.md: -------------------------------------------------------------------------------- 1 | # [vsync](../../README.md) / [thread](../README.md) / mutex 2 | _Different implementations of user-space mutex._ 3 | 4 | --- 5 | ## File Index 6 | 7 | 8 | | File|Description| 9 | | --- | --- | 10 | | [vsync/thread/mutex/musl.h](musl.h.md)|A simplified version of the mutex algorithm in musl libc. | 11 | | [vsync/thread/mutex/slim.h](slim.h.md)|Slim 3-state futex. | 12 | | [vsync/thread/mutex/tristate.h](tristate.h.md)|3-state mutex. | 13 | 14 | 15 | --- 16 | -------------------------------------------------------------------------------- /include/vsync/common/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_COMMON_ASSERT_H 7 | #define VSYNC_COMMON_ASSERT_H 8 | 9 | /* We include vtypes here to make sure vfreestanding.h inclusion (if available) 10 | * precedes the inclusion of this header. Through vfreestanding.h external users 11 | * can define their own ASSERT which should overwrite ours */ 12 | #include 13 | 14 | #ifndef ASSERT 15 | #include 16 | #define ASSERT(V) assert(V) 17 | #endif 18 | 19 | #ifndef BUG_ON 20 | #define BUG_ON(V) ASSERT(!(V)) 21 | #endif 22 | 23 | #define V_STATIC_ASSERT(_cond_, _str_) _Static_assert((_cond_), _str_) 24 | #endif 25 | -------------------------------------------------------------------------------- /include/vsync/common/cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_CACHE_H 7 | #define VSYNC_CACHE_H 8 | /******************************************************************************* 9 | * This file provides cache macros to align and pad data structures to the cache 10 | * line size. The cache alignment is disabled if the code is compiled for 11 | * verification (with VSYNC_VERIFICATION defined). 12 | ******************************************************************************/ 13 | 14 | #ifndef VSYNC_CACHELINE_SIZE 15 | /* L3 cache line size for ARM processors */ 16 | #define VSYNC_CACHELINE_SIZE 128 17 | #endif 18 | 19 | #ifdef VSYNC_VERIFICATION 20 | #define VSYNC_CACHEALIGN 21 | #define VSYNC_CACHEPAD(typ, var) typ var 22 | #else /* ! VSYNC_VERIFICATION */ 23 | #define VSYNC_CACHEALIGN __attribute__((aligned(VSYNC_CACHELINE_SIZE))) 24 | #define VSYNC_CACHEDIFF(sz) \ 25 | ((VSYNC_CACHELINE_SIZE - ((sz) % VSYNC_CACHELINE_SIZE)) % \ 26 | VSYNC_CACHELINE_SIZE) 27 | #define VSYNC_CACHEPAD(typ, var) char var[VSYNC_CACHEDIFF(sizeof(typ))] 28 | #endif /* ! VSYNC_VERIFICATION */ 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /include/vsync/map/internal/hashtable/hashtable_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VHASH_CONFIG_H 7 | #define VHASH_CONFIG_H 8 | 9 | #ifdef VSYNC_VERIFICATION 10 | #define VHASHTABLE_BUCKET_COUNT 2U 11 | #define VHASHTABLE_BUCKET_LEN 2U 12 | #else 13 | #ifndef VHASHTABLE_BUCKET_COUNT 14 | #define VHASHTABLE_BUCKET_COUNT 1024U 15 | #endif 16 | #define VHASHTABLE_BUCKET_LEN 4U 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /include/vsync/map/internal/treeset/treeset_alloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TREESET_ALLOC_H 7 | #define VSYNC_TREESET_ALLOC_H 8 | 9 | static inline treeset_node_t * 10 | _treeset_get_node(treeset_t *tree) 11 | { 12 | return tree->mem_lib.malloc_fun(sizeof(treeset_node_t), tree->mem_lib.arg); 13 | } 14 | 15 | static inline void 16 | _treeset_put_node(treeset_t *tree, treeset_node_t *node) 17 | { 18 | tree->mem_lib.free_fun(node, tree->mem_lib.arg); 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/vsync/map/internal/treeset/treeset_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TREESET_COMMON_H 7 | #define VSYNC_TREESET_COMMON_H 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | typedef vuintptr_t treeset_key_t; 14 | 15 | struct treeset_node_s; 16 | 17 | typedef void (*treeset_visitor)(treeset_key_t key, void *value, void *arg); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /include/vsync/map/internal/treeset/treeset_lock_fake.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TREESET_LOCK_FAKE_H 7 | #define VSYNC_TREESET_LOCK_FAKE_H 8 | 9 | typedef struct lock_s { 10 | vbool_t locked; 11 | } lock_t; 12 | 13 | static inline void 14 | l_init(lock_t *lock) 15 | { 16 | lock->locked = false; 17 | } 18 | 19 | static inline void 20 | l_destroy(lock_t *lock) 21 | { 22 | ASSERT(!lock->locked); 23 | } 24 | 25 | static inline void 26 | l_acquire(lock_t *lock) 27 | { 28 | ASSERT(!lock->locked); 29 | lock->locked = true; 30 | } 31 | 32 | static inline void 33 | l_release(lock_t *lock) 34 | { 35 | ASSERT(lock->locked); 36 | lock->locked = false; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/vsync/map/internal/treeset/treeset_lock_pthread.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TREESET_LOCK_PTHREAD_H 7 | #define VSYNC_TREESET_LOCK_PTHREAD_H 8 | 9 | #include 10 | 11 | typedef struct lock_s { 12 | pthread_mutex_t lock; 13 | } lock_t; 14 | 15 | static inline void 16 | l_init(lock_t *lock) 17 | { 18 | pthread_mutex_init(&lock->lock, NULL); 19 | } 20 | 21 | static inline void 22 | l_destroy(lock_t *lock) 23 | { 24 | pthread_mutex_destroy(&lock->lock); 25 | } 26 | 27 | static inline void 28 | l_acquire(lock_t *lock) 29 | { 30 | pthread_mutex_lock(&lock->lock); 31 | } 32 | 33 | static inline void 34 | l_release(lock_t *lock) 35 | { 36 | pthread_mutex_unlock(&lock->lock); 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/vsync/map/internal/treeset/treeset_lock_rw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TREESET_LOCK_RW_H 7 | #define VSYNC_TREESET_LOCK_RW_H 8 | 9 | #include 10 | 11 | #define TREESET_RW_LOCK_DEFINED 12 | 13 | typedef struct lock_s { 14 | rwlock_t lock; 15 | } lock_t; 16 | 17 | static inline void 18 | l_init(lock_t *lock) 19 | { 20 | rwlock_init(&lock->lock); 21 | } 22 | 23 | static inline void 24 | l_destroy(lock_t *lock) 25 | { 26 | (void)lock; 27 | } 28 | 29 | static inline void 30 | l_acquire(lock_t *lock) 31 | { 32 | rwlock_write_acquire(&lock->lock); 33 | } 34 | 35 | static inline void 36 | l_release(lock_t *lock) 37 | { 38 | rwlock_write_release(&lock->lock); 39 | } 40 | 41 | static inline void 42 | l_reader_acquire(lock_t *lock) 43 | { 44 | rwlock_read_acquire(&lock->lock); 45 | } 46 | 47 | static inline void 48 | l_reader_release(lock_t *lock) 49 | { 50 | rwlock_read_release(&lock->lock); 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /include/vsync/map/internal/treeset/treeset_lock_ttas.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TREESET_LOCK_TTAS_H 7 | #define VSYNC_TREESET_LOCK_TTAS_H 8 | 9 | #include 10 | 11 | typedef struct lock_s { 12 | ttaslock_t lock; 13 | } lock_t; 14 | 15 | static inline void 16 | l_init(lock_t *lock) 17 | { 18 | ttaslock_init(&lock->lock); 19 | } 20 | 21 | static inline void 22 | l_destroy(lock_t *lock) 23 | { 24 | (void)lock; 25 | } 26 | 27 | static inline void 28 | l_acquire(lock_t *lock) 29 | { 30 | ttaslock_acquire(&lock->lock); 31 | } 32 | 33 | static inline void 34 | l_release(lock_t *lock) 35 | { 36 | ttaslock_release(&lock->lock); 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/vsync/queue/internal/bounded_ret.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VQUEUE_BOUNDED_RET_H 7 | #define VQUEUE_BOUNDED_RET_H 8 | 9 | typedef enum { 10 | QUEUE_BOUNDED_OK = 0, 11 | QUEUE_BOUNDED_FULL = 1, 12 | QUEUE_BOUNDED_EMPTY = 2, 13 | QUEUE_BOUNDED_AGAIN = 3, 14 | } bounded_ret_t; 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /include/vsync/queue/internal/ub/vqueue_ub_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VQUEUE_UB_COMMON_H 7 | #define VQUEUE_UB_COMMON_H 8 | 9 | struct vqueue_ub_node_s; 10 | typedef void (*vqueue_ub_node_handler_t)(struct vqueue_ub_node_s *, void *); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /include/vsync/thread/internal/futex_mock_safety.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VTHREAD_FUTEX_MOCK_SAFETY_H 7 | #define VTHREAD_FUTEX_MOCK_SAFETY_H 8 | 9 | /******************************************************************************* 10 | * futex mock for verifying safety property only. 11 | * 12 | * This mock always wakes up every waiting thread, so it cannot be used for 13 | * verifying liveness. If there is more than one futex or waiter for the mutex, 14 | * consider using a different mock. 15 | * 16 | ******************************************************************************/ 17 | 18 | #include 19 | 20 | static vatomic32_t g_signal; 21 | 22 | static inline void 23 | vfutex_wait(vatomic32_t *m, vuint32_t v) 24 | { 25 | vuint32_t s = vatomic32_read_acq(&g_signal); 26 | if (vatomic32_read_rlx(m) != v) 27 | return; 28 | vatomic32_await_neq_rlx(&g_signal, s); 29 | } 30 | 31 | static inline void 32 | vfutex_wake(vatomic32_t *m, vuint32_t v) 33 | { 34 | vatomic32_inc_rel(&g_signal); 35 | } 36 | 37 | #endif /* VTHREAD_FUTEX_MOCK_SAFETY_H */ 38 | -------------------------------------------------------------------------------- /include/vsync/thread/mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VTHREAD_MUTEX_H 7 | #define VTHREAD_MUTEX_H 8 | /******************************************************************************* 9 | * @file mutex.h 10 | * @brief Futex-based mutex 11 | * 12 | * This file includes the default mutex implementation. See @ref mutex/slim.h 13 | * for details. 14 | * 15 | * @example 16 | * @include eg_mutex.c 17 | ******************************************************************************/ 18 | 19 | #include 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/vsync/utils/string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_UTILS_STRING_H 7 | #define VSYNC_UTILS_STRING_H 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /* 15 | * @note the following functions can trigger model checker bugs related to 16 | * memset. Developers should work around the issue by copying using a for-loop, 17 | * when VSYNC_VERIFICATION is defined. 18 | */ 19 | 20 | #if !defined(VSYNC_MEMCPY_S_EXISTS) && !defined(VSYNC_VERIFICATION) 21 | static inline int 22 | memcpy_s(void *dst, vsize_t dst_sz, const void *src, vsize_t src_sz) 23 | { 24 | if (v_memcpy_s_params_ok(dst, dst_sz, src, src_sz)) { 25 | memcpy(dst, src, src_sz); 26 | return 0; 27 | } else { 28 | return 1; 29 | } 30 | } 31 | #endif 32 | 33 | #if !defined(VSYNC_MEMSET_S_EXISTS) && !defined(VSYNC_VERIFICATION) 34 | static inline int 35 | memset_s(void *dst, vsize_t dst_sz, int ch, vsize_t count) 36 | { 37 | if (v_memset_s_params_ok(dst, dst_sz, ch, count)) { 38 | memset(dst, ch, count); 39 | return 0; 40 | } else { 41 | return 1; 42 | } 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /include/vsync/utils/string_helpers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_UTILS_STRING_HELPERS_H 7 | #define VSYNC_UTILS_STRING_HELPERS_H 8 | 9 | #include 10 | 11 | #define V_UTILS_MEMORY_NO_WRAP(src, sz) \ 12 | ((vuintptr_t)(src) < (vuintptr_t)(src) + (sz)) 13 | 14 | #define V_UTILS_MEMORY_NO_OVERLAP(src, src_sz, dst, dst_sz) \ 15 | (((src) < (dst) && ((vuintptr_t)(src) + (src_sz)) <= (vuintptr_t)(dst)) || \ 16 | ((dst) < (src) && ((vuintptr_t)(dst) + (dst_sz)) <= (vuintptr_t)(src))) 17 | 18 | static inline vbool_t 19 | v_memcpy_s_params_ok(void *dst, vsize_t dst_sz, const void *src, vsize_t src_sz) 20 | { 21 | return src != NULL && dst != NULL && V_UTILS_MEMORY_NO_WRAP(src, src_sz) && 22 | V_UTILS_MEMORY_NO_WRAP(dst, dst_sz) && 23 | V_UTILS_MEMORY_NO_OVERLAP(src, src_sz, dst, dst_sz); 24 | } 25 | 26 | static inline int 27 | v_memset_s_params_ok(void *dst, vsize_t dst_size, int ch, vsize_t count) 28 | { 29 | (void)ch; 30 | return dst != NULL && dst_size >= count && 31 | V_UTILS_MEMORY_NO_WRAP(dst, dst_size); 32 | } 33 | 34 | #undef V_UTILS_MEMORY_NO_WRAP 35 | #undef V_UTILS_MEMORY_NO_OVERLAP 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /scripts/clang-format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | if [ $# -lt 1 ]; then 6 | echo "Usage: $0 [PATH ...]" 7 | echo "" 8 | echo " PATH one or more directories (or source files) to recursively run " 9 | echo " clang-format on." 10 | echo "Environment variables:" 11 | echo " SILENT=true disable git diff and error code" 12 | echo " STYLE=FILE FILE is a configuration file, default = .clang-format" 13 | echo " " 14 | echo "" 15 | exit 1 16 | fi 17 | 18 | if [ "${STYLE}" != "" ]; then 19 | STYLE=":${STYLE}" 20 | fi 21 | 22 | # Apply clang-format to all *.h and *.c files in src folder. 23 | find "$@" \( -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.hpp' -o -name '*.cxx' \) \ 24 | -not -path '*/build/*' \ 25 | -not -path '*/deps/*' \ 26 | -not -path '*/vatomic/*' \ 27 | -type f \ 28 | -exec clang-format -style=file${STYLE} -i {} + 29 | 30 | if [ "${SILENT}" != "true" ]; then 31 | # Display changed files and exit with 1 if there were differences. 32 | git --no-pager diff --exit-code 33 | fi 34 | -------------------------------------------------------------------------------- /template/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_custom_target(vatomic-generate) 2 | # after running vatomic-generate, run clang-format-apply, in order to fix format 3 | # in autogenerted files. 4 | add_custom_command( 5 | TARGET vatomic-generate 6 | POST_BUILD 7 | COMMAND cmake --build "${CMAKE_BINARY_DIR}" --target clang-format-apply 8 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) 9 | 10 | add_subdirectory(include) 11 | -------------------------------------------------------------------------------- /template/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(vsync) 2 | -------------------------------------------------------------------------------- /template/include/vsync/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(atomic) 2 | -------------------------------------------------------------------------------- /template/include/vsync/atomic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(EXISTS internal) 2 | add_subdirectory(internal) 3 | endif() 4 | 5 | # find all template inputs 6 | file(GLOB TARGETS *.in) 7 | # exclude those generated for every type 8 | list(FILTER TARGETS EXCLUDE REGEX "TY.h.in") 9 | 10 | foreach(TARGET ${TARGETS}) 11 | get_filename_component(TARGET ${TARGET} NAME_WE) 12 | set(TARGET ${TARGET}.h) 13 | add_custom_target( 14 | ${TARGET} 15 | COMMAND 16 | $ ${CMAKE_CURRENT_SOURCE_DIR}/vatomic.rules 17 | ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.in > 18 | ${ATOMICS_DIR}/include/vsync/atomic/${TARGET}) 19 | add_dependencies(vatomic-generate ${TARGET}) 20 | endforeach() 21 | -------------------------------------------------------------------------------- /template/include/vsync/atomic/tmplr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VATOMIC_TMPLR_H 7 | #define VATOMIC_TMPLR_H 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * TT is an unsigned integer type or void *. 14 | */ 15 | typedef unsigned int TT; 16 | 17 | /** 18 | * AA is one of the vatomic types. 19 | * 20 | * These are vatomic{8,16,32,64,ptr}. 21 | */ 22 | typedef struct { 23 | TT _v; 24 | } AA; 25 | 26 | /* some further macros to make clangd happy */ 27 | #define _MAP_OP 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_include_directories( 2 | vsync INTERFACE $ 3 | $) 4 | 5 | target_compile_definitions(vsync INTERFACE DEFAULT_SMR_EBR _GNU_SOURCE) 6 | 7 | # add all subdirectories 8 | file(GLOB SUBDIRS CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/test/*) 9 | list(REMOVE_ITEM SUBDIRS "${CMAKE_SOURCE_DIR}/test/include") 10 | 11 | foreach(child ${SUBDIRS}) 12 | if(IS_DIRECTORY "${child}") 13 | add_subdirectory(${child}) 14 | endif() 15 | endforeach() 16 | -------------------------------------------------------------------------------- /test/atomics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ############################################################################## 2 | # vatomicptr markable and stamped 3 | # ############################################################################## 4 | 5 | add_executable(atomicptr_markable atomicptr_markable_test.c) 6 | target_link_libraries(atomicptr_markable vsync pthread) 7 | v_add_bin_test(NAME atomicptr_markable COMMAND atomicptr_markable) 8 | 9 | add_executable(atomicptr_stamped atomicptr_stamped_test.c) 10 | target_link_libraries(atomicptr_stamped vsync pthread) 11 | v_add_bin_test(NAME atomicptr_stamped COMMAND atomicptr_stamped) 12 | -------------------------------------------------------------------------------- /test/bitmap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRCS *.c) 2 | foreach(SRC ${SRCS}) 3 | get_filename_component(TEST ${SRC} NAME_WE) 4 | add_executable(${TEST} ${SRC}) 5 | target_link_libraries(${TEST} vsync pthread) 6 | v_add_bin_test(NAME ${TEST} COMMAND ${TEST}) 7 | endforeach() 8 | -------------------------------------------------------------------------------- /test/cachedq/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(FILE_NAME cachedq_stress.c) 2 | set(TEST_NAME "test_stress_cachedq") 3 | add_executable(${TEST_NAME} ${FILE_NAME}) 4 | target_link_libraries(${TEST_NAME} vsync pthread) 5 | v_add_bin_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) 6 | -------------------------------------------------------------------------------- /test/chaselev/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRCS *.c) 2 | foreach(SRC ${SRCS}) 3 | get_filename_component(TEST ${SRC} NAME_WE) 4 | 5 | add_executable(${TEST} ${SRC}) 6 | target_link_libraries(${TEST} vsync pthread) 7 | v_add_bin_test(NAME ${TEST} COMMAND ${TEST}) 8 | endforeach() 9 | -------------------------------------------------------------------------------- /test/chaselev/test_enq_deq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #define NUM_ENTRIES 3U 12 | 13 | vdeque_t g_vdeque; 14 | 15 | void 16 | test_push_pop(void) 17 | { 18 | vuint32_t array_size = vdeque_memsize(NUM_ENTRIES); 19 | vdeque_array_t *a = (vdeque_array_t *)malloc(array_size); 20 | 21 | ASSERT(a != NULL); 22 | vdeque_init(&g_vdeque, a, NUM_ENTRIES); 23 | 24 | vuint32_t num_push = 0, num_pop = 0; 25 | 26 | vuint32_t v1 = 1; 27 | vdeque_state_t status; 28 | while (vdeque_push_bottom(&g_vdeque, &v1) == VDEQUE_STATE_OK) { 29 | num_push++; 30 | } 31 | status = vdeque_push_bottom(&g_vdeque, &v1); 32 | ASSERT(status == VDEQUE_STATE_FULL); 33 | ASSERT(num_push == NUM_ENTRIES); 34 | 35 | void *v2 = NULL; 36 | while (vdeque_pop_bottom(&g_vdeque, &v2) == VDEQUE_STATE_OK) { 37 | num_pop++; 38 | } 39 | status = vdeque_pop_bottom(&g_vdeque, &v2); 40 | ASSERT(status == VDEQUE_STATE_EMPTY); 41 | 42 | V_UNUSED(status); 43 | 44 | ASSERT(num_push == num_pop); 45 | } 46 | 47 | int 48 | main(void) 49 | { 50 | test_push_pop(); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /test/hashtable/test_stress.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #define EVICT 10 10 | #define EVICT_FREQ 10 11 | 12 | void * 13 | run(void *args) 14 | { 15 | vsize_t tid = (vsize_t)(vuintptr_t)args; 16 | vsize_t succ_insert = 0; 17 | vsize_t succ_remove = 0; 18 | 19 | map_reg(tid); 20 | for (vsize_t i = 0; i < IT; i++) { 21 | map_enter(tid); 22 | user_key_t key = gen_key(); 23 | if (map_get(tid, key)) { 24 | succ_remove += map_remove(tid, key) ? 1 : 0; 25 | } else { 26 | succ_insert += map_insert(tid, key) ? 1 : 0; 27 | if (succ_insert % EVICT_FREQ == 0) { 28 | (void)map_evict(tid, EVICT); 29 | } 30 | } 31 | map_exit(tid); 32 | } 33 | map_dereg(tid); 34 | DBG_GREEN("[T%zu] removed %zu, inserted %zu\n", tid, succ_remove, 35 | succ_insert); 36 | 37 | return NULL; 38 | } 39 | 40 | int 41 | main(void) 42 | { 43 | map_init(); 44 | launch_threads(NTHREADS, run); 45 | map_destroy(); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /test/include/test/hashtable/hashtable.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VHASHTABLE_H 7 | #define VHASHTABLE_H 8 | 9 | #if defined(HASHTABLE_STANDARD) 10 | #include 11 | #elif defined(HASHTABLE_EVICTABLE) 12 | #include 13 | #include 14 | #else 15 | #error "undefined impl." 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /test/include/test/hashtable/hashtable_stats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VHASHTABLE_STATS_H 7 | #define VHASHTABLE_STATS_H 8 | 9 | typedef struct _ghost_ht_stats_s { 10 | double bucket_len_avg; 11 | vuint64_t bucket_len_min; 12 | vuint64_t bucket_len_max; 13 | vuint64_t bucket_len_sum; 14 | } _ghost_ht_stats_t; 15 | 16 | static inline _ghost_ht_stats_t 17 | _vhashtable_get_stats(vhashtable_t *table) 18 | { 19 | _ghost_ht_stats_t stats = {0}; 20 | stats.bucket_len_min = VUINT64_MAX; 21 | vuint64_t len = 0; 22 | 23 | for (vsize_t i = 0; i < VHASHTABLE_BUCKET_COUNT; i++) { 24 | len = vbucket_get_length(&table->buckets[i]); 25 | stats.bucket_len_sum += len; 26 | stats.bucket_len_min = VMIN(stats.bucket_len_min, len); 27 | stats.bucket_len_max = VMAX(stats.bucket_len_min, len); 28 | } 29 | stats.bucket_len_avg = 30 | (double)stats.bucket_len_sum / VHASHTABLE_BUCKET_COUNT; 31 | 32 | return stats; 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /test/include/test/locked_trace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VTRACE_LOCKED_H 7 | #define VTRACE_LOCKED_H 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | typedef struct locked_trace_s { 14 | trace_t trace; 15 | pthread_mutex_t lock; 16 | } locked_trace_t; 17 | 18 | static inline void 19 | locked_trace_init(locked_trace_t *trace, vsize_t capacity) 20 | { 21 | ASSERT(trace); 22 | pthread_mutex_init(&trace->lock, NULL); 23 | trace_init(&trace->trace, capacity); 24 | } 25 | 26 | static inline void 27 | locked_trace_add(locked_trace_t *trace, vuintptr_t obj) 28 | { 29 | ASSERT(trace); 30 | pthread_mutex_lock(&trace->lock); 31 | trace_add(&trace->trace, obj); 32 | pthread_mutex_unlock(&trace->lock); 33 | } 34 | 35 | static inline void 36 | locked_trace_destroy(locked_trace_t *trace, trace_verify_unit callback) 37 | { 38 | trace_verify(&trace->trace, callback); 39 | trace_destroy(&trace->trace); 40 | pthread_mutex_destroy(&trace->lock); 41 | } 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /test/include/test/map/itreeset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_ITREESET_H 7 | #define VSYNC_ITREESET_H 8 | 9 | #if defined TREESET_BST_FINE 10 | #include 11 | #elif defined TREESET_RB_FINE 12 | #include 13 | #elif defined TREESET_BST_COARSE 14 | #include 15 | #elif defined TREESET_RB_COARSE 16 | #include 17 | #else 18 | #error "Choose treeset implementation by setting TREESET_*" 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /test/include/test/map/treeset_test_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TREESET_TEST_INTERFACE_H 7 | #define VSYNC_TREESET_TEST_INTERFACE_H 8 | 9 | #include 10 | 11 | treeset_t g_tree; 12 | 13 | static inline vbool_t 14 | tr_add(treeset_key_t key) 15 | { 16 | vbool_t success = treeset_add(&g_tree, key, NULL, NULL); 17 | return success; 18 | } 19 | 20 | static inline vbool_t 21 | tr_rem(treeset_key_t key) 22 | { 23 | vbool_t success = treeset_remove(&g_tree, key, NULL); 24 | return success; 25 | } 26 | 27 | static inline vbool_t 28 | tr_con(treeset_key_t key) 29 | { 30 | vbool_t success = treeset_contains(&g_tree, key, NULL); 31 | return success; 32 | } 33 | 34 | static inline void 35 | tr_init(void) 36 | { 37 | vmem_lib_t mem_lib = VMEM_LIB_DEFAULT(); 38 | treeset_init(&g_tree, mem_lib); 39 | } 40 | 41 | static inline void 42 | tr_destroy(void) 43 | { 44 | treeset_destroy(&g_tree); 45 | } 46 | 47 | static inline void 48 | tr_verify(void) 49 | { 50 | _treeset_verify(&g_tree); 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /test/include/test/prio/queue_prio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef QUEUE_PRIO_DISPATCH_H 7 | #define QUEUE_PRIO_DISPATCH_H 8 | 9 | #if defined(VQUEUE_PRIO_STACK_ARRAY_BASED) 10 | #include 11 | typedef vsize_t vpriority_t; 12 | #define BM_TARGET_NAME "stack_arr_based" 13 | #elif defined(VQUEUE_PRIO_STACK_TREE_BASED) 14 | #include 15 | typedef vsize_t vpriority_t; 16 | #define BM_TARGET_NAME "stack_tree_based" 17 | #elif defined(VQUEUE_PRIO_SKIPLIST_BASED) 18 | #include 19 | typedef vskiplist_key_t vpriority_t; 20 | #define BM_TARGET_NAME "skiplist_based" 21 | #elif defined(VQUEUE_PRIO_HEAP_BASED) 22 | #include 23 | typedef vuint32_t vpriority_t; 24 | #define BM_TARGET_NAME "heap_based" 25 | #define SMR_NONE 26 | #else 27 | #error "QUEUE_PRIO implementation is not defined" 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /test/include/test/smr/mock_node.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_SMR_MOCK_NODE_H 7 | #define VSYNC_SMR_MOCK_NODE_H 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | typedef struct mock_node_s { 14 | uintptr_t x; 15 | vsize_t owner; 16 | vatomic64_t key; 17 | smr_node_t smr_node; 18 | vatomicptr_t next; 19 | #ifdef MOCK_INJECTED_FIELD 20 | MOCK_INJECTED_FIELD; 21 | #endif 22 | } mock_node_t; 23 | 24 | typedef void (*cb_notify)(mock_node_t *node); 25 | 26 | cb_notify g_notify = NULL; 27 | 28 | static inline void * 29 | mock_node_alloc(void) 30 | { 31 | return vmem_malloc(sizeof(mock_node_t)); 32 | } 33 | 34 | static inline vuint64_t 35 | mock_node_get_free_count(void) 36 | { 37 | return vmem_get_free_count(); 38 | } 39 | 40 | static inline void 41 | mock_node_free(smr_node_t *snode, void *args) 42 | { 43 | mock_node_t *node = V_CONTAINER_OF(snode, mock_node_t, smr_node); 44 | if (g_notify) { 45 | g_notify(node); 46 | } 47 | #if !defined(SMR_GBA) 48 | vmem_free(node); 49 | #endif 50 | V_UNUSED(args); 51 | } 52 | 53 | static inline vbool_t 54 | mock_node_no_leak(void) 55 | { 56 | return vmem_no_leak(); 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /test/include/test/smr/thread_lock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #ifndef VSYNC_SMR_TEST_LOCK_H 8 | #define VSYNC_SMR_TEST_LOCK_H 9 | 10 | typedef pthread_mutex_t thread_lock_t; 11 | 12 | static inline void 13 | thread_lock_init(void *arg) 14 | { 15 | pthread_mutex_t *lock = (pthread_mutex_t *)arg; 16 | int ret = pthread_mutex_init(lock, NULL); 17 | ASSERT(ret == 0); 18 | V_UNUSED(ret); 19 | } 20 | 21 | static inline void 22 | thread_lock_acq(void *arg) 23 | { 24 | pthread_mutex_t *lock = (pthread_mutex_t *)arg; 25 | int ret = pthread_mutex_lock(lock); 26 | ASSERT(ret == 0); 27 | V_UNUSED(ret); 28 | } 29 | static inline void 30 | thread_lock_rel(void *arg) 31 | { 32 | pthread_mutex_t *lock = (pthread_mutex_t *)arg; 33 | int ret = pthread_mutex_unlock(lock); 34 | ASSERT(ret == 0); 35 | V_UNUSED(ret); 36 | } 37 | 38 | #define LOCK_LIB_DEFAULT(_l_) \ 39 | (smr_lock_lib_t) \ 40 | { \ 41 | thread_lock_acq, thread_lock_rel, _l_ \ 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /test/include/test/vtid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_VTID_H 7 | #define VSYNC_VTID_H 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define VTID_NOT_ASSIGNED 0 15 | 16 | vatomic32_t g_pqueue_tid_generator = VATOMIC_INIT(1); 17 | 18 | __thread vuint32_t pqueue_tid = VTID_NOT_ASSIGNED; 19 | 20 | static inline vuint32_t 21 | vtid_get_thread_id(void) 22 | { 23 | if (pqueue_tid == VTID_NOT_ASSIGNED) { 24 | pqueue_tid = vatomic32_get_inc_rlx(&g_pqueue_tid_generator); 25 | ASSERT(pqueue_tid != VTID_NOT_ASSIGNED); 26 | } 27 | return pqueue_tid; 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /test/pool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRCS *.c) 2 | foreach(SRC ${SRCS}) 3 | 4 | get_filename_component(TEST ${SRC} NAME_WE) 5 | set(TEST test_${TEST}) 6 | 7 | add_executable(${TEST} ${SRC}) 8 | target_link_libraries(${TEST} vsync pthread) 9 | target_compile_options(${TEST} PRIVATE -O3) 10 | v_add_bin_test(NAME ${TEST} COMMAND ${TEST}) 11 | 12 | endforeach() 13 | -------------------------------------------------------------------------------- /test/priority_queue/include/test/prio/queue_prio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef QUEUE_PRIO_DISPATCH_H 7 | #define QUEUE_PRIO_DISPATCH_H 8 | 9 | #if defined(VQUEUE_PRIO_STACK_ARRAY_BASED) 10 | #include 11 | typedef vsize_t vpriority_t; 12 | #define BM_TARGET_NAME "stack_arr_based" 13 | #elif defined(VQUEUE_PRIO_STACK_TREE_BASED) 14 | #include 15 | typedef vsize_t vpriority_t; 16 | #define BM_TARGET_NAME "stack_tree_based" 17 | #elif defined(VQUEUE_PRIO_SKIPLIST_BASED) 18 | #include 19 | typedef vskiplist_key_t vpriority_t; 20 | #define BM_TARGET_NAME "skiplist_based" 21 | #elif defined(VQUEUE_PRIO_HEAP_BASED) 22 | #include 23 | typedef vuint32_t vpriority_t; 24 | #define BM_TARGET_NAME "heap_based" 25 | #define SMR_NONE 26 | #else 27 | #error "QUEUE_PRIO implementation is not defined" 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /test/quack/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRCS *.c) 2 | foreach(SRC ${SRCS}) 3 | get_filename_component(TEST ${SRC} NAME_WE) 4 | 5 | add_executable(${TEST} ${SRC}) 6 | target_link_libraries(${TEST} vsync pthread) 7 | target_compile_definitions(${TEST} PUBLIC _GNU_SOURCE) 8 | v_add_bin_test(NAME ${TEST} COMMAND ${TEST}) 9 | 10 | add_vsyncer_check( 11 | TARGET ${TEST}-check 12 | SOURCE ${SRC} 13 | DEPENDENCIES vsync) 14 | endforeach() 15 | -------------------------------------------------------------------------------- /test/queue/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRCS *.c) 2 | foreach(SRC ${SRCS}) 3 | 4 | get_filename_component(TEST ${SRC} NAME_WE) 5 | 6 | add_executable(${TEST} ${SRC}) 7 | target_link_libraries(${TEST} vsync pthread) 8 | v_add_bin_test(NAME ${TEST} COMMAND ${TEST}) 9 | 10 | add_vsyncer_check( 11 | TARGET ${TEST}-check 12 | SOURCE ${SRC} 13 | TIMEOUT 500 14 | DEPENDENCIES vsync 15 | MEMORY_MODELS imm) 16 | endforeach() 17 | 18 | # Enable some tests with VMM and set extra options for Dartagnan 19 | set(DAT3M_BOUND_bounded_spsc 4) 20 | set(DAT3M_BOUND_bounded_mpmc_check_empty 5) 21 | set(DAT3M_BOUND_bounded_mpmc_check_full 3) 22 | 23 | foreach(SRC ${SRCS}) 24 | get_filename_component(TEST ${SRC} NAME_WE) 25 | 26 | if(${DAT3M_BOUND_${TEST}}) 27 | add_vsyncer_check( 28 | TARGET check_${TEST} 29 | SOURCE ${SRC} 30 | MEMORY_MODELS vmm USE_DAT3M DARTAGNAN_OPTIONS 31 | --bound=${DAT3M_BOUND_${TEST}} 32 | TIMEOUT 500 33 | DEPENDENCIES vsync) 34 | endif() 35 | endforeach() 36 | -------------------------------------------------------------------------------- /test/simpleht/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_include_directories( 2 | vsync INTERFACE $ 3 | $) 4 | ProcessorCount(PCOUNT) 5 | 6 | include_directories(include) 7 | 8 | file(GLOB TEST_FILES *.c) 9 | 10 | set(NTHREADS ${PCOUNT}) 11 | 12 | set(TEST_DEFS TST_IT=10000) 13 | 14 | set(ALGOS simple) 15 | 16 | foreach(test_path IN ITEMS ${TEST_FILES}) 17 | foreach(algo IN ITEMS ${ALGOS}) 18 | # extract test_name with extension 19 | get_filename_component(test_name ${test_path} NAME) 20 | 21 | # name without extension 22 | get_filename_component(test_case ${test_path} NAME_WE) 23 | 24 | set(TEST_CASE ${test_case}_${algo}) 25 | 26 | string(TOLOWER ${TEST_CASE} TEST_CASE) 27 | 28 | add_executable(${TEST_CASE} ${test_name}) 29 | 30 | target_link_libraries(${TEST_CASE} vsync pthread) 31 | 32 | # add defines 33 | target_compile_definitions(${TEST_CASE} PUBLIC ${TEST_DEFS} ${algo}) 34 | 35 | v_add_bin_test_advanced( 36 | NAME 37 | ${TEST_CASE} 38 | COMMAND 39 | ${TEST_CASE} 40 | TIMEOUT 41 | 3600 42 | PROCESSORS 43 | 4) 44 | 45 | endforeach() 46 | endforeach() 47 | -------------------------------------------------------------------------------- /test/simpleht/mt_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define NTHREADS 24U 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #define MIN_KEY 1U 13 | #define MAX_KEY VSIMPLE_HT_CAPACITY 14 | #define TID MAIN_TID 15 | 16 | void 17 | run_operation(vsize_t tid, vuintptr_t key) 18 | { 19 | data_t *data = NULL; 20 | data = imap_get(tid, key); 21 | if (data) { 22 | imap_rem(tid, key); 23 | } else { 24 | imap_add(tid, key, key); 25 | } 26 | } 27 | 28 | void * 29 | run(void *args) 30 | { 31 | vsize_t tid = (vsize_t)(vuintptr_t)args; 32 | 33 | imap_reg(tid); 34 | 35 | for (vuintptr_t key = MIN_KEY; key <= MAX_KEY; key++) { 36 | run_operation(tid, key); 37 | } 38 | 39 | imap_dereg(tid); 40 | 41 | return NULL; 42 | } 43 | 44 | int 45 | main(void) 46 | { 47 | imap_init(); 48 | launch_threads(NTHREADS, run); 49 | imap_destroy(); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /test/simpleht/mt_test_no_rem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #define NTHREADS 24U 8 | #define VSIMPLEHT_DISABLE_REMOVE 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #define MIN_KEY 1U 15 | #define MAX_KEY VSIMPLE_HT_CAPACITY 16 | #define TID MAIN_TID 17 | 18 | vatomicsz_t g_cnt = VATOMIC_INIT(0); 19 | 20 | void 21 | run_operation(vsize_t tid, vuintptr_t key) 22 | { 23 | vbool_t added = false; 24 | data_t *data = imap_get(tid, key); 25 | if (!data) { 26 | added = imap_add(tid, key, key); 27 | if (added) { 28 | vatomicsz_inc_rlx(&g_cnt); 29 | } 30 | } 31 | } 32 | 33 | void * 34 | run(void *args) 35 | { 36 | vsize_t tid = (vsize_t)(vuintptr_t)args; 37 | for (vuintptr_t key = MIN_KEY; key <= MAX_KEY; key++) { 38 | run_operation(tid, key); 39 | } 40 | return NULL; 41 | } 42 | 43 | int 44 | main(void) 45 | { 46 | imap_init(); 47 | launch_threads(NTHREADS, run); 48 | imap_destroy(); 49 | vsize_t cnt = vatomicsz_read(&g_cnt); 50 | ASSERT(cnt == VSIMPLE_HT_CAPACITY); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /test/smr/test_sanity.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* 13 | * Ensure everything that was handed in to SMR is freed 14 | * Ensure retirement kept things safe till exit 15 | */ 16 | 17 | void * 18 | run(void *args) 19 | { 20 | mock_node_t *mock = NULL; 21 | vsize_t i = 0; 22 | vsize_t tid = (vsize_t)(vuintptr_t)args; 23 | 24 | ismr_reg(tid); 25 | 26 | for (i = 0; i < TST_IT; i++) { 27 | ismr_enter(tid); 28 | 29 | mock = mock_node_alloc(); 30 | 31 | ismr_retire(&mock->smr_node, mock_node_free, false); 32 | mock->x = tid; 33 | 34 | ismr_exit(tid); 35 | 36 | ismr_recycle(tid); 37 | } 38 | 39 | ismr_dereg(tid); 40 | return NULL; 41 | } 42 | 43 | int 44 | main(void) 45 | { 46 | ismr_init(); 47 | launch_threads(SMR_MAX_NTHREADS, run); 48 | mock_node_no_leak(); 49 | ismr_destroy(); 50 | ASSERT(mock_node_no_leak()); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /test/spinlock/arraylock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define WITH_INIT 7 | 8 | #define REACQUIRE 1 9 | 10 | #include 11 | #include 12 | 13 | #ifndef ARRAY_LOCK_LEN 14 | #define ARRAY_LOCK_LEN (NTHREADS + 1U) 15 | #endif 16 | arraylock_flag_t flags[ARRAY_LOCK_LEN]; 17 | arraylock_t lock; 18 | static __thread vuint32_t slot; 19 | 20 | V_STATIC_ASSERT(NTHREADS <= ARRAY_LOCK_LEN, 21 | "ARRAY_LOCK_LEN must be a power of two greater than NTHREADS. " 22 | "You can overwrite it with `-DARRAY_LOCK_LEN=N`"); 23 | 24 | // Static initialisation causes problems to Dartagnan for this benchmark 25 | void 26 | init(void) 27 | { 28 | arraylock_init(&lock, flags, ARRAY_LOCK_LEN); 29 | } 30 | 31 | void 32 | acquire(vuint32_t tid) 33 | { 34 | V_UNUSED(tid); 35 | arraylock_acquire(&lock, &slot); 36 | } 37 | 38 | void 39 | release(vuint32_t tid) 40 | { 41 | V_UNUSED(tid); 42 | arraylock_release(&lock, slot); 43 | } 44 | -------------------------------------------------------------------------------- /test/spinlock/caslock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define REACQUIRE 1 7 | 8 | #include 9 | #include 10 | 11 | caslock_t lock = CASLOCK_INIT(); 12 | 13 | void 14 | acquire(vuint32_t tid) 15 | { 16 | if (tid == NTHREADS - 1) { 17 | #if defined(VSYNC_VERIFICATION_DAT3M) || defined(VSYNC_VERIFICATION_GENERIC) 18 | vbool_t acquired = caslock_tryacquire(&lock); 19 | verification_assume(acquired); 20 | #else 21 | await_while (!caslock_tryacquire(&lock)) {} 22 | #endif 23 | } else { 24 | caslock_acquire(&lock); 25 | } 26 | } 27 | 28 | void 29 | release(vuint32_t tid) 30 | { 31 | V_UNUSED(tid); 32 | caslock_release(&lock); 33 | } 34 | -------------------------------------------------------------------------------- /test/spinlock/clhlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define REACQUIRE 1 7 | #define WITH_INIT 8 | 9 | #define NULL ((void *)(0)) 10 | #include 11 | #include 12 | 13 | clhlock_t lock; 14 | clh_qnode_t initial; 15 | clh_node_t node[NTHREADS]; 16 | 17 | void 18 | init(void) 19 | { 20 | clhlock_init(&lock); 21 | 22 | for (int i = 0; i < NTHREADS; i++) { 23 | clhlock_node_init(&node[i]); 24 | } 25 | } 26 | 27 | void 28 | acquire(vuint32_t tid) 29 | { 30 | clhlock_acquire(&lock, &node[tid]); 31 | } 32 | 33 | void 34 | release(vuint32_t tid) 35 | { 36 | clhlock_release(&lock, &node[tid]); 37 | } 38 | -------------------------------------------------------------------------------- /test/spinlock/cnalock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifdef VSYNC_VERIFICATION_QUICK 7 | #define NTHREADS 4 8 | #else 9 | #define NTHREADS 5 10 | #endif 11 | 12 | #define WITH_POST 13 | 14 | #include 15 | #include 16 | 17 | cnalock_t lock = CNALOCK_INIT(); 18 | struct cna_node_s nodes[NTHREADS]; 19 | 20 | void 21 | post(void) 22 | { 23 | #ifdef VSYNC_VERIFICATION 24 | vatomic32_write_rlx(&rand, 1); 25 | #endif 26 | } 27 | 28 | #define NUMA(_tid_) ((_tid_) < NTHREADS / 2) 29 | 30 | void 31 | acquire(vuint32_t tid) 32 | { 33 | cnalock_acquire(&lock, &nodes[tid], NUMA(tid)); 34 | } 35 | 36 | void 37 | release(vuint32_t tid) 38 | { 39 | cnalock_release(&lock, &nodes[tid], NUMA(tid)); 40 | } 41 | -------------------------------------------------------------------------------- /test/spinlock/hclhlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define HCLH_MAX_CLUSTERS 2 7 | #define REACQUIRE 1 8 | #define WITH_INIT 9 | 10 | #include 11 | #include 12 | 13 | hclh_lock_t lock; 14 | hclh_tnode_t tnode[NTHREADS]; 15 | hclh_qnode_t qnode[NTHREADS]; 16 | 17 | void 18 | init(void) 19 | { 20 | hclhlock_init(&lock); 21 | for (vsize_t i = 0; i < NTHREADS; i++) { 22 | vuint32_t cluster = i % HCLH_MAX_CLUSTERS; 23 | hclhlock_init_tnode(&tnode[i], &qnode[i], cluster); 24 | } 25 | } 26 | 27 | void 28 | acquire(vuint32_t tid) 29 | { 30 | hclhlock_acquire(&lock, &tnode[tid]); 31 | } 32 | 33 | void 34 | release(vuint32_t tid) 35 | { 36 | hclhlock_release(&tnode[tid]); 37 | } 38 | -------------------------------------------------------------------------------- /test/spinlock/hemlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifdef VSYNC_VERIFICATION_QUICK 7 | #define REACQUIRE 1 8 | #define NTHREADS 3 9 | #else 10 | #define REACQUIRE 1 11 | #define NTHREADS 4 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | hemlock_t lock = HEMLOCK_INIT(); 18 | struct hem_node_s nodes[NTHREADS]; 19 | 20 | void 21 | acquire(vuint32_t tid) 22 | { 23 | if (tid == NTHREADS - 1) { 24 | #if defined(VSYNC_VERIFICATION_DAT3M) || defined(VSYNC_VERIFICATION_GENERIC) 25 | vbool_t acquired = hemlock_tryacquire(&lock, &nodes[tid]); 26 | verification_assume(acquired); 27 | #else 28 | await_while (!hemlock_tryacquire(&lock, &nodes[tid])) {} 29 | #endif 30 | } else { 31 | hemlock_acquire(&lock, &nodes[tid]); 32 | } 33 | } 34 | 35 | void 36 | release(vuint32_t tid) 37 | { 38 | hemlock_release(&lock, &nodes[tid]); 39 | } 40 | -------------------------------------------------------------------------------- /test/spinlock/mcslock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define REACQUIRE 1 7 | 8 | #include 9 | #include 10 | 11 | mcslock_t lock = MCSLOCK_INIT(); 12 | struct mcs_node_s nodes[NTHREADS]; 13 | 14 | void 15 | acquire(vuint32_t tid) 16 | { 17 | if (tid == NTHREADS - 1) { 18 | #if defined(VSYNC_VERIFICATION_DAT3M) || defined(VSYNC_VERIFICATION_GENERIC) 19 | vbool_t acquired = mcslock_tryacquire(&lock, &nodes[tid]); 20 | verification_assume(acquired); 21 | #else 22 | await_while (!mcslock_tryacquire(&lock, &nodes[tid])) {} 23 | #endif 24 | } else { 25 | mcslock_acquire(&lock, &nodes[tid]); 26 | } 27 | } 28 | 29 | void 30 | release(vuint32_t tid) 31 | { 32 | mcslock_release(&lock, &nodes[tid]); 33 | } 34 | -------------------------------------------------------------------------------- /test/spinlock/rec_mcslock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define REENTRANT 1 7 | 8 | #include 9 | #include 10 | 11 | rec_mcslock_t lock = REC_MCSLOCK_INIT(); 12 | struct mcs_node_s nodes[NTHREADS]; 13 | 14 | void 15 | acquire(vuint32_t tid) 16 | { 17 | rec_mcslock_acquire(&lock, tid, &nodes[tid]); 18 | } 19 | 20 | void 21 | release(vuint32_t tid) 22 | { 23 | rec_mcslock_release(&lock, &nodes[tid]); 24 | } 25 | -------------------------------------------------------------------------------- /test/spinlock/rec_spinlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define REENTRANT 1 7 | 8 | #include 9 | #include 10 | 11 | rec_spinlock_t lock = REC_SPINLOCK_INIT(); 12 | 13 | void 14 | acquire(vuint32_t tid) 15 | { 16 | if (tid == NTHREADS - 1) { 17 | #if defined(VSYNC_VERIFICATION_DAT3M) || defined(VSYNC_VERIFICATION_GENERIC) 18 | vbool_t acquired = rec_spinlock_tryacquire(&lock, tid); 19 | verification_assume(acquired); 20 | #else 21 | await_while (!rec_spinlock_tryacquire(&lock, tid)) {} 22 | #endif 23 | } else { 24 | rec_spinlock_acquire(&lock, tid); 25 | } 26 | } 27 | 28 | void 29 | release(vuint32_t tid) 30 | { 31 | V_UNUSED(tid); 32 | rec_spinlock_release(&lock); 33 | } 34 | -------------------------------------------------------------------------------- /test/spinlock/rec_ticketlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define REENTRANT 1 7 | 8 | #include 9 | #include 10 | 11 | rec_ticketlock_t lock = REC_TICKETLOCK_INIT(); 12 | 13 | void 14 | acquire(vuint32_t tid) 15 | { 16 | if (tid == NTHREADS - 1) { 17 | await_while (!rec_ticketlock_tryacquire(&lock, tid)) {} 18 | } else { 19 | rec_ticketlock_acquire(&lock, tid); 20 | } 21 | } 22 | 23 | void 24 | release(vuint32_t tid) 25 | { 26 | V_UNUSED(tid); 27 | rec_ticketlock_release(&lock); 28 | } 29 | -------------------------------------------------------------------------------- /test/spinlock/rwlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifdef VSYNC_VERIFICATION_QUICK 7 | #define NREADERS 1 8 | #define NWRITERS 2 9 | #else 10 | #define NREADERS 2 11 | #define NWRITERS 2 12 | #endif 13 | 14 | #include 15 | #include 16 | 17 | rwlock_t lock = RWLOCK_INIT(); 18 | 19 | void 20 | writer_acquire(vuint32_t tid) 21 | { 22 | V_UNUSED(tid); 23 | rwlock_write_acquire(&lock); 24 | } 25 | void 26 | writer_release(vuint32_t tid) 27 | { 28 | V_UNUSED(tid); 29 | rwlock_write_release(&lock); 30 | } 31 | void 32 | reader_acquire(vuint32_t tid) 33 | { 34 | V_UNUSED(tid); 35 | rwlock_read_acquire(&lock); 36 | } 37 | void 38 | reader_release(vuint32_t tid) 39 | { 40 | V_UNUSED(tid); 41 | rwlock_read_release(&lock); 42 | } 43 | -------------------------------------------------------------------------------- /test/spinlock/semaphore.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define WITH_INIT 7 | 8 | #ifdef VSYNC_VERIFICATION_QUICK 9 | #define NREADERS 1 10 | #define NWRITERS 2 11 | #else 12 | #define NREADERS 2 13 | #define NWRITERS 2 14 | #endif 15 | 16 | #include 17 | #include 18 | 19 | #define M NTHREADS 20 | semaphore_t g_semaphore; 21 | 22 | // Static initialisation causes problems to Dartagnan for this benchmark 23 | void 24 | init(void) 25 | { 26 | semaphore_init(&g_semaphore, M); 27 | } 28 | 29 | void 30 | writer_acquire(vuint32_t tid) 31 | { 32 | V_UNUSED(tid); 33 | semaphore_acquire(&g_semaphore, M); 34 | } 35 | 36 | void 37 | writer_release(vuint32_t tid) 38 | { 39 | V_UNUSED(tid); 40 | semaphore_release(&g_semaphore, M); 41 | } 42 | void 43 | reader_acquire(vuint32_t tid) 44 | { 45 | V_UNUSED(tid); 46 | semaphore_acquire(&g_semaphore, 1); 47 | } 48 | 49 | void 50 | reader_release(vuint32_t tid) 51 | { 52 | V_UNUSED(tid); 53 | semaphore_release(&g_semaphore, 1); 54 | } 55 | -------------------------------------------------------------------------------- /test/spinlock/seqcount.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define WITH_CS 7 | 8 | #include 9 | // this impl works only with single writer 10 | #define NWRITERS 1U 11 | #include 12 | 13 | seqcount_t g_seq_cnt; 14 | vuint32_t g_cs_x, g_cs_y; 15 | 16 | void 17 | writer_cs(vuint32_t tid) 18 | { 19 | V_UNUSED(tid); 20 | seqvalue_t s = seqcount_wbegin(&g_seq_cnt); 21 | g_cs_x++; 22 | g_cs_y++; 23 | seqcount_wend(&g_seq_cnt, s); 24 | } 25 | 26 | void 27 | reader_cs(vuint32_t tid) 28 | { 29 | vuint32_t a = 0; 30 | vuint32_t b = 0; 31 | seqvalue_t s = 0; 32 | 33 | await_do { 34 | s = seqcount_rbegin(&g_seq_cnt); 35 | a = g_cs_x; 36 | b = g_cs_y; 37 | } 38 | while_await(!seqcount_rend(&g_seq_cnt, s)); 39 | 40 | ASSERT(a == b); 41 | ASSERT((s >> 1) == a); 42 | 43 | V_UNUSED(a, b, tid); 44 | } 45 | -------------------------------------------------------------------------------- /test/spinlock/seqlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define NREADERS 2 7 | #define NWRITERS 2 8 | #define EXPECTED_FINAL_VALUE NWRITERS 9 | #define WITH_CS 10 | #define WITH_FINI 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | seqlock_t lock = SEQ_LOCK_INIT(); 17 | 18 | vuint32_t g_cs_x; 19 | vuint32_t g_cs_y; 20 | 21 | void 22 | writer_cs(vuint32_t tid) 23 | { 24 | seqlock_acquire(&lock); 25 | g_cs_x++; 26 | g_cs_y++; 27 | seqlock_release(&lock); 28 | V_UNUSED(tid); 29 | } 30 | 31 | void 32 | reader_cs(vuint32_t tid) 33 | { 34 | vuint32_t a = 0; 35 | vuint32_t b = 0; 36 | seqvalue_t s = 0; 37 | 38 | await_do { 39 | s = seqlock_rbegin(&lock); 40 | a = g_cs_x; 41 | b = g_cs_y; 42 | } 43 | while_await(!seqlock_rend(&lock, s)); 44 | 45 | ASSERT(a == b); 46 | ASSERT(VIS_EVEN(s)); 47 | V_UNUSED(tid, a, b); 48 | } 49 | 50 | void 51 | fini(void) 52 | { 53 | vuint32_t x = g_cs_x; 54 | vuint32_t y = g_cs_y; 55 | ASSERT(x == y); 56 | ASSERT(x == EXPECTED_FINAL_VALUE); 57 | V_UNUSED(x, y); 58 | } 59 | -------------------------------------------------------------------------------- /test/spinlock/ticketlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | ticketlock_t lock = TICKETLOCK_INIT(); 10 | 11 | void 12 | acquire(vuint32_t tid) 13 | { 14 | if (tid == NTHREADS - 1) { 15 | await_while (!ticketlock_tryacquire(&lock)) {} 16 | } else { 17 | ticketlock_acquire(&lock); 18 | } 19 | } 20 | 21 | void 22 | release(vuint32_t tid) 23 | { 24 | V_UNUSED(tid); 25 | ticketlock_release(&lock); 26 | } 27 | -------------------------------------------------------------------------------- /test/spinlock/ttaslock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | ttaslock_t lock = TTASLOCK_INIT(); 10 | 11 | void 12 | acquire(vuint32_t tid) 13 | { 14 | V_UNUSED(tid); 15 | ttaslock_acquire(&lock); 16 | } 17 | 18 | void 19 | release(vuint32_t tid) 20 | { 21 | V_UNUSED(tid); 22 | 23 | ttaslock_release(&lock); 24 | } 25 | -------------------------------------------------------------------------------- /test/spinlock/twalock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | TWALOCK_ARRAY_DECL; 10 | twalock_t lock = TWALOCK_INIT(); 11 | 12 | void 13 | acquire(vuint32_t tid) 14 | { 15 | if (tid == NTHREADS - 1) { 16 | #if defined(VSYNC_VERIFICATION_DAT3M) || defined(VSYNC_VERIFICATION_GENERIC) 17 | vbool_t acquired = twalock_tryacquire(&lock); 18 | verification_assume(acquired); 19 | #else 20 | await_while (!twalock_tryacquire(&lock)) {} 21 | #endif 22 | } else { 23 | twalock_acquire(&lock); 24 | } 25 | } 26 | 27 | void 28 | release(vuint32_t tid) 29 | { 30 | V_UNUSED(tid); 31 | twalock_release(&lock); 32 | } 33 | -------------------------------------------------------------------------------- /test/treeset/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_include_directories( 2 | vsync INTERFACE $ 3 | $) 4 | 5 | ProcessorCount(PCOUNT) 6 | 7 | file(GLOB TEST_FILES test_*.c) 8 | 9 | set(ALGOS BST_FINE RB_FINE BST_COARSE RB_COARSE) 10 | set(TEST_DEFS TREESET_LOCK_TTAS) 11 | 12 | # For Code coverage mode use only 4 threads, otherwise PCOUNT. 13 | set(NUM_THREADS $,4,${PCOUNT}>) 14 | 15 | list(APPEND TEST_DEFS NTHREADS=${NUM_THREADS}) 16 | 17 | foreach(test_path IN ITEMS ${TEST_FILES}) 18 | get_filename_component(test_name ${test_path} NAME) 19 | get_filename_component(test_prefix ${test_path} NAME_WE) 20 | 21 | foreach(algo IN ITEMS ${ALGOS}) 22 | set(TEST ${test_prefix}_${algo}) 23 | string(TOLOWER ${TEST} TEST) 24 | add_executable(${TEST} ${test_name}) 25 | target_link_libraries(${TEST} vsync pthread) 26 | target_compile_definitions(${TEST} PUBLIC TREESET_${algo} ${TEST_DEFS}) 27 | 28 | v_add_heavy_stress_test( 29 | NAME 30 | ${TEST} 31 | COMMAND 32 | ${TEST} 33 | STRESS_TIMEOUT 34 | 4200 35 | TIMEOUT 36 | 3600) 37 | endforeach() 38 | 39 | endforeach() 40 | -------------------------------------------------------------------------------- /test/treeset/include/test/map/itreeset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_ITREESET_H 7 | #define VSYNC_ITREESET_H 8 | 9 | #if defined TREESET_BST_FINE 10 | #include 11 | #elif defined TREESET_RB_FINE 12 | #include 13 | #elif defined TREESET_BST_COARSE 14 | #include 15 | #elif defined TREESET_RB_COARSE 16 | #include 17 | #else 18 | #error "Choose treeset implementation by setting TREESET_*" 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /test/treeset/include/test/map/treeset_test_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TREESET_TEST_INTERFACE_H 7 | #define VSYNC_TREESET_TEST_INTERFACE_H 8 | 9 | #include 10 | 11 | treeset_t g_tree; 12 | 13 | static inline vbool_t 14 | tr_add(treeset_key_t key) 15 | { 16 | vbool_t success = treeset_add(&g_tree, key, NULL, NULL); 17 | return success; 18 | } 19 | 20 | static inline vbool_t 21 | tr_rem(treeset_key_t key) 22 | { 23 | vbool_t success = treeset_remove(&g_tree, key, NULL); 24 | return success; 25 | } 26 | 27 | static inline vbool_t 28 | tr_con(treeset_key_t key) 29 | { 30 | vbool_t success = treeset_contains(&g_tree, key, NULL); 31 | return success; 32 | } 33 | 34 | static inline void 35 | tr_init(void) 36 | { 37 | vmem_lib_t mem_lib = VMEM_LIB_DEFAULT(); 38 | treeset_init(&g_tree, mem_lib); 39 | } 40 | 41 | static inline void 42 | tr_destroy(void) 43 | { 44 | treeset_destroy(&g_tree); 45 | } 46 | 47 | static inline void 48 | tr_verify(void) 49 | { 50 | _treeset_verify(&g_tree); 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /test/treeset/test_treeset_sanity_visit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | void 12 | visitor(treeset_key_t key, void *value, void *arg) 13 | { 14 | ASSERT(*(int *)arg == -1); 15 | vbool_t key_3 = (key == 3 && *(int *)value == 30); 16 | vbool_t key_5 = (key == 5 && *(int *)value == 50); 17 | ASSERT(key_3 || key_5); 18 | } 19 | 20 | int 21 | main(void) 22 | { 23 | treeset_t tree; 24 | 25 | vmem_lib_t mem_lib = VMEM_LIB_DEFAULT(); 26 | treeset_init(&tree, mem_lib); 27 | 28 | int value3 = 30; 29 | treeset_add(&tree, 3, &value3, NULL); 30 | 31 | int value5 = 50; 32 | treeset_add(&tree, 5, &value5, NULL); 33 | 34 | int arg = -1; 35 | treeset_visit(&tree, visitor, &arg); 36 | 37 | treeset_destroy(&tree); 38 | } 39 | -------------------------------------------------------------------------------- /test/treeset/test_treeset_traces.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifndef NTHREADS 14 | #error "Choose number of threads by setting NTHREADS" 15 | #endif 16 | 17 | #define NITERS 20000 18 | 19 | void * 20 | run(void *arg) 21 | { 22 | vsize_t tid = (vsize_t)(vuintptr_t)arg; 23 | 24 | for (vsize_t i = 0; i < NITERS; ++i) { 25 | int key = i; 26 | if (tr_con_trace(tid, key)) { 27 | tr_rem_trace(tid, key); 28 | } else { 29 | tr_add_trace(tid, key); 30 | } 31 | } 32 | 33 | return NULL; 34 | } 35 | 36 | int 37 | main(void) 38 | { 39 | tr_init_trace(); 40 | 41 | launch_threads(NTHREADS, run); 42 | 43 | tr_verify_traces(); 44 | 45 | tr_destroy_trace(); 46 | 47 | tr_verify_allocs(); 48 | } 49 | -------------------------------------------------------------------------------- /vatomic/.cmake-format: -------------------------------------------------------------------------------- 1 | { 2 | "parse": { 3 | "additional_commands": { 4 | "add_toolchain": { 5 | "pargs": { 6 | "nargs": 3 7 | } 8 | }, 9 | "get_filename_wext": { 10 | "pargs": { 11 | "nargs": 2 12 | } 13 | }, 14 | "get_git_tag": { 15 | "pargs": { 16 | "nargs": 1 17 | } 18 | }, 19 | "get_includes": { 20 | "pargs": { 21 | "nargs": 1 22 | } 23 | }, 24 | "get_toolkit_qemu": { 25 | "pargs": { 26 | "nargs": 3 27 | } 28 | }, 29 | "project_tag": { 30 | "pargs": { 31 | "nargs": 0 32 | } 33 | }, 34 | "CPMAddPackage": {}, 35 | "_CPMAddPackage": {}, 36 | "vsync_install": { 37 | "kwargs": { 38 | "DIRECTORY": "+", 39 | "DESTINATION": "+", 40 | "COMPONENTS": "+", 41 | "EXTRA_ARGS": "+" 42 | }, 43 | "pargs": { 44 | "flags": [], 45 | "nargs": "*" 46 | } 47 | } 48 | } 49 | }, 50 | "format": { 51 | "tab_size": 4 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /vatomic/.github/Dockerfile.boogie: -------------------------------------------------------------------------------- 1 | FROM ubuntu:22.04 2 | 3 | # Install useful package 4 | RUN apt-get update && apt-get install -y --no-install-recommends \ 5 | build-essential \ 6 | ca-certificates \ 7 | cmake \ 8 | ninja-build \ 9 | g++-aarch64-linux-gnu \ 10 | gcc-aarch64-linux-gnu \ 11 | dotnet-sdk-6.0 \ 12 | z3 \ 13 | ghc \ 14 | && rm -rf /var/lib/apt/lists/* 15 | 16 | RUN dotnet tool install --tool-path /usr/local/bin boogie --version 3.4.3 17 | 18 | -------------------------------------------------------------------------------- /vatomic/.github/docker-context/placeholder: -------------------------------------------------------------------------------- 1 | This placeholder file guarantees git will not get rid of the docker-context 2 | directory. 3 | 4 | When building our ci images, we use the docker-context directory as "empty 5 | context", ie, a context that does not change in every commit. In this way, only 6 | when the Dockerfiles are modified, the docker build will actually build another 7 | image. It is ok to use an empty context for our ci images because they only 8 | contain external tools (and no code from this repository). 9 | -------------------------------------------------------------------------------- /vatomic/.github/toolchains/arm64.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | set(CMAKE_SYSTEM_NAME Linux) 4 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 5 | 6 | set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) 7 | set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) 8 | set(CMAKE_CROSSCOMPILING_EMULATOR qemu-aarch64 -L /usr/aarch64-linux-gnu) 9 | 10 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a") 11 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") 12 | 13 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 15 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 16 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 17 | -------------------------------------------------------------------------------- /vatomic/.github/toolchains/arm64_lse.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | set(CMAKE_SYSTEM_NAME Linux) 4 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 5 | 6 | set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc) 7 | set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++) 8 | set(CMAKE_CROSSCOMPILING_EMULATOR qemu-aarch64 -L /usr/aarch64-linux-gnu) 9 | 10 | option(VATOMIC_ENABLE_ARM64_LXE 11 | "Use LXE atomics ldx/stx in fastpath, LSE in slowpath" off) 12 | 13 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+lse") 14 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") 15 | 16 | if(VATOMIC_ENABLE_ARM64_LXE) 17 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVATOMIC_ENABLE_ARM64_LXE") 18 | endif() 19 | 20 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 22 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 24 | -------------------------------------------------------------------------------- /vatomic/.github/toolchains/armeb.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | set(CMAKE_SYSTEM_NAME Linux) 4 | set(CMAKE_SYSTEM_PROCESSOR arm) 5 | 6 | set(ARMEB_PATH /tmp/gcc-linaro-7.5.0-2019.12-x86_64_armeb-linux-gnueabi/bin) 7 | set(CMAKE_C_COMPILER ${ARMEB_PATH}/armeb-linux-gnueabi-gcc) 8 | set(CMAKE_CXX_COMPILER ${ARMEB_PATH}/armeb-linux-gnueabi-g++) 9 | set(CMAKE_CROSSCOMPILING_EMULATOR qemu-armeb -L /usr/armeb-linux-gnueabi) 10 | 11 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mbig-endian") 12 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static") 13 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a -marm") 14 | set(CMAKE_C_FLAGS 15 | "${CMAKE_C_FLAGS} -mno-thumb-interwork -mfpu=vfp -msoft-float") 16 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mcpu=cortex-a9") 17 | 18 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") 19 | set(CROSS_COMPILING_ARMEB TRUE) 20 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 22 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 24 | -------------------------------------------------------------------------------- /vatomic/.github/toolchains/armeb8.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | set(CMAKE_SYSTEM_NAME Linux) 4 | set(CMAKE_SYSTEM_PROCESSOR arm) 5 | 6 | set(ARMEB_PATH /tmp/gcc-linaro-7.5.0-2019.12-x86_64_armeb-linux-gnueabi/bin) 7 | set(CMAKE_C_COMPILER ${ARMEB_PATH}/armeb-linux-gnueabi-gcc) 8 | set(CMAKE_CXX_COMPILER ${ARMEB_PATH}/armeb-linux-gnueabi-g++) 9 | set(CMAKE_CROSSCOMPILING_EMULATOR qemu-armeb -L /usr/armeb-linux-gnueabi/libc) 10 | 11 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mbig-endian") 12 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static") 13 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a -marm") 14 | set(CMAKE_C_FLAGS 15 | "${CMAKE_C_FLAGS} -mno-thumb-interwork -mfpu=vfp -msoft-float") 16 | 17 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") 18 | set(CROSS_COMPILING_ARMEB TRUE) 19 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 20 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 22 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 23 | -------------------------------------------------------------------------------- /vatomic/.github/toolchains/armel.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | 4 | # the name of the target operating system 5 | set(CMAKE_SYSTEM_NAME Linux) 6 | set(CMAKE_SYSTEM_PROCESSOR arm) 7 | 8 | set(CMAKE_C_COMPILER arm-linux-gnueabi-gcc) 9 | set(CMAKE_CXX_COMPILER arm-linux-gnueabi-g++) 10 | set(CMAKE_CROSSCOMPILING_EMULATOR qemu-arm -L /usr/arm-linux-gnueabi) 11 | 12 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlittle-endian") 13 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv7-a") 14 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp -mno-thumb-interwork") 15 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=cortex-a9") 16 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") 17 | 18 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 19 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 20 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 22 | -------------------------------------------------------------------------------- /vatomic/.github/toolchains/armel8.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | 4 | # the name of the target operating system 5 | set(CMAKE_SYSTEM_NAME Linux) 6 | set(CMAKE_SYSTEM_PROCESSOR arm) 7 | 8 | set(CMAKE_C_COMPILER arm-linux-gnueabi-gcc) 9 | set(CMAKE_CXX_COMPILER arm-linux-gnueabi-g++) 10 | set(CMAKE_CROSSCOMPILING_EMULATOR qemu-arm -L /usr/arm-linux-gnueabi) 11 | 12 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlittle-endian") 13 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a -marm") 14 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mno-thumb-interwork -mfpu=vfp") 15 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=cortex-a9") 16 | set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS}") 17 | 18 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 19 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 20 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 22 | -------------------------------------------------------------------------------- /vatomic/.github/toolchains/riscv.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | set(CMAKE_SYSTEM_NAME Linux) 4 | set(CMAKE_SYSTEM_PROCESSOR riscv) 5 | 6 | set(CMAKE_C_COMPILER riscv64-linux-gnu-gcc) 7 | set(CMAKE_CXX_COMPILER riscv64-linux-gnu-g++) 8 | set(CMAKE_CROSSCOMPILING_EMULATOR qemu-riscv64 -L /usr/riscv64-linux-gnu) 9 | 10 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 13 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 14 | -------------------------------------------------------------------------------- /vatomic/.github/toolchains/x86_64.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | set(CMAKE_SYSTEM_NAME Linux) 4 | set(CMAKE_SYSTEM_PROCESSOR x86_64) 5 | 6 | set(CMAKE_C_COMPILER gcc) 7 | set(CMAKE_CXX_COMPILER g++) 8 | 9 | option(VSYNC_BUILTINS "Use atomic builtins" off) 10 | 11 | # x86 always uses builtin atomics, so it does not really make a difference here 12 | if(VSYNC_BUILTINS) 13 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVSYNC_BUILTINS") 14 | endif() 15 | 16 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 18 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 19 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 20 | -------------------------------------------------------------------------------- /vatomic/.gitignore: -------------------------------------------------------------------------------- 1 | *build*/ 2 | .kakrc 3 | -------------------------------------------------------------------------------- /vatomic/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | This project partially comply with [Semantic Versioning][]. 5 | 6 | [Semantic Versioning]: https://semver.org/spec/v2.0.0.html 7 | 8 | ## [2.3.1] 9 | 10 | - Added verification of AArch64 atomic implementation 11 | - Enabled RISC-V tests (linking with libatomic) 12 | - Fixed installation of CMake find_package scripts 13 | 14 | ## [2.3.0] 15 | 16 | - **Forked** from libvsync v4.1.0 as standalone project 17 | - Compilation on macOS-arm and NetBSD 18 | 19 | ## [2.2.1] 20 | 21 | Released as part of libvsync v4.0.2 22 | 23 | - type conversion warnings in `vatomic32_get_*` rmw APIs. 24 | 25 | ## [2.2.0] 26 | 27 | Released as part of libvsync v4.0.1 28 | 29 | - added `const` to `vatomic*_t *a` parameter in read-only vatomic APIs 30 | - remove undef of used macros from `vtypes.h`. 31 | - deprecated `atomic*_wait_mask_neq` and `atomic*_wait_mask_eq` APIs 32 | 33 | ## [2.1.1] 34 | 35 | Released as part of libvsync v3.5.0 36 | 37 | - Added vmm.cat 38 | - Documentation updates 39 | 40 | ## [2.1.0] - 2024-01-26 41 | 42 | Initial public release as part of libvsync v3.2.0. 43 | 44 | ## [2.0.0] 45 | 46 | - Moved to `vatomic_` prefix to avoid name clashing. 47 | - Introduced new atomics such as `max`. 48 | 49 | ## [1.0.0] 50 | 51 | Initial version using `atomic_` prefix. 52 | -------------------------------------------------------------------------------- /vatomic/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2023 Huawei Technologies Co., Ltd. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /vatomic/README.md: -------------------------------------------------------------------------------- 1 | # VSync atomics - formally-verified atomic operations library 2 | 3 | vatomic is a header library of *atomics operations*, supporting mainstream 4 | architectures: ARMv7, ARMv8 (AArch32 and AArch64), RISC-V, and x86_64. The 5 | memory ordering guarantees provided by the atomic interface are formally 6 | described in the [VSync Memory Model (VMM)](vmm.cat) file. 7 | 8 | Users can use the `vmm.cat` file to verify the correctness of their algorithms 9 | with a model checker such as [Dartagnan][] or [vsyncer][]. 10 | 11 | The atomics implementations are being gradually verified to comply with VMM. At 12 | the moment, we have completed the verification of ARMv8 64-bits with and 13 | without LSE instructions. 14 | 15 | This project is a spinoff of the VSync project and a key component in 16 | [libvsync][]. 17 | 18 | Refer to our ASPLOS'21 [publication][paper] describing part of the 19 | research effort put into this library. 20 | 21 | ## Acknowledgements 22 | 23 | This project was initially developed under the support of 24 | [OpenHarmony Concurrency & Coordination TSG, 并发与协同TSG][tsg]. 25 | 26 | [libvsync]: https://github.com/open-s4c/libvsync 27 | [vsyncer]: https://github.com/open-s4c/vsyncer 28 | [Dartagnan]: https://github.com/hernanponcedeleon/dat3m 29 | [paper]: https://dl.acm.org/doi/abs/10.1145/3445814.3446748 30 | [tsg]: https://www.openharmony.cn/techCommittee/aboutTSG 31 | -------------------------------------------------------------------------------- /vatomic/cmake/config.cmake.in: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | @PACKAGE_INIT@ 4 | 5 | include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") 6 | check_required_components("@PROJECT_NAME@") 7 | -------------------------------------------------------------------------------- /vatomic/cmake/export.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | set(CONFIG_IN_FILE "cmake/config.cmake.in") 4 | 5 | if(NOT DEFINED PROJECT_TARGETS) 6 | set(PROJECT_TARGETS "${PROJECT_NAME}Targets") 7 | endif() 8 | 9 | set(PROJECT_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") 10 | set(PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake") 11 | set(PROJECT_VERSION_FILE 12 | "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") 13 | 14 | include(CMakePackageConfigHelpers) 15 | configure_package_config_file(${CONFIG_IN_FILE} ${PROJECT_CONFIG_FILE} 16 | INSTALL_DESTINATION ${PROJECT_CMAKE_DIR}) 17 | 18 | write_basic_package_version_file( 19 | ${PROJECT_VERSION_FILE} 20 | VERSION ${PROJECT_VERSION} 21 | COMPATIBILITY SameMajorVersion) 22 | 23 | install( 24 | EXPORT ${PROJECT_TARGETS} 25 | FILE ${PROJECT_TARGETS}.cmake 26 | NAMESPACE ${PROJECT_NAME}:: 27 | DESTINATION ${PROJECT_CMAKE_DIR}) 28 | install(FILES ${PROJECT_CONFIG_FILE} ${PROJECT_VERSION_FILE} 29 | DESTINATION ${PROJECT_CMAKE_DIR}) 30 | -------------------------------------------------------------------------------- /vatomic/include/vsync/atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_ATOMIC_H 7 | #define VSYNC_ATOMIC_H 8 | /******************************************************************************* 9 | * @file atomic.h 10 | * @brief Rich interface of atomic operations and fences 11 | * 12 | * Atomics are implemented in custom assembly or compiler builtins. 13 | * 14 | * - check core.h for the documentation of the core interface. 15 | * - check await.h for the documentation of the await interface. 16 | * - check config.h to learn about libvsync available configurations. 17 | * - check atomic/dispatch.h an additional dispatch layer allows for a more 18 | * flexible use of the interface. 19 | ******************************************************************************/ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #endif /* VSYNC_ATOMIC_H */ 26 | -------------------------------------------------------------------------------- /vatomic/include/vsync/atomic/internal/config/fnc_rlx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VATOMIC_CONFIG_FNC_RLX_H 7 | #define VATOMIC_CONFIG_FNC_RLX_H 8 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 9 | 10 | #include 11 | 12 | #if defined(VATOMIC_ENABLE_ATOMIC_RLX) 13 | 14 | #define VATOMIC_FENCE 15 | static inline void 16 | vatomic_fence(void) 17 | { 18 | vatomic_fence_rlx(); 19 | } 20 | #define VATOMIC_FENCE_ACQ 21 | static inline void 22 | vatomic_fence_acq(void) 23 | { 24 | vatomic_fence_rlx(); 25 | } 26 | #define VATOMIC_FENCE_REL 27 | static inline void 28 | vatomic_fence_rel(void) 29 | { 30 | vatomic_fence_rlx(); 31 | } 32 | 33 | #endif 34 | #endif 35 | -------------------------------------------------------------------------------- /vatomic/include/vsync/atomic/internal/config/fnc_sc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VATOMIC_CONFIG_FNC_SC_H 7 | #define VATOMIC_CONFIG_FNC_SC_H 8 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 9 | 10 | #include 11 | 12 | #if defined(VATOMIC_ENABLE_ATOMIC_SC) 13 | 14 | #define VATOMIC_FENCE_RLX 15 | static inline void 16 | vatomic_fence_rlx(void) 17 | { 18 | vatomic_fence(); 19 | } 20 | #define VATOMIC_FENCE_ACQ 21 | static inline void 22 | vatomic_fence_acq(void) 23 | { 24 | vatomic_fence(); 25 | } 26 | #define VATOMIC_FENCE_REL 27 | static inline void 28 | vatomic_fence_rel(void) 29 | { 30 | vatomic_fence(); 31 | } 32 | 33 | #endif 34 | #endif 35 | -------------------------------------------------------------------------------- /vatomic/include/vsync/atomic/internal/undef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VATOMIC_UNDEF_H 7 | #define VATOMIC_UNDEF_H 8 | 9 | #undef V_ALIGNED2 10 | #undef V_ALIGNED4 11 | #undef V_ALIGNED8 12 | #undef V_ALIGNEDP 13 | #undef V_ALIGNEDSZ 14 | #undef V_FENCE_RLX_INSTRUCTION 15 | #undef V_DEFINE_FUNC 16 | #undef V_DEFINE_FUNC_1 17 | #undef V_DEFINE_FUNC_2 18 | #undef V_DEFINE_FUNC_3 19 | #undef V_DEFINE_FUNC_4 20 | #undef V_DEFINE_FUNC_5 21 | #undef V_DEFINE_FUNC_6 22 | #endif /* VATOMIC_UNDEF_H */ 23 | -------------------------------------------------------------------------------- /vatomic/include/vsync/atomic/internal/x86.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VATOMIC_X86_H 7 | #define VATOMIC_X86_H 8 | 9 | #if !defined(VATOMIC_DISABLE_POLITE_AWAIT) 10 | #define vatomic_cpu_pause() __asm__ volatile("pause\n" ::: "memory") 11 | #endif 12 | 13 | #endif /* VATOMIC_X86_H */ 14 | -------------------------------------------------------------------------------- /vatomic/include/vsync/common/await_while.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_AWAIT_WHILE_H 7 | #define VSYNC_AWAIT_WHILE_H 8 | 9 | #if defined(VSYNC_VERIFICATION) && !defined(VSYNC_DISABLE_SPIN_ANNOTATION) 10 | #include 11 | #elif defined(VSYNC_LOTTO) && !defined(LOTTO_DISABLE_SPIN_ANNOTATION) 12 | #include 13 | #else 14 | #define await_while(cond) while (cond) 15 | #define await_do do 16 | #define while_await(cond) while (cond) 17 | #define await_break break 18 | #endif 19 | 20 | #endif /* VSYNC_AWAIT_WHILE_H */ 21 | -------------------------------------------------------------------------------- /vatomic/scripts/clang-format.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | # SPDX-License-Identifier: MIT 4 | set -e 5 | 6 | if [ $# -lt 1 ]; then 7 | echo "Usage: $0 [PATH ...]" 8 | echo "" 9 | echo " PATH one or more directories (or source files) to recursively run " 10 | echo " clang-format on." 11 | echo "Environment variables:" 12 | echo " SILENT=true disable git diff and error code" 13 | echo " STYLE=FILE FILE is a configuration file, default = .clang-format" 14 | echo " " 15 | echo "" 16 | exit 1 17 | fi 18 | 19 | if [ "${STYLE}" != "" ]; then 20 | STYLE=":${STYLE}" 21 | fi 22 | 23 | # Apply clang-format to all *.h and *.c files in src folder. 24 | find "$@" \( -name '*.h' -o -name '*.c' -o -name '*.cpp' -o -name '*.hpp' -o -name '*.cxx' \) \ 25 | -not -path '*/build/*' \ 26 | -not -path '*/deps/*' \ 27 | -type f \ 28 | -exec clang-format -style=file${STYLE} -i {} + 29 | 30 | if [ "${SILENT}" != "true" ]; then 31 | # Display changed files and exit with 1 if there were differences. 32 | git --no-pager diff --exit-code 33 | fi 34 | -------------------------------------------------------------------------------- /vatomic/template/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | add_custom_target(vatomic-generate) 4 | # after running vatomic-generate, run clang-format-apply, in order to fix format 5 | # in autogenerted files. 6 | add_custom_command( 7 | TARGET vatomic-generate 8 | POST_BUILD 9 | COMMAND cmake --build "${CMAKE_BINARY_DIR}" --target clang-format-apply 10 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) 11 | 12 | add_subdirectory(include) 13 | 14 | # The following empty file helps LSP servers (eg, clangd) to figure out the 15 | # symbols in the .h.in template files by updating the compile_commands.json 16 | add_executable(empty empty.c) 17 | set_target_properties(empty PROPERTIES COMPILE_OPTIONS "") 18 | target_compile_features(empty INTERFACE c_std_99) 19 | target_include_directories(empty PRIVATE include) 20 | target_link_libraries(empty INTERFACE vatomic tmplr) 21 | -------------------------------------------------------------------------------- /vatomic/template/empty.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | int 7 | main(void) 8 | { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /vatomic/template/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | add_subdirectory(vsync) 4 | -------------------------------------------------------------------------------- /vatomic/template/include/vsync/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | add_subdirectory(atomic) 4 | -------------------------------------------------------------------------------- /vatomic/template/include/vsync/atomic/internal/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | add_subdirectory(config) 4 | 5 | # grep templates for each .in .h will be generated 6 | file(GLOB TARGETS *.in) 7 | 8 | foreach(TARGET ${TARGETS}) 9 | get_filename_component(TARGET ${TARGET} NAME_WE) 10 | set(TARGET ${TARGET}.h) 11 | add_custom_target( 12 | ${TARGET} 13 | COMMAND 14 | $ 15 | ${CMAKE_CURRENT_SOURCE_DIR}/../vatomic.rules 16 | ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET}.in > 17 | ${PROJECT_SOURCE_DIR}/include/vsync/atomic/internal/${TARGET}) 18 | add_dependencies(vatomic-generate ${TARGET}) 19 | endforeach() 20 | -------------------------------------------------------------------------------- /vatomic/template/include/vsync/atomic/internal/config/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | 4 | # grep templates for each .in .h will be generated 5 | file(GLOB TARGETS *.in) 6 | 7 | set(ALL_TYPES 8 | u8 9 | u16 10 | u32 11 | u64 12 | sz 13 | ptr 14 | fnc) 15 | 16 | foreach(TARGET IN ITEMS ${TARGETS}) 17 | 18 | get_filename_component(TARGET ${TARGET} NAME_WE) 19 | 20 | if(DEFINED ${TARGET}_TYPES) 21 | set(TYPES ${${TARGET}_TYPES}) 22 | else() 23 | set(TYPES ${ALL_TYPES}) 24 | endif() 25 | 26 | set(TMPL ${TARGET}.h) 27 | 28 | foreach(TY IN ITEMS ${TYPES}) 29 | string(REPLACE TY ${TY} OUT ${TMPL}) 30 | add_custom_target( 31 | ${OUT} 32 | COMMAND 33 | $ -DTY=${TY} 34 | ${CMAKE_CURRENT_SOURCE_DIR}/../../vatomic.rules 35 | ${CMAKE_CURRENT_SOURCE_DIR}/${TMPL}.in > 36 | ${PROJECT_SOURCE_DIR}/include/vsync/atomic/internal/config/${OUT} 37 | ) 38 | add_dependencies(vatomic-generate ${OUT}) 39 | endforeach() 40 | endforeach() 41 | -------------------------------------------------------------------------------- /vatomic/template/include/vsync/atomic/tmplr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VATOMIC_TMPLR_H 7 | #define VATOMIC_TMPLR_H 8 | 9 | #include 10 | #include 11 | 12 | /** 13 | * TT is an unsigned integer type or void *. 14 | */ 15 | typedef unsigned int TT; 16 | 17 | /** 18 | * AA is one of the vatomic types. 19 | * 20 | * These are vatomic{8,16,32,64,ptr}. 21 | */ 22 | typedef struct { 23 | TT _v; 24 | } AA; 25 | 26 | /* some further macros to make clangd happy */ 27 | #define _MAP_OP 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /vatomic/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | target_compile_definitions(vatomic INTERFACE _GNU_SOURCE) 4 | 5 | if(CMAKE_SYSTEM_PROCESSOR MATCHES riscv) 6 | # 8- and 16-bit atomics are taken from the platform's libatomic library. 7 | link_libraries(atomic) 8 | endif() 9 | 10 | add_subdirectory(atomics_basic) 11 | add_subdirectory(atomics_cxx) 12 | add_subdirectory(atomics_gen) 13 | add_subdirectory(atomics) 14 | -------------------------------------------------------------------------------- /vatomic/test/atomics/freestanding_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | #define VSYNC_ENABLE_FREESTANDING 6 | #include 7 | 8 | void 9 | test_vuintptr(void) 10 | { 11 | int x = 1337; 12 | int *p = &x; 13 | vuintptr_t p2 = (vuintptr_t)p; 14 | (void)p2; 15 | } 16 | int 17 | main(void) 18 | { 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /vatomic/test/atomics/include/vfreestanding.h.tpl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2020. All rights reserved. 3 | * Author: Huawei Dresden Research Center 4 | * Create: 2022-10-19 5 | */ 6 | #ifndef VSYNC_VFREESTANDING_H 7 | #define VSYNC_VFREESTANDING_H 8 | 9 | #define vbool_t _Bool 10 | #define vuint8_t unsigned char 11 | #define vuint16_t unsigned short int 12 | #define vuint32_t unsigned int 13 | 14 | #ifndef NULL 15 | #define NULL ((void *)0) 16 | #endif 17 | #ifndef __SIZEOF_LONG__ 18 | #error "__SIZEOF_LONG__ not defined" 19 | #endif /* __SIZEOF_LONG__ */ 20 | 21 | #ifndef __SIZE_TYPE__ 22 | #error "__SIZE_TYPE__ not defined" 23 | #endif /* __SIZE_TYPE__ */ 24 | 25 | #ifndef __SIZEOF_POINTER__ 26 | #error "__SIZEOF_POINTER__ not defined" 27 | #endif /* __SIZEOF_POINTER */ 28 | 29 | #if 8 == __SIZEOF_LONG__ 30 | #define vuint64_t unsigned long int 31 | #else 32 | #if 8 == __SIZEOF_LONG_LONG__ 33 | #define vuint64_t unsigned long long int 34 | #else 35 | #error "long long must be 64 bits on this architecture" 36 | #endif /* 8 == __SIZEOF_LONG_LONG__ */ 37 | #endif /* 8 == __SIZEOF_LONG__ */ 38 | 39 | #if 8 == __SIZEOF_POINTER__ 40 | #define vuintptr_t vuint64_t 41 | #else 42 | #define vuintptr_t vuint32_t 43 | #endif /* 8 == __SIZEOF_POINTER__ */ 44 | 45 | typedef __SIZE_TYPE__ vsize_t; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /vatomic/test/atomics/leftover_patterns.txt: -------------------------------------------------------------------------------- 1 | .*_H 2 | await_break 3 | await_do 4 | await_while 5 | while_await 6 | VATOMIC.* 7 | VATOMIC_INIT 8 | ATOMIC_INIT 9 | v?atomic_ 10 | v?atomic[0-9]* 11 | v?atomicptr 12 | ^vuint.*_t 13 | ^vint.*_t 14 | __VERIFIER_.* 15 | V_ASSERT 16 | V_CAST 17 | V_CAST_INT 18 | V_DISPATCH 19 | V_PTR_ARG 20 | V_CONCAT 21 | V_FUNC 22 | V_JOIN 23 | V_MAP_A 24 | V_MAP_T 25 | V_NR_VARS 26 | V_NR_VARS_ 27 | V_PASTE 28 | V_SUFFIX 29 | V_SUFFIX_mo_acq 30 | V_SUFFIX_mo_rel 31 | V_SUFFIX_mo_rlx 32 | V_SUFFIX_mo_seq 33 | V_STRING 34 | V_UNUSED 35 | V_DEFINE_FUNC.* 36 | V_DEFINE_await_eq 37 | V_MAP_.* 38 | VUINTPTR_MAX 39 | VUINT8_MAX 40 | VUINT16_MAX 41 | VUINT32_MAX 42 | VUINT64_MAX 43 | VINT32_MAX 44 | VUINTPTR_WIDTH 45 | VUINT64_WIDTH 46 | VUINT64_FORMAT 47 | VUINT32_FORMAT 48 | VUINTPTR_FORMAT 49 | V_DEPRECATED 50 | V_ATOMICPTR_MARKABLE_COMBINE_ADDRESS_MARK 51 | V_ATOMICPTR_MARKABLE_EXTRACT_ADDRESS 52 | V_ATOMICPTR_MARKABLE_GET_ADDRESS 53 | V_ATOMICPTR_MARKABLE_IS_ALIGNED 54 | V_ATOMICPTR_STAMPED_IS_ALIGNED 55 | V_ATOMICPTR_STAMPED_REQUIRED_ALIGNMENT 56 | V_ATOMICPTR_STAMPED_ADDRESS_MASK 57 | V_ATOMICPTR_STAMPED_STAMP_MASK 58 | ASSERT 59 | BUG_ON 60 | V_STATIC_ASSERT 61 | V_COMPILER_BARRIER 62 | 63 | -------------------------------------------------------------------------------- /vatomic/test/atomics/pause_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | int 10 | main(void) 11 | { 12 | vatomic_cpu_pause(); 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /vatomic/test/atomics/vatomic_empty.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | int 8 | main(void) 9 | { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /vatomic/test/atomics_cxx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | project(vatomic_cpp LANGUAGES CXX) 4 | # ############################################################################## 5 | # compilation with C++ 6 | # ############################################################################## 7 | 8 | add_executable(vatomic_compile_cxx vatomic_empty.cpp) 9 | target_link_libraries(vatomic_compile_cxx vatomic) 10 | v_add_bin_test(NAME vatomic-compile-cxx COMMAND vatomic_compile_cxx) 11 | -------------------------------------------------------------------------------- /vatomic/test/atomics_cxx/vatomic_empty.cpp: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | #include 3 | } 4 | 5 | int 6 | main(void) 7 | { 8 | return 0; 9 | } -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | set(V_TEST_LABELS "CROSS") 4 | # currently not installed with distros 5 | if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/templates) 6 | add_subdirectory(templates) 7 | endif() 8 | 9 | file(GLOB TESTS *test*.c) 10 | foreach(test IN ITEMS ${TESTS}) 11 | get_filename_component(TEST ${test} NAME_WE) 12 | # add the executable 13 | add_executable(${TEST} ${test}) 14 | # link libs 15 | target_link_libraries(${TEST} vatomic pthread) 16 | # add test 17 | v_add_bin_test(NAME ${TEST} COMMAND ${TEST}) 18 | endforeach() 19 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_eq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_eq(&g_u32_a, g_u32_v); 32 | vatomic32_await_eq_acq(&g_u32_a, g_u32_v); 33 | vatomic32_await_eq_rlx(&g_u32_a, g_u32_v); 34 | vatomic64_await_eq(&g_u64_a, g_u64_v); 35 | vatomic64_await_eq_acq(&g_u64_a, g_u64_v); 36 | vatomic64_await_eq_rlx(&g_u64_a, g_u64_v); 37 | vatomicptr_await_eq(&g_ptr_a, g_ptr_v); 38 | vatomicptr_await_eq_acq(&g_ptr_a, g_ptr_v); 39 | vatomicptr_await_eq_rlx(&g_ptr_a, g_ptr_v); 40 | } 41 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_eq_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_eq_add(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_eq_add_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_eq_add_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_eq_add_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_eq_add(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_eq_add_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_eq_add_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_eq_add_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_eq_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_eq_sub(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_eq_sub_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_eq_sub_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_eq_sub_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_eq_sub(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_eq_sub_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_eq_sub_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_eq_sub_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_ge.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_ge(&g_u32_a, g_u32_v); 32 | vatomic32_await_ge_acq(&g_u32_a, g_u32_v); 33 | vatomic32_await_ge_rlx(&g_u32_a, g_u32_v); 34 | vatomic64_await_ge(&g_u64_a, g_u64_v); 35 | vatomic64_await_ge_acq(&g_u64_a, g_u64_v); 36 | vatomic64_await_ge_rlx(&g_u64_a, g_u64_v); 37 | } 38 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_ge_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_ge_add(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_ge_add_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_ge_add_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_ge_add_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_ge_add(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_ge_add_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_ge_add_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_ge_add_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_ge_set.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_ge_set(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_ge_set_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_ge_set_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_ge_set_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_ge_set(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_ge_set_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_ge_set_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_ge_set_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_ge_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_ge_sub(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_ge_sub_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_ge_sub_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_ge_sub_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_ge_sub(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_ge_sub_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_ge_sub_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_ge_sub_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_gt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_gt(&g_u32_a, g_u32_v); 32 | vatomic32_await_gt_acq(&g_u32_a, g_u32_v); 33 | vatomic32_await_gt_rlx(&g_u32_a, g_u32_v); 34 | vatomic64_await_gt(&g_u64_a, g_u64_v); 35 | vatomic64_await_gt_acq(&g_u64_a, g_u64_v); 36 | vatomic64_await_gt_rlx(&g_u64_a, g_u64_v); 37 | } 38 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_gt_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_gt_add(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_gt_add_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_gt_add_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_gt_add_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_gt_add(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_gt_add_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_gt_add_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_gt_add_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_gt_set.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_gt_set(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_gt_set_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_gt_set_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_gt_set_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_gt_set(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_gt_set_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_gt_set_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_gt_set_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_gt_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_gt_sub(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_gt_sub_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_gt_sub_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_gt_sub_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_gt_sub(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_gt_sub_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_gt_sub_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_gt_sub_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_le.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_le(&g_u32_a, g_u32_v); 32 | vatomic32_await_le_acq(&g_u32_a, g_u32_v); 33 | vatomic32_await_le_rlx(&g_u32_a, g_u32_v); 34 | vatomic64_await_le(&g_u64_a, g_u64_v); 35 | vatomic64_await_le_acq(&g_u64_a, g_u64_v); 36 | vatomic64_await_le_rlx(&g_u64_a, g_u64_v); 37 | } 38 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_le_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_le_add(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_le_add_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_le_add_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_le_add_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_le_add(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_le_add_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_le_add_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_le_add_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_le_set.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_le_set(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_le_set_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_le_set_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_le_set_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_le_set(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_le_set_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_le_set_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_le_set_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_le_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_le_sub(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_le_sub_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_le_sub_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_le_sub_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_le_sub(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_le_sub_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_le_sub_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_le_sub_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_lt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_lt(&g_u32_a, g_u32_v); 32 | vatomic32_await_lt_acq(&g_u32_a, g_u32_v); 33 | vatomic32_await_lt_rlx(&g_u32_a, g_u32_v); 34 | vatomic64_await_lt(&g_u64_a, g_u64_v); 35 | vatomic64_await_lt_acq(&g_u64_a, g_u64_v); 36 | vatomic64_await_lt_rlx(&g_u64_a, g_u64_v); 37 | } 38 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_lt_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_lt_add(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_lt_add_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_lt_add_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_lt_add_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_lt_add(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_lt_add_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_lt_add_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_lt_add_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_lt_set.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_lt_set(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_lt_set_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_lt_set_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_lt_set_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_lt_set(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_lt_set_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_lt_set_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_lt_set_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_lt_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_lt_sub(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_lt_sub_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_lt_sub_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_lt_sub_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_lt_sub(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_lt_sub_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_lt_sub_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_lt_sub_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_neq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_neq(&g_u32_a, g_u32_v); 32 | vatomic32_await_neq_acq(&g_u32_a, g_u32_v); 33 | vatomic32_await_neq_rlx(&g_u32_a, g_u32_v); 34 | vatomic64_await_neq(&g_u64_a, g_u64_v); 35 | vatomic64_await_neq_acq(&g_u64_a, g_u64_v); 36 | vatomic64_await_neq_rlx(&g_u64_a, g_u64_v); 37 | vatomicptr_await_neq(&g_ptr_a, g_ptr_v); 38 | vatomicptr_await_neq_acq(&g_ptr_a, g_ptr_v); 39 | vatomicptr_await_neq_rlx(&g_ptr_a, g_ptr_v); 40 | } 41 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_neq_add.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_neq_add(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_neq_add_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_neq_add_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_neq_add_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_neq_add(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_neq_add_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_neq_add_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_neq_add_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_await_neq_sub.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic32_await_neq_sub(&g_u32_a, g_u32_v, g_u32_v); 32 | vatomic32_await_neq_sub_acq(&g_u32_a, g_u32_v, g_u32_v); 33 | vatomic32_await_neq_sub_rel(&g_u32_a, g_u32_v, g_u32_v); 34 | vatomic32_await_neq_sub_rlx(&g_u32_a, g_u32_v, g_u32_v); 35 | vatomic64_await_neq_sub(&g_u64_a, g_u64_v, g_u64_v); 36 | vatomic64_await_neq_sub_acq(&g_u64_a, g_u64_v, g_u64_v); 37 | vatomic64_await_neq_sub_rel(&g_u64_a, g_u64_v, g_u64_v); 38 | vatomic64_await_neq_sub_rlx(&g_u64_a, g_u64_v, g_u64_v); 39 | } 40 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_dec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic8_dec(&g_u8_a); 32 | vatomic8_dec_rel(&g_u8_a); 33 | vatomic8_dec_rlx(&g_u8_a); 34 | vatomic16_dec(&g_u16_a); 35 | vatomic16_dec_rel(&g_u16_a); 36 | vatomic16_dec_rlx(&g_u16_a); 37 | vatomic32_dec(&g_u32_a); 38 | vatomic32_dec_rel(&g_u32_a); 39 | vatomic32_dec_rlx(&g_u32_a); 40 | vatomic64_dec(&g_u64_a); 41 | vatomic64_dec_rel(&g_u64_a); 42 | vatomic64_dec_rlx(&g_u64_a); 43 | vatomicsz_dec(&g_sz_a); 44 | vatomicsz_dec_rel(&g_sz_a); 45 | vatomicsz_dec_rlx(&g_sz_a); 46 | } 47 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_fence.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic_fence(); 32 | vatomic_fence_acq(); 33 | vatomic_fence_rel(); 34 | vatomic_fence_rlx(); 35 | } 36 | -------------------------------------------------------------------------------- /vatomic/test/atomics_gen/call_tests/call_inc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | /** 7 | * This C file call all available atomic APIs 8 | * It is not meant for running. It is to be used with `vsyncer info` in 9 | * different Configs to ensure the used barriers match the config. 10 | */ 11 | #include 12 | 13 | /* !!!Warning: File generated by tmplr; DO NOT EDIT.!!! */ 14 | 15 | vatomic8_t g_u8_a; 16 | vuint8_t g_u8_v; 17 | vatomic16_t g_u16_a; 18 | vuint16_t g_u16_v; 19 | vatomic32_t g_u32_a; 20 | vuint32_t g_u32_v; 21 | vatomic64_t g_u64_a; 22 | vuint64_t g_u64_v; 23 | vatomicptr_t g_ptr_a; 24 | void *g_ptr_v; 25 | vatomicsz_t g_sz_a; 26 | vsize_t g_sz_v; 27 | 28 | int 29 | main(void) 30 | { 31 | vatomic8_inc(&g_u8_a); 32 | vatomic8_inc_rel(&g_u8_a); 33 | vatomic8_inc_rlx(&g_u8_a); 34 | vatomic16_inc(&g_u16_a); 35 | vatomic16_inc_rel(&g_u16_a); 36 | vatomic16_inc_rlx(&g_u16_a); 37 | vatomic32_inc(&g_u32_a); 38 | vatomic32_inc_rel(&g_u32_a); 39 | vatomic32_inc_rlx(&g_u32_a); 40 | vatomic64_inc(&g_u64_a); 41 | vatomic64_inc_rel(&g_u64_a); 42 | vatomic64_inc_rlx(&g_u64_a); 43 | vatomicsz_inc(&g_sz_a); 44 | vatomicsz_inc_rel(&g_sz_a); 45 | vatomicsz_inc_rlx(&g_sz_a); 46 | } 47 | -------------------------------------------------------------------------------- /vatomic/test/project/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | 4 | # set CMAKE_PREFIX_PATH with the CMAKE_INSTALL_PATH used to install vatomic 5 | 6 | cmake_minimum_required(VERSION 3.16) 7 | project(test LANGUAGES C) 8 | find_package(vatomic CONFIG REQUIRED) 9 | add_executable(test test.c) 10 | target_link_libraries(test PRIVATE vatomic::vatomic) 11 | -------------------------------------------------------------------------------- /vatomic/test/project/test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | #include 6 | #include 7 | 8 | vatomic32_t count; 9 | 10 | int 11 | main() 12 | { 13 | vatomic_inc(&count); 14 | printf("count: %u\n", vatomic_read(&count)); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /vatomic/tmplr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 2 | # SPDX-License-Identifier: MIT 3 | add_library(tmplr INTERFACE) 4 | target_include_directories(tmplr INTERFACE include) 5 | 6 | add_executable(tmplr.bin tmplr.c) 7 | -------------------------------------------------------------------------------- /vatomic/tmplr/test/test-drop.in: -------------------------------------------------------------------------------- 1 | _tmpl_map(FILTER_ptr_lt, DROP!); 2 | _tmpl_begin(TY = [[ptr]], COND = [[neq;lt]], MO = [[seq]], DROP!=_tmpl_skip, FILTER=_tmpl_dl); 3 | FILTER_TY_COND; 4 | static inline TT _vatomic_await_COND_MS(AA *a, TT v); 5 | _tmpl_end; 6 | 7 | -------------------------------------------------------------------------------- /vatomic/tmplr/test/test-skip.in: -------------------------------------------------------------------------------- 1 | _tmpl_begin(TY = [[u32; ptr]], COND = [[eq; ge]], 2 | OP = [[sub; set]], MO = [[seq]], 3 | FILTER_ptr_eq = KEEP, 4 | FILTER_ptr_set = KEEP, 5 | FILTER_ptr = SKIP, 6 | FILTER = KEEP, 7 | KEEP = _tmpl_dl, 8 | SKIP = _tmpl_skip); 9 | FILTER_TY_COND 10 | FILTER_TY_OP 11 | ---> ty = TY, cond = COND, op = OP 12 | _tmpl_end; 13 | -------------------------------------------------------------------------------- /vatomic/tmplr/test/test1.in: -------------------------------------------------------------------------------- 1 | _tmpl_begin(X=[[dog;cat;rat]]); 2 | X is an animal. 3 | _tmpl_end; 4 | -------------------------------------------------------------------------------- /vatomic/tmplr/test/test2.in: -------------------------------------------------------------------------------- 1 | _tmpl_begin(X=[[dog;cat;rat]], Y=[[hello;hallo;oi]]); 2 | X is an animal. 3 | Say Y! 4 | -------- 5 | _tmpl_end; 6 | 7 | -------------------------------------------------------------------------------- /vatomic/tmplr/test/test3.in: -------------------------------------------------------------------------------- 1 | _tmpl_begin(X=[[dog;cat;rat]], Y=[[hello;hallo;oi]]); 2 | X is an animal. 3 | Say Y! 4 | -------- 5 | _tmpl_end; 6 | HERE IS THE EMPTY LINE 7 | _tmpl_begin(X=[[cat;rat]]); 8 | X is nice. 9 | _tmpl_end; 10 | -------------------------------------------------------------------------------- /vatomic/tmplr/test/test4.in: -------------------------------------------------------------------------------- 1 | THIS IS A FILE 2 | _tmpl_map(VAR, value); 3 | _tmpl_begin(Y=[[something]]); 4 | --> Y 5 | _tmpl_end; 6 | AND IT HAS ALREADY ENDED 7 | -------------------------------------------------------------------------------- /vatomic/tmplr/test/test5.in: -------------------------------------------------------------------------------- 1 | THIS IS A NEW FILE 2 | 3 | _tmpl_begin(X=[[cat;dog]]); 4 | X has some VAR. And Y? 5 | _tmpl_end; 6 | -------------------------------------------------------------------------------- /vatomic/tmplr/test/test6.in: -------------------------------------------------------------------------------- 1 | _tmpl_dl; this is a comment 2 | _tmpl_map(OP_seq, sequential consistent); 3 | _tmpl_map(OP_acq, acquire); 4 | _tmpl_map(OP_acq, acquired); 5 | _tmpl_begin(mo=[[seq;acq;rel]]); 6 | OP_mo 7 | _tmpl_end; 8 | -------------------------------------------------------------------------------- /vatomic/tmplr/test/test7.in: -------------------------------------------------------------------------------- 1 | _tmpl_map(DROP_IF_cat, _tmpl_skip); 2 | _tmpl_begin(X=[[dog;cat;rat]]); 3 | DROP_IF_X 4 | after drop 5 | X is running. 6 | _tmpl_end; 7 | -------------------------------------------------------------------------------- /vatomic/verify/atomics_list.txt: -------------------------------------------------------------------------------- 1 | xchg 2 | xchg_acq 3 | xchg_rel 4 | xchg_rlx 5 | cmpxchg 6 | cmpxchg_acq 7 | cmpxchg_rel 8 | cmpxchg_rlx 9 | get_max 10 | get_max_acq 11 | get_max_rel 12 | get_max_rlx 13 | max 14 | max_rel 15 | max_rlx 16 | get_and 17 | get_or 18 | get_xor 19 | get_add 20 | get_sub 21 | get_and_acq 22 | get_or_acq 23 | get_xor_acq 24 | get_add_acq 25 | get_sub_acq 26 | get_and_rel 27 | get_or_rel 28 | get_xor_rel 29 | get_add_rel 30 | get_sub_rel 31 | get_and_rlx 32 | get_or_rlx 33 | get_xor_rlx 34 | get_add_rlx 35 | get_sub_rlx 36 | and 37 | or 38 | xor 39 | add 40 | sub 41 | and_rel 42 | or_rel 43 | xor_rel 44 | add_rel 45 | sub_rel 46 | and_rlx 47 | or_rlx 48 | xor_rlx 49 | add_rlx 50 | sub_rlx 51 | read 52 | read_acq 53 | read_rlx 54 | write 55 | write_rel 56 | write_rlx 57 | await_eq 58 | await_neq 59 | await_lt 60 | await_le 61 | await_gt 62 | await_ge 63 | await_eq_acq 64 | await_neq_acq 65 | await_lt_acq 66 | await_le_acq 67 | await_gt_acq 68 | await_ge_acq 69 | await_eq_rlx 70 | await_neq_rlx 71 | await_lt_rlx 72 | await_le_rlx 73 | await_gt_rlx 74 | await_ge_rlx 75 | -------------------------------------------------------------------------------- /vatomic/verify/read.bpl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | procedure read(load_order: OrderRelation, addr: Register) returns (v : Register); 6 | modifies step, states, effects, ordering, global_monitor_exclusive, event_register; 7 | ensures {:msg "load happens within function bounds"} ( 8 | var i := states[step]->last_load; 9 | old(step) <= i && i < step 10 | ); 11 | ensures {:msg "no write effects"} ( 12 | forall i: StateIndex, e: Effect :: 13 | old(step) <= i && i < step ==> 14 | !(effects[i][e] && e is write) 15 | ); 16 | ensures {:msg "read effect produced and correct"} 17 | effects[states[step]->last_load][read(old(states[step]->gpr[addr]))]; 18 | ensures {:msg "order"} 19 | load_order[states[step]->last_load, old(step), step, ordering]; 20 | ensures {:msg "output register contains loaded value"} 21 | states[step]->gpr[v] == memory[states[step]->last_load, old(states[step]->gpr[addr])]; 22 | 23 | 24 | -------------------------------------------------------------------------------- /vatomic/verify/write.bpl: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | procedure write(store_order: OrderRelation, addr, src: Register); 6 | modifies step, states, effects, ordering, global_monitor_exclusive, event_register; 7 | ensures {:msg "store happens within function bounds"} ( 8 | var i := states[step]->last_store; 9 | old(step) <= i && i < step 10 | ); 11 | ensures {:msg "order"} 12 | store_order[states[step]->last_store, old(step), step, ordering]; 13 | ensures {:msg "produces write effect"} ( 14 | var gpr := old(states[step]->gpr); 15 | effects[states[step]->last_store][write(gpr[addr], gpr[src])] 16 | ); 17 | ensures {:msg "no other writes"} ( 18 | forall i : StateIndex, e : Effect :: 19 | old(step) <= i && i < step && i != states[step]->last_store ==> 20 | !(effects[i][e] && (e is write)) 21 | ); 22 | 23 | -------------------------------------------------------------------------------- /verify/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | target_include_directories( 2 | vsync INTERFACE $ 3 | $) 4 | 5 | target_compile_definitions(vsync INTERFACE DEFAULT_SMR_EBR _GNU_SOURCE) 6 | 7 | # add all subdirectories 8 | file(GLOB SUBDIRS CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/verify/*) 9 | list(REMOVE_ITEM SUBDIRS "${CMAKE_SOURCE_DIR}/verify/include") 10 | 11 | foreach(child ${SUBDIRS}) 12 | if(IS_DIRECTORY "${child}") 13 | add_subdirectory(${child}) 14 | endif() 15 | endforeach() 16 | -------------------------------------------------------------------------------- /verify/bitmap/test_case_clr_interset.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | void 9 | pre(void) 10 | { 11 | vbitmap_init(g_bitmap, BITMAP_LEN, true); 12 | } 13 | void 14 | t0(vsize_t tid) 15 | { 16 | vbitmap_clr_range(g_bitmap, 60, 62); 17 | vbitmap_set_bit(g_bitmap, 61); 18 | V_UNUSED(tid); 19 | } 20 | void 21 | t1(vsize_t tid) 22 | { 23 | vbitmap_clr_range(g_bitmap, 62, 64); 24 | vbitmap_set_bit(g_bitmap, 63); 25 | V_UNUSED(tid); 26 | } 27 | void 28 | t2(vsize_t tid) 29 | { 30 | vbitmap_clr_range(g_bitmap, 64, 66); 31 | vbitmap_set_bit(g_bitmap, 65); 32 | V_UNUSED(tid); 33 | } 34 | void 35 | post(void) 36 | { 37 | for (vsize_t i = 0; i < 59; i++) { 38 | vbool_t set = vbitmap_get(g_bitmap, i); 39 | ASSERT(set); 40 | } 41 | for (vsize_t i = 60; i < 66; i++) { 42 | vbool_t set = vbitmap_get(g_bitmap, i); 43 | 44 | if (i == 61 || i == 63 || i == 65) { 45 | ASSERT(set); 46 | } else { 47 | ASSERT(!set); 48 | } 49 | } 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /verify/bitmap/test_case_intact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | void 9 | pre(void) 10 | { 11 | vbitmap_set_range(g_bitmap, NTHREADS, BITMAP_LEN - 1); 12 | } 13 | void 14 | t(vsize_t tid) 15 | { 16 | vbool_t set = false; 17 | 18 | vbitmap_set_bit(g_bitmap, tid); 19 | set = vbitmap_get(g_bitmap, tid); 20 | ASSERT(set); 21 | 22 | vbitmap_clr_bit(g_bitmap, tid); 23 | set = vbitmap_get(g_bitmap, tid); 24 | ASSERT(!set); 25 | } 26 | void 27 | t0(vsize_t tid) 28 | { 29 | t(tid); 30 | } 31 | void 32 | t1(vsize_t tid) 33 | { 34 | t(tid); 35 | } 36 | void 37 | t2(vsize_t tid) 38 | { 39 | t(tid); 40 | } 41 | void 42 | post(void) 43 | { 44 | for (vsize_t i = 0; i < BITMAP_LEN; i++) { 45 | vbool_t set = vbitmap_get(g_bitmap, i); 46 | if (i < NTHREADS) { 47 | ASSERT(!set); 48 | } else { 49 | ASSERT(set); 50 | } 51 | } 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /verify/bitmap/test_case_iter.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | 9 | #define RANGE_MIN 31U 10 | #define RANGE_MAX (BITMAP_LEN - 1U) 11 | 12 | void 13 | pre(void) 14 | { 15 | } 16 | 17 | void 18 | t0(vsize_t tid) 19 | { 20 | vbitmap_set_range(g_bitmap, RANGE_MIN, VUINT64_WIDTH); 21 | V_UNUSED(tid); 22 | } 23 | void 24 | t1(vsize_t tid) 25 | { 26 | vbitmap_set_range(g_bitmap, VUINT64_WIDTH, RANGE_MAX); 27 | V_UNUSED(tid); 28 | } 29 | void 30 | t2(vsize_t tid) 31 | { 32 | vbitmap_iter_t iter; 33 | vsize_t idx = 0; 34 | vbitmap_iter_init(g_bitmap, &iter); 35 | 36 | while (vbitmap_iter_next(&iter, &idx)) { 37 | ASSERT(idx >= RANGE_MIN); 38 | ASSERT(idx <= RANGE_MAX); 39 | } 40 | 41 | V_UNUSED(tid); 42 | } 43 | void 44 | post(void) 45 | { 46 | vbitmap_iter_t iter; 47 | vsize_t idx = 0; 48 | vsize_t expected = RANGE_MIN; 49 | vbitmap_iter_init(g_bitmap, &iter); 50 | 51 | while (vbitmap_iter_next(&iter, &idx)) { 52 | ASSERT(idx >= RANGE_MIN); 53 | ASSERT(idx <= RANGE_MAX); 54 | ASSERT(idx == expected); 55 | expected++; 56 | } 57 | ASSERT(idx == RANGE_MAX); 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /verify/bitmap/test_case_range.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | void 9 | pre(void) 10 | { 11 | } 12 | void 13 | t0(vsize_t tid) 14 | { 15 | V_UNUSED(tid); 16 | vbitmap_set_range(g_bitmap, 1, 4); 17 | } 18 | void 19 | t1(vsize_t tid) 20 | { 21 | V_UNUSED(tid); 22 | vbitmap_clr_range(g_bitmap, 2, 3); 23 | } 24 | void 25 | t2(vsize_t tid) 26 | { 27 | V_UNUSED(tid); 28 | vbitmap_set_range(g_bitmap, 63, 66); 29 | } 30 | void 31 | post(void) 32 | { 33 | vsize_t set_indexes[6] = {1, 4, 63, 64, 65, 66}; 34 | for (vsize_t i = 0; i < 6; i++) { 35 | vbool_t set = vbitmap_get(g_bitmap, set_indexes[i]); 36 | ASSERT(set); 37 | } 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /verify/bitmap/test_case_set_intersect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | void 9 | pre(void) 10 | { 11 | } 12 | void 13 | t0(vsize_t tid) 14 | { 15 | vbitmap_set_range(g_bitmap, 60, 62); 16 | vbitmap_clr_bit(g_bitmap, 61); 17 | V_UNUSED(tid); 18 | } 19 | void 20 | t1(vsize_t tid) 21 | { 22 | vbitmap_set_range(g_bitmap, 62, 64); 23 | vbitmap_clr_bit(g_bitmap, 63); 24 | V_UNUSED(tid); 25 | } 26 | void 27 | t2(vsize_t tid) 28 | { 29 | vbitmap_set_range(g_bitmap, 64, 66); 30 | vbitmap_clr_bit(g_bitmap, 65); 31 | V_UNUSED(tid); 32 | } 33 | void 34 | post(void) 35 | { 36 | for (vsize_t i = 0; i < 59; i++) { 37 | vbool_t set = vbitmap_get(g_bitmap, i); 38 | ASSERT(!set); 39 | } 40 | for (vsize_t i = 60; i < 66; i++) { 41 | vbool_t set = vbitmap_get(g_bitmap, i); 42 | 43 | if (i == 61 || i == 63 || i == 65) { 44 | ASSERT(!set); 45 | } else { 46 | ASSERT(set); 47 | } 48 | } 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /verify/bitmap/verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #define NTHREADS 3U 8 | 9 | #include 10 | #define BITMAP_LEN (VUINT64_WIDTH + 3U) 11 | #define BITMAP_SLOTS 2U 12 | #define BITMAP_SIZE (sizeof(vbitmap_t) + (sizeof(vatomic64_t) * BITMAP_SLOTS)) 13 | char g_mem[BITMAP_SIZE]; // workaround 14 | vbitmap_t *g_bitmap; 15 | 16 | #include 17 | 18 | int 19 | main(void) 20 | { 21 | tc(); 22 | return 0; 23 | } 24 | 25 | void 26 | init(void) 27 | { 28 | vsize_t size = vbitmap_size(BITMAP_LEN); 29 | ASSERT(BITMAP_SIZE == size); 30 | g_bitmap = (vbitmap_t *)g_mem; 31 | ASSERT(g_bitmap); 32 | vbitmap_init(g_bitmap, BITMAP_LEN, false); 33 | } 34 | 35 | void 36 | fini(void) 37 | { 38 | } 39 | 40 | void 41 | reg(vsize_t tid) 42 | { 43 | V_UNUSED(tid); 44 | } 45 | 46 | void 47 | dereg(vsize_t tid) 48 | { 49 | V_UNUSED(tid); 50 | } 51 | -------------------------------------------------------------------------------- /verify/cachedq/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(FILE_NAME cachedq_verify.c) 2 | 3 | set(TEST_NAME test_cachedq) 4 | add_executable(${TEST_NAME} ${FILE_NAME}) 5 | target_link_libraries(${TEST_NAME} vsync pthread) 6 | v_add_bin_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME}) 7 | 8 | add_vsyncer_check( 9 | TARGET check_cachedq 10 | SOURCE ${FILE_NAME} 11 | TIMEOUT 30 12 | DEPENDENCIES vsync 13 | MEMORY_MODELS imm rc11) 14 | -------------------------------------------------------------------------------- /verify/chaselev/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRCS *.c) 2 | 3 | foreach(SRC ${SRCS}) 4 | get_filename_component(TEST ${SRC} NAME_WE) 5 | 6 | add_executable(${TEST} ${SRC}) 7 | target_link_libraries(${TEST} vsync pthread) 8 | v_add_bin_test(NAME ${TEST} COMMAND ${TEST}) 9 | 10 | add_vsyncer_check( 11 | TARGET check_${TEST} 12 | SOURCE ${SRC} 13 | TIMEOUT 300 14 | DEPENDENCIES vsync) 15 | endforeach() 16 | 17 | # Enable some tests with VMM and set extra options for Dartagnan 18 | set(DAT3M_BOUND_verify_basic_variation 5) 19 | set(DAT3M_BOUND_verify_basic 5) 20 | set(DAT3M_BOUND_verify_mutual_exclusion 5) 21 | set(DAT3M_BOUND_verify_empty 10) 22 | 23 | foreach(SRC ${SRCS}) 24 | get_filename_component(TEST ${SRC} NAME_WE) 25 | 26 | if(${DAT3M_BOUND_${TEST}}) 27 | add_vsyncer_check( 28 | TARGET check_${TEST} 29 | SOURCE ${SRC} 30 | MEMORY_MODELS vmm USE_DAT3M DARTAGNAN_OPTIONS 31 | --bound=${DAT3M_BOUND_${TEST}} 32 | TIMEOUT 700 33 | DEPENDENCIES vsync) 34 | endif() 35 | endforeach() 36 | -------------------------------------------------------------------------------- /verify/listset/test_case_1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | /* range of keys to preinsert */ 9 | #define INIT_K1 0 10 | #define INIT_K2 0 11 | 12 | /* Preinsert keys \in [0, 0] 13 | * goal: SC of add 14 | */ 15 | int msg = 0; 16 | const vsize_t g_lst_idx = 0; 17 | void 18 | pre(void) 19 | { 20 | for (vlistset_key_t k = INIT_K1; k <= INIT_K2; k++) { 21 | lst_add(MAIN_TID, g_lst_idx, k); 22 | } 23 | } 24 | void 25 | t0(vsize_t tid) 26 | { 27 | vbool_t success = false; 28 | success = lst_add(tid, g_lst_idx, 2); 29 | ASSERT(success); 30 | msg = 1; 31 | success = lst_add(tid, g_lst_idx, 3); 32 | ASSERT(success); 33 | } 34 | void 35 | t1(vsize_t tid) 36 | { 37 | if (lst_rem(tid, g_lst_idx, 3)) { 38 | ASSERT(lst_con(tid, g_lst_idx, 2)); 39 | ASSERT(msg); 40 | } else { 41 | verification_ignore(); 42 | } 43 | } 44 | void 45 | t2(vsize_t tid) 46 | { 47 | V_UNUSED(tid); 48 | } 49 | void 50 | post(void) 51 | { 52 | lst_verify_traces(g_lst_idx); 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /verify/listset/test_case_2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | #define INIT_K1 0 9 | #define INIT_K2 4 10 | 11 | /* Preinsert keys \in [1, 4] 12 | * goal: SC of remove 13 | */ 14 | const vsize_t g_lst_idx = 0; 15 | #define KEY_A 3U 16 | #define KEY_B 2U 17 | void 18 | pre(void) 19 | { 20 | for (vlistset_key_t k = INIT_K1; k <= INIT_K2; k++) { 21 | lst_add(MAIN_TID, g_lst_idx, k); 22 | } 23 | } 24 | void 25 | t0(vsize_t tid) 26 | { 27 | vbool_t success = false; 28 | success = lst_rem(tid, g_lst_idx, KEY_A); 29 | ASSERT(success); 30 | 31 | success = lst_rem(tid, g_lst_idx, KEY_B); 32 | ASSERT(success); 33 | } 34 | void 35 | t1(vsize_t tid) 36 | { 37 | if (!lst_con(tid, g_lst_idx, KEY_B)) { 38 | ASSERT(!lst_con(tid, g_lst_idx, KEY_A)); 39 | } else { 40 | verification_ignore(); 41 | } 42 | } 43 | void 44 | t2(vsize_t tid) 45 | { 46 | lst_clean(tid); 47 | } 48 | void 49 | post(void) 50 | { 51 | lst_verify_traces(g_lst_idx); 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /verify/listset/test_case_3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | /* Preinsert keys \in [0, 2] */ 9 | #define INIT_K1 0 10 | #define INIT_K2 2 11 | 12 | /* goal: 13 | * message passing contains vs. rem 14 | * remove from the middle 15 | */ 16 | int msg = 0; 17 | const vsize_t g_lst_idx = 0; 18 | void 19 | pre(void) 20 | { 21 | for (vlistset_key_t k = INIT_K1; k <= INIT_K2; k++) { 22 | lst_add(MAIN_TID, g_lst_idx, k); 23 | } 24 | } 25 | void 26 | t0(vsize_t tid) 27 | { 28 | if (!lst_con(tid, g_lst_idx, 1)) { 29 | ASSERT(msg == 1); 30 | } else { 31 | verification_ignore(); 32 | } 33 | } 34 | void 35 | t1(vsize_t tid) 36 | { 37 | msg = 1; 38 | ASSERT(lst_rem(tid, g_lst_idx, 1)); 39 | } 40 | void 41 | t2(vsize_t tid) 42 | { 43 | lst_clean(tid); 44 | } 45 | void 46 | post(void) 47 | { 48 | lst_verify_traces(g_lst_idx); 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /verify/listset/test_case_4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | /* Preinsert keys \in [0, 1] in all lists */ 9 | #define INIT_K1 0 10 | #define INIT_K2 1 11 | 12 | /* goal: 13 | * Linearizability 14 | * multiple listsets 15 | */ 16 | const vsize_t g_fst_lst_idx = 0; 17 | const vsize_t g_2nd_lst_idx = 1; 18 | void 19 | pre(void) 20 | { 21 | for (vlistset_key_t k = INIT_K1; k <= INIT_K2; k++) { 22 | for (vsize_t i = 0; i < N_DS; i++) { 23 | lst_add(MAIN_TID, i, k); 24 | } 25 | } 26 | } 27 | void 28 | t0(vsize_t tid) 29 | { 30 | /* remove 0 from list 0 */ 31 | ASSERT(lst_rem(tid, g_fst_lst_idx, 0)); 32 | /* remove 1 from list 1 */ 33 | ASSERT(lst_rem(tid, g_2nd_lst_idx, 1)); 34 | } 35 | void 36 | t1(vsize_t tid) 37 | { 38 | /* if 1 is removed from list 1 */ 39 | if (!lst_con(tid, g_2nd_lst_idx, 1)) { 40 | /* 0 must be removed from list 0 */ 41 | ASSERT(!lst_con(tid, g_fst_lst_idx, 0)); 42 | } else { 43 | verification_ignore(); 44 | } 45 | } 46 | void 47 | t2(vsize_t tid) 48 | { 49 | lst_clean(tid); 50 | } 51 | void 52 | post(void) 53 | { 54 | lst_verify_traces(g_fst_lst_idx); 55 | lst_verify_traces(g_2nd_lst_idx); 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /verify/listset/test_case_5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | /* Preinsert keys \in [0, 2] */ 9 | #define INIT_K1 0 10 | #define INIT_K2 2 11 | 12 | /* goal: 13 | * removing from head, middle, tail 14 | */ 15 | const vsize_t g_lst_idx = 0; 16 | void 17 | pre(void) 18 | { 19 | for (vlistset_key_t k = INIT_K1; k <= INIT_K2; k++) { 20 | ASSERT(lst_add(MAIN_TID, g_lst_idx, k)); 21 | } 22 | } 23 | void 24 | t0(vsize_t tid) 25 | { 26 | ASSERT(lst_rem(tid, g_lst_idx, 0)); 27 | ASSERT(!lst_con(tid, g_lst_idx, 0)); 28 | } 29 | void 30 | t1(vsize_t tid) 31 | { 32 | ASSERT(lst_rem(tid, g_lst_idx, 1)); 33 | ASSERT(!lst_con(tid, g_lst_idx, 1)); 34 | } 35 | void 36 | t2(vsize_t tid) 37 | { 38 | #if !defined(VSYNC_VERIFICATION_QUICK) 39 | ASSERT(lst_rem(tid, g_lst_idx, 2)); 40 | ASSERT(!lst_con(tid, g_lst_idx, 2)); 41 | #else 42 | V_UNUSED(tid); 43 | #endif 44 | } 45 | void 46 | post(void) 47 | { 48 | lst_verify_traces(g_lst_idx); 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /verify/listset/test_case_6.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | /* Preinsert keys \in [1] in all lists */ 9 | #define INIT_K1 0 10 | #define INIT_K2 1 11 | 12 | /* goal: 13 | * Linearizability 14 | * multiple listsets add 15 | */ 16 | const vsize_t g_fst_lst_idx = 0; 17 | const vsize_t g_2nd_lst_idx = 1; 18 | 19 | void 20 | pre(void) 21 | { 22 | for (vlistset_key_t k = INIT_K1; k <= INIT_K2; k++) { 23 | for (vsize_t i = 0; i < N_DS; i++) { 24 | lst_add(MAIN_TID, i, k); 25 | } 26 | } 27 | } 28 | void 29 | t0(vsize_t tid) 30 | { 31 | /* add 2 to list 0 */ 32 | ASSERT(lst_add(tid, g_fst_lst_idx, 2)); 33 | /* add 2 to list 1 */ 34 | ASSERT(lst_add(tid, g_2nd_lst_idx, 2)); 35 | } 36 | void 37 | t1(vsize_t tid) 38 | { 39 | /* if 2 is added to list 1 */ 40 | if (lst_con(tid, g_2nd_lst_idx, 2)) { 41 | /* 1 must be added to list 0 */ 42 | ASSERT(lst_con(tid, g_fst_lst_idx, 2)); 43 | } else { 44 | verification_ignore(); 45 | } 46 | } 47 | void 48 | t2(vsize_t tid) 49 | { 50 | V_UNUSED(tid); 51 | } 52 | 53 | void 54 | post(void) 55 | { 56 | lst_verify_traces(g_fst_lst_idx); 57 | lst_verify_traces(g_2nd_lst_idx); 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /verify/listset/test_case_7.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #ifndef VSYNC_TEST_CASE_H 8 | #define VSYNC_TEST_CASE_H 9 | /* start with empty list insert head, middle, tail */ 10 | /* goal: 11 | * removing from head, middle, tail 12 | */ 13 | const vsize_t g_lst_idx = 0; 14 | void 15 | t0(vsize_t tid) 16 | { 17 | ASSERT(lst_add(tid, g_lst_idx, 0)); 18 | ASSERT(lst_con(tid, g_lst_idx, 0)); 19 | } 20 | void 21 | t1(vsize_t tid) 22 | { 23 | ASSERT(lst_add(tid, g_lst_idx, 1)); 24 | ASSERT(lst_con(tid, g_lst_idx, 1)); 25 | } 26 | void 27 | t2(vsize_t tid) 28 | { 29 | ASSERT(lst_add(tid, g_lst_idx, 2)); 30 | ASSERT(lst_con(tid, g_lst_idx, 2)); 31 | } 32 | void 33 | pre(void) 34 | { 35 | } 36 | void 37 | post(void) 38 | { 39 | lst_verify_traces(g_lst_idx); 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /verify/listset/test_case_8.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #ifndef VSYNC_TEST_CASE_H 8 | #define VSYNC_TEST_CASE_H 9 | /* goal: 10 | * removing from head, middle, tail 11 | */ 12 | const vsize_t g_lst_idx = 0; 13 | void 14 | pre(void) 15 | { 16 | ASSERT(lst_add(MAIN_TID, g_lst_idx, 1)); 17 | } 18 | void 19 | t0(vsize_t tid) 20 | { 21 | /* add existing value */ 22 | ASSERT(!lst_add(tid, g_lst_idx, 1)); 23 | } 24 | void 25 | t1(vsize_t tid) 26 | { 27 | /* add non exisitng value at the head */ 28 | ASSERT(lst_add(tid, g_lst_idx, 0)); 29 | ASSERT(lst_con(tid, g_lst_idx, 0)); 30 | } 31 | void 32 | t2(vsize_t tid) 33 | { 34 | /* remove non existing value */ 35 | ASSERT(!lst_rem(tid, g_lst_idx, 2)); 36 | lst_clean(tid); 37 | } 38 | void 39 | post(void) 40 | { 41 | lst_verify_traces(g_lst_idx); 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /verify/listset/verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define NTHREADS 3U 7 | #include 8 | #include 9 | 10 | void 11 | init(void) 12 | { 13 | lsts_init(); 14 | } 15 | 16 | void 17 | fini(void) 18 | { 19 | lsts_destroy(); 20 | } 21 | 22 | void 23 | reg(vsize_t tid) 24 | { 25 | lst_reg(tid); 26 | } 27 | 28 | void 29 | dereg(vsize_t tid) 30 | { 31 | lst_dereg(tid); 32 | } 33 | 34 | int 35 | main(void) 36 | { 37 | tc(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /verify/pool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRCS *.c) 2 | foreach(SRC ${SRCS}) 3 | get_filename_component(TEST ${SRC} NAME_WE) 4 | 5 | add_executable(${TEST} ${SRC}) 6 | target_link_libraries(${TEST} vsync pthread) 7 | v_add_bin_test(NAME ${TEST} COMMAND ${TEST}) 8 | 9 | add_vsyncer_check( 10 | TARGET check_${TEST} 11 | SOURCE ${SRC} 12 | TIMEOUT 500 13 | DEPENDENCIES vsync) 14 | endforeach() 15 | -------------------------------------------------------------------------------- /verify/priority_queue/test_case_add_vs_add_diff_prio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | vsize_t ds_idx = 0; 9 | 10 | void 11 | pre(void) 12 | { 13 | } 14 | 15 | void 16 | t0(vsize_t tid) 17 | { 18 | pqueue_enq(tid, ds_idx, 2, 2); 19 | } 20 | 21 | void 22 | t1(vsize_t tid) 23 | { 24 | pqueue_enq(tid, ds_idx, 1, 1); 25 | } 26 | 27 | void 28 | t2(vsize_t tid) 29 | { 30 | V_UNUSED(tid); 31 | } 32 | 33 | void 34 | post(void) 35 | { 36 | vpriority_t priority; 37 | vuintptr_t key; 38 | key = pqueue_deq(MAIN_TID, ds_idx, &priority); 39 | ASSERT(key == 1); 40 | ASSERT(priority == 1); 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /verify/priority_queue/test_case_add_vs_add_same_prio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #ifndef VSYNC_TEST_CASE_H 8 | #define VSYNC_TEST_CASE_H 9 | vsize_t ds_idx = 0; 10 | 11 | void 12 | pre(void) 13 | { 14 | } 15 | void 16 | t0(vsize_t tid) 17 | { 18 | pqueue_enq(tid, ds_idx, 5, 1); 19 | } 20 | 21 | void 22 | t1(vsize_t tid) 23 | { 24 | pqueue_enq(tid, ds_idx, 6, 1); 25 | } 26 | 27 | void 28 | t2(vsize_t tid) 29 | { 30 | V_UNUSED(tid); 31 | } 32 | 33 | void 34 | post(void) 35 | { 36 | vpriority_t priority = 0; 37 | vuintptr_t key1 = 0; 38 | vuintptr_t key2 = 0; 39 | 40 | key1 = pqueue_deq(MAIN_TID, ds_idx, &priority); 41 | ASSERT(priority == 1); 42 | ASSERT(key1 == 5 || key1 == 6); 43 | 44 | priority = 0; 45 | key2 = pqueue_deq(MAIN_TID, ds_idx, &priority); 46 | ASSERT(priority == 1); 47 | 48 | if (key1 == 5) 49 | ASSERT(key2 == 6); 50 | else 51 | ASSERT(key2 == 5); 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /verify/priority_queue/test_case_rem_vs_rem_diff_prio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | 9 | vsize_t ds_idx = 0; 10 | vpriority_t t0_p = 0; 11 | vpriority_t t1_p = 0; 12 | 13 | void 14 | pre(void) 15 | { 16 | for (vpriority_t i = 1; i <= 3U; i++) { 17 | pqueue_enq(MAIN_TID, ds_idx, i, i); 18 | } 19 | } 20 | 21 | void 22 | t0(vsize_t tid) 23 | { 24 | vuintptr_t key = 0; 25 | key = pqueue_deq(tid, ds_idx, &t0_p); 26 | ASSERT(key == t0_p); 27 | } 28 | 29 | void 30 | t1(vsize_t tid) 31 | { 32 | vuintptr_t key = 0; 33 | 34 | key = pqueue_deq(tid, ds_idx, &t1_p); 35 | ASSERT(key == t1_p); 36 | } 37 | 38 | void 39 | t2(vsize_t tid) 40 | { 41 | #if defined(VSYNC_VERIFICATION_QUICK) 42 | V_UNUSED(tid); 43 | #else 44 | /* trigger smr cleaning if available */ 45 | pqueue_clean(tid); 46 | #endif 47 | } 48 | 49 | void 50 | post(void) 51 | { 52 | vpriority_t priority = 0; 53 | vuintptr_t key = 0; 54 | key = pqueue_deq(MAIN_TID, ds_idx, &priority); 55 | ASSERT(key == 3); 56 | ASSERT(priority == 3); 57 | ASSERT((t0_p == 1 && t1_p == 2) || (t0_p == 2 && t1_p == 1)); 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /verify/priority_queue/test_case_rem_vs_rem_same_prio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #ifndef VSYNC_TEST_CASE_H 8 | #define VSYNC_TEST_CASE_H 9 | vsize_t ds_idx = 0; 10 | 11 | void 12 | pre(void) 13 | { 14 | pqueue_enq(MAIN_TID, ds_idx, 1, 1); 15 | pqueue_enq(MAIN_TID, ds_idx, 1, 1); 16 | pqueue_enq(MAIN_TID, ds_idx, 2, 2); 17 | } 18 | 19 | void 20 | t0(vsize_t tid) 21 | { 22 | /* remove minimum priority should be one */ 23 | vpriority_t priority; 24 | vuintptr_t key; 25 | key = pqueue_deq(tid, ds_idx, &priority); 26 | ASSERT(key == 1); 27 | ASSERT(priority == 1); 28 | } 29 | 30 | void 31 | t1(vsize_t tid) 32 | { 33 | /* remove minimum priority should be one */ 34 | vpriority_t priority; 35 | vuintptr_t key; 36 | key = pqueue_deq(tid, ds_idx, &priority); 37 | ASSERT(key == 1); 38 | ASSERT(priority == 1); 39 | } 40 | 41 | void 42 | t2(vsize_t tid) 43 | { 44 | #if defined(VSYNC_VERIFICATION_QUICK) 45 | // skip cleaning on quick 46 | #else 47 | pqueue_clean(tid); 48 | #endif 49 | } 50 | 51 | void 52 | post(void) 53 | { 54 | vpriority_t priority; 55 | vuintptr_t key; 56 | 57 | key = pqueue_deq(MAIN_TID, ds_idx, &priority); 58 | ASSERT(key == 2); 59 | ASSERT(priority == 2); 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /verify/priority_queue/verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #define NTHREADS 3U 8 | #include 9 | #include 10 | 11 | void 12 | init(void) 13 | { 14 | pqueue_init(); 15 | } 16 | void 17 | fini(void) 18 | { 19 | pqueue_destroy(); 20 | } 21 | void 22 | reg(vsize_t tid) 23 | { 24 | pqueue_reg(tid); 25 | } 26 | void 27 | dereg(vsize_t tid) 28 | { 29 | pqueue_dereg(tid); 30 | } 31 | int 32 | main(void) 33 | { 34 | tc(); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /verify/simpleht/test_case_add.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | void 9 | pre(void) 10 | { 11 | } 12 | void 13 | t0(vsize_t tid) 14 | { 15 | vbool_t success = imap_add(tid, 1, 1); 16 | ASSERT(success); 17 | } 18 | void 19 | t1(vsize_t tid) 20 | { 21 | vbool_t success = imap_add(tid, 2, 2); 22 | ASSERT(success); 23 | } 24 | void 25 | t2(vsize_t tid) 26 | { 27 | vbool_t success = imap_add(tid, 3, 3); 28 | ASSERT(success); 29 | } 30 | void 31 | post(void) 32 | { 33 | for (vuintptr_t k = 1; k <= 3; k++) { 34 | data_t *d = imap_get(MAIN_TID, k); 35 | ASSERT(d); 36 | ASSERT(d->val == k); 37 | } 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /verify/simpleht/test_case_same_bucket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #ifndef VSYNC_TEST_CASE_H 8 | #define VSYNC_TEST_CASE_H 9 | #define LEN (VSIMPLE_HT_CAPACITY - 1U) 10 | vuintptr_t g_keys[LEN]; 11 | void 12 | pre(void) 13 | { 14 | vsize_t cnt = 0; 15 | vuintptr_t k = 0; 16 | vuintptr_t b = LEN; 17 | 18 | while (cnt < LEN) { 19 | k++; 20 | if (k % VSIMPLE_HT_CAPACITY == b) { 21 | vbool_t success = imap_add(MAIN_TID, k, k); 22 | ASSERT(success); 23 | g_keys[cnt] = k; 24 | cnt++; 25 | } 26 | } 27 | } 28 | void 29 | t0(vsize_t tid) 30 | { 31 | ASSERT(tid < LEN); 32 | vbool_t success = imap_add(tid, g_keys[tid], g_keys[tid]); 33 | ASSERT(!success); 34 | } 35 | void 36 | t1(vsize_t tid) 37 | { 38 | ASSERT(tid < LEN); 39 | data_t *data = imap_get(tid, g_keys[tid]); 40 | ASSERT(data); 41 | } 42 | void 43 | t2(vsize_t tid) 44 | { 45 | ASSERT(tid < LEN); 46 | vbool_t success = imap_rem(tid, g_keys[tid]); 47 | ASSERT(success); 48 | } 49 | void 50 | post(void) 51 | { 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /verify/simpleht/verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define NTHREADS 3U 7 | #include 8 | #include 9 | 10 | void 11 | reg(vsize_t tid) 12 | { 13 | imap_reg(tid); 14 | } 15 | void 16 | dereg(vsize_t tid) 17 | { 18 | imap_dereg(tid); 19 | } 20 | 21 | void 22 | init(void) 23 | { 24 | imap_init(); 25 | } 26 | void 27 | fini(void) 28 | { 29 | imap_destroy(); 30 | } 31 | 32 | int 33 | main(void) 34 | { 35 | tc(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /verify/skiplist/test_case_add_rem_lku_msg_passing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | #define INIT_SIZE 4 9 | 10 | vskiplist_key_t g_init_keys[INIT_SIZE] = {0, 2, 5, 10}; 11 | int g_msg = 0; 12 | const vskiplist_key_t g_key = 3; 13 | vbool_t g_t2_rem_3_ret = false; 14 | void 15 | t0(vsize_t tid) 16 | { 17 | g_msg = 10; 18 | skip_enter(tid); 19 | add_key(tid, g_key, SUCC_EXPECTED); 20 | skip_exit(tid); 21 | } 22 | void 23 | t1(vsize_t tid) 24 | { 25 | skip_enter(tid); 26 | g_t2_rem_3_ret = rem_key(tid, g_key, NO_EXPECTATION); 27 | skip_exit(tid); 28 | if (g_t2_rem_3_ret) { 29 | ASSERT(g_msg == 10); 30 | skip_clean(tid); 31 | } 32 | } 33 | void 34 | t2(vsize_t tid) 35 | { 36 | skip_enter(tid); 37 | lookup_key(tid, 5, SUCC_EXPECTED); 38 | skip_exit(tid); 39 | } 40 | void 41 | pre(void) 42 | { 43 | } 44 | void 45 | post(void) 46 | { 47 | // if remove succeeded, we expect not to find the key 48 | // and if it fails we expect to find it 49 | lookup_key(MAIN_TID, g_key, g_t2_rem_3_ret ? FAIL_EXPECTED : SUCC_EXPECTED); 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /verify/skiplist/test_case_add_rem_succ.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | #define INIT_SIZE 3 9 | vskiplist_key_t g_init_keys[INIT_SIZE] = {3, 5, 6}; 10 | void 11 | t0(vsize_t tid) 12 | { 13 | skip_enter(tid); 14 | add_key(tid, 4, SUCC_EXPECTED); 15 | skip_exit(tid); 16 | } 17 | void 18 | t1(vsize_t tid) 19 | { 20 | skip_enter(tid); 21 | rem_key(tid, 5, SUCC_EXPECTED); 22 | skip_exit(tid); 23 | skip_clean(tid); 24 | } 25 | void 26 | t2(vsize_t tid) 27 | { 28 | skip_enter(tid); 29 | lookup_key(tid, 6, SUCC_EXPECTED); 30 | skip_exit(tid); 31 | } 32 | void 33 | pre(void) 34 | { 35 | } 36 | void 37 | post(void) 38 | { 39 | lookup_key(MAIN_TID, 4, SUCC_EXPECTED); 40 | lookup_key(MAIN_TID, 5, FAIL_EXPECTED); 41 | // replacing 5 with 6, 5 is removed 42 | g_init_keys[1] = 6; 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /verify/skiplist/test_case_rem_node.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | #define INIT_SIZE 3 9 | #define DONT_CHECK_KEY_EXIST 10 | vskiplist_key_t g_init_keys[INIT_SIZE] = {1, 2, 3}; 11 | vbool_t success[2]; 12 | 13 | vbool_t 14 | _t(vsize_t tid, vskiplist_key_t key) 15 | { 16 | vbool_t success = false; 17 | skip_enter(tid); 18 | vskiplist_node_t *node = skip_lookup(tid, DS_IDX, key); 19 | if (node) { 20 | success = skip_rem_node(tid, DS_IDX, key, node); 21 | } 22 | skip_exit(tid); 23 | return success; 24 | } 25 | 26 | void 27 | t0(vsize_t tid) 28 | { 29 | success[tid] = _t(tid, 2); 30 | } 31 | void 32 | t1(vsize_t tid) 33 | { 34 | success[tid] = _t(tid, 2); 35 | } 36 | void 37 | t2(vsize_t tid) 38 | { 39 | #if defined(VSYNC_VERIFICATION_QUICK) 40 | V_UNUSED(tid); 41 | #else 42 | skip_clean(tid); 43 | #endif 44 | } 45 | void 46 | pre(void) 47 | { 48 | } 49 | void 50 | post(void) 51 | { 52 | ASSERT(success[0] ^ success[1]); 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /verify/smr/verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef SMR_MAX_NTHREADS 7 | #define SMR_MAX_NTHREADS 3U 8 | #endif 9 | #define NTHREADS SMR_MAX_NTHREADS 10 | #include 11 | 12 | void 13 | init(void) 14 | { 15 | ismr_init(); 16 | } 17 | 18 | void 19 | fini(void) 20 | { 21 | ismr_destroy(); 22 | ASSERT(mock_node_no_leak()); 23 | } 24 | 25 | void 26 | reg(vsize_t tid) 27 | { 28 | ismr_reg(tid); 29 | } 30 | 31 | void 32 | dereg(vsize_t tid) 33 | { 34 | ismr_dereg(tid); 35 | } 36 | 37 | int 38 | main(void) 39 | { 40 | tc(); 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /verify/stack/test_case_2push_2pop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | vsize_t ds_idx = 0; 9 | 10 | void 11 | pre(void) 12 | { 13 | } 14 | 15 | void 16 | t0(vsize_t tid) 17 | { 18 | push(tid, ds_idx, 1); 19 | stack_enter(tid); 20 | pop(tid, ds_idx); 21 | stack_exit(tid); 22 | } 23 | 24 | void 25 | t1(vsize_t tid) 26 | { 27 | stack_enter(tid); 28 | pop(tid, ds_idx); 29 | stack_exit(tid); 30 | push(tid, ds_idx, 2); 31 | } 32 | 33 | void 34 | t2(vsize_t tid) 35 | { 36 | stack_enter(tid); 37 | pop(tid, ds_idx); 38 | stack_exit(tid); 39 | #if !defined(VSYNC_VERIFICATION_QUICK) 40 | stack_clean(tid); 41 | #endif 42 | } 43 | 44 | void 45 | post(void) 46 | { 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /verify/stack/test_case_2push_msg_passing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | 9 | vsize_t ds_idx = 0; 10 | 11 | int msg_pushed_1 = 0; 12 | int msg_pushed_2 = 0; 13 | 14 | void 15 | pre(void) 16 | { 17 | } 18 | void 19 | t0(vsize_t tid) 20 | { 21 | msg_pushed_1 = 1; 22 | push(tid, ds_idx, 1); 23 | 24 | msg_pushed_2 = 1; 25 | push(tid, ds_idx, 2); 26 | } 27 | 28 | void 29 | t1(vsize_t tid) 30 | { 31 | stack_enter(tid); 32 | vuintptr_t val = pop(tid, ds_idx); 33 | if (val == 2) { 34 | ASSERT(msg_pushed_1); 35 | ASSERT(msg_pushed_2); 36 | val = pop(tid, ds_idx); 37 | ASSERT(val == 1); 38 | } else if (val == 1) { 39 | ASSERT(msg_pushed_1); 40 | } 41 | stack_exit(tid); 42 | } 43 | 44 | void 45 | t2(vsize_t tid) 46 | { 47 | stack_clean(tid); 48 | } 49 | 50 | void 51 | post(void) 52 | { 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /verify/stack/test_case_only_pop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | vsize_t ds_idx = 0; 9 | 10 | void 11 | pre(void) 12 | { 13 | for (vsize_t i = 1; i <= 4; i++) { 14 | push(MAIN_TID, ds_idx, i); 15 | } 16 | } 17 | 18 | void 19 | t0(vsize_t tid) 20 | { 21 | stack_enter(tid); 22 | vuintptr_t val_1 = pop(tid, ds_idx); 23 | vuintptr_t val_2 = pop(tid, ds_idx); 24 | stack_exit(tid); 25 | ASSERT(val_1 > val_2); 26 | } 27 | 28 | void 29 | t1(vsize_t tid) 30 | { 31 | stack_enter(tid); 32 | vuintptr_t val_1 = pop(tid, ds_idx); 33 | stack_exit(tid); 34 | ASSERT(val_1); 35 | } 36 | 37 | vbool_t t2_is_active = false; 38 | void 39 | t2(vsize_t tid) 40 | { 41 | #if !defined(VSYNC_VERIFICATION_QUICK) 42 | t2_is_active = true; 43 | stack_enter(tid); 44 | vuintptr_t val_1 = pop(tid, ds_idx); 45 | stack_exit(tid); 46 | stack_clean(tid); 47 | ASSERT(val_1); 48 | #endif 49 | V_UNUSED(tid); 50 | } 51 | 52 | void 53 | post(void) 54 | { 55 | vuintptr_t val = pop(MAIN_TID, ds_idx); 56 | if (t2_is_active) { 57 | ASSERT(val == 0); 58 | } else { 59 | ASSERT(val == 1); 60 | } 61 | } 62 | #endif 63 | -------------------------------------------------------------------------------- /verify/stack/test_case_only_push.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | vsize_t ds_idx = 0; 9 | vuintptr_t popped[5] = {0}; 10 | 11 | void 12 | pre(void) 13 | { 14 | } 15 | 16 | void 17 | t0(vsize_t tid) 18 | { 19 | push(tid, ds_idx, 1); 20 | push(tid, ds_idx, 2); 21 | } 22 | 23 | void 24 | t1(vsize_t tid) 25 | { 26 | push(tid, ds_idx, 3); 27 | } 28 | 29 | vbool_t t2_is_active = false; 30 | void 31 | t2(vsize_t tid) 32 | { 33 | #if !defined(VSYNC_VERIFICATION_QUICK) 34 | t2_is_active = true; 35 | push(tid, ds_idx, 4); 36 | #endif 37 | } 38 | 39 | void 40 | post(void) 41 | { 42 | vsize_t len = t2_is_active ? 4 : 3; 43 | 44 | for (vsize_t i = 0; i < len; i++) { 45 | popped[i] = pop(MAIN_TID, ds_idx); 46 | ASSERT(popped[i]); 47 | if (popped[i] == 1) { 48 | vbool_t found = false; 49 | /* if 1 is popped then then 2 have been popped ... */ 50 | for (vsize_t j = 0; j < i; j++) { 51 | if (2 == popped[j]) { 52 | found = true; 53 | } 54 | } 55 | ASSERT(found); 56 | } 57 | } 58 | 59 | ASSERT(pop(MAIN_TID, ds_idx) == 0); 60 | } 61 | #endif 62 | -------------------------------------------------------------------------------- /verify/stack/test_case_pop_twice_push_pop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #ifndef VSYNC_TEST_CASE_H 8 | #define VSYNC_TEST_CASE_H 9 | vsize_t ds_idx = 0; 10 | 11 | vuintptr_t v1 = 0; 12 | vuintptr_t v2 = 0; 13 | vuintptr_t v3 = 0; 14 | 15 | vbool_t g_push_msg = false; 16 | 17 | void 18 | pre(void) 19 | { 20 | push(0, ds_idx, 1); 21 | push(0, ds_idx, 2); 22 | push(0, ds_idx, 3); 23 | } 24 | 25 | void 26 | t0(vsize_t tid) 27 | { 28 | stack_enter(tid); 29 | v1 = pop(tid, ds_idx); 30 | v2 = pop(tid, ds_idx); 31 | stack_exit(tid); 32 | 33 | if (v2 == 4 || v1 == 4) 34 | ASSERT(g_push_msg); 35 | else 36 | ASSERT(v1 > v2); 37 | } 38 | 39 | void 40 | t1(vsize_t tid) 41 | { 42 | g_push_msg = true; 43 | push(tid, ds_idx, 4); 44 | } 45 | 46 | void 47 | t2(vsize_t tid) 48 | { 49 | #if defined(VSYNC_VERIFICATION_QUICK) 50 | V_UNUSED(tid); 51 | #else 52 | stack_enter(tid); 53 | v3 = pop(tid, ds_idx); 54 | stack_exit(tid); 55 | if (v3 == 4) 56 | ASSERT(g_push_msg); 57 | stack_clean(tid); 58 | #endif 59 | } 60 | 61 | void 62 | post(void) 63 | { 64 | printf("%lu %lu %lu\n", v1, v2, v3); 65 | ASSERT(v1 != v3); 66 | ASSERT(v2 != v3); 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /verify/stack/verify_stack.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | 7 | #define NTHREADS 3U 8 | #include 9 | #include 10 | 11 | void 12 | init(void) 13 | { 14 | istack_init(); 15 | } 16 | void 17 | fini(void) 18 | { 19 | #ifndef SKIP_VERIFY 20 | verify(0); 21 | #endif 22 | istack_destroy(); 23 | } 24 | 25 | void 26 | reg(vsize_t tid) 27 | { 28 | istack_reg(tid); 29 | } 30 | void 31 | dereg(vsize_t tid) 32 | { 33 | istack_dereg(tid); 34 | } 35 | 36 | int 37 | main(void) 38 | { 39 | tc(); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /verify/thread/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SRCS *.c) 2 | 3 | set(DAT3M_BOUND_mutex_tristate 3) 4 | set(DAT3M_BOUND_once 5) 5 | if(${VSYNCER_CHECK_FULL}) 6 | set(DAT3M_BOUND_cond_test1 4) 7 | set(DAT3M_BOUND_cond_test2 6) 8 | set(DAT3M_BOUND_mutex_musl 5) 9 | set(DAT3M_BOUND_mutex_slim 4) 10 | set(DAT3M_BOUND_mutex_waiters 5) 11 | else() 12 | set(DAT3M_BOUND_cond_test1 3) 13 | set(DAT3M_BOUND_cond_test2 3) 14 | set(DAT3M_BOUND_mutex_musl 3) 15 | set(DAT3M_BOUND_mutex_slim 2) 16 | set(DAT3M_BOUND_mutex_waiters 3) 17 | endif() 18 | 19 | foreach(SRC ${SRCS}) 20 | get_filename_component(TEST ${SRC} NAME_WE) 21 | 22 | add_executable(${TEST} ${SRC}) 23 | target_link_libraries(${TEST} vsync pthread) 24 | target_include_directories(${TEST} PRIVATE include) 25 | v_add_bin_test(NAME ${TEST} COMMAND ${TEST}) 26 | 27 | add_vsyncer_check( 28 | TARGET ${TEST}-check 29 | SOURCE ${SRC} 30 | TIMEOUT 20 31 | DEPENDENCIES vsync) 32 | 33 | if(${DAT3M_BOUND_${TEST}}) 34 | add_vsyncer_check( 35 | TARGET ${TEST}-check 36 | SOURCE ${SRC} 37 | TIMEOUT 60 38 | MEMORY_MODELS vmm USE_DAT3M DARTAGNAN_OPTIONS 39 | --bound=${DAT3M_BOUND_${TEST}} 40 | DEPENDENCIES vsync) 41 | endif() 42 | endforeach() 43 | -------------------------------------------------------------------------------- /verify/thread/cond_test1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "mock_mutex.h" 11 | #include 12 | #include 13 | 14 | #ifdef VSYNC_VERIFICATION_QUICK 15 | #define NTHREADS 2U 16 | #else 17 | #define NTHREADS 3U 18 | #endif 19 | 20 | vcond_t g_cond; 21 | vmutex_t g_mutex; 22 | vuint32_t g_cs_x, g_cs_y; 23 | 24 | void * 25 | run(void *arg) 26 | { 27 | vmutex_acquire(&g_mutex); 28 | if (g_cs_x++ < NTHREADS - 1) { 29 | while (g_cs_x != NTHREADS) { 30 | vcond_wait(&g_cond, &g_mutex); 31 | } 32 | g_cs_y++; 33 | } else { 34 | g_cs_y++; 35 | } 36 | vmutex_release(&g_mutex); 37 | vcond_signal(&g_cond); 38 | 39 | V_UNUSED(arg); 40 | return NULL; 41 | } 42 | 43 | int 44 | main(void) 45 | { 46 | vmutex_init(&g_mutex); 47 | launch_threads(NTHREADS, run); 48 | ASSERT(g_cs_x == NTHREADS); 49 | ASSERT(g_cs_y == NTHREADS); 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /verify/thread/cond_test2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "mock_mutex.h" 11 | #include 12 | #include 13 | 14 | #ifdef VSYNC_VERIFICATION_QUICK 15 | #define NTHREADS 2U 16 | #else 17 | #define NTHREADS 4U 18 | #endif 19 | 20 | vcond_t g_cond; 21 | vmutex_t g_mutex; 22 | vuint32_t g_shared; 23 | 24 | void * 25 | run(void *arg) 26 | { 27 | vsize_t i = (vsize_t)(vuintptr_t)arg; 28 | vmutex_acquire(&g_mutex); 29 | g_shared++; 30 | while (i == 0 && g_shared != NTHREADS) { 31 | vcond_wait(&g_cond, &g_mutex); 32 | } 33 | vmutex_release(&g_mutex); 34 | vcond_signal(&g_cond); 35 | return NULL; 36 | } 37 | 38 | int 39 | main(void) 40 | { 41 | vmutex_init(&g_mutex); 42 | launch_threads(NTHREADS, run); 43 | ASSERT(g_shared == NTHREADS); 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /verify/thread/mock_mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VMOCK_MUTEX_H 7 | #define VMOCK_MUTEX_H 8 | 9 | #if 1 10 | #include 11 | 12 | typedef pthread_mutex_t vmutex_t; 13 | 14 | static inline void 15 | vmutex_init(vmutex_t *l) 16 | { 17 | pthread_mutex_init(l, NULL); 18 | } 19 | 20 | static inline void 21 | vmutex_acquire(vmutex_t *l) 22 | { 23 | pthread_mutex_lock(l); 24 | } 25 | static inline void 26 | vmutex_release(vmutex_t *l) 27 | { 28 | pthread_mutex_unlock(l); 29 | } 30 | #else 31 | #include 32 | 33 | typedef caslock_t vmutex_t; 34 | 35 | vmutex_init(vmutex_t *l) 36 | { 37 | caslock_init(l); 38 | } 39 | 40 | static inline void 41 | vmutex_acquire(vmutex_t *l) 42 | { 43 | caslock_acquire(l); 44 | } 45 | static inline void 46 | vmutex_release(vmutex_t *l) 47 | { 48 | caslock_release(l); 49 | } 50 | #endif 51 | #endif 52 | -------------------------------------------------------------------------------- /verify/thread/mutex_musl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifdef VSYNC_VERIFICATION_QUICK 7 | #define NTHREADS 2 8 | #else 9 | #define NTHREADS 3 10 | #endif 11 | 12 | #include 13 | #include 14 | 15 | vmutex_t lock; 16 | 17 | void 18 | acquire(vuint32_t tid) 19 | { 20 | V_UNUSED(tid); 21 | vmutex_acquire(&lock); 22 | } 23 | 24 | void 25 | release(vuint32_t tid) 26 | { 27 | V_UNUSED(tid); 28 | vmutex_release(&lock); 29 | } 30 | -------------------------------------------------------------------------------- /verify/thread/mutex_slim.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifdef VSYNC_VERIFICATION_QUICK 7 | #define NTHREADS 2 8 | #else 9 | #define NTHREADS 3 10 | #endif 11 | 12 | #include 13 | #include 14 | 15 | vmutex_t lock; 16 | 17 | void 18 | acquire(vuint32_t tid) 19 | { 20 | V_UNUSED(tid); 21 | vmutex_acquire(&lock); 22 | } 23 | 24 | void 25 | release(vuint32_t tid) 26 | { 27 | V_UNUSED(tid); 28 | vmutex_release(&lock); 29 | } 30 | -------------------------------------------------------------------------------- /verify/thread/mutex_slim_liveness.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define VFUTEX_LIVENESS 7 | #define NTHREADS 2 8 | 9 | #include 10 | #include 11 | 12 | vmutex_t lock; 13 | 14 | void 15 | acquire(vuint32_t tid) 16 | { 17 | V_UNUSED(tid); 18 | vmutex_acquire(&lock); 19 | } 20 | 21 | void 22 | release(vuint32_t tid) 23 | { 24 | V_UNUSED(tid); 25 | vmutex_release(&lock); 26 | } 27 | -------------------------------------------------------------------------------- /verify/thread/mutex_slim_liveness_simple.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define VFUTEX_LIVENESS_SIMPLE 7 | #define NTHREADS 2 8 | 9 | #include 10 | #include 11 | 12 | vmutex_t lock; 13 | 14 | void 15 | acquire(vuint32_t tid) 16 | { 17 | V_UNUSED(tid); 18 | vmutex_acquire(&lock); 19 | } 20 | 21 | void 22 | release(vuint32_t tid) 23 | { 24 | V_UNUSED(tid); 25 | vmutex_release(&lock); 26 | } 27 | -------------------------------------------------------------------------------- /verify/thread/mutex_tristate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | 9 | vmutex_t lock; 10 | 11 | void 12 | acquire(vuint32_t tid) 13 | { 14 | V_UNUSED(tid); 15 | vmutex_acquire(&lock); 16 | } 17 | 18 | void 19 | release(vuint32_t tid) 20 | { 21 | V_UNUSED(tid); 22 | vmutex_release(&lock); 23 | } 24 | -------------------------------------------------------------------------------- /verify/thread/once.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define NTHREADS 4U 13 | 14 | vonce_t g_once = VONCE_INIT(); 15 | vsize_t g_winner = 0; 16 | 17 | void * 18 | verification_once_cb(void *arg) 19 | { 20 | g_winner = (vsize_t)(vuintptr_t)arg; 21 | ASSERT(g_winner != 0); 22 | return arg; 23 | } 24 | 25 | void * 26 | run(void *arg) 27 | { 28 | vsize_t tid = ((vsize_t)(vuintptr_t)arg) + 1U; 29 | ASSERT(tid != 0); 30 | 31 | void *r = 32 | vonce_call(&g_once, verification_once_cb, (void *)(vuintptr_t)tid); 33 | 34 | if (r != NULL) { 35 | /* if once returns something, then I was the winner */ 36 | ASSERT(tid == (vsize_t)(vuintptr_t)r); 37 | ASSERT(g_winner == tid); 38 | } else { 39 | /* if once returned nothing, then somebody else is the winner */ 40 | ASSERT(g_winner != tid); 41 | } 42 | return NULL; 43 | } 44 | 45 | int 46 | main(void) 47 | { 48 | launch_threads(NTHREADS, run); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /verify/treeset/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB TEST_CASES testcase_*.h) 2 | 3 | set(VERIFY_FILE verify.c) 4 | 5 | set(NUM_THREADS 4) 6 | 7 | set(ALGOS BST_FINE RB_FINE BST_COARSE RB_COARSE) 8 | set(TEST_DEFS TREESET_LOCK_TTAS) 9 | set(CHECK_FLAGS -DVSYNC_VERIFICATION -DVMEM_LIB_ALLOC_TRACKING_OFF) 10 | 11 | foreach(test_path IN ITEMS ${TEST_CASES}) 12 | get_filename_component(test_prefix ${test_path} NAME_WE) 13 | 14 | set(tc TEST_CASE="${test_path}") 15 | set(tc_check -DTEST_CASE="'\"${test_path}\"'") 16 | 17 | foreach(algo IN ITEMS ${ALGOS}) 18 | set(TEST treeset_${test_prefix}_${algo}) 19 | string(TOLOWER ${TEST} TEST) 20 | add_executable(${TEST} ${VERIFY_FILE}) 21 | target_link_libraries(${TEST} vsync pthread) 22 | target_compile_definitions(${TEST} PUBLIC TREESET_${algo} ${TEST_DEFS} 23 | ${tc}) 24 | add_test(NAME ${TEST} COMMAND ${TEST}) 25 | set_tests_properties(${TEST} PROPERTIES TIMEOUT 10) 26 | 27 | add_vsyncer_check( 28 | TARGET ${TEST}_check 29 | SOURCE ${VERIFY_FILE} 30 | CFLAGS -DTREESET_${algo} ${tc_check} ${CHECK_FLAGS} 31 | TIMEOUT 240 32 | DEPENDENCIES vsync) 33 | endforeach() 34 | 35 | endforeach() 36 | -------------------------------------------------------------------------------- /verify/treeset/testcase_add_1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | 9 | // Concurrent adds with different keys 10 | void 11 | pre(void) 12 | { 13 | } 14 | 15 | void 16 | t0(vsize_t tid) 17 | { 18 | V_UNUSED(tid); 19 | ASSERT(!tr_con(0)); 20 | ASSERT(tr_add(0)); 21 | ASSERT(tr_con(0)); 22 | } 23 | 24 | void 25 | t1(vsize_t tid) 26 | { 27 | V_UNUSED(tid); 28 | ASSERT(!tr_con(1)); 29 | ASSERT(tr_add(1)); 30 | ASSERT(tr_con(1)); 31 | } 32 | 33 | void 34 | t2(vsize_t tid) 35 | { 36 | V_UNUSED(tid); 37 | ASSERT(!tr_con(2)); 38 | ASSERT(tr_add(2)); 39 | ASSERT(tr_con(2)); 40 | } 41 | 42 | void 43 | t3(vsize_t tid) 44 | { 45 | V_UNUSED(tid); 46 | } 47 | 48 | void 49 | post(void) 50 | { 51 | } 52 | #endif 53 | -------------------------------------------------------------------------------- /verify/treeset/testcase_add_2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | 9 | // Concurrent adds with the same key 10 | 11 | int r0, r1, r2; 12 | 13 | void 14 | pre(void) 15 | { 16 | } 17 | 18 | void 19 | t0(vsize_t tid) 20 | { 21 | V_UNUSED(tid); 22 | r0 = tr_add(0); 23 | } 24 | 25 | void 26 | t1(vsize_t tid) 27 | { 28 | V_UNUSED(tid); 29 | r1 = tr_add(0); 30 | } 31 | 32 | void 33 | t2(vsize_t tid) 34 | { 35 | V_UNUSED(tid); 36 | r2 = tr_add(0); 37 | } 38 | 39 | void 40 | t3(vsize_t tid) 41 | { 42 | V_UNUSED(tid); 43 | tr_add(-1); 44 | tr_add(1); 45 | tr_add(-2); 46 | tr_add(2); 47 | } 48 | 49 | void 50 | post(void) 51 | { 52 | ASSERT(r0 + r1 + r2 == 1); 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /verify/treeset/testcase_add_3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Linearizability of adds from the same thread 9 | 10 | void 11 | pre(void) 12 | { 13 | } 14 | 15 | void 16 | t0(vsize_t tid) 17 | { 18 | V_UNUSED(tid); 19 | ASSERT(tr_add(0)); 20 | ASSERT(tr_add(1)); 21 | ASSERT(tr_add(2)); 22 | } 23 | 24 | void 25 | t1(vsize_t tid) 26 | { 27 | V_UNUSED(tid); 28 | if (tr_con(1)) { 29 | ASSERT(tr_con(0)); 30 | } 31 | if (tr_con(2)) { 32 | ASSERT(tr_con(0)); 33 | ASSERT(tr_con(1)); 34 | } 35 | } 36 | 37 | void 38 | t2(vsize_t tid) 39 | { 40 | V_UNUSED(tid); 41 | } 42 | 43 | void 44 | t3(vsize_t tid) 45 | { 46 | V_UNUSED(tid); 47 | } 48 | 49 | void 50 | post(void) 51 | { 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /verify/treeset/testcase_add_4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Forcing execution of complicated cases when adding 9 | 10 | void 11 | pre(void) 12 | { 13 | } 14 | 15 | void 16 | t0(vsize_t tid) 17 | { 18 | V_UNUSED(tid); 19 | ASSERT(tr_add(0)); 20 | ASSERT(tr_add(3)); 21 | ASSERT(tr_add(6)); 22 | } 23 | 24 | void 25 | t1(vsize_t tid) 26 | { 27 | V_UNUSED(tid); 28 | ASSERT(tr_add(1)); 29 | ASSERT(tr_add(4)); 30 | ASSERT(tr_add(7)); 31 | } 32 | 33 | void 34 | t2(vsize_t tid) 35 | { 36 | V_UNUSED(tid); 37 | ASSERT(tr_add(2)); 38 | ASSERT(tr_add(5)); 39 | ASSERT(tr_add(8)); 40 | } 41 | 42 | void 43 | t3(vsize_t tid) 44 | { 45 | V_UNUSED(tid); 46 | } 47 | 48 | void 49 | post(void) 50 | { 51 | } 52 | #endif 53 | -------------------------------------------------------------------------------- /verify/treeset/testcase_add_5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Linearizability of adds from different threads 9 | 10 | int r2, r3; 11 | 12 | void 13 | pre(void) 14 | { 15 | } 16 | 17 | void 18 | t0(vsize_t tid) 19 | { 20 | V_UNUSED(tid); 21 | ASSERT(tr_add(0)); 22 | } 23 | 24 | void 25 | t1(vsize_t tid) 26 | { 27 | V_UNUSED(tid); 28 | ASSERT(tr_add(1)); 29 | } 30 | 31 | void 32 | t2(vsize_t tid) 33 | { 34 | V_UNUSED(tid); 35 | r2 = tr_con(0) && !tr_con(1); 36 | } 37 | 38 | void 39 | t3(vsize_t tid) 40 | { 41 | V_UNUSED(tid); 42 | r3 = tr_con(1) && !tr_con(0); 43 | } 44 | 45 | void 46 | post(void) 47 | { 48 | ASSERT(!(r2 && r3)); 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /verify/treeset/testcase_add_rem_1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Concurrent adds/removes with same/different keys 9 | 10 | int r00, r01, r10, r11, r20, r21, r30, r31; 11 | 12 | void 13 | pre(void) 14 | { 15 | } 16 | 17 | void 18 | t0(vsize_t tid) 19 | { 20 | V_UNUSED(tid); 21 | r00 = tr_add(0); 22 | r01 = tr_add(1); 23 | } 24 | 25 | void 26 | t1(vsize_t tid) 27 | { 28 | V_UNUSED(tid); 29 | r10 = tr_add(0); 30 | r11 = tr_add(1); 31 | } 32 | 33 | void 34 | t2(vsize_t tid) 35 | { 36 | V_UNUSED(tid); 37 | r20 = tr_rem(0); 38 | r21 = tr_rem(1); 39 | } 40 | 41 | void 42 | t3(vsize_t tid) 43 | { 44 | V_UNUSED(tid); 45 | r30 = tr_rem(0); 46 | r31 = tr_rem(1); 47 | } 48 | 49 | void 50 | post(void) 51 | { 52 | int con0 = r00 + r10 - r20 - r30; 53 | int con1 = r01 + r11 - r21 - r31; 54 | int real_con0 = tr_con(0); 55 | int real_con1 = tr_con(1); 56 | ASSERT(con0 == real_con0); 57 | ASSERT(con1 == real_con1); 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /verify/treeset/testcase_add_rem_2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Linearizability of adds/removes from the same thread 9 | 10 | void 11 | pre(void) 12 | { 13 | tr_add(1); 14 | tr_add(3); 15 | } 16 | 17 | void 18 | t0(vsize_t tid) 19 | { 20 | V_UNUSED(tid); 21 | ASSERT(tr_add(0)); 22 | ASSERT(tr_add(2)); 23 | } 24 | 25 | void 26 | t1(vsize_t tid) 27 | { 28 | V_UNUSED(tid); 29 | if (tr_rem(2)) { 30 | ASSERT(tr_rem(0)); 31 | } else { 32 | verification_ignore(); 33 | } 34 | } 35 | 36 | void 37 | t2(vsize_t tid) 38 | { 39 | V_UNUSED(tid); 40 | ASSERT(tr_rem(1)); 41 | ASSERT(tr_rem(3)); 42 | } 43 | 44 | void 45 | t3(vsize_t tid) 46 | { 47 | V_UNUSED(tid); 48 | if (tr_add(3)) { 49 | ASSERT(tr_add(1)); 50 | } else { 51 | verification_ignore(); 52 | } 53 | } 54 | 55 | void 56 | post(void) 57 | { 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /verify/treeset/testcase_add_rem_3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Linearizability of adds/removes from the same thread 9 | 10 | void 11 | pre(void) 12 | { 13 | tr_add(0); 14 | tr_add(3); 15 | } 16 | 17 | void 18 | t0(vsize_t tid) 19 | { 20 | V_UNUSED(tid); 21 | ASSERT(tr_rem(0)); 22 | ASSERT(tr_add(2)); 23 | } 24 | 25 | void 26 | t1(vsize_t tid) 27 | { 28 | V_UNUSED(tid); 29 | if (tr_rem(2)) { 30 | ASSERT(tr_add(0)); 31 | } else { 32 | verification_ignore(); 33 | } 34 | } 35 | 36 | void 37 | t2(vsize_t tid) 38 | { 39 | V_UNUSED(tid); 40 | ASSERT(tr_add(1)); 41 | ASSERT(tr_rem(3)); 42 | } 43 | 44 | void 45 | t3(vsize_t tid) 46 | { 47 | V_UNUSED(tid); 48 | if (tr_add(3)) { 49 | ASSERT(tr_rem(1)); 50 | } else { 51 | verification_ignore(); 52 | } 53 | } 54 | 55 | void 56 | post(void) 57 | { 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /verify/treeset/testcase_add_rem_4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Concurrent adds/removes with same/different keys 9 | 10 | void 11 | pre(void) 12 | { 13 | tr_add(2); 14 | tr_add(3); 15 | } 16 | 17 | void 18 | t0(vsize_t tid) 19 | { 20 | V_UNUSED(tid); 21 | ASSERT(tr_add(0)); 22 | tr_add(2); 23 | } 24 | 25 | void 26 | t1(vsize_t tid) 27 | { 28 | V_UNUSED(tid); 29 | tr_add(3); 30 | ASSERT(tr_add(1)); 31 | } 32 | 33 | void 34 | t2(vsize_t tid) 35 | { 36 | V_UNUSED(tid); 37 | tr_rem(0); 38 | ASSERT(tr_rem(2)); 39 | } 40 | 41 | void 42 | t3(vsize_t tid) 43 | { 44 | V_UNUSED(tid); 45 | ASSERT(tr_rem(3)); 46 | tr_rem(1); 47 | } 48 | 49 | void 50 | post(void) 51 | { 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /verify/treeset/testcase_add_rem_5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Linearizability of add/remove from different threads 9 | 10 | int r2, r3; 11 | 12 | void 13 | pre(void) 14 | { 15 | tr_add(1); 16 | } 17 | 18 | void 19 | t0(vsize_t tid) 20 | { 21 | V_UNUSED(tid); 22 | ASSERT(tr_add(0)); 23 | } 24 | 25 | void 26 | t1(vsize_t tid) 27 | { 28 | V_UNUSED(tid); 29 | ASSERT(tr_rem(1)); 30 | } 31 | 32 | void 33 | t2(vsize_t tid) 34 | { 35 | V_UNUSED(tid); 36 | r2 = tr_con(0) && tr_con(1); 37 | } 38 | 39 | void 40 | t3(vsize_t tid) 41 | { 42 | V_UNUSED(tid); 43 | r3 = !tr_con(1) && !tr_con(0); 44 | } 45 | 46 | void 47 | post(void) 48 | { 49 | ASSERT(!(r2 && r3)); 50 | } 51 | #endif 52 | -------------------------------------------------------------------------------- /verify/treeset/testcase_add_rem_6.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Forcing execution of complicated cases when adding/removing 9 | 10 | void 11 | pre(void) 12 | { 13 | ASSERT(tr_add(0)); 14 | ASSERT(tr_add(4)); 15 | ASSERT(tr_add(8)); 16 | ASSERT(tr_add(9)); 17 | ASSERT(tr_add(-1)); 18 | } 19 | 20 | void 21 | t0(vsize_t tid) 22 | { 23 | V_UNUSED(tid); 24 | ASSERT(tr_add(3)); 25 | ASSERT(tr_add(6)); 26 | ASSERT(tr_rem(0)); 27 | } 28 | 29 | void 30 | t1(vsize_t tid) 31 | { 32 | V_UNUSED(tid); 33 | ASSERT(tr_add(1)); 34 | ASSERT(tr_add(7)); 35 | ASSERT(tr_rem(4)); 36 | } 37 | 38 | void 39 | t2(vsize_t tid) 40 | { 41 | V_UNUSED(tid); 42 | ASSERT(tr_add(2)); 43 | ASSERT(tr_add(5)); 44 | ASSERT(tr_rem(8)); 45 | } 46 | 47 | void 48 | t3(vsize_t tid) 49 | { 50 | V_UNUSED(tid); 51 | } 52 | 53 | void 54 | post(void) 55 | { 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /verify/treeset/testcase_rem_1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Concurrent removes with different keys 9 | 10 | void 11 | pre(void) 12 | { 13 | tr_add(0); 14 | tr_add(1); 15 | tr_add(2); 16 | } 17 | 18 | void 19 | t0(vsize_t tid) 20 | { 21 | V_UNUSED(tid); 22 | ASSERT(tr_con(0)); 23 | ASSERT(tr_rem(0)); 24 | ASSERT(!tr_con(0)); 25 | } 26 | 27 | void 28 | t1(vsize_t tid) 29 | { 30 | V_UNUSED(tid); 31 | ASSERT(tr_con(1)); 32 | ASSERT(tr_rem(1)); 33 | ASSERT(!tr_con(1)); 34 | } 35 | 36 | void 37 | t2(vsize_t tid) 38 | { 39 | V_UNUSED(tid); 40 | ASSERT(tr_con(2)); 41 | ASSERT(tr_rem(2)); 42 | ASSERT(!tr_con(2)); 43 | } 44 | 45 | void 46 | t3(vsize_t tid) 47 | { 48 | V_UNUSED(tid); 49 | } 50 | 51 | void 52 | post(void) 53 | { 54 | } 55 | #endif 56 | -------------------------------------------------------------------------------- /verify/treeset/testcase_rem_2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Concurrent removes with the same key 9 | 10 | int r0, r1, r2; 11 | 12 | void 13 | pre(void) 14 | { 15 | tr_add(0); 16 | } 17 | 18 | void 19 | t0(vsize_t tid) 20 | { 21 | V_UNUSED(tid); 22 | r0 = tr_rem(0); 23 | } 24 | 25 | void 26 | t1(vsize_t tid) 27 | { 28 | V_UNUSED(tid); 29 | r1 = tr_rem(0); 30 | } 31 | 32 | void 33 | t2(vsize_t tid) 34 | { 35 | V_UNUSED(tid); 36 | r2 = tr_rem(0); 37 | } 38 | 39 | void 40 | t3(vsize_t tid) 41 | { 42 | V_UNUSED(tid); 43 | tr_add(-1); 44 | tr_add(1); 45 | tr_add(-2); 46 | tr_add(2); 47 | } 48 | 49 | void 50 | post(void) 51 | { 52 | ASSERT(r0 + r1 + r2 == 1); 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /verify/treeset/testcase_rem_3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Linearizability of removes from the same thread 9 | 10 | void 11 | pre(void) 12 | { 13 | tr_add(0); 14 | tr_add(1); 15 | tr_add(2); 16 | } 17 | 18 | void 19 | t0(vsize_t tid) 20 | { 21 | V_UNUSED(tid); 22 | ASSERT(tr_rem(0)); 23 | ASSERT(tr_rem(1)); 24 | ASSERT(tr_rem(2)); 25 | } 26 | 27 | void 28 | t1(vsize_t tid) 29 | { 30 | V_UNUSED(tid); 31 | if (!tr_con(1)) { 32 | ASSERT(!tr_con(0)); 33 | } 34 | if (!tr_con(2)) { 35 | ASSERT(!tr_con(0)); 36 | ASSERT(!tr_con(1)); 37 | } 38 | } 39 | 40 | void 41 | t2(vsize_t tid) 42 | { 43 | V_UNUSED(tid); 44 | } 45 | 46 | void 47 | t3(vsize_t tid) 48 | { 49 | V_UNUSED(tid); 50 | } 51 | 52 | void 53 | post(void) 54 | { 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /verify/treeset/testcase_rem_4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Forcing execution of complicated cases when removing 9 | 10 | void 11 | pre(void) 12 | { 13 | for (int i = 0; i < 9; ++i) { 14 | tr_add(i); 15 | } 16 | } 17 | 18 | void 19 | t0(vsize_t tid) 20 | { 21 | V_UNUSED(tid); 22 | ASSERT(tr_rem(0)); 23 | ASSERT(tr_rem(3)); 24 | ASSERT(tr_rem(6)); 25 | } 26 | 27 | void 28 | t1(vsize_t tid) 29 | { 30 | V_UNUSED(tid); 31 | ASSERT(tr_rem(1)); 32 | ASSERT(tr_rem(4)); 33 | ASSERT(tr_rem(7)); 34 | } 35 | 36 | void 37 | t2(vsize_t tid) 38 | { 39 | V_UNUSED(tid); 40 | ASSERT(tr_rem(2)); 41 | ASSERT(tr_rem(5)); 42 | ASSERT(tr_rem(8)); 43 | } 44 | 45 | void 46 | t3(vsize_t tid) 47 | { 48 | V_UNUSED(tid); 49 | } 50 | 51 | void 52 | post(void) 53 | { 54 | } 55 | #endif 56 | -------------------------------------------------------------------------------- /verify/treeset/testcase_rem_5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | // Linearizability of removes from different threads 9 | 10 | int r2, r3; 11 | 12 | void 13 | pre(void) 14 | { 15 | tr_add(0); 16 | tr_add(1); 17 | } 18 | 19 | void 20 | t0(vsize_t tid) 21 | { 22 | V_UNUSED(tid); 23 | ASSERT(tr_rem(0)); 24 | } 25 | 26 | void 27 | t1(vsize_t tid) 28 | { 29 | V_UNUSED(tid); 30 | ASSERT(tr_rem(1)); 31 | } 32 | 33 | void 34 | t2(vsize_t tid) 35 | { 36 | V_UNUSED(tid); 37 | r2 = !tr_con(0) && tr_con(1); 38 | } 39 | 40 | void 41 | t3(vsize_t tid) 42 | { 43 | V_UNUSED(tid); 44 | r3 = !tr_con(1) && tr_con(0); 45 | } 46 | 47 | void 48 | post(void) 49 | { 50 | ASSERT(!(r2 && r3)); 51 | } 52 | #endif 53 | -------------------------------------------------------------------------------- /verify/treeset/verify.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #define NTHREADS 4U 7 | #include 8 | #include 9 | #include 10 | 11 | void 12 | init(void) 13 | { 14 | tr_init(); 15 | } 16 | 17 | void 18 | fini(void) 19 | { 20 | tr_destroy(); 21 | } 22 | 23 | void 24 | reg(vsize_t tid) 25 | { 26 | V_UNUSED(tid); 27 | } 28 | void 29 | dereg(vsize_t tid) 30 | { 31 | V_UNUSED(tid); 32 | } 33 | 34 | int 35 | main(void) 36 | { 37 | tc(); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /verify/unbounded_queue/test_case_3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | 9 | void 10 | pre(void) 11 | { 12 | enq(MAIN_TID, 1U, 'a'); 13 | } 14 | 15 | /** 16 | * for thread with tid = 0 17 | * 18 | */ 19 | void 20 | t0(vsize_t tid) 21 | { 22 | enq(tid, 2, 'A'); 23 | } 24 | 25 | /** 26 | * for thread with tid = 1 27 | * 28 | */ 29 | data_t *deq_1 = NULL; 30 | void 31 | t1(vsize_t tid) 32 | { 33 | deq_1 = deq(tid); 34 | ASSERT(deq_1); 35 | // must succeed because the queue was initialized with one element 36 | ASSERT(deq_1->key == 1); 37 | queue_clean(tid); 38 | } 39 | /** 40 | * for thread with tid = 2 41 | * 42 | */ 43 | void 44 | t2(vsize_t tid) 45 | { 46 | enq(tid, 3, 'B'); 47 | } 48 | void 49 | post(void) 50 | { 51 | queue_print(&g_queue, get_final_state_cb); 52 | ASSERT(g_len == 2); 53 | for (vsize_t i = 0; i < g_len; i++) { 54 | ASSERT(g_final_state[i] == 2 || g_final_state[i] == 3); 55 | } 56 | } 57 | #endif 58 | -------------------------------------------------------------------------------- /verify/unbounded_queue/test_case_5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. 3 | * SPDX-License-Identifier: MIT 4 | */ 5 | 6 | #ifndef VSYNC_TEST_CASE_H 7 | #define VSYNC_TEST_CASE_H 8 | /** 9 | * check queue_empty() 10 | */ 11 | 12 | void 13 | pre(void) 14 | { 15 | enq(MAIN_TID, 1U, 'a'); 16 | } 17 | 18 | /** 19 | * for thread with tid = 0 20 | * 21 | */ 22 | void 23 | t0(vsize_t tid) 24 | { 25 | enq(tid, 2, 'A'); 26 | void *data = deq(tid); 27 | free(data); 28 | } 29 | 30 | /** 31 | * for thread with tid = 1 32 | * 33 | */ 34 | int msg = 0; 35 | void 36 | t1(vsize_t tid) 37 | { 38 | msg = 1; 39 | void *data = deq(tid); 40 | free(data); 41 | } 42 | /** 43 | * for thread with tid = 2 44 | * 45 | */ 46 | void 47 | t2(vsize_t tid) 48 | { 49 | /* must imply both dequeues are done and thus the msg must be passed */ 50 | if (empty(tid)) { 51 | ASSERT(msg == 1); 52 | } else { 53 | queue_clean(tid); 54 | } 55 | } 56 | void 57 | post(void) 58 | { 59 | queue_print(&g_queue, get_final_state_cb); 60 | ASSERT(g_len == 0); 61 | } 62 | #endif 63 | --------------------------------------------------------------------------------