summaryrefslogtreecommitdiff
path: root/libddekit
diff options
context:
space:
mode:
Diffstat (limited to 'libddekit')
-rw-r--r--libddekit/Makefile2
-rw-r--r--libddekit/init.c2
-rw-r--r--libddekit/memory.c277
3 files changed, 16 insertions, 265 deletions
diff --git a/libddekit/Makefile b/libddekit/Makefile
index e9daa648..59e5c5a9 100644
--- a/libddekit/Makefile
+++ b/libddekit/Makefile
@@ -21,7 +21,7 @@ makemode := library
libname = libddekit
SRCS= condvar.c init.c initcall.c interrupt.c lock.c malloc.c memory.c \
panic.c pci.c pgtab-old.c pgtab.c printf.c resources.c list.c \
- thread.c timer.c
+ thread.c timer.c kmem.c
LCLHDRS = include/ddekit/condvar.h include/ddekit/lock.h \
include/ddekit/initcall.h include/ddekit/debug.h \
include/ddekit/inline.h include/ddekit/panic.h \
diff --git a/libddekit/init.c b/libddekit/init.c
index 2104d80f..9708ba1d 100644
--- a/libddekit/init.c
+++ b/libddekit/init.c
@@ -7,6 +7,8 @@
void ddekit_init(void)
{
+ extern void linux_kmem_init ();
ddekit_init_threads();
+ linux_kmem_init ();
}
diff --git a/libddekit/memory.c b/libddekit/memory.c
index b6db0cac..93853e55 100644
--- a/libddekit/memory.c
+++ b/libddekit/memory.c
@@ -10,16 +10,9 @@
* FIXME check thread-safety and add locks where appropriate
*/
-#include <l4/dde/ddekit/memory.h>
-#include <l4/dde/ddekit/panic.h>
-#include <l4/dde/ddekit/pgtab.h>
-#include <l4/dde/ddekit/printf.h>
+#include "ddekit/memory.h"
-#include <l4/lock/lock.h>
-#include <l4/slab/slab.h>
-#include <l4/dm_mem/dm_mem.h>
-#include <l4/util/atomic.h>
-#include <l4/util/util.h>
+extern void * linux_kmalloc (unsigned int size, int priority);
/****************
@@ -56,21 +49,6 @@ struct ddekit_pcache
};
-/* head of single-linked list containing used page-cache entries, non-contiguous */
-static struct ddekit_pcache *pcache_used;
-/* head of single-linked list containing free page-cache entries, non-contiguous */
-static struct ddekit_pcache *pcache_free;
-
-/* head of single-linked list containing used page-cache entries, contiguous */
-static struct ddekit_pcache *pcache_used_contig;
-/* head of single-linked list containing free page-cache entries, contiguous */
-static struct ddekit_pcache *pcache_free_contig;
-
-/* maximum number of pages to cache. defaults to a minimum of 1 page
- * because having none hits the performance too hard. */
-static l4_uint32_t pcache_num_entries = 1;
-
-
/**
* Setup page cache for all slabs
*
@@ -82,88 +60,8 @@ static l4_uint32_t pcache_num_entries = 1;
*/
void ddekit_slab_setup_page_cache(unsigned pages)
{
- /* FIXME just allowing to grow at the moment */
- while (pcache_num_entries < pages) {
- struct ddekit_pcache *new_entry, *new_contig;
-
- /* create new list element */
- new_entry = (struct ddekit_pcache *) ddekit_simple_malloc(sizeof(*new_entry));
- new_contig = (struct ddekit_pcache *) ddekit_simple_malloc(sizeof(*new_contig));
-
- /* insert into lists of unused cache entries */
- do {
- new_entry->next = pcache_free;
- } while (!l4util_cmpxchg32((l4_uint32_t*)&pcache_free,
- (l4_uint32_t)new_entry->next,
- (l4_uint32_t)new_entry));
-
- do {
- new_contig->next = pcache_free_contig;
- } while (!l4util_cmpxchg32((l4_uint32_t*)&pcache_free_contig,
- (l4_uint32_t)new_entry->next,
- (l4_uint32_t)new_entry));
-
- /* increment number of list elements */
- l4util_inc32(&pcache_num_entries);
- }
}
-
-/**
- * Try to allocate a new page from the pcache.
- */
-static inline struct ddekit_pcache *_try_from_cache(int contig)
-{
- struct ddekit_pcache *head = NULL;
- struct ddekit_pcache *the_cache = contig ? pcache_used_contig : pcache_used;
-
- do {
- head = the_cache;
- if (!head) break;
- } while (!l4util_cmpxchg32((l4_uint32_t*)&the_cache, (l4_uint32_t)head,
- (l4_uint32_t)head->next));
-
- return head;
-}
-
-
-static inline void _add_to_cache(struct ddekit_pcache *entry, int contig)
-{
- struct ddekit_pcache *the_cache = contig ? pcache_used_contig : pcache_used;
- do {
- entry->next = the_cache;
- } while (! l4util_cmpxchg32((l4_uint32_t*)&the_cache, (l4_uint32_t)entry->next,
- (l4_uint32_t)entry));
-}
-
-/**
- * Return free entry to cached entry list.
- */
-static inline void _free_cache_entry(struct ddekit_pcache *entry, int contig)
-{
- struct ddekit_pcache *the_cache = contig ? pcache_free_contig : pcache_free;
- do {
- entry->next = the_cache;
- } while (!l4util_cmpxchg32((l4_uint32_t*)&the_cache, (l4_uint32_t)entry->next,
- (l4_uint32_t)entry));
-}
-
-
-static inline struct ddekit_pcache *_get_free_cache_entry(int contig)
-{
- struct ddekit_pcache *the_cache = contig ? pcache_free_contig : pcache_free;
- struct ddekit_pcache *head = NULL;
-
- do {
- head = the_cache;
- if (!head) break;
- } while (!l4util_cmpxchg32((l4_uint32_t*)&the_cache, (l4_uint32_t)head,
- (l4_uint32_t) head->next));
-
- return head;
-}
-
-
/*******************************
** Slab cache implementation **
*******************************/
@@ -171,132 +69,16 @@ static inline struct ddekit_pcache *_get_free_cache_entry(int contig)
/* ddekit slab facilitates l4slabs */
struct ddekit_slab
{
- l4slab_cache_t cache;
- /*
- * Lock to prevent concurrent access to the slab's grow() and
- * shrink() functions.
- */
- l4lock_t lock;
+ int size;
int contiguous;
};
-
-/**
- * Get the ddekit slab for a given L4 slab.
- *
- * We cheat here, because we know that the L4 slab is the first member
- * of the ddekit slab.
- */
-static inline struct ddekit_slab *ddekit_slab_from_l4slab(l4slab_cache_t *s)
-{
- return (struct ddekit_slab *)s;
-}
-
-/**
- * Grow slab cache
- */
-static void *_slab_grow(l4slab_cache_t *cache, void **data)
-{
- /* the page(s) to be returned */
- void *res = NULL;
- /* whether this cache needs physically contiguous pages */
- int is_contig = ddekit_slab_from_l4slab(cache)->contiguous;
-
- /* free cache entry, will be used afterwards */
- struct ddekit_pcache *head = NULL;
-
- /* We don't reuse pages for slabs > 1 page, because this makes caching
- * somewhat harder. */
- if (cache->slab_size <= L4_PAGESIZE)
- /* try to aquire cached page */
- head = _try_from_cache(is_contig);
-
- if (head) {
- /* use cached page */
- res = head->page;
- /* this cache entry is now available */
- _free_cache_entry(head, is_contig);
- } else {
- /* allocate new page at memory server */
- int err;
- l4_size_t tmp;
- l4dm_mem_addr_t dm_paddr;
- int num_pages = cache->slab_size / L4_PAGESIZE;
- int flags = L4DM_PINNED | L4RM_MAP | L4RM_LOG2_ALIGNED;
-
- if (is_contig)
- flags |= L4DM_CONTIGUOUS;
-
- /* allocate and map new page(s) */
- res = l4dm_mem_allocate_named(num_pages * L4_PAGESIZE,
- flags,
- "ddekit slab");
- if (res == NULL)
- ddekit_debug("__grow: error allocating a new page");
-
- /* physically contiguous pages need some special treatment */
- if (is_contig) {
- err = l4dm_mem_phys_addr(res, num_pages, &dm_paddr, 1, &tmp);
- if (err != 1)
- ddekit_debug("__grow: error getting physical address of new page!");
-
- ddekit_pgtab_set_region(res, dm_paddr.addr, num_pages, PTE_TYPE_UMA);
- }
- }
-
- /* save pointer to cache in page for ddekit_slab_get_slab() */
- *data = cache;
-
- return res;
-}
-
-/**
- * Shrink slab cache
- */
-static void _slab_shrink(l4slab_cache_t *cache, void *page, void *data)
-{
- /* cache deallocated page here */
- struct ddekit_pcache *head = NULL;
- /* whether this cache needs physically contiguous pages */
- int is_contig = ddekit_slab_from_l4slab(cache)->contiguous;
-
- /* we do not return slabs to the page cache, if they are larger than one page */
- if (cache->slab_size <= L4_PAGESIZE)
- /* try to aquire free cache entry */
- head = _get_free_cache_entry(is_contig);
-
- if (head) {
- /* use free cache entry to cache page */
-
- /* set the page info */
- head->page = page;
-
- /* this cache entry contains a free page */
- _add_to_cache(head, is_contig);
- } else {
- /* cache is full */
-
- if (is_contig)
- /* unset pte */
- ddekit_pgtab_clear_region(page, PTE_TYPE_UMA);
-
- /* free page */
- l4dm_mem_release(page);
- }
-}
-
-
/**
* Allocate object in slab
*/
void *ddekit_slab_alloc(struct ddekit_slab * slab)
{
- void *ret = NULL;
- l4lock_lock(&slab->lock);
- ret = l4slab_alloc(&slab->cache);
- l4lock_unlock(&slab->lock);
-
- return ret;
+ return linux_kmalloc (slab->size, 0);
}
@@ -305,9 +87,7 @@ void *ddekit_slab_alloc(struct ddekit_slab * slab)
*/
void ddekit_slab_free(struct ddekit_slab * slab, void *objp)
{
- l4lock_lock(&slab->lock);
- l4slab_free(&slab->cache, objp);
- l4lock_unlock(&slab->lock);
+ linux_kfree (objp);
}
@@ -316,7 +96,9 @@ void ddekit_slab_free(struct ddekit_slab * slab, void *objp)
*/
void ddekit_slab_set_data(struct ddekit_slab * slab, void *data)
{
+#if 0
l4slab_set_data(&slab->cache, data);
+#endif
}
@@ -325,7 +107,9 @@ void ddekit_slab_set_data(struct ddekit_slab * slab, void *data)
*/
void *ddekit_slab_get_data(struct ddekit_slab * slab)
{
+#if 0
return l4slab_get_data(&slab->cache);
+#endif
}
@@ -336,7 +120,6 @@ void *ddekit_slab_get_data(struct ddekit_slab * slab)
*/
void ddekit_slab_destroy (struct ddekit_slab * slab)
{
- l4slab_destroy(&slab->cache);
ddekit_simple_free(slab);
}
@@ -352,19 +135,10 @@ void ddekit_slab_destroy (struct ddekit_slab * slab)
struct ddekit_slab * ddekit_slab_init(unsigned size, int contiguous)
{
struct ddekit_slab * slab;
- int err;
slab = (struct ddekit_slab *) ddekit_simple_malloc(sizeof(*slab));
- slab->lock = L4LOCK_UNLOCKED;
- err = l4slab_cache_init(&slab->cache, size, 0, _slab_grow, _slab_shrink);
- if (err) {
- ddekit_debug("error initializing cache");
- ddekit_simple_free(slab);
- return 0;
- }
-
+ slab->size = size;
slab->contiguous = contiguous;
-
return slab;
}
@@ -380,11 +154,7 @@ struct ddekit_slab * ddekit_slab_init(unsigned size, int contiguous)
*/
void ddekit_large_free(void *objp)
{
- /* clear PTEs */
- ddekit_pgtab_clear_region(objp, PTE_TYPE_LARGE);
-
- /* release */
- l4dm_mem_release(objp);
+ return linux_kfree (objp);
}
@@ -395,29 +165,8 @@ void ddekit_large_free(void *objp)
*/
void *ddekit_large_malloc(int size)
{
- void *res;
- int err;
- l4_size_t tmp;
- int pages;
- l4dm_mem_addr_t dm_paddr;
-
- size = l4_round_page(size);
- pages = size >> L4_PAGESHIFT;
-
- res = l4dm_mem_allocate_named(size,
- L4DM_CONTIGUOUS | L4DM_PINNED |
- L4RM_MAP | L4RM_LOG2_ALIGNED,
- "ddekit mem");
- if (! res)
- return NULL;
-
- err = l4dm_mem_phys_addr(res, 1, &dm_paddr, 1, &tmp);
- if (err != 1)
- ddekit_debug("ddekit_large_malloc: error getting physical address of new memory!\n");
-
- ddekit_pgtab_set_region(res, dm_paddr.addr, pages, PTE_TYPE_LARGE);
-
- return res;
+ // TODO I hope linux_kmalloc can provide large enough pages.
+ return linux_kmalloc (size, 0);
}