mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-15 03:17:56 +08:00
Add and use rtems_bsd_get_allocator_domain_size()
This commit is contained in:
1
Makefile
1
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
|
||||
|
@@ -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',
|
||||
|
@@ -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
|
||||
|
@@ -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.
|
||||
*
|
||||
|
58
rtemsbsd/rtems/rtems-bsd-get-allocator-domain-size.c
Normal file
58
rtemsbsd/rtems/rtems-bsd-get-allocator-domain-size.c
Normal file
@@ -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@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);
|
||||
}
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user