diff options
author | eb <eb@221aa14e-8319-0410-a670-987f0aec2ac5> | 2008-04-22 22:24:16 +0000 |
---|---|---|
committer | eb <eb@221aa14e-8319-0410-a670-987f0aec2ac5> | 2008-04-22 22:24:16 +0000 |
commit | b9ba2711addfc9057c136b520afc9e121ec19be9 (patch) | |
tree | 059e93ef559bb837c9ca46549688c86d2e153f1c /gcell/src/lib/runtime | |
parent | 2ae538ed6a5d18615fb9eea280d861ed3a8600e5 (diff) |
Merged eb/gcell -r8215:8243 into trunk. This adds gr-gcell, the GNU
Radio interface to the Cell Broadband Engine.
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8244 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'gcell/src/lib/runtime')
-rw-r--r-- | gcell/src/lib/runtime/Makefile.am | 2 | ||||
-rw-r--r-- | gcell/src/lib/runtime/gc_aligned_alloc.cc | 54 | ||||
-rw-r--r-- | gcell/src/lib/runtime/gc_aligned_alloc.h | 52 | ||||
-rw-r--r-- | gcell/src/lib/runtime/gc_job_manager.cc | 26 | ||||
-rw-r--r-- | gcell/src/lib/runtime/gc_job_manager.h | 27 | ||||
-rw-r--r-- | gcell/src/lib/runtime/gc_job_manager_impl.cc | 33 |
6 files changed, 166 insertions, 28 deletions
diff --git a/gcell/src/lib/runtime/Makefile.am b/gcell/src/lib/runtime/Makefile.am index a68d2bcd01..89d6f1bb97 100644 --- a/gcell/src/lib/runtime/Makefile.am +++ b/gcell/src/lib/runtime/Makefile.am @@ -32,6 +32,7 @@ dist_bin_SCRIPTS = gcell-embedspu-libtool noinst_LTLIBRARIES = libruntime.la libruntime-qa.la libruntime_la_SOURCES = \ + gc_aligned_alloc.cc \ gc_job_manager.cc \ gc_job_manager_impl.cc \ gc_jd_queue.c \ @@ -46,6 +47,7 @@ libruntime_qa_la_SOURCES = \ gcellinclude_HEADERS = \ + gc_aligned_alloc.h \ gc_job_manager.h noinst_HEADERS = \ diff --git a/gcell/src/lib/runtime/gc_aligned_alloc.cc b/gcell/src/lib/runtime/gc_aligned_alloc.cc new file mode 100644 index 0000000000..fa20a64432 --- /dev/null +++ b/gcell/src/lib/runtime/gc_aligned_alloc.cc @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif +#include <gc_aligned_alloc.h> +#include <stdlib.h> +#include <stdexcept> + +// custom deleter of anything that can be freed with "free" +class free_deleter { +public: + void operator()(void *p) { + free(p); + } +}; + +void * +gc_aligned_alloc(size_t size, size_t alignment) +{ + void *p = 0; + if (posix_memalign(&p, alignment, size) != 0){ + perror("posix_memalign"); + throw std::runtime_error("memory"); + } + memset(p, 0, size); // zero the memory + return p; +} + +boost::shared_ptr<void> +gc_aligned_alloc_sptr(size_t size, size_t alignment) +{ + return boost::shared_ptr<void>(gc_aligned_alloc(size, alignment), + free_deleter()); +} diff --git a/gcell/src/lib/runtime/gc_aligned_alloc.h b/gcell/src/lib/runtime/gc_aligned_alloc.h new file mode 100644 index 0000000000..bdc21c278a --- /dev/null +++ b/gcell/src/lib/runtime/gc_aligned_alloc.h @@ -0,0 +1,52 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef INCLUDED_GC_ALIGNED_ALLOC_H +#define INCLUDED_GC_ALIGNED_ALLOC_H + +#include <boost/shared_ptr.hpp> + +/*! + * \brief Return pointer to chunk of storage of size size bytes. + * The allocation will be aligned to an \p alignment boundary. + * + * \param size is the number of bytes to allocate + * \param alignment is the minimum storage alignment in bytes; must be a power of 2. + * + * Throws if can't allocate memory. The storage should be freed + * with "free" when done. The memory is initialized to zero. + */ +void * +gc_aligned_alloc(size_t size, size_t alignment = 128); + +/*! + * \brief Return boost::shared_ptr to chunk of storage of size size bytes. + * The allocation will be aligned to an \p alignment boundary. + * + * \param size is the number of bytes to allocate + * \param alignment is the minimum storage alignment in bytes; must be a power of 2. + * + * Throws if can't allocate memory. The storage should be freed + * with "free" when done. The memory is initialized to zero. + */ +boost::shared_ptr<void> +gc_aligned_alloc_sptr(size_t size, size_t alignment = 128); + +#endif /* INCLUDED_GC_ALIGNED_ALLOC_H */ diff --git a/gcell/src/lib/runtime/gc_job_manager.cc b/gcell/src/lib/runtime/gc_job_manager.cc index 9ede5e156c..ac2e989a4e 100644 --- a/gcell/src/lib/runtime/gc_job_manager.cc +++ b/gcell/src/lib/runtime/gc_job_manager.cc @@ -31,6 +31,19 @@ static boost::weak_ptr<gc_job_manager> s_singleton; +// custom deleter of gc_job_desc allocated via alloc_job_desc_sptr +class job_desc_deleter { + gc_job_manager_sptr d_mgr; +public: + job_desc_deleter(gc_job_manager_sptr mgr) : d_mgr(mgr) {} + + void operator()(gc_job_desc *jd) { + d_mgr->free_job_desc(jd); + } +}; + + + gc_job_manager_sptr gc_make_job_manager(const gc_jm_options *options) { @@ -71,6 +84,19 @@ gc_job_manager::singleton() return gc_job_manager_sptr(s_singleton); } +gc_job_desc_sptr +gc_job_manager::make_jd_sptr(gc_job_manager_sptr mgr, gc_job_desc *jd) +{ + return gc_job_desc_sptr(jd, job_desc_deleter(mgr)); +} + +gc_job_desc_sptr +gc_job_manager::alloc_job_desc(gc_job_manager_sptr mgr) +{ + return make_jd_sptr(mgr, mgr->alloc_job_desc()); +} + + // ------------------------------------------------------------------------ diff --git a/gcell/src/lib/runtime/gc_job_manager.h b/gcell/src/lib/runtime/gc_job_manager.h index aa30dc24ba..67abce7ed0 100644 --- a/gcell/src/lib/runtime/gc_job_manager.h +++ b/gcell/src/lib/runtime/gc_job_manager.h @@ -33,6 +33,7 @@ class gc_job_manager; typedef boost::shared_ptr<gc_job_manager> gc_job_manager_sptr; typedef boost::shared_ptr<spe_program_handle_t> spe_program_handle_sptr; +typedef boost::shared_ptr<gc_job_desc> gc_job_desc_sptr; /*! * \brief Return a boost::shared_ptr to an spe_program_handle_t @@ -86,10 +87,19 @@ struct gc_jm_options { gc_jm_options() : max_jobs(0), max_client_threads(0), nspes(0), - gang_schedule(true), use_affinity(false), + gang_schedule(false), use_affinity(false), enable_logging(false), log2_nlog_entries(12) { } + + gc_jm_options(spe_program_handle_sptr program_handle_, + unsigned int nspes_ = 0) : + max_jobs(0), max_client_threads(0), nspes(nspes_), + gang_schedule(false), use_affinity(false), + enable_logging(false), log2_nlog_entries(12), + program_handle(program_handle_) + { + } }; enum gc_wait_mode { @@ -236,6 +246,11 @@ public: */ virtual std::vector<std::string> proc_names() = 0; + virtual void set_debug(int debug); + virtual int debug(); + + /* ----- static methods ----- */ + /*! * \brief Set the singleton gc_job_manager instance. * \param mgr is the job manager instance. @@ -256,9 +271,15 @@ public: */ static gc_job_manager_sptr singleton(); + /*! + * \brief return a boost::shared_ptr to a job descriptor. + */ + static gc_job_desc_sptr make_jd_sptr(gc_job_manager_sptr mgr, gc_job_desc *jd); - virtual void set_debug(int debug); - virtual int debug(); + /*! + * \brief allocate a job descriptor and return a boost::shared_ptr to it. + */ + static gc_job_desc_sptr alloc_job_desc(gc_job_manager_sptr mgr); }; diff --git a/gcell/src/lib/runtime/gc_job_manager_impl.cc b/gcell/src/lib/runtime/gc_job_manager_impl.cc index 59deb4ae53..9c859511b9 100644 --- a/gcell/src/lib/runtime/gc_job_manager_impl.cc +++ b/gcell/src/lib/runtime/gc_job_manager_impl.cc @@ -25,7 +25,7 @@ #include <gc_job_manager_impl.h> #include <gc_mbox.h> #include <gc_proc_def_utils.h> - +#include <gc_aligned_alloc.h> #include <stdio.h> #include <stdexcept> #include <stdlib.h> @@ -85,23 +85,6 @@ client_key_destructor(void *p) ((gc_client_thread_info *) p)->d_free = 1; } -/* - * Return pointer to cache-aligned chunk of storage of size size bytes. - * Throw if can't allocate memory. The storage should be freed - * with "free" when done. The memory is initialized to zero. - */ -static void * -aligned_alloc(size_t size, size_t alignment = CACHE_LINE_SIZE) -{ - void *p = 0; - if (posix_memalign(&p, alignment, size) != 0){ - perror("posix_memalign"); - throw std::runtime_error("memory"); - } - memset(p, 0, size); // zero the memory - return p; -} - static bool is_power_of_2(uint32_t x) { @@ -196,7 +179,7 @@ gc_job_manager_impl::gc_job_manager_impl(const gc_jm_options *options) // ---------------------------------------------------------------- // initalize the job queue - d_queue = (gc_jd_queue_t *) aligned_alloc(sizeof(gc_jd_queue_t)); + d_queue = (gc_jd_queue_t *) gc_aligned_alloc(sizeof(gc_jd_queue_t), CACHE_LINE_SIZE); _d_queue_boost = boost::shared_ptr<void>((void *) d_queue, free_deleter()); gc_jd_queue_init(d_queue); @@ -208,15 +191,15 @@ gc_job_manager_impl::gc_job_manager_impl(const gc_jm_options *options) // 1 spu_arg struct for each SPE assert(sizeof(gc_spu_args_t) % 16 == 0); d_spu_args = - (gc_spu_args_t *) aligned_alloc(MAX_SPES * sizeof(gc_spu_args_t), 16); + (gc_spu_args_t *) gc_aligned_alloc(MAX_SPES * sizeof(gc_spu_args_t), 16); _d_spu_args_boost = boost::shared_ptr<void>((void *) d_spu_args, free_deleter()); // 2 completion info structs for each SPE (we double buffer them) assert(sizeof(gc_comp_info_t) % CACHE_LINE_SIZE == 0); d_comp_info = - (gc_comp_info_t *) aligned_alloc(2 * MAX_SPES * sizeof(gc_comp_info_t), - CACHE_LINE_SIZE); + (gc_comp_info_t *) gc_aligned_alloc(2 * MAX_SPES * sizeof(gc_comp_info_t), + CACHE_LINE_SIZE); _d_comp_info_boost = boost::shared_ptr<void>((void *) d_comp_info, free_deleter()); @@ -269,7 +252,7 @@ gc_job_manager_impl::gc_job_manager_impl(const gc_jm_options *options) // ---------------------------------------------------------------- // initalize the free list of job descriptors - d_free_list = (gc_jd_stack_t *) aligned_alloc(sizeof(gc_jd_stack_t)); + d_free_list = (gc_jd_stack_t *) gc_aligned_alloc(sizeof(gc_jd_stack_t), CACHE_LINE_SIZE); // This ensures that the memory associated with d_free_list is // automatically freed in the destructor or if an exception occurs // here in the constructor. @@ -283,7 +266,7 @@ gc_job_manager_impl::gc_job_manager_impl(const gc_jm_options *options) } // Initialize the array of job descriptors. - d_jd = (gc_job_desc_t *) aligned_alloc(sizeof(d_jd[0]) * d_options.max_jobs); + d_jd = (gc_job_desc_t *) gc_aligned_alloc(sizeof(d_jd[0]) * d_options.max_jobs, CACHE_LINE_SIZE); _d_jd_boost = boost::shared_ptr<void>((void *) d_jd, free_deleter()); @@ -317,7 +300,7 @@ gc_job_manager_impl::gc_job_manager_impl(const gc_jm_options *options) // allocate all bitvectors in a single cache-aligned chunk size_t nlongs = d_bvlen * d_options.max_client_threads; - void *p = aligned_alloc(nlongs * sizeof(unsigned long)); + void *p = gc_aligned_alloc(nlongs * sizeof(unsigned long), CACHE_LINE_SIZE); _d_all_bitvectors = boost::shared_ptr<void>(p, free_deleter()); // Now point the gc_client_thread_info bitvectors into this storage |