mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
mm/mm_gran: Add a function to get information about the state of the granuale allocator.
This commit is contained in:
@@ -71,7 +71,7 @@
|
|||||||
|
|
||||||
typedef FAR void *GRAN_HANDLE;
|
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
|
struct graninfo_s
|
||||||
{
|
{
|
||||||
@@ -233,7 +233,7 @@ void gran_free(GRAN_HANDLE handle, FAR void *memory, size_t size);
|
|||||||
* Name: gran_info
|
* Name: gran_info
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Return memory to the granule heap.
|
* Return information about the granule heap.
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* handle - The handle previously returned by gran_initialize
|
* handle - The handle previously returned by gran_initialize
|
||||||
|
|||||||
+30
-1
@@ -2,7 +2,7 @@
|
|||||||
* include/nuttx/pgalloc.h
|
* include/nuttx/pgalloc.h
|
||||||
* Page memory allocator.
|
* 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>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -95,6 +95,17 @@
|
|||||||
* Public Types
|
* 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
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -186,6 +197,24 @@ uintptr_t mm_pgalloc(unsigned int npages);
|
|||||||
|
|
||||||
void mm_pgfree(uintptr_t paddr, 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
|
#undef EXTERN
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
ifeq ($(CONFIG_GRAN),y)
|
ifeq ($(CONFIG_GRAN),y)
|
||||||
CSRCS += mm_graninit.c mm_granrelease.c mm_granreserve.c mm_granalloc.c
|
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
|
# A page allocator based on the granule allocator
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
/* 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.
|
* to the next candidate allocation address.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
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 */
|
#endif /* CONFIG_MM_PGALLOC */
|
||||||
|
|||||||
Reference in New Issue
Block a user