From b6e79990c66fa30d55fc43259c50f98ffb24e8d9 Mon Sep 17 00:00:00 2001 From: khizmax Date: Sat, 27 Jun 2015 18:40:31 +0300 Subject: [PATCH 1/1] Changed: OptimisticQueue: use padding option instead of alignment one --- cds/container/optimistic_queue.h | 16 ++++----- cds/intrusive/optimistic_queue.h | 34 ++++++++++--------- .../hdr_intrusive_optimisticqueue_dhp.cpp | 24 ++++++------- .../hdr_intrusive_optimisticqueue_hp.cpp | 24 ++++++------- tests/test-hdr/queue/hdr_optimistic_dhp.cpp | 8 ++--- tests/test-hdr/queue/hdr_optimistic_hp.cpp | 8 ++--- 6 files changed, 58 insertions(+), 56 deletions(-) diff --git a/cds/container/optimistic_queue.h b/cds/container/optimistic_queue.h index 8c493ea9..fa099200 100644 --- a/cds/container/optimistic_queue.h +++ b/cds/container/optimistic_queue.h @@ -46,23 +46,23 @@ namespace cds { namespace container { */ typedef opt::v::relaxed_ordering memory_model; - /// Alignment of internal queue data. Default is \p opt::cache_line_alignment - enum { alignment = opt::cache_line_alignment }; + /// Padding for internal critical atomic data. Default is \p opt::cache_line_padding + enum { padding = opt::cache_line_padding }; }; /// Metafunction converting option list to \p msqueue::traits /** Supported \p Options are: - - opt::allocator - allocator (like \p std::allocator) used for allocating queue nodes. Default is \ref CDS_DEFAULT_ALLOCATOR - - opt::back_off - back-off strategy used, default is \p cds::backoff::empty. - - opt::item_counter - the type of item counting feature. Default is \p cds::atomicity::empty_item_counter (item counting disabled) + - \p opt::allocator - allocator (like \p std::allocator) used for allocating queue nodes. Default is \ref CDS_DEFAULT_ALLOCATOR + - \p opt::back_off - back-off strategy used, default is \p cds::backoff::empty. + - \p opt::item_counter - the type of item counting feature. Default is \p cds::atomicity::empty_item_counter (item counting disabled) To enable item counting use \p cds::atomicity::item_counter - - opt::stat - the type to gather internal statistics. + - \p opt::stat - the type to gather internal statistics. Possible statistics types are: \p optimistic_queue::stat, \p optimistic_queue::empty_stat, user-provided class that supports \p %optimistic_queue::stat interface. Default is \p %optimistic_queue::empty_stat. - - opt::alignment - the alignment for internal queue data. Default is \p opt::cache_line_alignment - - opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default) + - \p opt::padding - padding for internal critical atomic data. Default is \p opt::cache_line_padding + - \p opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default) or \p opt::v::sequential_consistent (sequentially consisnent memory model). Example: declare \p OptimisticQueue with item counting and internal statistics diff --git a/cds/intrusive/optimistic_queue.h b/cds/intrusive/optimistic_queue.h index a7684849..a3ce3fa2 100644 --- a/cds/intrusive/optimistic_queue.h +++ b/cds/intrusive/optimistic_queue.h @@ -268,28 +268,28 @@ namespace cds { namespace intrusive { /// Link checking, see \p cds::opt::link_checker static CDS_CONSTEXPR const opt::link_check_type link_checker = opt::debug_check_link; - /// Alignment for internal queue data. Default is \p opt::cache_line_alignment - enum { alignment = opt::cache_line_alignment }; + /// Padding for internal critical atomic data. Default is \p opt::cache_line_padding + enum { padding = opt::cache_line_padding }; }; /// Metafunction converting option list to \p optimistic_queue::traits /** Supported \p Options are: - - opt::hook - hook used. Possible hooks are: \p optimistic_queue::base_hook, \p optimistic_queue::member_hook, \p optimistic_queue::traits_hook. + - \p opt::hook - hook used. Possible hooks are: \p optimistic_queue::base_hook, \p optimistic_queue::member_hook, \p optimistic_queue::traits_hook. If the option is not specified, \p %optimistic_queue::base_hook<> is used. - - opt::back_off - back-off strategy used, default is \p cds::backoff::empty. - - opt::disposer - the functor used for dispose removed items. Default is \p opt::v::empty_disposer. This option is used + - \p opt::back_off - back-off strategy used, default is \p cds::backoff::empty. + - \p opt::disposer - the functor used for dispose removed items. Default is \p opt::v::empty_disposer. This option is used when dequeuing. - - opt::link_checker - the type of node's link fields checking. Default is \p opt::debug_check_link - - opt::item_counter - the type of item counting feature. Default is \p cds::atomicity::empty_item_counter (item counting disabled) + - \p opt::link_checker - the type of node's link fields checking. Default is \p opt::debug_check_link + - \p opt::item_counter - the type of item counting feature. Default is \p cds::atomicity::empty_item_counter (item counting disabled) To enable item counting use \p cds::atomicity::item_counter - - opt::stat - the type to gather internal statistics. + - \p opt::stat - the type to gather internal statistics. Possible statistics types are: \p optimistic_queue::stat, \p optimistic_queue::empty_stat, user-provided class that supports \p %optimistic_queue::stat interface. Default is \p %optimistic_queue::empty_stat (internal statistics disabled). - - opt::alignment - the alignment for internal queue data. Default is \p opt::cache_line_alignment - - opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default) + - \p opt::padding - padding for internal critical atomic data. Default is \p opt::cache_line_padding + - \p opt::memory_model - C++ memory ordering model. Can be \p opt::v::relaxed_ordering (relaxed memory model, the default) or \p opt::v::sequential_consistent (sequentially consisnent memory model). Example: declare \p %OptimisticQueue with item counting and internal statistics @@ -422,16 +422,18 @@ namespace cds { namespace intrusive { protected: //@cond - typedef typename opt::details::alignment_setter< typename node_type::atomic_node_ptr, traits::alignment >::type aligned_node_ptr; + typedef typename node_type::atomic_node_ptr atomic_node_ptr; // GC and node_type::gc must be the same static_assert((std::is_same::value), "GC and node_type::gc must be the same"); - //@endcond - aligned_node_ptr m_pTail ; ///< Pointer to tail node - aligned_node_ptr m_pHead ; ///< Pointer to head node - node_type m_Dummy ; ///< dummy node + atomic_node_ptr m_pTail; ///< Pointer to tail node + typename opt::details::apply_padding< atomic_node_ptr, traits::padding >::padding_type pad1_; + atomic_node_ptr m_pHead; ///< Pointer to head node + typename opt::details::apply_padding< atomic_node_ptr, traits::padding >::padding_type pad2_; + node_type m_Dummy ; ///< dummy node + typename opt::details::apply_padding< atomic_node_ptr, traits::padding >::padding_type pad3_; item_counter m_ItemCounter ; ///< Item counter stat m_Stat ; ///< Internal statistics @@ -584,7 +586,7 @@ namespace cds { namespace intrusive { pTail->m_pPrev.store( pNew, memory_model::memory_order_release ); // Success, write prev ++m_ItemCounter; m_Stat.onEnqueue(); - break ; // Enqueue done! + break; // Enqueue done! } guards.assign( 0, node_traits::to_value_ptr( pTail )); // pTail has been changed by CAS above m_Stat.onEnqueueRace(); diff --git a/tests/test-hdr/queue/hdr_intrusive_optimisticqueue_dhp.cpp b/tests/test-hdr/queue/hdr_intrusive_optimisticqueue_dhp.cpp index 13210240..321bfe60 100644 --- a/tests/test-hdr/queue/hdr_intrusive_optimisticqueue_dhp.cpp +++ b/tests/test-hdr/queue/hdr_intrusive_optimisticqueue_dhp.cpp @@ -94,18 +94,18 @@ namespace queue { >::type > OptimisticQueue_DHP_member_stat; - // DHP base hook + alignment + // DHP base hook + padding typedef ci::OptimisticQueue< cds::gc::DHP, base_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > ,ci::opt::hook< ci::optimistic_queue::base_hook< ci::opt::gc > > - ,co::alignment< 32 > + ,co::padding< 32 > >::type > OptimisticQueue_DHP_base_align; - // DHP member hook + alignment + // DHP member hook + padding typedef ci::OptimisticQueue< cds::gc::DHP, member_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::hook< @@ -114,23 +114,23 @@ namespace queue { ci::opt::gc > > - ,co::alignment< 32 > + ,co::padding< 32 > ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > >::type > OptimisticQueue_DHP_member_align; - // DHP base hook + no alignment + // DHP base hook + no padding typedef ci::OptimisticQueue< cds::gc::DHP, base_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::hook< ci::optimistic_queue::base_hook< ci::opt::gc > > ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > - ,co::alignment< co::no_special_alignment > + ,co::padding< co::no_special_padding > >::type > OptimisticQueue_DHP_base_noalign; - // DHP member hook + no alignment + // DHP member hook + no padding typedef ci::OptimisticQueue< cds::gc::DHP, member_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > @@ -140,23 +140,23 @@ namespace queue { ci::opt::gc > > - ,co::alignment< co::no_special_alignment > + ,co::padding< co::no_special_padding > >::type > OptimisticQueue_DHP_member_noalign; - // DHP base hook + cache alignment + // DHP base hook + cache padding typedef ci::OptimisticQueue< cds::gc::DHP, base_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::hook< ci::optimistic_queue::base_hook< ci::opt::gc > > - ,co::alignment< co::cache_line_alignment > + ,co::padding< co::cache_line_padding > ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > >::type > OptimisticQueue_DHP_base_cachealign; - // DHP member hook + cache alignment + // DHP member hook + cache padding typedef ci::OptimisticQueue< cds::gc::DHP, member_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::hook< @@ -165,7 +165,7 @@ namespace queue { ci::opt::gc > > - ,co::alignment< co::cache_line_alignment > + ,co::padding< co::cache_line_padding > ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > >::type > OptimisticQueue_DHP_member_cachealign; diff --git a/tests/test-hdr/queue/hdr_intrusive_optimisticqueue_hp.cpp b/tests/test-hdr/queue/hdr_intrusive_optimisticqueue_hp.cpp index d11714fe..2ae8d41d 100644 --- a/tests/test-hdr/queue/hdr_intrusive_optimisticqueue_hp.cpp +++ b/tests/test-hdr/queue/hdr_intrusive_optimisticqueue_hp.cpp @@ -117,18 +117,18 @@ namespace queue { >::type > OptimisticQueue_HP_member_stat; - // HP base hook + alignment + // HP base hook + padding typedef ci::OptimisticQueue< cds::gc::HP, base_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > ,ci::opt::hook< ci::optimistic_queue::base_hook< ci::opt::gc > > - ,co::alignment< 32 > + ,co::padding< 32 > >::type > OptimisticQueue_HP_base_align; - // HP member hook + alignment + // HP member hook + padding typedef ci::OptimisticQueue< cds::gc::HP, member_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::hook< @@ -137,23 +137,23 @@ namespace queue { ci::opt::gc > > - ,co::alignment< 32 > + ,co::padding< 32 > ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > >::type > OptimisticQueue_HP_member_align; - // HP base hook + no alignment + // HP base hook + no padding typedef ci::OptimisticQueue< cds::gc::HP, base_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::hook< ci::optimistic_queue::base_hook< ci::opt::gc > > ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > - ,co::alignment< co::no_special_alignment > + ,co::padding< co::no_special_padding > >::type > OptimisticQueue_HP_base_noalign; - // HP member hook + no alignment + // HP member hook + no padding typedef ci::OptimisticQueue< cds::gc::HP, member_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > @@ -163,23 +163,23 @@ namespace queue { ci::opt::gc > > - ,co::alignment< co::no_special_alignment > + ,co::padding< co::no_special_padding > >::type > OptimisticQueue_HP_member_noalign; - // HP base hook + cache alignment + // HP base hook + cache padding typedef ci::OptimisticQueue< cds::gc::HP, base_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::hook< ci::optimistic_queue::base_hook< ci::opt::gc > > - ,co::alignment< co::cache_line_alignment > + ,co::padding< co::cache_line_padding > ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > >::type > OptimisticQueue_HP_base_cachealign; - // HP member hook + cache alignment + // HP member hook + cache padding typedef ci::OptimisticQueue< cds::gc::HP, member_hook_item, typename ci::optimistic_queue::make_traits< ci::opt::hook< @@ -188,7 +188,7 @@ namespace queue { ci::opt::gc > > - ,co::alignment< co::cache_line_alignment > + ,co::padding< co::cache_line_padding > ,ci::opt::disposer< IntrusiveQueueHeaderTest::faked_disposer > >::type > OptimisticQueue_HP_member_cachealign; diff --git a/tests/test-hdr/queue/hdr_optimistic_dhp.cpp b/tests/test-hdr/queue/hdr_optimistic_dhp.cpp index a9d7fb0a..38b33c0a 100644 --- a/tests/test-hdr/queue/hdr_optimistic_dhp.cpp +++ b/tests/test-hdr/queue/hdr_optimistic_dhp.cpp @@ -70,7 +70,7 @@ namespace queue { cds::container::OptimisticQueue< cds::gc::DHP, int, typename cds::container::optimistic_queue::make_traits< cds::opt::memory_model< cds::opt::v::relaxed_ordering> - ,cds::opt::alignment< 16 > + ,cds::opt::padding< 16 > >::type > >(); @@ -83,7 +83,7 @@ namespace queue { typename cds::container::optimistic_queue::make_traits< cds::opt::item_counter< cds::atomicity::item_counter > ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> - ,cds::opt::alignment< 32 > + ,cds::opt::padding< 32 > >::type > >(); @@ -95,7 +95,7 @@ namespace queue { cds::container::OptimisticQueue< cds::gc::DHP, int, typename cds::container::optimistic_queue::make_traits< cds::opt::memory_model< cds::opt::v::sequential_consistent> - ,cds::opt::alignment< cds::opt::no_special_alignment > + ,cds::opt::padding< cds::opt::no_special_padding > >::type > >(); @@ -108,7 +108,7 @@ namespace queue { typename cds::container::optimistic_queue::make_traits< cds::opt::item_counter< cds::atomicity::item_counter > ,cds::opt::memory_model< cds::opt::v::sequential_consistent> - ,cds::opt::alignment< cds::opt::cache_line_alignment > + ,cds::opt::padding< cds::opt::cache_line_padding > >::type > >(); diff --git a/tests/test-hdr/queue/hdr_optimistic_hp.cpp b/tests/test-hdr/queue/hdr_optimistic_hp.cpp index 2b16c6aa..6e3f5922 100644 --- a/tests/test-hdr/queue/hdr_optimistic_hp.cpp +++ b/tests/test-hdr/queue/hdr_optimistic_hp.cpp @@ -70,7 +70,7 @@ namespace queue { cds::container::OptimisticQueue< cds::gc::HP, int, typename cds::container::optimistic_queue::make_traits< cds::opt::memory_model< cds::opt::v::relaxed_ordering> - ,cds::opt::alignment< 16 > + ,cds::opt::padding< 16 > >::type > >(); @@ -83,7 +83,7 @@ namespace queue { typename cds::container::optimistic_queue::make_traits< cds::opt::item_counter< cds::atomicity::item_counter > ,cds::opt::memory_model< cds::opt::v::relaxed_ordering> - ,cds::opt::alignment< 32 > + ,cds::opt::padding< 32 > >::type > >(); @@ -95,7 +95,7 @@ namespace queue { cds::container::OptimisticQueue< cds::gc::HP, int, typename cds::container::optimistic_queue::make_traits< cds::opt::memory_model< cds::opt::v::sequential_consistent> - ,cds::opt::alignment< cds::opt::no_special_alignment > + ,cds::opt::padding< cds::opt::no_special_padding > >::type > >(); @@ -108,7 +108,7 @@ namespace queue { typename cds::container::optimistic_queue::make_traits< cds::opt::item_counter< cds::atomicity::item_counter > ,cds::opt::memory_model< cds::opt::v::sequential_consistent> - ,cds::opt::alignment< cds::opt::cache_line_alignment > + ,cds::opt::padding< cds::opt::cache_line_padding > >::type > >(); -- 2.34.1