summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJennifer Averett <jennifer.averett@oarcorp.com>2012-07-20 14:17:05 -0500
committerJennifer Averett <jennifer.averett@oarcorp.com>2012-07-20 14:17:05 -0500
commit2c3d8b981b96508b38a0eee8e750916b1559df3a (patch)
tree100ab9948a6a6e5c3a363777f7bd4146f3feb8cb
parentAdded more initialization of FIXME_ucred elements. (diff)
downloadrtems-libbsd-2c3d8b981b96508b38a0eee8e750916b1559df3a.tar.bz2
Added rtems specific page tracking methods for uma page allocation.
-rw-r--r--Makefile1
-rwxr-xr-xfreebsd-to-rtems.py1
-rw-r--r--freebsd/vm/uma_core.c25
-rw-r--r--rtemsbsd/src/rtems-bsd-page.c116
4 files changed, 137 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 442e85a0..e29df9a8 100644
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,7 @@ C_FILES += rtemsbsd/src/rtems-bsd-log.c
C_FILES += rtemsbsd/src/rtems-bsd-sx.c
C_FILES += rtemsbsd/src/rtems-bsd-rwlock.c
C_FILES += rtemsbsd/src/rtems-bsd-generic.c
+C_FILES += rtemsbsd/src/rtems-bsd-page.c
C_FILES += rtemsbsd/src/rtems-bsd-panic.c
C_FILES += rtemsbsd/src/rtems-bsd-synch.c
C_FILES += rtemsbsd/src/rtems-bsd-signal.c
diff --git a/freebsd-to-rtems.py b/freebsd-to-rtems.py
index 41f4e349..7ff90424 100755
--- a/freebsd-to-rtems.py
+++ b/freebsd-to-rtems.py
@@ -642,6 +642,7 @@ rtems.addRTEMSSourceFiles(
'src/rtems-bsd-sx.c',
'src/rtems-bsd-rwlock.c',
'src/rtems-bsd-generic.c',
+ 'src/rtems-bsd-page.c',
'src/rtems-bsd-panic.c',
'src/rtems-bsd-synch.c',
'src/rtems-bsd-signal.c',
diff --git a/freebsd/vm/uma_core.c b/freebsd/vm/uma_core.c
index 47c811a1..a53fceb9 100644
--- a/freebsd/vm/uma_core.c
+++ b/freebsd/vm/uma_core.c
@@ -85,6 +85,10 @@ __FBSDID("$FreeBSD$");
#include <freebsd/vm/vm_map.h>
#include <freebsd/vm/vm_kern.h>
#include <freebsd/vm/vm_extern.h>
+#else
+void *rtems_page_alloc(int bytes);
+void *rtems_page_find( void *address );
+void rtems_page_free( void *address );
#endif /* __rtems__ */
#include <freebsd/vm/uma.h>
#include <freebsd/vm/uma_int.h>
@@ -1006,19 +1010,24 @@ startup_alloc(uma_zone_t zone, int bytes, u_int8_t *pflag, int wait)
* A pointer to the alloced memory or possibly
* NULL if M_NOWAIT is set.
*/
+#ifdef __rtems__
+#define PAGE_MASK (PAGE_SIZE-1)
+
+#define round_page(x) ((((unsigned long )(x)) + PAGE_MASK) & ~(PAGE_MASK))
+#endif
static void *
page_alloc(uma_zone_t zone, int bytes, u_int8_t *pflag, int wait)
{
- void *p; /* Returned page */
+ void *p; /* Returned page */
- *pflag = UMA_SLAB_KMEM;
+ *pflag = UMA_SLAB_KMEM;
#ifndef __rtems__
- p = (void *) kmem_malloc(kmem_map, bytes, wait);
+ p = (void *) kmem_malloc(kmem_map, bytes, wait);
#else /* __rtems__ */
- p = (void *) malloc(bytes, M_TEMP, wait);
+ p = rtems_page_alloc(bytes);
#endif /* __rtems__ */
- return (p);
+ return (p);
}
#ifndef __rtems__
@@ -1111,7 +1120,7 @@ page_free(void *mem, int size, u_int8_t flags)
kmem_free(map, (vm_offset_t)mem, size);
#else /* __rtems__ */
- free( mem, M_TEMP );
+ rtems_page_free( mem );
#endif /* __rtems__ */
}
@@ -2772,7 +2781,11 @@ zone_free_item(uma_zone_t zone, void *item, void *udata,
zone->uz_frees++;
if (!(zone->uz_flags & UMA_ZONE_VTOSLAB)) {
+#ifndef __rtems__
mem = (u_int8_t *)((unsigned long)item & (~UMA_SLAB_MASK));
+#else /* __rtems__ */
+ mem = rtems_page_find(item);
+#endif /* __rtems__ */
keg = zone_first_keg(zone); /* Must only be one. */
if (zone->uz_flags & UMA_ZONE_HASH) {
slab = hash_sfind(&keg->uk_hash, mem);
diff --git a/rtemsbsd/src/rtems-bsd-page.c b/rtemsbsd/src/rtems-bsd-page.c
new file mode 100644
index 00000000..2a807178
--- /dev/null
+++ b/rtemsbsd/src/rtems-bsd-page.c
@@ -0,0 +1,116 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bsd_rtems
+ *
+ * @brief FreeBSD uma source used pages which where there was an
+ * assumption of page alignment. Doing this alignment would waste
+ * more memory than we were willing to do. Therefore, a set of
+ * rtems-bsd-page routines track the allocation of pages and the
+ * small sections of source in the uma source were modified to use
+ * these methods on an rtems system.
+ */
+
+/*
+ * COPYRIGHT (c) 2012. On-Line Applications Research Corporation (OAR).
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <freebsd/machine/rtems-bsd-config.h>
+
+#include <freebsd/sys/types.h>
+#include <freebsd/sys/systm.h>
+#include <freebsd/sys/malloc.h>
+#include <rtems/chain.h>
+
+
+#define RTEMS_PAGE_COUNT 100
+
+typedef struct {
+ rtems_chain_node node;
+ void *page;
+ void *end;
+
+} rtems_page_t;
+
+// chain of pages that have been allocated
+static rtems_chain_control rtems_page_list = RTEMS_CHAIN_INITIALIZER_EMPTY( rtems_page_list );
+
+void *
+rtems_page_alloc(int bytes)
+{
+ static void *p;
+ static rtems_page_t *page;
+
+ bytes = round_page(bytes);
+ p = (void *) malloc(bytes, M_TEMP, M_NOWAIT | M_ZERO);
+
+ page = (rtems_page_t *) malloc(sizeof(rtems_page_t), M_TEMP, M_NOWAIT | M_ZERO);
+ page->page = p;
+ page->end = p + bytes;
+
+ rtems_chain_append( &rtems_page_list, page );
+
+ return p;
+}
+
+rtems_page_t *rtems_page_t_find( void *address )
+{
+ rtems_chain_node *the_node;
+ rtems_page_t *the_page = NULL;
+
+ for (the_node = rtems_chain_first( &rtems_page_list );
+ !rtems_chain_is_tail(&rtems_page_list, the_node);
+ the_node = rtems_chain_next(the_node)) {
+ the_page = the_node;
+
+ if ((address >= the_page->page) &&
+ (address <= the_page->end))
+ return the_page;
+ }
+ return NULL;
+}
+
+void *rtems_page_find( void *address )
+{
+ rtems_page_t *ptr;
+
+ ptr = rtems_page_t_find( address );
+
+ if (ptr)
+ return ptr->page;
+
+ return ptr;
+}
+
+void rtems_page_free( void *address )
+{
+ rtems_page_t *ptr;
+
+ ptr = rtems_page_t_find( address );
+ KASSERT(ptr != NULL, ("Unable to locate page for freed element"));
+
+ free( ptr->page, M_TEMP );
+ free( ptr, M_TEMP );
+}