int main( int argc, char * argv[]) { try { coro::flag_fpu_t preserve_fpu = coro::fpu_not_preserved; bind_to_processor( 0); #ifdef BOOST_CONTEXT_CYCLE { cycle_t ov( overhead_cycles() ); std::cout << "overhead for rdtsc == " << ov << " cycles" << std::endl; unsigned int res = test_cycles( ov, preserve_fpu); std::cout << "coroutine: average of " << res << " cycles per switch" << std::endl; } #endif #if _POSIX_C_SOURCE >= 199309L { zeit_t ov( overhead_zeit() ); std::cout << "\noverhead for clock_gettime() == " << ov << " ns" << std::endl; unsigned int res = test_zeit( ov, preserve_fpu); std::cout << "coroutine: average of " << res << " ns per switch" << std::endl; } #endif return EXIT_SUCCESS; } catch ( std::exception const& e) { std::cerr << "exception: " << e.what() << std::endl; } catch (...) { std::cerr << "unhandled exception" << std::endl; } return EXIT_FAILURE; }
void thread( unsigned int i, barrier * b) { bind_to_processor( i); boost::fibers::use_scheduling_algorithm< boost::fibers::algo::shared_work >(); b->wait(); lock_type lk( mtx); cnd.wait( lk, [](){ return done; }); BOOST_ASSERT( done); }
int main( int argc, char * argv[]) { try { bool preserve = false, bind = false; boost::program_options::options_description desc("allowed options"); desc.add_options() ("help", "help message") ("bind,b", boost::program_options::value< bool >( & bind), "bind thread to CPU") ("fpu,f", boost::program_options::value< bool >( & preserve), "preserve FPU registers") ("jobs,j", boost::program_options::value< boost::uint64_t >( & jobs), "jobs to run"); boost::program_options::variables_map vm; boost::program_options::store( boost::program_options::parse_command_line( argc, argv, desc), vm); boost::program_options::notify( vm); if ( vm.count("help") ) { std::cout << desc << std::endl; return EXIT_SUCCESS; } if ( preserve) preserve_fpu = boost::coroutines::fpu_preserved; if ( bind) bind_to_processor( 0); duration_type overhead_c = overhead_clock(); std::cout << "overhead " << overhead_c.count() << " nano seconds" << std::endl; boost::uint64_t res = measure_time_void( overhead_c).count(); std::cout << "void: average of " << res << " nano seconds" << std::endl; res = measure_time_int( overhead_c).count(); std::cout << "int: average of " << res << " nano seconds" << std::endl; res = measure_time_x( overhead_c).count(); std::cout << "X: average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE cycle_type overhead_y = overhead_cycle(); std::cout << "overhead " << overhead_y << " cpu cycles" << std::endl; res = measure_cycles_void( overhead_y); std::cout << "void: average of " << res << " cpu cycles" << std::endl; res = measure_cycles_int( overhead_y); std::cout << "int: average of " << res << " cpu cycles" << std::endl; res = measure_cycles_x( overhead_y); std::cout << "X: average of " << res << " cpu cycles" << std::endl; #endif return EXIT_SUCCESS; } catch ( std::exception const& e) { std::cerr << "exception: " << e.what() << std::endl; } catch (...) { std::cerr << "unhandled exception" << std::endl; } return EXIT_FAILURE; }
int main( int argc, char * argv[]) { try { bind_to_processor( 0); boost::program_options::options_description desc("allowed options"); desc.add_options() ("help", "help message") ("fpu,f", boost::program_options::value< bool >( & preserve_fpu), "preserve FPU registers") ("jobs,j", boost::program_options::value< boost::uint64_t >( & jobs), "jobs to run"); boost::program_options::variables_map vm; boost::program_options::store( boost::program_options::parse_command_line( argc, argv, desc), vm); boost::program_options::notify( vm); if ( vm.count("help") ) { std::cout << desc << std::endl; return EXIT_SUCCESS; } stack_allocator stack_alloc; fc = boost::context::make_fcontext( stack_alloc.allocate( stack_allocator::default_stacksize() ), stack_allocator::default_stacksize(), foo); boost::uint64_t res = measure_time_fc().count(); std::cout << "fcontext_t: average of " << res << " nano seconds" << std::endl; # if __cplusplus >= 201103L res = measure_time_ec().count(); std::cout << "execution_context: average of " << res << " nano seconds" << std::endl; # endif #ifdef BOOST_CONTEXT_CYCLE res = measure_cycles_fc(); std::cout << "fcontext_t: average of " << res << " cpu cycles" << std::endl; # if __cplusplus >= 201103L res = measure_cycles_ec(); std::cout << "execution_context: average of " << res << " cpu cycles" << std::endl; # endif #endif return EXIT_SUCCESS; } catch ( std::exception const& e) { std::cerr << "exception: " << e.what() << std::endl; } catch (...) { std::cerr << "unhandled exception" << std::endl; } return EXIT_FAILURE; }
int main( int argc, char * argv[]) { try { bind_to_processor( 0); #ifdef BOOST_CONTEXT_CYCLE { cycle_t ov( overhead_cycles() ); std::cout << "overhead for rdtsc == " << ov << " cycles" << std::endl; unsigned int res = test_fcontext_cycle( ov); std::cout << "fcontext: average of " << res << " cycles per switch" << std::endl; # ifdef BOOST_USE_UCONTEXT res = test_ucontext_cycle( ov); std::cout << "ucontext: average of " << res << " cycles per switch" << std::endl; # endif res = test_function_cycle( ov); std::cout << "boost::function: average of " << res << " cycles per switch" << std::endl; } #endif #if _POSIX_C_SOURCE >= 199309L { zeit_t ov( overhead_zeit() ); std::cout << "\noverhead for clock_gettime() == " << ov << " ns" << std::endl; unsigned int res = test_fcontext_zeit( ov); std::cout << "fcontext: average of " << res << " ns per switch" << std::endl; # ifdef BOOST_USE_UCONTEXT res = test_ucontext_zeit( ov); std::cout << "ucontext: average of " << res << " ns per switch" << std::endl; # endif res = test_function_zeit( ov); std::cout << "boost::function: average of " << res << " ns per switch" << std::endl; } #endif return EXIT_SUCCESS; } catch ( std::exception const& e) { std::cerr << "exception: " << e.what() << std::endl; } catch (...) { std::cerr << "unhandled exception" << std::endl; } return EXIT_FAILURE; }
int main( int argc, char * argv[]) { try { bind_to_processor( 0); boost::program_options::options_description desc("allowed options"); desc.add_options() ("help", "help message") ("jobs,j", boost::program_options::value< boost::uint64_t >( & jobs), "jobs to run"); boost::program_options::variables_map vm; boost::program_options::store( boost::program_options::parse_command_line( argc, argv, desc), vm); boost::program_options::notify( vm); if ( vm.count("help") ) { std::cout << desc << std::endl; return EXIT_SUCCESS; } boost::uint64_t res = measure_time_fc().count(); std::cout << "fcontext_t: average of " << res << " nano seconds" << std::endl; #ifdef BOOST_CONTEXT_CYCLE res = measure_cycles_fc(); std::cout << "fcontext_t: average of " << res << " cpu cycles" << std::endl; #endif return EXIT_SUCCESS; } catch ( std::exception const& e) { std::cerr << "exception: " << e.what() << std::endl; } catch (...) { std::cerr << "unhandled exception" << std::endl; } return EXIT_FAILURE; }
int main() { try { boost::fibers::use_scheduling_algorithm< boost::fibers::algo::shared_work >(); unsigned int n = std::thread::hardware_concurrency(); barrier b( n); bind_to_processor( n - 1); std::size_t size{ 1000000 }; std::size_t div{ 10 }; std::vector< std::thread > threads; for ( unsigned int i = 1; i < n; ++i) { threads.push_back( std::thread( thread, i - 1, & b) ); }; allocator_type salloc{ allocator_type::traits_type::page_size() }; std::uint64_t result{ 0 }; duration_type duration{ duration_type::zero() }; channel_type rc{ 2 }; b.wait(); time_point_type start{ clock_type::now() }; skynet( salloc, rc, 0, size, div); result = rc.value_pop(); duration = clock_type::now() - start; std::cout << "Result: " << result << " in " << duration.count() / 1000000 << " ms" << std::endl; lock_type lk( mtx); done = true; lk.unlock(); cnd.notify_all(); for ( std::thread & t : threads) { t.join(); } std::cout << "done." << std::endl; return EXIT_SUCCESS; } catch ( std::exception const& e) { std::cerr << "exception: " << e.what() << std::endl; } catch (...) { std::cerr << "unhandled exception" << std::endl; } return EXIT_FAILURE; }
static void sit_and_spin(int child_index) { long *my_counter_ptr; /* only use C stuff if we are not WIN32 unless and until we */ /* switch from CreateThread to _beginthread. raj 1/96 */ #ifndef WIN32 /* we are the child. we could decide to exec some separate */ /* program, but that doesn't really seem worthwhile - raj 4/95 */ if (debug > 1) { fprintf(where, "Looper child %d is born, pid %d\n", child_index, getpid()); fflush(where); } #endif /* WIN32 */ /* reset our base pointer to be at the appropriate offset */ my_counter_ptr = (long *) ((char *)lib_base_pointer + (netlib_get_page_size() * PAGES_PER_CHILD * child_index)); /* in the event we are running on an MP system, it would */ /* probably be good to bind the soaker processes to specific */ /* processors. I *think* this is the most reasonable thing to */ /* do, and would be closes to simulating the information we get */ /* on HP-UX with pstat. I could put all the system-specific code */ /* here, but will "abstract it into another routine to keep this */ /* area more readable. I'll probably do the same thine with the */ /* "low pri code" raj 10/95 */ /* NOTE. I do *NOT* think it would be appropriate for the actual */ /* test processes to be bound to a particular processor - that */ /* is something that should be left up to the operating system. */ bind_to_processor(child_index); for (*my_counter_ptr = 0L; ; (*my_counter_ptr)++) { if (!(*lib_base_pointer % 1)) { /* every once and again, make sure that our process priority is */ /* nice and low. also, by making system calls, it may be easier */ /* for us to be pre-empted by something that needs to do useful */ /* work - like the thread of execution actually sending and */ /* receiving data across the network :) */ #ifdef _AIX int pid,prio; prio = PRIORITY; pid = getpid(); /* if you are not root, this call will return EPERM - why one */ /* cannot change one's own priority to lower value is beyond */ /* me. raj 2/26/96 */ setpri(pid, prio); #else /* _AIX */ #ifdef __sgi int pid,prio; prio = PRIORITY; pid = getpid(); schedctl(NDPRI, pid, prio); sginap(0); #else /* __sgi */ #ifdef WIN32 SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_IDLE); #else /* WIN32 */ #if defined(__sun) && defined(__SVR4) #include <sys/types.h> #include <sys/priocntl.h> #include <sys/rtpriocntl.h> #include <sys/tspriocntl.h> /* I would *really* like to know how to use priocntl to make the */ /* priority low for this looper process. however, either my mind */ /* is addled, or the manpage in section two for priocntl is not */ /* terribly helpful - for one, it has no examples :( so, if you */ /* can help, I'd love to hear from you. in the meantime, we will */ /* rely on nice(39). raj 2/26/96 */ nice(39); #else /* __sun && __SVR4 */ nice(39); #endif /* __sun && _SVR4 */ #endif /* WIN32 */ #endif /* __sgi */ #endif /* _AIX */ } } }