commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8228 - gnuradio/branches/developers/eb/gcell/gcell/sr


From: eb
Subject: [Commit-gnuradio] r8228 - gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime
Date: Sat, 19 Apr 2008 20:59:55 -0600 (MDT)

Author: eb
Date: 2008-04-19 20:59:54 -0600 (Sat, 19 Apr 2008)
New Revision: 8228

Added:
   
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_aligned_alloc.cc
   
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_aligned_alloc.h
Modified:
   gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/Makefile.am
   
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager_impl.cc
Log:
Extracted gc_aligned_alloc from gc_job_manager_impl


Modified: 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/Makefile.am
===================================================================
--- gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/Makefile.am     
2008-04-20 02:34:05 UTC (rev 8227)
+++ gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/Makefile.am     
2008-04-20 02:59:54 UTC (rev 8228)
@@ -32,6 +32,7 @@
 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 @@
 
 
 gcellinclude_HEADERS = \
+       gc_aligned_alloc.h \
        gc_job_manager.h
 
 noinst_HEADERS = \

Added: 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_aligned_alloc.cc
===================================================================
--- 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_aligned_alloc.cc 
                            (rev 0)
+++ 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_aligned_alloc.cc 
    2008-04-20 02:59:54 UTC (rev 8228)
@@ -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());
+}


Property changes on: 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_aligned_alloc.cc
___________________________________________________________________
Name: svn:eol-style
   + native

Added: 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_aligned_alloc.h
===================================================================
--- 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_aligned_alloc.h  
                            (rev 0)
+++ 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_aligned_alloc.h  
    2008-04-20 02:59:54 UTC (rev 8228)
@@ -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 */


Property changes on: 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_aligned_alloc.h
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager_impl.cc
===================================================================
--- 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager_impl.cc
  2008-04-20 02:34:05 UTC (rev 8227)
+++ 
gnuradio/branches/developers/eb/gcell/gcell/src/lib/runtime/gc_job_manager_impl.cc
  2008-04-20 02:59:54 UTC (rev 8228)
@@ -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 @@
   ((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 @@
   // ----------------------------------------------------------------
   // 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 @@
   // 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 @@
   // ----------------------------------------------------------------
   // 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 @@
   }
 
   // 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 @@
 
   // 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]