]> xenbits.xensource.com Git - people/liuw/rumprun.git/commitdiff
Cache thread stack sized allocations.
authorAntti Kantee <pooka@iki.fi>
Sat, 18 Apr 2015 16:42:16 +0000 (16:42 +0000)
committerAntti Kantee <pooka@iki.fi>
Sat, 18 Apr 2015 16:42:16 +0000 (16:42 +0000)
platform/baremetal/kernel.c

index 1944300cf10a479882c5d52e05087a49b0096147..1ddc582af8365c6159cc5915501145b150ff5858 100644 (file)
 #include <bmk-core/memalloc.h>
 #include <bmk-core/platform.h>
 #include <bmk-core/printf.h>
+#include <bmk-core/queue.h>
 
 #include <bmk-base/netbsd_initfini.h>
 
 unsigned long bmk_membase;
 unsigned long bmk_memsize;
 
+LIST_HEAD(, stackcache) cacheofstacks = LIST_HEAD_INITIALIZER(cacheofstacks);
+struct stackcache {
+       void *sc_stack;
+       LIST_ENTRY(stackcache) sc_entries;
+};
+
 /*
- * we don't need freepg
- * (for the humour impaired: it was a joke, on the TODO ... but really,
+ * We don't need freepg.
+ *
+ * For the humour impaired: it was a joke, on the TODO ... but really,
  * it's not that urgent since the rump kernel uses its own caching
  * allocators, so once the backing pages are allocated, they tend to
- * never get freed)
+ * never get freed.  The only thing that in practical terms gets
+ * deallocated is thread stacks, and for now we simply cache those
+ * as a special case. (nb. even that holds only for native thread stacks,
+ * not pthread stacks).
  */
 void *
 bmk_allocpg(size_t howmany)
 {
+       struct stackcache *sc;
        static size_t current = 0;
        unsigned long rv;
 
+       if (howmany == 1<<BMK_THREAD_STACK_PAGE_ORDER &&
+           (sc = LIST_FIRST(&cacheofstacks)) != NULL) {
+               LIST_REMOVE(sc, sc_entries);
+               return sc;
+       }
+
        rv = bmk_membase + PAGE_SIZE*current;
        current += howmany;
        if (current*PAGE_SIZE > bmk_memsize)
@@ -72,6 +90,13 @@ void
 bmk_platform_freepg2(void *mem, int shift)
 {
 
+       if (shift == BMK_THREAD_STACK_PAGE_ORDER) {
+               struct stackcache *sc = mem;
+
+               LIST_INSERT_HEAD(&cacheofstacks, sc, sc_entries);
+               return;
+       }
+
        bmk_printf("WARNING: freepg2 called! (%p, %d)\n", mem, shift);
 }