From f1f103dd29d271a5018a11ebfb64c118f74c88b4 Mon Sep 17 00:00:00 2001 From: khizmax Date: Sat, 6 Aug 2016 10:10:37 +0300 Subject: [PATCH] Added RCU lock for iterating thread --- test/stress/set/iteration/set_iteration.h | 50 +++++++++++++++++-- .../set_iteration_feldman_hashset.cpp | 4 +- test/stress/set/set_type_feldman_hashset.h | 34 +++++++++---- 3 files changed, 74 insertions(+), 14 deletions(-) diff --git a/test/stress/set/iteration/set_iteration.h b/test/stress/set/iteration/set_iteration.h index b8ea3b3c..decf002d 100644 --- a/test/stress/set/iteration/set_iteration.h +++ b/test/stress/set/iteration/set_iteration.h @@ -370,7 +370,7 @@ namespace set { } }; - template + template class Iterator: public cds_test::thread { typedef cds_test::thread base_class; @@ -413,13 +413,57 @@ namespace set { } }; + template + class Iterator, Set>: public cds_test::thread + { + typedef cds_test::thread base_class; + + Set& m_Set; + typedef typename Set::value_type keyval_type; + + public: + size_t m_nPassCount = 0; + size_t m_nVisitCount = 0; // how many items the iterator visited + + public: + Iterator( cds_test::thread_pool& pool, Set& set ) + : base_class( pool, iterator_thread ) + , m_Set( set ) + {} + + Iterator( Iterator& src ) + : base_class( src ) + , m_Set( src.m_Set ) + {} + + virtual thread * clone() + { + return new Iterator( *this ); + } + + virtual void test() + { + Set& rSet = m_Set; + + Set_Iteration& fixture = pool().template fixture(); + while ( !fixture.all_modifiers_done() ) { + ++m_nPassCount; + typename Set::rcu_lock l; + for ( auto it = rSet.begin(); it != rSet.end(); ++it ) { + it->val.hash = CityHash64( it->key.c_str(), it->key.length() ); + ++m_nVisitCount; + } + } + } + }; + protected: template void do_test( Set& testSet ) { typedef Inserter InserterThread; typedef Deleter DeleterThread; - typedef Iterator IteratorThread; + typedef Iterator IteratorThread; cds_test::thread_pool& pool = get_pool(); pool.add( new InserterThread( pool, testSet ), s_nInsertThreadCount ); @@ -495,7 +539,7 @@ namespace set { typedef Inserter InserterThread; typedef Deleter DeleterThread; typedef Extractor ExtractThread; - typedef Iterator IteratorThread; + typedef Iterator IteratorThread; size_t const nDelThreadCount = s_nDeleteThreadCount / 2; size_t const nExtractThreadCount = s_nDeleteThreadCount - nDelThreadCount; diff --git a/test/stress/set/iteration/set_iteration_feldman_hashset.cpp b/test/stress/set/iteration/set_iteration_feldman_hashset.cpp index 805c5640..32e4f9ac 100644 --- a/test/stress/set/iteration/set_iteration_feldman_hashset.cpp +++ b/test/stress/set/iteration/set_iteration_feldman_hashset.cpp @@ -33,7 +33,7 @@ namespace set { - CDSSTRESS_FeldmanHashSet_stdhash( Set_Iteration, run_test_extract, std::string, Set_Iteration::value_type ) - CDSSTRESS_FeldmanHashSet_city( Set_Iteration, run_test_extract, std::string, Set_Iteration::value_type ) + CDSSTRESS_FeldmanHashSet_stdhash_quick( Set_Iteration, run_test_extract, std::string, Set_Iteration::value_type ) + CDSSTRESS_FeldmanHashSet_city_quick( Set_Iteration, run_test_extract, std::string, Set_Iteration::value_type ) } // namespace set diff --git a/test/stress/set/set_type_feldman_hashset.h b/test/stress/set/set_type_feldman_hashset.h index 3fa62eda..7b074c77 100644 --- a/test/stress/set/set_type_feldman_hashset.h +++ b/test/stress/set/set_type_feldman_hashset.h @@ -25,7 +25,7 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef CDSUNIT_SET_TYPE_FELDMAN_HASHSET_H @@ -373,43 +373,59 @@ namespace set { CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpt_fixed_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_fixed_SHRCU( fixture, test_case, key_type, value_type ) -#define CDSSTRESS_FeldmanHashSet_stdhash( fixture, test_case, key_type, value_type ) \ +#define CDSSTRESS_FeldmanHashSet_stdhash_rcu_gpi( fixture, test_case, key_type, value_type ) \ + CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_stdhash, key_type, value_type ) \ + CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_stdhash_stat, key_type, value_type ) \ + +#define CDSSTRESS_FeldmanHashSet_stdhash_quick( fixture, test_case, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_hp_stdhash, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_dhp_stdhash, key_type, value_type ) \ - CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_stdhash, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpb_stdhash, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpt_stdhash, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_hp_stdhash_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_dhp_stdhash_stat, key_type, value_type ) \ - CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_stdhash_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpb_stdhash_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpt_stdhash_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_stdhash_SHRCU( fixture, test_case, key_type, value_type ) +#define CDSSTRESS_FeldmanHashSet_stdhash( fixture, test_case, key_type, value_type ) \ + CDSSTRESS_FeldmanHashSet_stdhash_quick( fixture, test_case, key_type, value_type ) \ + CDSSTRESS_FeldmanHashSet_stdhash_rcu_gpi( fixture, test_case, key_type, value_type ) \ + #if CDS_BUILD_BITS == 64 -# define CDSSTRESS_FeldmanHashSet_city( fixture, test_case, key_type, value_type ) \ +# define CDSSTRESS_FeldmanHashSet_city_rcu_gpi( fixture, test_case, key_type, value_type ) \ + CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_city64, key_type, value_type ) \ + CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_city64_stat, key_type, value_type ) \ + CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_city128, key_type, value_type ) \ + CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_city128_stat, key_type, value_type ) \ + +# define CDSSTRESS_FeldmanHashSet_city_quick( fixture, test_case, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_hp_city64, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_dhp_city64, key_type, value_type ) \ - CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_city64, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpb_city64, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpt_city64, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_hp_city64_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_dhp_city64_stat, key_type, value_type ) \ - CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_city64_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpb_city64_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpt_city64_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_hp_city128, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_dhp_city128, key_type, value_type ) \ - CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_city128, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpb_city128, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpt_city128, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_hp_city128_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_dhp_city128_stat, key_type, value_type ) \ - CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpi_city128_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpb_city128_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_case( fixture, test_case, FeldmanHashSet_rcu_gpt_city128_stat, key_type, value_type ) \ CDSSTRESS_FeldmanHashSet_city_SHRCU( fixture, test_case, key_type, value_type ) + +# define CDSSTRESS_FeldmanHashSet_city( fixture, test_case, key_type, value_type ) \ + CDSSTRESS_FeldmanHashSet_city_quick( fixture, test_case, key_type, value_type ) \ + CDSSTRESS_FeldmanHashSet_city_rcu_gpi( fixture, test_case, key_type, value_type ) \ + + #else +# define CDSSTRESS_FeldmanHashSet_city_rcu_gpi( fixture, test_case, key_type, value_type ) +# define CDSSTRESS_FeldmanHashSet_city_quick( fixture, test_case, key_type, value_type ) # define CDSSTRESS_FeldmanHashSet_city( fixture, test_case, key_type, value_type ) #endif -- 2.34.1