Revision: 55056
          http://brlcad.svn.sourceforge.net/brlcad/?rev=55056&view=rev
Author:   brlcad
Date:     2013-04-05 05:17:28 +0000 (Fri, 05 Apr 2013)
Log Message:
-----------
save a few more instructions and reduce per-real-allocation overhead slightly 
by not tracking per page usage.  just keep track of the last page being filled 
since we know the rest are full.

Modified Paths:
--------------
    brlcad/trunk/src/libbu/heap.c

Modified: brlcad/trunk/src/libbu/heap.c
===================================================================
--- brlcad/trunk/src/libbu/heap.c       2013-04-05 04:20:05 UTC (rev 55055)
+++ brlcad/trunk/src/libbu/heap.c       2013-04-05 05:17:28 UTC (rev 55056)
@@ -67,14 +67,10 @@
     size_t pages;
 
     /**
-     * used is an array of page sizes for tabulating how much memory
-     * each page is currently using (allocate).  not a counter so we
-     * avoid a multiply.
+     * used tabulates how much memory the current page is using
+     * (allocated).  it's not a counter so we can avoid a multiply.
      */
-    size_t *used;
-
-    /** keep track of our allocation counts for reporting stats */
-    size_t alloc;
+    size_t used;
 };
 
 struct cpus {
@@ -89,7 +85,7 @@
  * store data in a cpu-specific structure so we can avoid the need for
  * mutex locking entirely.  relies on static zero-initialization.
  */
-static struct cpus per_cpu[MAX_PSW] = {{{{0, 0, 0, 0}}, 0}};
+static struct cpus per_cpu[MAX_PSW] = {{{{0, 0, 0}}, 0}};
 
 
 static void
@@ -97,11 +93,11 @@
 {
     static int printed = 0;
 
-    size_t h, i, j;
+    size_t h, i;
+    size_t allocs = 0;
     size_t misses = 0;
-    size_t allocations = 0;
+    size_t got = 0;
     size_t total_pages = 0;
-    size_t total_alloc = 0;
     size_t ncpu = bu_avail_cpus();
 
     /* this may get registered for atexit() multiple times, so make
@@ -117,24 +113,27 @@
 
     for (h=0; h < ncpu; h++) {
        for (i=0; i < BINS; i++) {
-           allocations = 0;
-           for (j=0; j < per_cpu[h].bin[i].pages; j++) {
-               allocations += per_cpu[h].bin[i].used[j] / (i+1);
+
+           /* capacity across all pages */
+           got = per_cpu[h].bin[i].pages * (PAGESIZE/(i+1));
+
+           if (got > 0) {
+               /* last page is partial */
+               got -= (PAGESIZE - per_cpu[h].bin[i].used)/(i+1);
+               bu_log("%04zu [%02zu] => %zu\n", i, per_cpu[h].bin[i].pages, 
got);
+               allocs += got;
            }
-           if (allocations > 0)
-               bu_log("%04zd [%02zd] => %zd\n", i, per_cpu[h].bin[i].pages, 
allocations);
            total_pages += per_cpu[h].bin[i].pages;
-           total_alloc += allocations;
        }
        misses += per_cpu[h].misses;
     }
     bu_log("-----------------------\n"
-          "size [pages] => allocs\n"
+          "size [pages] => count\n"
           "Heap range: 1-%d bytes\n"
           "Page size: %d bytes\n"
-          "Pages: %zd (%.2lfMB)\n"
-          "%zd hits, %zd misses\n"
-          "=======================\n", BINS, PAGESIZE, total_pages, 
(double)(total_pages * PAGESIZE) / (1024.0*1024.0), total_alloc, misses);
+          "Pages: %zu (%.2lfMB)\n"
+          "%zu allocs, %zu misses\n"
+          "=======================\n", BINS, PAGESIZE, total_pages, 
(double)(total_pages * PAGESIZE) / (1024.0*1024.0), allocs, misses);
 }
 
 
@@ -164,7 +163,6 @@
     }
 
     bin = &per_cpu[oncpu].bin[smo];
-    bin->alloc++;
 
     /* init */
     if (bin->pages == 0) {
@@ -177,22 +175,20 @@
        bin->pages++;
        bin->heaps = (char **)bu_malloc(1 * sizeof(char *), "heap malloc 
heaps[]");
        bin->heaps[0] = (char *)bu_calloc(1, PAGESIZE, "heap calloc 
heaps[][0]");
-       bin->used = (size_t *)bu_malloc(1 * sizeof(size_t), "heap malloc 
used[]");
-       bin->used[0] = 0;
+       bin->used = 0;
     }
 
     /* grow */
-    if (bin->used[bin->pages-1]+sz > PAGESIZE) {
+    if (bin->used+sz > PAGESIZE) {
        bin->pages++;
        bin->heaps = (char **)bu_realloc(bin->heaps, bin->pages * sizeof(char 
*), "heap realloc heaps[]");
        bin->heaps[bin->pages-1] = (char *)bu_calloc(1, PAGESIZE, "heap calloc 
heaps[][]");
-       bin->used = (size_t *)bu_realloc(bin->used, bin->pages * 
sizeof(size_t), "heap realloc used[]");
-       bin->used[bin->pages-1] = 0;
+       bin->used = 0;
     }
 
     /* give */
-    ret = &(bin->heaps[bin->pages-1][bin->used[bin->pages-1]]);
-    bin->used[bin->pages-1] += sz;
+    ret = &(bin->heaps[bin->pages-1][bin->used]);
+    bin->used += sz;
 
     return (void *)ret;
 }

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Minimize network downtime and maximize team effectiveness.
Reduce network management and security costs.Learn how to hire 
the most talented Cisco Certified professionals. Visit the 
Employer Resources Portal
http://www.cisco.com/web/learning/employer_resources/index.html
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to