Attached test program shows some additional effects of PMC size and
   timing. [...]

Nifty.

The attached patch adds a scheme where:
 - gc flags are in the pool, and
 - pmc->pool mapping is done with aligned pools and pmc pointer masking.

Observations:
 - It's fast.  (The _test_ is anyway.)  Perhaps 4x random, 10x+ linear.
 - PMC size doesn't matter here, because we never actually touch them.

Mitchell
(I assume at some point Dan will say "ok, we've demonstrated the
 minimally required gc performace... so now let's get back to actually
 writing the thing...".  That will quiet my currently fluttering
 premature optimization warning flags. ;)

--- tpmc.c      Mon Jan  6 14:55:14 2003
+++ r02.c       Mon Jan  6 17:24:32 2003
@@ -52,6 +52,11 @@
     int fill[3];
 } SPMC;
 
+struct pool_pmc {
+    char *flags;
+    PMC mem[1];
+} * pool_pmc[N];
+
 
 int main(int argc, char *argv[])
 {
@@ -152,6 +157,76 @@
     rdtsc(&b);
     printf("%d empty       ticks %10ld\n", i, b - a - e);
 
+    /* alternate aligned pool with sep flags */
+
+#define SIZE2 (SIZE-1)
+#define ALIGN      (SIZE*(8*sizeof(int)))
+    for (i = 0; i < N; i++) {
+        pool_pmc[i] = memalign(ALIGN, SIZE*sizeof(PMC));
+        pool_pmc[i]->flags = calloc(SIZE, sizeof(char));
+        /*printf("pool %d %p\n", i, pool_pmc[i]);*/
+    }
+
+    for  (n = 0; n < 3; n++) {
+        rdtsc(&a);
+        for (j = 0; j < N; j++) {
+            l = (int) ((double)N * rand()/(RAND_MAX+1.0));
+            for (i = 0; i < SIZE2; i++) {
+                k = (int) ((double)SIZE2 * rand()/(RAND_MAX+1.0));
+                pool_pmc[j]->flags[i] |= 1;
+            }
+        }
+        rdtsc(&b);
+        printf("%d linear  PMC sep-flags flag-only ticks %10ld\n", i, b - a - e);
+
+        rdtsc(&a);
+        for (j = 0; j < N; j++) {
+            l = (int) ((double)N * rand()/(RAND_MAX+1.0));
+            for (i = 0; i < SIZE2; i++) {
+                k = (int) ((double)SIZE2 * rand()/(RAND_MAX+1.0));
+                pool_pmc[j]->flags[k] |= 1;
+            }
+        }
+        rdtsc(&b);
+        printf("%d random  PMC sep-flags flag-only ticks %10ld\n", i, b - a - e);
+
+#define P2I(ptr) ((unsigned long)(ptr))
+#define CALC(ik) \
+                { \
+                    PMC *ppmc = (PMC*)&(pool_pmc[j]->mem[(ik)]); \
+                    struct pool_pmc *pool = ((struct pool_pmc *) \
+                                             (P2I(ppmc) & ~(ALIGN-1))); \
+                    size_t n   = ((P2I(ppmc) - P2I(&(pool->mem[0]))) \
+                                  /sizeof(PMC)); \
+                    /*printf(">> pool %d %p pmc# %d %p ->pool %p pmc# %d\n", \
+                      j,pool_pmc[j],i,ppmc,pool,n);*/ \
+                    pool->flags[n] |= 1; \
+                }
+
+
+        rdtsc(&a);
+        for (j = 0; j < N; j++) {
+            l = (int) ((double)N * rand()/(RAND_MAX+1.0));
+            for (i = 0; i < SIZE2; i++) {
+                k = (int) ((double)SIZE2 * rand()/(RAND_MAX+1.0));
+                CALC(i);
+            }
+        }
+        rdtsc(&b);
+        printf("%d linear  PMC sep-flags PMC->flag ticks %10ld\n", i, b - a - e);
+
+        rdtsc(&a);
+        for (j = 0; j < N; j++) {
+            l = (int) ((double)N * rand()/(RAND_MAX+1.0));
+            for (i = 0; i < SIZE2; i++) {
+                k = (int) ((double)SIZE2 * rand()/(RAND_MAX+1.0));
+                CALC(k);
+            }
+        }
+        rdtsc(&b);
+        printf("%d random  PMC sep-flags PMC->flag ticks %10ld\n", i, b - a - e);
+
+    }
     return 0;
 }
 

Reply via email to