From: khizmax Date: Sat, 21 Jan 2017 08:19:41 +0000 (+0300) Subject: Added HP/DHP internal stats to test X-Git-Tag: v2.3.0~188 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=6f64d14be57853caa486c471ed99302b8004cfe0;p=libcds.git Added HP/DHP internal stats to test --- diff --git a/cds/gc/dhp.h b/cds/gc/dhp.h index d06bbedb..76511795 100644 --- a/cds/gc/dhp.h +++ b/cds/gc/dhp.h @@ -470,16 +470,16 @@ namespace cds { namespace gc { thread_hp_storage hazards_; ///< Hazard pointers private to the thread retired_array retired_; ///< Retired data private to the thread + char pad1_[cds::c_nCacheLineSize]; + atomics::atomic sync_; ///< dummy var to introduce synchronizes-with relationship between threads + char pad2_[cds::c_nCacheLineSize]; + # ifdef CDS_ENABLE_HPSTAT size_t free_call_count_; size_t scan_call_count_; size_t help_scan_call_count_; # endif - char pad1_[cds::c_nCacheLineSize]; - atomics::atomic sync_; ///< dummy var to introduce synchronizes-with relationship between threads - char pad2_[cds::c_nCacheLineSize]; - // CppCheck warn: pad1_ and pad2_ is uninitialized in ctor // cppcheck-suppress uninitMemberVar thread_data( guard* guards, size_t guard_count ) @@ -504,7 +504,7 @@ namespace cds { namespace gc { //@endcond //@cond - // Dynmic (adaptive) Hazard Pointer SMR (Safe Memory Reclamation) + // Dynamic (adaptive) Hazard Pointer SMR (Safe Memory Reclamation) class smr { struct thread_record; diff --git a/cds/gc/hp.h b/cds/gc/hp.h index 42c64f04..76df6145 100644 --- a/cds/gc/hp.h +++ b/cds/gc/hp.h @@ -349,18 +349,28 @@ namespace cds { namespace gc { thread_hp_storage hazards_; ///< Hazard pointers private to the thread retired_array retired_; ///< Retired data private to the thread - stat stat_; ///< Internal statistics for the thread - char pad1_[cds::c_nCacheLineSize]; atomics::atomic sync_; ///< dummy var to introduce synchronizes-with relationship between threads char pad2_[cds::c_nCacheLineSize]; +# ifdef CDS_ENABLE_HPSTAT + // Internal statistics: + size_t free_count_; + size_t scan_count_; + size_t help_scan_count_; +# endif + // CppCheck warn: pad1_ and pad2_ is uninitialized in ctor // cppcheck-suppress uninitMemberVar thread_data( guard* guards, size_t guard_count, retired_ptr* retired_arr, size_t retired_capacity ) : hazards_( guards, guard_count ) , retired_( retired_arr, retired_capacity ) , sync_(0) +# ifdef CDS_ENABLE_HPSTAT + , free_count_(0) + , scan_count_(0) + , help_scan_count_(0) +# endif {} thread_data() = delete; diff --git a/projects/Win/vc14/cds.sln b/projects/Win/vc14/cds.sln index d18e78f4..d420364f 100644 --- a/projects/Win/vc14/cds.sln +++ b/projects/Win/vc14/cds.sln @@ -22,9 +22,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "cds_test", "cds_test", "{3A ..\..\..\test\include\cds_test\hash_func.h = ..\..\..\test\include\cds_test\hash_func.h ..\..\..\test\include\cds_test\stat_bronson_avltree_out.h = ..\..\..\test\include\cds_test\stat_bronson_avltree_out.h ..\..\..\test\include\cds_test\stat_cuckoo_out.h = ..\..\..\test\include\cds_test\stat_cuckoo_out.h + ..\..\..\test\include\cds_test\stat_dhp_out.h = ..\..\..\test\include\cds_test\stat_dhp_out.h ..\..\..\test\include\cds_test\stat_ellenbintree_out.h = ..\..\..\test\include\cds_test\stat_ellenbintree_out.h ..\..\..\test\include\cds_test\stat_feldman_hashset_out.h = ..\..\..\test\include\cds_test\stat_feldman_hashset_out.h ..\..\..\test\include\cds_test\stat_flat_combining_out.h = ..\..\..\test\include\cds_test\stat_flat_combining_out.h + ..\..\..\test\include\cds_test\stat_hp_out.h = ..\..\..\test\include\cds_test\stat_hp_out.h ..\..\..\test\include\cds_test\stat_iterable_list_out.h = ..\..\..\test\include\cds_test\stat_iterable_list_out.h ..\..\..\test\include\cds_test\stat_lazy_list_out.h = ..\..\..\test\include\cds_test\stat_lazy_list_out.h ..\..\..\test\include\cds_test\stat_michael_list_out.h = ..\..\..\test\include\cds_test\stat_michael_list_out.h diff --git a/src/hp.cpp b/src/hp.cpp index 8da02d18..50dd6053 100644 --- a/src/hp.cpp +++ b/src/hp.cpp @@ -318,7 +318,7 @@ namespace cds { namespace gc { namespace hp { } } - CDS_HPSTAT( ++pRec->stat_.scan_count ); + CDS_HPSTAT( ++pRec->scan_count_ ); // Sort retired pointer array std::sort( first_retired, last_retired, retired_ptr::less ); @@ -373,7 +373,7 @@ namespace cds { namespace gc { namespace hp { else { // Retired pointer may be freed it->free(); - CDS_HPSTAT( ++pRec->stat_.free_count ); + CDS_HPSTAT( ++pRec->free_count_ ); } } const size_t nDeferred = insert_pos - first_retired; @@ -386,7 +386,7 @@ namespace cds { namespace gc { namespace hp { { thread_record* pRec = static_cast( pThreadRec ); - CDS_HPSTAT( ++pRec->stat_.scan_count ); + CDS_HPSTAT( ++pRec->scan_count_ ); std::vector< void*, allocator> plist; plist.reserve( get_max_thread_count() * get_hazard_ptr_count()); @@ -429,7 +429,7 @@ namespace cds { namespace gc { namespace hp { } else { it->free(); - CDS_HPSTAT( ++pRec->stat_.free_count ); + CDS_HPSTAT( ++pRec->free_count_ ); } } @@ -441,7 +441,7 @@ namespace cds { namespace gc { namespace hp { { assert( static_cast( pThis )->m_idOwner.load( atomics::memory_order_relaxed ) == cds::OS::get_current_thread_id() ); - CDS_HPSTAT( ++pThis->stat_.help_scan_count ); + CDS_HPSTAT( ++pThis->help_scan_count_ ); const cds::OS::ThreadId nullThreadId = cds::OS::c_NullThreadId; const cds::OS::ThreadId curThreadId = cds::OS::get_current_thread_id(); @@ -496,9 +496,9 @@ namespace cds { namespace gc { namespace hp { st.guard_allocated += hprec->hazards_.alloc_guard_count_; st.guard_freed += hprec->hazards_.free_guard_count_; st.retired_count += hprec->retired_.retire_call_count_; - st.free_count += hprec->stat_.free_count; - st.scan_count += hprec->stat_.scan_count; - st.help_scan_count += hprec->stat_.help_scan_count; + st.free_count += hprec->free_count_; + st.scan_count += hprec->scan_count_; + st.help_scan_count += hprec->help_scan_count_; } # endif } diff --git a/test/include/cds_test/stat_dhp_out.h b/test/include/cds_test/stat_dhp_out.h new file mode 100644 index 00000000..ea4bd539 --- /dev/null +++ b/test/include/cds_test/stat_dhp_out.h @@ -0,0 +1,87 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + 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. +*/ + +#ifndef CDSTEST_STAT_DHP_OUT_H +#define CDSTEST_STAT_DHP_OUT_H + +#include +#include + +namespace cds_test { + + static inline property_stream& operator <<( property_stream& o, cds::gc::DHP::stat const& s ) + { +#ifdef CDS_ENABLE_HPSTAT +# define CDS_HPSTAT_OUT( stat, fld ) std::make_pair( "dhp_" + property_stream::stat_prefix() + "." #fld, stat.fld ) + return o + << CDS_HPSTAT_OUT( s, guard_allocated ) + << CDS_HPSTAT_OUT( s, guard_freed ) + << CDS_HPSTAT_OUT( s, retired_count ) + << CDS_HPSTAT_OUT( s, free_count ) + << CDS_HPSTAT_OUT( s, scan_count ) + << CDS_HPSTAT_OUT( s, help_scan_count ) + << CDS_HPSTAT_OUT( s, thread_rec_count ) + << CDS_HPSTAT_OUT( s, hp_block_count ) + << CDS_HPSTAT_OUT( s, retired_block_count ) + << CDS_HPSTAT_OUT( s, hp_extend_count ) + << CDS_HPSTAT_OUT( s, retired_extend_count ); +# undef CDS_HPSTAT_OUT +#else + return o; +#endif + } + +} // namespace cds_test + +static inline std::ostream& operator <<( std::ostream& o, cds::gc::DHP::stat const& s ) +{ +#ifdef CDS_ENABLE_HPSTAT +# define CDS_HPSTAT_OUT( stat, fld ) "\t" << #fld << "=" << stat.fld << "\n" + return o + << "DHP post-mortem statistics:\n" + << CDS_HPSTAT_OUT( s, guard_allocated ) + << CDS_HPSTAT_OUT( s, guard_freed ) + << CDS_HPSTAT_OUT( s, retired_count ) + << CDS_HPSTAT_OUT( s, free_count ) + << CDS_HPSTAT_OUT( s, scan_count ) + << CDS_HPSTAT_OUT( s, help_scan_count ) + << CDS_HPSTAT_OUT( s, thread_rec_count ) + << CDS_HPSTAT_OUT( s, hp_block_count ) + << CDS_HPSTAT_OUT( s, retired_block_count ) + << CDS_HPSTAT_OUT( s, hp_extend_count ) + << CDS_HPSTAT_OUT( s, retired_extend_count ); +# undef CDS_HPSTAT_OUT +#else + return o; +#endif +} + + +#endif // #ifndef CDSTEST_STAT_DHP_OUT_H diff --git a/test/include/cds_test/stat_hp_out.h b/test/include/cds_test/stat_hp_out.h new file mode 100644 index 00000000..3a5d239e --- /dev/null +++ b/test/include/cds_test/stat_hp_out.h @@ -0,0 +1,78 @@ +/* + This file is a part of libcds - Concurrent Data Structures library + + (C) Copyright Maxim Khizhinsky (libcds.dev@gmail.com) 2006-2017 + + Source code repo: http://github.com/khizmax/libcds/ + Download: http://sourceforge.net/projects/libcds/files/ + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + 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. +*/ + +#ifndef CDSTEST_STAT_HP_OUT_H +#define CDSTEST_STAT_HP_OUT_H + +#include +#include + +namespace cds_test { + + static inline property_stream& operator <<( property_stream& o, cds::gc::HP::stat const& s ) + { +#ifdef CDS_ENABLE_HPSTAT +# define CDS_HPSTAT_OUT( stat, fld ) std::make_pair( "hp_" + property_stream::stat_prefix() + "." #fld, stat.fld ) + return o + << CDS_HPSTAT_OUT( s, guard_allocated ) + << CDS_HPSTAT_OUT( s, guard_freed ) + << CDS_HPSTAT_OUT( s, retired_count ) + << CDS_HPSTAT_OUT( s, free_count ) + << CDS_HPSTAT_OUT( s, scan_count ) + << CDS_HPSTAT_OUT( s, help_scan_count ) + << CDS_HPSTAT_OUT( s, thread_rec_count ); +# undef CDS_HPSTAT_OUT +#else + return o; +#endif + } + +} // namespace cds_test + +static inline std::ostream& operator <<( std::ostream& o, cds::gc::HP::stat const& s ) +{ +#ifdef CDS_ENABLE_HPSTAT +# define CDS_HPSTAT_OUT( stat, fld ) "\t" << #fld << "=" << stat.fld << "\n" + return o + << "HP post-mortem statistics:\n" + << CDS_HPSTAT_OUT( s, guard_allocated ) + << CDS_HPSTAT_OUT( s, guard_freed ) + << CDS_HPSTAT_OUT( s, retired_count ) + << CDS_HPSTAT_OUT( s, free_count ) + << CDS_HPSTAT_OUT( s, scan_count ) + << CDS_HPSTAT_OUT( s, help_scan_count ) + << CDS_HPSTAT_OUT( s, thread_rec_count ); +# undef CDS_HPSTAT_OUT +#else + return o; +#endif +} + +#endif // #ifndef CDSTEST_STAT_HP_OUT_H diff --git a/test/include/cds_test/stress_test.h b/test/include/cds_test/stress_test.h index a739a4b4..9e3053f0 100644 --- a/test/include/cds_test/stress_test.h +++ b/test/include/cds_test/stress_test.h @@ -172,6 +172,8 @@ namespace cds_test { class stress_fixture : public fixture { + typedef fixture base_class; + protected: stress_fixture() : m_thread_pool( *this ) @@ -179,13 +181,18 @@ namespace cds_test { //static void SetUpTestCase(); //static void TearDownTestCase(); + void TearDown() + { + print_hp_stat(); + base_class::TearDown(); + } thread_pool& get_pool() { return m_thread_pool; } - static property_stream& propout(); + static void print_hp_stat(); public: static config const& get_config( char const * slot ); @@ -196,6 +203,8 @@ namespace cds_test { static void init_detail_level( int argc, char **argv ); static bool check_detail_level( int nLevel ); + static property_stream& propout(); + private: thread_pool m_thread_pool; }; diff --git a/test/stress/framework/stress_test.cpp b/test/stress/framework/stress_test.cpp index 1497cc7d..2cd19db3 100644 --- a/test/stress/framework/stress_test.cpp +++ b/test/stress/framework/stress_test.cpp @@ -32,6 +32,11 @@ #include #include +#ifdef CDS_ENABLE_HPSTAT +# include +# include +#endif + namespace cds_test { static std::string s_stat_prefix( "stat" ); @@ -55,6 +60,23 @@ namespace cds_test { return s_prop_stream; } + /*static*/ void stress_fixture::print_hp_stat() + { +#ifdef CDS_ENABLE_HPSTAT + { + cds::gc::HP::stat st; + cds::gc::HP::statistics( st ); + propout() << st; + } + { + cds::gc::DHP::stat st; + cds::gc::DHP::statistics( st ); + propout() << st; + } +#endif + } + + /*static*/ std::vector stress_fixture::load_dictionary() { std::vector arrString; diff --git a/test/stress/main.cpp b/test/stress/main.cpp index 0c7acd83..14eb93eb 100644 --- a/test/stress/main.cpp +++ b/test/stress/main.cpp @@ -41,6 +41,12 @@ # include #endif +#ifdef CDS_ENABLE_HPSTAT +# include +# include +# include +#endif + int main( int argc, char **argv ) { int result; @@ -97,6 +103,13 @@ int main( int argc, char **argv ) cds::threading::Manager::detachThread(); } + +#ifdef CDS_ENABLE_HPSTAT + std::cout << cds::gc::HP::postmortem_statistics(); + std::cout << cds::gc::DHP::postmortem_statistics(); +#endif + cds::Terminate(); + return result; }