[rtems-libbsd commit] Add and use rtems_bsd_get_allocator_domain_size()

Sebastian Huber sebh at rtems.org
Fri Feb 13 09:48:12 UTC 2015


Module:    rtems-libbsd
Branch:    master
Commit:    5383ed40490ba6dd4ac9a41be269db2b0ace1787
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=5383ed40490ba6dd4ac9a41be269db2b0ace1787

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Feb 13 10:31:27 2015 +0100

Add and use rtems_bsd_get_allocator_domain_size()

---

 Makefile                                           |  1 +
 freebsd-to-rtems.py                                |  1 +
 libbsd.txt                                         |  8 +++
 rtemsbsd/include/rtems/bsd/bsd.h                   | 20 ++++++++
 .../rtems/rtems-bsd-get-allocator-domain-size.c    | 58 ++++++++++++++++++++++
 rtemsbsd/rtems/rtems-bsd-page.c                    | 18 ++++---
 6 files changed, 98 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index 6c0625b..523e974 100644
--- a/Makefile
+++ b/Makefile
@@ -72,6 +72,7 @@ LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-delay.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-get-ethernet-addr.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-get-file.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-get-mac-address.c
+LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-get-allocator-domain-size.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-get-task-priority.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-get-task-stack-size.c
 LIB_C_FILES += rtemsbsd/rtems/rtems-bsd-init.c
diff --git a/freebsd-to-rtems.py b/freebsd-to-rtems.py
index 439c4b1..2f4574a 100755
--- a/freebsd-to-rtems.py
+++ b/freebsd-to-rtems.py
@@ -670,6 +670,7 @@ rtems.addRTEMSSourceFiles(
 		'rtems/rtems-bsd-get-ethernet-addr.c',
 		'rtems/rtems-bsd-get-file.c',
 		'rtems/rtems-bsd-get-mac-address.c',
+		'rtems/rtems-bsd-get-allocator-domain-size.c',
 		'rtems/rtems-bsd-get-task-priority.c',
 		'rtems/rtems-bsd-get-task-stack-size.c',
 		'rtems/rtems-bsd-init.c',
diff --git a/libbsd.txt b/libbsd.txt
index 718ac10..f965667 100644
--- a/libbsd.txt
+++ b/libbsd.txt
@@ -240,6 +240,14 @@ The task stack size is determined by the `rtems_bsd_get_task_stack_size()`
 function which may be provided by the application in case the default is not
 appropriate.
 
+=== Size for Allocator Domains ===
+
+The size for an allocator domain can be specified via the
+`rtems_bsd_get_allocator_domain_size()` function.  The application may provide
+their own implementation of the `rtems_bsd_get_allocator_domain_size()`
+function (for example in the module which calls `rtems_bsd_initialize()`) if
+different values are desired.  The default size is 8MiB for all domains.
+
 == Network Stack Features
 
 http://roy.marples.name/projects/dhcpcd/index[DHCPCD(8)]:: DHCP client
diff --git a/rtemsbsd/include/rtems/bsd/bsd.h b/rtemsbsd/include/rtems/bsd/bsd.h
index 38247a8..1014a96 100644
--- a/rtemsbsd/include/rtems/bsd/bsd.h
+++ b/rtemsbsd/include/rtems/bsd/bsd.h
@@ -103,6 +103,26 @@ rtems_task_priority rtems_bsd_get_task_priority(const char *name);
  */
 size_t rtems_bsd_get_task_stack_size(const char *name);
 
+typedef enum {
+	RTEMS_BSD_ALLOCATOR_DOMAIN_PAGE,
+	RTEMS_BSD_ALLOCATOR_DOMAIN_MBUF,
+	RTEMS_BSD_ALLOCATOR_DOMAIN_MALLOC
+} rtems_bsd_allocator_domain;
+
+/**
+ * @brief Returns the size for a specific allocator domain.
+ *
+ * Applications may provide their own implementation of this function.  For
+ * example they can define their implementation in the same module which calls
+ * rtems_bsd_initialize().
+ *
+ * @param[in] domain The allocator domain.
+ *
+ * @return The desired size for the specified allocator domain.
+ */
+uintptr_t rtems_bsd_get_allocator_domain_size(
+    rtems_bsd_allocator_domain domain);
+
 /**
  * @brief Returns the Ethernet MAC address for a specified device.
  *
diff --git a/rtemsbsd/rtems/rtems-bsd-get-allocator-domain-size.c b/rtemsbsd/rtems/rtems-bsd-get-allocator-domain-size.c
new file mode 100644
index 0000000..6471911
--- /dev/null
+++ b/rtemsbsd/rtems/rtems-bsd-get-allocator-domain-size.c
@@ -0,0 +1,58 @@
+/**
+ * @file
+ *
+ * @ingroup rtems_bsd_rtems
+ *
+ * @brief TODO.
+ */
+
+/*
+ * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * 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 <rtems/bsd/bsd.h>
+
+uintptr_t
+rtems_bsd_get_allocator_domain_size(rtems_bsd_allocator_domain domain)
+{
+	uintptr_t size;
+
+	switch (domain) {
+		case RTEMS_BSD_ALLOCATOR_DOMAIN_PAGE:
+		case RTEMS_BSD_ALLOCATOR_DOMAIN_MBUF:
+			size = 8 * 1024 * 1024;
+			break;
+		default:
+			size = 0;
+			break;
+	}
+
+	return (size);
+}
diff --git a/rtemsbsd/rtems/rtems-bsd-page.c b/rtemsbsd/rtems/rtems-bsd-page.c
index 929d466..4721fc6 100644
--- a/rtemsbsd/rtems/rtems-bsd-page.c
+++ b/rtemsbsd/rtems/rtems-bsd-page.c
@@ -50,12 +50,10 @@
 
 #include <stdlib.h>
 
+#include <rtems/bsd/bsd.h>
 #include <rtems/malloc.h>
 #include <rtems/rbheap.h>
 
-/* FIXME: This must be application configurable */
-#define PAGE_HEAP_SIZE (8 * 1024 * 1024)
-
 void **rtems_bsd_page_object_table;
 
 uintptr_t rtems_bsd_page_area_begin;
@@ -116,21 +114,25 @@ rtems_bsd_page_init(void *arg)
 	rtems_rbheap_chunk *chunks;
 	size_t i;
 	size_t n;
+	uintptr_t heap_size;
 
 	mtx_init(&page_heap_mtx, "page heap", NULL, MTX_DEF);
 
-	area = rtems_heap_allocate_aligned_with_boundary(PAGE_HEAP_SIZE,
-	    PAGE_SIZE, 0);
+	heap_size = rtems_bsd_get_allocator_domain_size(
+	    RTEMS_BSD_ALLOCATOR_DOMAIN_PAGE);
+
+	area = rtems_heap_allocate_aligned_with_boundary(heap_size, PAGE_SIZE,
+	    0);
 	BSD_ASSERT(area != NULL);
 
-	sc = rtems_rbheap_initialize(&page_heap, area, PAGE_HEAP_SIZE,
-	    PAGE_SIZE, rtems_rbheap_extend_descriptors_with_malloc, NULL);
+	sc = rtems_rbheap_initialize(&page_heap, area, heap_size, PAGE_SIZE,
+	    rtems_rbheap_extend_descriptors_with_malloc, NULL);
 	BSD_ASSERT(sc == RTEMS_SUCCESSFUL);
 
 	rtems_rbheap_set_extend_descriptors(&page_heap,
 	    rtems_rbheap_extend_descriptors_never);
 
-	n = PAGE_HEAP_SIZE / PAGE_SIZE;
+	n = heap_size / PAGE_SIZE;
 
 	chunks = malloc(n * sizeof(*chunks), M_RTEMS_HEAP, M_NOWAIT);
 	BSD_ASSERT(chunks != NULL);




More information about the vc mailing list