diff --git a/include/nuttx/mm/gran.h b/include/nuttx/mm/gran.h index c5928a069b1..1bbccb29738 100644 --- a/include/nuttx/mm/gran.h +++ b/include/nuttx/mm/gran.h @@ -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 diff --git a/include/nuttx/pgalloc.h b/include/nuttx/pgalloc.h index c4b6ecab0a2..30d57c5d341 100644 --- a/include/nuttx/pgalloc.h +++ b/include/nuttx/pgalloc.h @@ -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 * * 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 } diff --git a/mm/mm_gran/Make.defs b/mm/mm_gran/Make.defs index e80db7fd001..a146ef5e255 100644 --- a/mm/mm_gran/Make.defs +++ b/mm/mm_gran/Make.defs @@ -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 diff --git a/mm/mm_gran/mm_granalloc.c b/mm/mm_gran/mm_granalloc.c index 7ded221a07d..c02c1b2c373 100644 --- a/mm/mm_gran/mm_granalloc.c +++ b/mm/mm_gran/mm_granalloc.c @@ -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. */ diff --git a/mm/mm_gran/mm_pgalloc.c b/mm/mm_gran/mm_pgalloc.c index 0019896bee0..69e52d03d3a 100644 --- a/mm/mm_gran/mm_pgalloc.c +++ b/mm/mm_gran/mm_pgalloc.c @@ -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 */