mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-16 01:02:07 +08:00
Added rtems specific page tracking methods for uma page allocation.
This commit is contained in:
1
Makefile
1
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-sx.c
|
||||||
C_FILES += rtemsbsd/src/rtems-bsd-rwlock.c
|
C_FILES += rtemsbsd/src/rtems-bsd-rwlock.c
|
||||||
C_FILES += rtemsbsd/src/rtems-bsd-generic.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-panic.c
|
||||||
C_FILES += rtemsbsd/src/rtems-bsd-synch.c
|
C_FILES += rtemsbsd/src/rtems-bsd-synch.c
|
||||||
C_FILES += rtemsbsd/src/rtems-bsd-signal.c
|
C_FILES += rtemsbsd/src/rtems-bsd-signal.c
|
||||||
|
@@ -642,6 +642,7 @@ rtems.addRTEMSSourceFiles(
|
|||||||
'src/rtems-bsd-sx.c',
|
'src/rtems-bsd-sx.c',
|
||||||
'src/rtems-bsd-rwlock.c',
|
'src/rtems-bsd-rwlock.c',
|
||||||
'src/rtems-bsd-generic.c',
|
'src/rtems-bsd-generic.c',
|
||||||
|
'src/rtems-bsd-page.c',
|
||||||
'src/rtems-bsd-panic.c',
|
'src/rtems-bsd-panic.c',
|
||||||
'src/rtems-bsd-synch.c',
|
'src/rtems-bsd-synch.c',
|
||||||
'src/rtems-bsd-signal.c',
|
'src/rtems-bsd-signal.c',
|
||||||
|
@@ -85,6 +85,10 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <freebsd/vm/vm_map.h>
|
#include <freebsd/vm/vm_map.h>
|
||||||
#include <freebsd/vm/vm_kern.h>
|
#include <freebsd/vm/vm_kern.h>
|
||||||
#include <freebsd/vm/vm_extern.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__ */
|
#endif /* __rtems__ */
|
||||||
#include <freebsd/vm/uma.h>
|
#include <freebsd/vm/uma.h>
|
||||||
#include <freebsd/vm/uma_int.h>
|
#include <freebsd/vm/uma_int.h>
|
||||||
@@ -1006,6 +1010,11 @@ startup_alloc(uma_zone_t zone, int bytes, u_int8_t *pflag, int wait)
|
|||||||
* A pointer to the alloced memory or possibly
|
* A pointer to the alloced memory or possibly
|
||||||
* NULL if M_NOWAIT is set.
|
* 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 *
|
static void *
|
||||||
page_alloc(uma_zone_t zone, int bytes, u_int8_t *pflag, int wait)
|
page_alloc(uma_zone_t zone, int bytes, u_int8_t *pflag, int wait)
|
||||||
{
|
{
|
||||||
@@ -1015,7 +1024,7 @@ page_alloc(uma_zone_t zone, int bytes, u_int8_t *pflag, int wait)
|
|||||||
#ifndef __rtems__
|
#ifndef __rtems__
|
||||||
p = (void *) kmem_malloc(kmem_map, bytes, wait);
|
p = (void *) kmem_malloc(kmem_map, bytes, wait);
|
||||||
#else /* __rtems__ */
|
#else /* __rtems__ */
|
||||||
p = (void *) malloc(bytes, M_TEMP, wait);
|
p = rtems_page_alloc(bytes);
|
||||||
#endif /* __rtems__ */
|
#endif /* __rtems__ */
|
||||||
|
|
||||||
return (p);
|
return (p);
|
||||||
@@ -1111,7 +1120,7 @@ page_free(void *mem, int size, u_int8_t flags)
|
|||||||
|
|
||||||
kmem_free(map, (vm_offset_t)mem, size);
|
kmem_free(map, (vm_offset_t)mem, size);
|
||||||
#else /* __rtems__ */
|
#else /* __rtems__ */
|
||||||
free( mem, M_TEMP );
|
rtems_page_free( mem );
|
||||||
#endif /* __rtems__ */
|
#endif /* __rtems__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2772,7 +2781,11 @@ zone_free_item(uma_zone_t zone, void *item, void *udata,
|
|||||||
zone->uz_frees++;
|
zone->uz_frees++;
|
||||||
|
|
||||||
if (!(zone->uz_flags & UMA_ZONE_VTOSLAB)) {
|
if (!(zone->uz_flags & UMA_ZONE_VTOSLAB)) {
|
||||||
|
#ifndef __rtems__
|
||||||
mem = (u_int8_t *)((unsigned long)item & (~UMA_SLAB_MASK));
|
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. */
|
keg = zone_first_keg(zone); /* Must only be one. */
|
||||||
if (zone->uz_flags & UMA_ZONE_HASH) {
|
if (zone->uz_flags & UMA_ZONE_HASH) {
|
||||||
slab = hash_sfind(&keg->uk_hash, mem);
|
slab = hash_sfind(&keg->uk_hash, mem);
|
||||||
|
116
rtemsbsd/src/rtems-bsd-page.c
Normal file
116
rtemsbsd/src/rtems-bsd-page.c
Normal file
@@ -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 );
|
||||||
|
}
|
Reference in New Issue
Block a user