$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r78032 - trunk/libs/context/performance
From: oliver.kowalke_at_[hidden]
Date: 2012-04-17 03:09:21
Author: olli
Date: 2012-04-17 03:09:19 EDT (Tue, 17 Apr 2012)
New Revision: 78032
URL: http://svn.boost.org/trac/boost/changeset/78032
Log:
context: support of other compilers for performance test
Added:
   trunk/libs/context/performance/cycle.hpp   (contents, props changed)
   trunk/libs/context/performance/cycle_i386.hpp   (contents, props changed)
   trunk/libs/context/performance/cycle_x86-64.hpp   (contents, props changed)
Removed:
   trunk/libs/context/performance/performance.hpp
   trunk/libs/context/performance/performance_gcc_i386.hpp
   trunk/libs/context/performance/performance_gcc_x86-64.hpp
   trunk/libs/context/performance/performance_msvc_i386.hpp
Text files modified: 
   trunk/libs/context/performance/performance.cpp |    30 ++++++++++++++----------------          
   1 files changed, 14 insertions(+), 16 deletions(-)
Added: trunk/libs/context/performance/cycle.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/context/performance/cycle.hpp	2012-04-17 03:09:19 EDT (Tue, 17 Apr 2012)
@@ -0,0 +1,28 @@
+
+//          Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef CYCLE_H
+#define CYCLE_H
+
+// x86_64
+// test x86_64 before i386 because icc might
+// define __i686__ for x86_64 too
+#if defined(__x86_64__) || defined(__x86_64) \
+    || defined(__amd64__) || defined(__amd64) \
+    || defined(_M_X64) || defined(_M_AMD64)
+# include "cycle_x86-64.hpp"
+// i386
+#elif defined(i386) || defined(__i386__) || defined(__i386) \
+    || defined(__i486__) || defined(__i586__) || defined(__i686__) \
+    || defined(__X86__) || defined(_X86_) || defined(__THW_INTEL__) \
+    || defined(__I86__) || defined(__INTEL__) || defined(__IA32__) \
+    || defined(_M_IX86) || defined(_I86_)
+# include "cycle_i386.hpp"
+#else
+# error "this platform is not supported"
+#endif
+
+#endif // CYCLE_H
Added: trunk/libs/context/performance/cycle_i386.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/context/performance/cycle_i386.hpp	2012-04-17 03:09:19 EDT (Tue, 17 Apr 2012)
@@ -0,0 +1,81 @@
+
+//          Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef CYCLE_I386_H
+#define CYCLE_I386_H
+
+#include <algorithm>
+#include <numeric>
+#include <cstddef>
+#include <vector>
+
+#include <boost/assert.hpp>
+#include <boost/bind.hpp>
+#include <boost/cstdint.hpp>
+
+typedef boost::uint64_t cycle_t;
+
+#if _MSC_VER
+inline
+cycle_t cycles()
+{
+    cycle_t c;
+    __asm {
+        cpuid 
+        rdtsc
+        mov dword ptr [c + 0], eax
+        mov dword ptr [c + 4], edx
+    }
+    return c;
+}
+#elif defined(__GNUC__) || \
+      defined(__INTEL_COMPILER) || defined(__ICC) || defined(_ECC) || defined(__ICL)
+inline
+cycle_t cycles()
+{
+    boost::uint32_t lo, hi;
+
+    __asm__ __volatile__ (
+        "xorl %%eax, %%eax\n"
+        "cpuid\n"
+        ::: "%eax", "%ebx", "%ecx", "%edx"
+    );
+    __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi) );
+    __asm__ __volatile__ (
+        "xorl %%eax, %%eax\n"
+        "cpuid\n"
+        ::: "%eax", "%ebx", "%ecx", "%edx"
+    );
+   
+    return ( cycle_t)hi << 32 | lo; 
+}
+#else
+# error "this compiler is not supported"
+#endif
+
+struct measure
+{
+    cycle_t operator()()
+    {
+        cycle_t start( cycles() );
+        return cycles() - start;
+    }
+};
+
+inline
+cycle_t overhead()
+{
+    std::size_t iterations( 10);
+    std::vector< cycle_t >  overhead( iterations, 0);
+    for ( std::size_t i( 0); i < iterations; ++i)
+        std::generate(
+            overhead.begin(), overhead.end(),
+            measure() );
+    BOOST_ASSERT( overhead.begin() != overhead.end() );
+    return std::accumulate( overhead.begin(), overhead.end(), 0) / iterations;
+}
+
+#endif // CYCLE_I386_H
Added: trunk/libs/context/performance/cycle_x86-64.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/context/performance/cycle_x86-64.hpp	2012-04-17 03:09:19 EDT (Tue, 17 Apr 2012)
@@ -0,0 +1,85 @@
+
+//          Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+//    (See accompanying file LICENSE_1_0.txt or copy at
+//          http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef CYCLE_X86_64_H
+#define CYCLE_X86_64_H
+
+#include <algorithm>
+#include <numeric>
+#include <cstddef>
+#include <vector>
+
+#include <boost/assert.hpp>
+#include <boost/bind.hpp>
+#include <boost/cstdint.hpp>
+
+typedef boost::uint64_t cycle_t;
+
+#if _MSC_VER >= 1400
+# include <intrin.h>
+# pragma intrinsic(__rdtsc)
+inline
+cycle_t cycles()
+{ return __rdtsc(); }
+#elif defined(__INTEL_COMPILER) || defined(__ICC) || defined(_ECC) || defined(__ICL)
+inline
+cycle_t cycles()
+{ return __rdtsc(); }
+#elif defined(__PGI)
+inline
+cycle_t cycles()
+{
+    asm (
+        " rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; "
+    );
+}
+#elif defined(__GNUC__) || defined(__SUNPRO_C)
+inline
+cycle_t cycles()
+{
+    boost::uint32_t lo, hi;
+    
+    __asm__ __volatile__ (
+        "xorl %%eax, %%eax\n"
+        "cpuid\n"
+        ::: "%rax", "%rbx", "%rcx", "%rdx"
+    );
+    __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi) );
+    __asm__ __volatile__ (
+        "xorl %%eax, %%eax\n"
+        "cpuid\n"
+        ::: "%rax", "%rbx", "%rcx", "%rdx"
+    );
+   
+    return ( cycle_t)hi << 32 | lo; 
+}
+#else
+# error "this compiler is not supported"
+#endif
+
+struct measure
+{
+    cycle_t operator()()
+    {
+        cycle_t start( cycles() );
+        return cycles() - start;
+    }
+};
+
+inline
+cycle_t overhead()
+{
+    std::size_t iterations( 10);
+    std::vector< cycle_t >  overhead( iterations, 0);
+    for ( std::size_t i( 0); i < iterations; ++i)
+        std::generate(
+            overhead.begin(), overhead.end(),
+            measure() );
+    BOOST_ASSERT( overhead.begin() != overhead.end() );
+    return std::accumulate( overhead.begin(), overhead.end(), 0) / iterations;
+}
+
+#endif // CYCLE_X86_64_H
Modified: trunk/libs/context/performance/performance.cpp
==============================================================================
--- trunk/libs/context/performance/performance.cpp	(original)
+++ trunk/libs/context/performance/performance.cpp	2012-04-17 03:09:19 EDT (Tue, 17 Apr 2012)
@@ -22,7 +22,7 @@
 #endif
 
 #include "bind_processor.hpp"
-#include "performance.hpp"
+#include "cycle.hpp"
 
 namespace ctx = boost::ctx;
 
@@ -52,10 +52,8 @@
 }
 
 #ifndef BOOST_WINDOWS
-unsigned int test_ucontext()
+unsigned int test_ucontext( cycle_t ov)
 {
-    cycle_t overhead( get_overhead() );
-    std::cout << "overhead for rdtsc == " << overhead << " cycles" << std::endl;
 
     ctx::stack_allocator alloc;
 
@@ -69,12 +67,12 @@
     // cache warum-up
 BOOST_PP_REPEAT_FROM_TO( 0, BOOST_PP_LIMIT_MAG, CALL_UCONTEXT, ~)
 
-    cycle_t start( get_cycles() );
+    cycle_t start( cycles() );
 BOOST_PP_REPEAT_FROM_TO( 0, BOOST_PP_LIMIT_MAG, CALL_UCONTEXT, ~)
-    cycle_t total( get_cycles() - start);
+    cycle_t total( cycles() - start);
 
     // we have two jumps and two measuremt-overheads
-    total -= overhead; // overhead of measurement
+    total -= ov; // overhead of measurement
     total /= BOOST_PP_LIMIT_MAG; // per call
     total /= 2; // 2x jump_to c1->c2 && c2->c1
 
@@ -82,11 +80,8 @@
 }
 #endif
 
-unsigned int test_fcontext()
+unsigned int test_fcontext( cycle_t ov)
 {
-    cycle_t overhead( get_overhead() );
-    std::cout << "overhead for rdtsc == " << overhead << " cycles" << std::endl;
-
     ctx::stack_allocator alloc;
     fc.fc_stack.base = alloc.allocate(ctx::default_stacksize());
     fc.fc_stack.limit =
@@ -98,12 +93,12 @@
     // cache warum-up
 BOOST_PP_REPEAT_FROM_TO( 0, BOOST_PP_LIMIT_MAG, CALL_FCONTEXT, ~)
 
-    cycle_t start( get_cycles() );
+    cycle_t start( cycles() );
 BOOST_PP_REPEAT_FROM_TO( 0, BOOST_PP_LIMIT_MAG, CALL_FCONTEXT, ~)
-    cycle_t total( get_cycles() - start);
+    cycle_t total( cycles() - start);
 
     // we have two jumps and two measuremt-overheads
-    total -= overhead; // overhead of measurement
+    total -= ov; // overhead of measurement
     total /= BOOST_PP_LIMIT_MAG; // per call
     total /= 2; // 2x jump_to c1->c2 && c2->c1
 
@@ -116,10 +111,13 @@
     {
         bind_to_processor( 0);
 
-        unsigned int res = test_fcontext();
+        cycle_t ov( overhead() );
+        std::cout << "overhead for rdtsc == " << ov << " cycles" << std::endl;
+
+        unsigned int res = test_fcontext( ov);
         std::cout << "fcontext: average of " << res << " cycles per switch" << std::endl;
 #ifndef BOOST_WINDOWS
-        res = test_ucontext();
+        res = test_ucontext( ov);
         std::cout << "ucontext: average of " << res << " cycles per switch" << std::endl;
 #endif
 
Deleted: trunk/libs/context/performance/performance.hpp
==============================================================================
--- trunk/libs/context/performance/performance.hpp	2012-04-17 03:09:19 EDT (Tue, 17 Apr 2012)
+++ (empty file)
@@ -1,37 +0,0 @@
-
-//          Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-//    (See accompanying file LICENSE_1_0.txt or copy at
-//          http://www.boost.org/LICENSE_1_0.txt)
-
-#ifndef PERFORMANCE_H
-#define PERFORMANCE_H
-
-// x86_64
-// test x86_64 before i386 because icc might
-// define __i686__ for x86_64 too
-#if defined(__x86_64__) || defined(__x86_64) \
-    || defined(__amd64__) || defined(__amd64) \
-    || defined(_M_X64) || defined(_M_AMD64)
-# if defined(BOOST_WINDOWS)
-#  error "this platform is not supported"
-# else
-#  include "performance_gcc_x86-64.hpp"
-# endif
-// i386
-#elif defined(i386) || defined(__i386__) || defined(__i386) \
-    || defined(__i486__) || defined(__i586__) || defined(__i686__) \
-    || defined(__X86__) || defined(_X86_) || defined(__THW_INTEL__) \
-    || defined(__I86__) || defined(__INTEL__) || defined(__IA32__) \
-    || defined(_M_IX86) || defined(_I86_)
-# if defined(BOOST_WINDOWS)
-#  include "performance_msvc_i386.hpp"
-# else
-#  include "performance_gcc_i386.hpp"
-# endif
-
-#else
-#error "this platform is not supported"
-#endif
-
-#endif // PERFORMANCE_H
Deleted: trunk/libs/context/performance/performance_gcc_i386.hpp
==============================================================================
--- trunk/libs/context/performance/performance_gcc_i386.hpp	2012-04-17 03:09:19 EDT (Tue, 17 Apr 2012)
+++ (empty file)
@@ -1,67 +0,0 @@
-
-//          Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-//    (See accompanying file LICENSE_1_0.txt or copy at
-//          http://www.boost.org/LICENSE_1_0.txt)
-
-#ifndef PERFORMANCE_GCC_I386_H
-#define PERFORMANCE_GCC_I386_H
-
-#include <algorithm>
-#include <numeric>
-#include <cstddef>
-#include <vector>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/cstdint.hpp>
-
-typedef boost::uint64_t cycle_t;
-
-inline
-cycle_t get_cycles()
-{
-#if defined(__INTEL_COMPILER) || defined(__ICC) || defined(_ECC) || defined(__ICL)
-    return __rdtsc();
-#else
-    boost::uint32_t res[2];
-
-    __asm__ __volatile__ (
-        "xorl %%eax, %%eax\n"
-        "cpuid\n"
-        ::: "%eax", "%ebx", "%ecx", "%edx"
-    );
-    __asm__ __volatile__ ("rdtsc" : "=a" (res[0]), "=d" (res[1]) );
-    __asm__ __volatile__ (
-        "xorl %%eax, %%eax\n"
-        "cpuid\n"
-        ::: "%eax", "%ebx", "%ecx", "%edx"
-    );
-
-    return * reinterpret_cast< cycle_t * >( res);
-#endif
-}
-
-struct measure
-{
-    cycle_t operator()()
-    {
-        cycle_t start( get_cycles() );
-        return get_cycles() - start;
-    }
-};
-
-inline
-cycle_t get_overhead()
-{
-    std::size_t iterations( 10);
-    std::vector< cycle_t >  overhead( iterations, 0);
-    for ( std::size_t i( 0); i < iterations; ++i)
-        std::generate(
-            overhead.begin(), overhead.end(),
-            measure() );
-    BOOST_ASSERT( overhead.begin() != overhead.end() );
-    return std::accumulate( overhead.begin(), overhead.end(), 0) / iterations;
-}
-
-#endif // PERFORMANCE_GCC_I386_H
Deleted: trunk/libs/context/performance/performance_gcc_x86-64.hpp
==============================================================================
--- trunk/libs/context/performance/performance_gcc_x86-64.hpp	2012-04-17 03:09:19 EDT (Tue, 17 Apr 2012)
+++ (empty file)
@@ -1,67 +0,0 @@
-
-//          Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-//    (See accompanying file LICENSE_1_0.txt or copy at
-//          http://www.boost.org/LICENSE_1_0.txt)
-
-#ifndef PERFORMANCE_GCC_X86_64_H
-#define PERFORMANCE_GCC_X86_64_H
-
-#include <algorithm>
-#include <numeric>
-#include <cstddef>
-#include <vector>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/cstdint.hpp>
-
-typedef boost::uint64_t cycle_t;
-
-inline
-cycle_t get_cycles()
-{
-#if defined(__INTEL_COMPILER) || defined(__ICC) || defined(_ECC) || defined(__ICL)
-    return __rdtsc();
-#else
-    boost::uint32_t res[2];
-    
-    __asm__ __volatile__ (
-        "xorl %%eax, %%eax\n"
-        "cpuid\n"
-        ::: "%rax", "%rbx", "%rcx", "%rdx"
-    );
-    __asm__ __volatile__ ("rdtsc" : "=a" (res[0]), "=d" (res[1]) );
-    __asm__ __volatile__ (
-        "xorl %%eax, %%eax\n"
-        "cpuid\n"
-        ::: "%rax", "%rbx", "%rcx", "%rdx"
-    );
-    
-    return * ( cycle_t *)res;
-#endif
-}
-
-struct measure
-{
-    cycle_t operator()()
-    {
-        cycle_t start( get_cycles() );
-        return get_cycles() - start;
-    }
-};
-
-inline
-cycle_t get_overhead()
-{
-    std::size_t iterations( 10);
-    std::vector< cycle_t >  overhead( iterations, 0);
-    for ( std::size_t i( 0); i < iterations; ++i)
-        std::generate(
-            overhead.begin(), overhead.end(),
-            measure() );
-    BOOST_ASSERT( overhead.begin() != overhead.end() );
-    return std::accumulate( overhead.begin(), overhead.end(), 0) / iterations;
-}
-
-#endif // PERFORMANCE_GCC_X86_64_H
Deleted: trunk/libs/context/performance/performance_msvc_i386.hpp
==============================================================================
--- trunk/libs/context/performance/performance_msvc_i386.hpp	2012-04-17 03:09:19 EDT (Tue, 17 Apr 2012)
+++ (empty file)
@@ -1,60 +0,0 @@
-
-//          Copyright Oliver Kowalke 2009.
-// Distributed under the Boost Software License, Version 1.0.
-//    (See accompanying file LICENSE_1_0.txt or copy at
-//          http://www.boost.org/LICENSE_1_0.txt)
-
-#ifndef PERFORMANCE_MSVC_I86_H
-#define PERFORMANCE_MSVC_I86_H
-
-#include <algorithm>
-#include <cstddef>
-#include <vector>
-
-#include <boost/assert.hpp>
-#include <boost/bind.hpp>
-#include <boost/cstdint.hpp>
-
-typedef boost::uint64_t cycle_t;
-
-inline
-cycle_t get_cycles()
-{
-    boost::uint32_t res[2];
-
-    __asm {
-        xor eax, eax
-        cpuid
-        rdtsc
-        mov dword ptr res[0], eax
-        mov dword ptr res[1], edx
-        xor eax, eax
-        cpuid
-    };
-
-    return * ( cycle_t *)res;
-}
-
-struct measure
-{
-    cycle_t operator()()
-    {
-        cycle_t start( get_cycles() );
-        return get_cycles() - start;
-    }
-};
-
-inline
-cycle_t get_overhead()
-{
-    std::size_t iterations( 10);
-    std::vector< cycle_t >  overhead( iterations, 0);
-    for ( std::size_t i( 0); i < iterations; ++i)
-        std::generate(
-            overhead.begin(), overhead.end(),
-            measure() );
-    BOOST_ASSERT( overhead.begin() != overhead.end() );
-    return * std::min_element( overhead.begin(), overhead.end() );
-}
-
-#endif // PERFORMANCE_MSVC_X86_64_H