From: Johnathan Corgan Date: Mon, 19 Apr 2010 03:13:47 +0000 (-0700) Subject: Convert gcell to use boost::threads instead of omnithread. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=052638a76f3c07be744b603c3ba0f392ccc1569b;p=debian%2Fgnuradio Convert gcell to use boost::threads instead of omnithread. Passes make check. --- diff --git a/config/grc_gcell.m4 b/config/grc_gcell.m4 index ff289d1a..b94deb4d 100644 --- a/config/grc_gcell.m4 +++ b/config/grc_gcell.m4 @@ -1,4 +1,4 @@ -dnl Copyright 2001,2002,2003,2004,2005,2006,2008 Free Software Foundation, Inc. +dnl Copyright 2001,2002,2003,2004,2005,2006,2008,2010 Free Software Foundation, Inc. dnl dnl This file is part of GNU Radio dnl @@ -21,9 +21,6 @@ AC_DEFUN([GRC_GCELL],[ GRC_ENABLE(gcell) dnl GRC_WITH(gcell) - dnl Don't do gcell if omnithread skipped - GRC_CHECK_DEPENDENCY(gcell, omnithread) - dnl If execution gets to here, $passed will be: dnl with : if the --with code didn't error out dnl yes : if the --enable code passed muster and all dependencies are met diff --git a/gcell/apps/benchmark_dma.cc b/gcell/apps/benchmark_dma.cc index a84defe3..bc3b3f32 100644 --- a/gcell/apps/benchmark_dma.cc +++ b/gcell/apps/benchmark_dma.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,7 +23,7 @@ #include #endif #include -#include +#include #include #include #include @@ -95,6 +95,8 @@ init_jd(gc_job_desc *jd, unsigned int usecs, static void run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, int getput_mask) { + using namespace boost::posix_time; + static const int64_t TOTAL_SIZE_DMA = 5LL << 30; static const int NJDS = 64; unsigned int njobs = (unsigned int)(TOTAL_SIZE_DMA / dma_size); @@ -148,7 +150,7 @@ run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, int getp for (int iter = 0; iter < 1; iter++){ - omni_time t_start = omni_time::time(); + ptime t_start(microsec_clock::universal_time()); nsubmitted = 0; ncompleted = 0; @@ -203,9 +205,9 @@ run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, int getp } // stop timing - omni_time t_stop = omni_time::time(); + ptime t_stop(microsec_clock::universal_time()); - double delta = (t_stop - t_start).double_time(); + double delta = (t_stop - t_start).total_microseconds() * 1e-6; printf("nspes: %2d udelay: %4d elapsed_time: %7.3f dma_size: %5d dma_throughput: %7.3e\n", mgr->nspes(), usecs, delta, dma_size, (double) njobs * dma_size / delta * (getput_mask == BENCHMARK_GET_PUT ? 2.0 : 1.0)); diff --git a/gcell/apps/benchmark_nop.cc b/gcell/apps/benchmark_nop.cc index dee46c84..a27373db 100644 --- a/gcell/apps/benchmark_nop.cc +++ b/gcell/apps/benchmark_nop.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008 Free Software Foundation, Inc. + * Copyright 2007,2008,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,7 +23,7 @@ #include #endif #include -#include +#include #include #include #include @@ -47,6 +47,8 @@ init_jd(gc_job_desc *jd, unsigned int usecs) static void run_test(unsigned int nspes, unsigned int usecs, int njobs) { + using namespace boost::posix_time; + static const int NJDS = 64; int nsubmitted = 0; int ncompleted = 0; @@ -73,7 +75,7 @@ run_test(unsigned int nspes, unsigned int usecs, int njobs) init_jd(all_jds[i], usecs); } - omni_time t_start = omni_time::time(); + ptime t_start(microsec_clock::universal_time()); ci = 0; njds[0] = 0; @@ -122,8 +124,8 @@ run_test(unsigned int nspes, unsigned int usecs, int njobs) } // stop timing - omni_time t_stop = omni_time::time(); - double delta = (t_stop - t_start).double_time(); + ptime t_stop(microsec_clock::universal_time()); + double delta = (t_stop - t_start).total_microseconds() * 1e-6; printf("nspes: %2d udelay: %4d elapsed_time: %7.3f njobs: %g speedup: %6.3f\n", mgr->nspes(), usecs, delta, (double) njobs, njobs * usecs * 1e-6 / delta); diff --git a/gcell/apps/benchmark_roundtrip.cc b/gcell/apps/benchmark_roundtrip.cc index 8ba37c96..b994182a 100644 --- a/gcell/apps/benchmark_roundtrip.cc +++ b/gcell/apps/benchmark_roundtrip.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. + * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -23,7 +23,7 @@ #include #endif #include -#include +#include #include #include #include @@ -96,6 +96,8 @@ static void run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, int getput_mask, int njobs_at_once) { + using namespace boost::posix_time; + int NJDS = njobs_at_once; gc_job_desc *all_jds[NJDS]; bool done[NJDS]; @@ -140,7 +142,7 @@ run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, } int niter = 100000; - omni_time t_start = omni_time::time(); + ptime t_start(microsec_clock::universal_time()); for (int iter = 0; iter < niter; iter++){ @@ -164,8 +166,8 @@ run_test(unsigned int nspes, unsigned int usecs, unsigned int dma_size, } // stop timing - omni_time t_stop = omni_time::time(); - double delta = (t_stop - t_start).double_time(); + ptime t_stop(microsec_clock::universal_time()); + double delta = (t_stop - t_start).total_microseconds() * 1e-6; printf("nspes: %2d udelay: %4d elapsed_time: %7.3f dma_size: %5d dma_throughput: %7.3e round_trip: %gus\n", mgr->nspes(), usecs, delta, dma_size, (double) NJDS * niter * dma_size / delta * (getput_mask == BENCHMARK_GET_PUT ? 2.0 : 1.0), diff --git a/gcell/lib/Makefile.am b/gcell/lib/Makefile.am index e7b34933..fa9c4a00 100644 --- a/gcell/lib/Makefile.am +++ b/gcell/lib/Makefile.am @@ -36,7 +36,7 @@ libgcell_la_LIBADD = \ runtime/libruntime.la \ wrapper/libwrapper.la \ -lspe2 \ - $(OMNITHREAD_LA) + $(BOOST_LDFLAGS) $(BOOST_THREAD_LIB) libgcell_qa_la_LIBADD = \ runtime/libruntime-qa.la \ diff --git a/gcell/lib/runtime/Makefile.am b/gcell/lib/runtime/Makefile.am index 2c653918..4d13790c 100644 --- a/gcell/lib/runtime/Makefile.am +++ b/gcell/lib/runtime/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2010 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -23,7 +23,7 @@ include $(top_srcdir)/Makefile.common IBM_PPU_SYNC_INCLUDES = -I$(top_srcdir)/gcell/ibm/sync/ppu_source -AM_CPPFLAGS = $(DEFINES) $(OMNITHREAD_INCLUDES) $(MBLOCK_INCLUDES) $(CPPUNIT_INCLUDES) \ +AM_CPPFLAGS = $(DEFINES) $(BOOST_CPPFLAGS) $(CPPUNIT_INCLUDES) \ $(GCELL_INCLUDES) $(IBM_PPU_SYNC_INCLUDES) $(WITH_INCLUDES) diff --git a/gcell/lib/runtime/gc_client_thread_info.h b/gcell/lib/runtime/gc_client_thread_info.h index 9f46ecca..e49c0709 100644 --- a/gcell/lib/runtime/gc_client_thread_info.h +++ b/gcell/lib/runtime/gc_client_thread_info.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007 Free Software Foundation, Inc. + * Copyright 2007,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -21,7 +21,7 @@ #ifndef INCLUDED_GC_CLIENT_THREAD_INFO_H #define INCLUDED_GC_CLIENT_THREAD_INFO_H -#include +#include #include enum gc_ct_state { @@ -40,7 +40,7 @@ enum gc_ct_state { class gc_client_thread_info : boost::noncopyable { public: gc_client_thread_info() : - d_free(1), d_cond(&d_mutex), d_state(CT_NOT_WAITING), + d_free(1), d_cond(), d_state(CT_NOT_WAITING), d_jobs_done(0), d_njobs_waiting_for(0), d_jobs_waiting_for(0){ } @@ -59,10 +59,10 @@ public: uint16_t d_client_id; //! hold this mutex to manipulate anything below here - omni_mutex d_mutex; + boost::mutex d_mutex; //! signaled by event handler to wake client thread up - omni_condition d_cond; + boost::condition_variable d_cond; //! Is this client waiting? gc_ct_state d_state; diff --git a/gcell/lib/runtime/gc_job_manager_impl.cc b/gcell/lib/runtime/gc_job_manager_impl.cc index cc49fd1f..58597cf2 100644 --- a/gcell/lib/runtime/gc_job_manager_impl.cc +++ b/gcell/lib/runtime/gc_job_manager_impl.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. + * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -39,6 +39,7 @@ #include #include +typedef boost::unique_lock scoped_lock; #define __nop() __asm__ volatile ("ori 0,0,0" : : : "memory") #define __cctpl() __asm__ volatile ("or 1,1,1" : : : "memory") @@ -116,9 +117,9 @@ is_power_of_2(uint32_t x) gc_job_manager_impl::gc_job_manager_impl(const gc_jm_options *options) : d_debug(0), d_spu_args(0), - d_eh_cond(&d_eh_mutex), d_eh_thread(0), d_eh_state(EHS_INIT), + d_eh_cond(), d_eh_thread(0), d_eh_state(EHS_INIT), d_shutdown_requested(false), - d_jc_cond(&d_jc_mutex), d_jc_thread(0), d_jc_state(JCS_INIT), d_jc_njobs_active(0), + d_jc_cond(), d_jc_thread(0), d_jc_state(JCS_INIT), d_jc_njobs_active(0), d_ntell(0), d_tell_start(0), d_client_thread(0), d_ea_args_maxsize(0), d_proc_def(0), d_proc_def_ls_addr(0), d_nproc_defs(0) @@ -368,12 +369,12 @@ gc_job_manager_impl::~gc_job_manager_impl() bool gc_job_manager_impl::shutdown() { - omni_mutex_lock l(d_eh_mutex); + scoped_lock l(d_eh_mutex); { - omni_mutex_lock l2(d_jc_mutex); + scoped_lock l2(d_jc_mutex); d_shutdown_requested = true; // set flag for event handler thread - d_jc_cond.signal(); // wake up job completer + d_jc_cond.notify_one(); // wake up job completer } // should only happens during early QA code @@ -381,7 +382,7 @@ gc_job_manager_impl::shutdown() return false; while (d_eh_state != EHS_DEAD) // wait for it to finish - d_eh_cond.wait(); + d_eh_cond.wait(l); return true; } @@ -459,13 +460,13 @@ gc_job_manager_impl::free_job_desc(gc_job_desc *jd) inline bool gc_job_manager_impl::incr_njobs_active() { - omni_mutex_lock l(d_jc_mutex); + scoped_lock l(d_jc_mutex); if (d_shutdown_requested) return false; if (d_jc_njobs_active++ == 0) // signal on 0 to 1 transition - d_jc_cond.signal(); + d_jc_cond.notify_one(); return true; } @@ -473,7 +474,7 @@ gc_job_manager_impl::incr_njobs_active() inline void gc_job_manager_impl::decr_njobs_active(int n) { - omni_mutex_lock l(d_jc_mutex); + scoped_lock l(d_jc_mutex); d_jc_njobs_active -= n; } @@ -614,7 +615,7 @@ gc_job_manager_impl::wait_jobs(unsigned int njobs, } { - omni_mutex_lock l(cti->d_mutex); + scoped_lock l(cti->d_mutex); // setup info for event handler cti->d_state = (mode == GC_WAIT_ANY) ? CT_WAIT_ANY : CT_WAIT_ALL; @@ -646,7 +647,7 @@ gc_job_manager_impl::wait_jobs(unsigned int njobs, // FIXME what happens when somebody calls shutdown? - cti->d_cond.wait(); // wait for event handler to wake us up + cti->d_cond.wait(l); // wait for event handler to wake us up } cti->d_state = CT_NOT_WAITING; @@ -835,17 +836,17 @@ gc_job_manager_impl::create_event_handler() void gc_job_manager_impl::set_eh_state(evt_handler_state s) { - omni_mutex_lock l(d_eh_mutex); + scoped_lock l(d_eh_mutex); d_eh_state = s; - d_eh_cond.broadcast(); + d_eh_cond.notify_all(); } void gc_job_manager_impl::set_ea_args_maxsize(int maxsize) { - omni_mutex_lock l(d_eh_mutex); + scoped_lock l(d_eh_mutex); d_ea_args_maxsize = maxsize; - d_eh_cond.broadcast(); + d_eh_cond.notify_all(); } void @@ -956,7 +957,7 @@ gc_job_manager_impl::notify_clients_jobs_are_done(unsigned int spe_num, // FIXME we could distinguish between CT_WAIT_ALL & CT_WAIT_ANY if (last_cti->d_state == CT_WAIT_ANY || last_cti->d_state == CT_WAIT_ALL) - last_cti->d_cond.signal(); // wake client thread up + last_cti->d_cond.notify_one(); // wake client thread up last_cti->d_mutex.unlock(); cti->d_mutex.lock(); @@ -970,7 +971,7 @@ gc_job_manager_impl::notify_clients_jobs_are_done(unsigned int spe_num, // "wind-out" if (last_cti->d_state == CT_WAIT_ANY || last_cti->d_state == CT_WAIT_ALL) - last_cti->d_cond.signal(); // wake client thread up + last_cti->d_cond.notify_one(); // wake client thread up last_cti->d_mutex.unlock(); ci->in_use = 0; // clear flag so SPE knows we're done with it @@ -1189,13 +1190,13 @@ gc_job_manager_impl::job_completer_loop() while (1){ { - omni_mutex_lock l(d_jc_mutex); + scoped_lock l(d_jc_mutex); if (d_jc_njobs_active == 0){ if (d_shutdown_requested){ d_jc_state = JCS_DEAD; return; } - d_jc_cond.wait(); + d_jc_cond.wait(l); } } @@ -1280,10 +1281,10 @@ gc_job_manager_impl::free_cti(gc_client_thread_info *cti) int gc_job_manager_impl::ea_args_maxsize() { - omni_mutex_lock l(d_eh_mutex); + scoped_lock l(d_eh_mutex); while (d_ea_args_maxsize == 0) // wait for it to be initialized - d_eh_cond.wait(); + d_eh_cond.wait(l); return d_ea_args_maxsize; } diff --git a/gcell/lib/runtime/gc_job_manager_impl.h b/gcell/lib/runtime/gc_job_manager_impl.h index a5611787..640fdfe7 100644 --- a/gcell/lib/runtime/gc_job_manager_impl.h +++ b/gcell/lib/runtime/gc_job_manager_impl.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2007,2008,2009 Free Software Foundation, Inc. + * Copyright 2007,2008,2009,2010 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -107,16 +107,16 @@ class gc_job_manager_impl : public gc_job_manager boost::shared_ptr _d_comp_info_boost; // hack for automatic storage mgmt // used to coordinate communication w/ the event handling thread - omni_mutex d_eh_mutex; - omni_condition d_eh_cond; + boost::mutex d_eh_mutex; + boost::condition_variable d_eh_cond; pthread_t d_eh_thread; // the event handler thread volatile evt_handler_state d_eh_state; volatile bool d_shutdown_requested; spe_event_handler d_spe_event_handler; // used to coordinate communication w/ the job completer thread - omni_mutex d_jc_mutex; - omni_condition d_jc_cond; + boost::mutex d_jc_mutex; + boost::condition_variable d_jc_cond; pthread_t d_jc_thread; // the job completion thread volatile job_completer_state d_jc_state; int d_jc_njobs_active; // # of jobs submitted but not yet reaped