mm/mm_gran: Add a function to get information about the state of the granuale allocator.

This commit is contained in:
Gregory Nutt 2017-11-14 14:41:03 -06:00
parent 62b8026976
commit 54fad8d04f
5 changed files with 62 additions and 5 deletions

View File

@ -71,7 +71,7 @@
typedef FAR void *GRAN_HANDLE;
/* For in which the state of the granule allocator is returned */
/* Form in which the state of the granule allocator is returned */
struct graninfo_s
{
@ -233,7 +233,7 @@ void gran_free(GRAN_HANDLE handle, FAR void *memory, size_t size);
* Name: gran_info
*
* Description:
* Return memory to the granule heap.
* Return information about the granule heap.
*
* Input Parameters:
* handle - The handle previously returned by gran_initialize

View File

@ -2,7 +2,7 @@
* include/nuttx/pgalloc.h
* Page memory allocator.
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -95,6 +95,17 @@
* Public Types
****************************************************************************/
/* Form in which the state of the granule allocator is returned, The size of
* each page is MM_PGSIZE/MM_PGSHIFT
*/
struct pginfo_s
{
uint16_t ntotal; /* The total number of pages */
uint16_t nfree; /* The number of free pages */
uint16_t mxfree; /* The longest sequence of free pages */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@ -186,6 +197,24 @@ uintptr_t mm_pgalloc(unsigned int npages);
void mm_pgfree(uintptr_t paddr, unsigned int npages);
/****************************************************************************
* Name: mm_pginfo
*
* Description:
* Return information about the page allocator.
*
* Input Parameters:
* handle - The handle previously returned by gran_initialize
* info - Memory location to return the gran allocator info.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is return on
* any failure.
*
****************************************************************************/
void mm_pginfo(FAR struct pginfo_s *info);
#undef EXTERN
#ifdef __cplusplus
}

View File

@ -37,7 +37,7 @@
ifeq ($(CONFIG_GRAN),y)
CSRCS += mm_graninit.c mm_granrelease.c mm_granreserve.c mm_granalloc.c
CSRCS += mm_granmark.c mm_granfree.c mm_grancritical.c
CSRCS += mm_granmark.c mm_granfree.c mm_graninfo.c mm_grancritical.c
# A page allocator based on the granule allocator

View File

@ -237,7 +237,7 @@ FAR void *gran_alloc(GRAN_HANDLE handle, size_t size)
}
/* Set up for the next time through the loop. Perform a 64
* bit shift to move to the next gran position andi ncrement
* bit shift to move to the next gran position and increment
* to the next candidate allocation address.
*/

View File

@ -194,4 +194,32 @@ void mm_pgfree(uintptr_t paddr, unsigned int npages)
gran_free(g_pgalloc, (FAR void *)paddr, (size_t)npages << MM_PGSHIFT);
}
/****************************************************************************
* Name: mm_pginfo
*
* Description:
* Return information about the page allocator.
*
* Input Parameters:
* handle - The handle previously returned by gran_initialize
* info - Memory location to return the gran allocator info.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is return on
* any failure.
*
****************************************************************************/
void mm_pginfo(FAR struct pginfo_s *info)
{
struct graninfo_s graninfo;
DEBUGASSERT(info != NULL);
gran_info(g_pgalloc, &graninfo);
info->ntotal = graninfo.ngranules;
info->nfree = graninfo.nfree;
info->mxfree = graninfo.mxfree;
}
#endif /* CONFIG_MM_PGALLOC */