From 5383ed40490ba6dd4ac9a41be269db2b0ace1787 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 13 Feb 2015 10:31:27 +0100 Subject: 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(-) create mode 100644 rtemsbsd/rtems/rtems-bsd-get-allocator-domain-size.c diff --git a/Makefile b/Makefile index 6c0625b9..523e974b 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 439c4b17..2f4574a7 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 718ac10e..f965667f 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 38247a83..1014a96e 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 00000000..6471911a --- /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 + * + * + * 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 + +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 929d466d..4721fc6e 100644 --- a/rtemsbsd/rtems/rtems-bsd-page.c +++ b/rtemsbsd/rtems/rtems-bsd-page.c @@ -50,12 +50,10 @@ #include +#include #include #include -/* 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); -- cgit v1.2.3